Build Rich Client Forms with ADF Swing and ADF Business Components Purpose In this tutorial, you use Oracle JDeveloper (10.1.3.1.0) to quickly build ADF Swing forms. ADF Business Components is used to build the data model. You can use ADF Swing to build rich client applications if your application requires immediate response to user input or for events that change the user display. This is also true for complex user interfaces that have multiple master-detail dependencies displayed on one screen. Applications that need to perform immediate item validation, which could be based on complex logic, also find better support in Swing than on the web. Another reason for using Swing clients is when, for business reasons, applications require to work offline, disconnected from the network. Time to Complete 30 minutes Topics This tutorial covers the following topics: Viewing Screenshots Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.) Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it. Overview In this tutorial, you are going to build a Swing application with ADF Swing that leverages ADF Business Components as a business service. Though not in the focus of this exercise, ADF Swing applications can also be built on top of business services like EJB, Web Services, TopLink, POJOs etc. The steps to develop an application with ADF Swing are similar. First in this OBE, you create an ADF Business Component model as a persistence layer that contains the business logic and the validation rules. Using ADF Swing, you build a master-detail Swing application that displays customer information along with their placed orders. ADF Swing applications that use ADF Business Components can be deployed in a 2-tier and 3-tier architecture. For this tutorial, you will run and test the application locally using the JDeveloper embedded Java Runtime Environment (JRE). ADF Swing is a binding layer that connects standard Swing components to the Oracle Application Development Framework (ADF) binding layer. Through ADF, applications use a consistent client API to access the various business services mentioned above. ADF Swing provides a productivity advantage to all application developers that need to build scalable client-server applications for their enterprises. Back to Topic List Overview Prerequisites Creating a Database Connection Building the Business Model with ADF Business Components Creating a Master Detail ADF Swing Form Creating an Edit ADF Swing Form Summary Page 1 of 64 Build Rich Client Forms with ADF Swing and ADF Business Components 08/06/2010 http://www.oracle.com/technology/obe/obe1013jdev/10131/adf%20swing/master_detail_...
64
Embed
Build Rich Client Forms with ADF Swing and ADF … · ADF Swing is a binding layer that connects standard Swing co mponents to the Oracle ... Build Rich Client Forms with ADF Swing
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Build Rich Client Forms with ADF Swing and ADF Business Components
Purpose
In this tutorial, you use Oracle JDeveloper (10.1.3.1.0) to quickly build ADF Swing forms. ADF Business Components is used to build the data model.
You can use ADF Swing to build rich client applications if your application requires immediate response to user input or for events that change the user display. This is also true for complex user interfaces that have multiple master-detail dependencies displayed on one screen. Applications that need to perform immediate item validation, which could be based on complex logic, also find better support in Swing than on the web. Another reason for using Swing clients is when, for business reasons, applications require to work offline, disconnected from the network.
Time to Complete
30 minutes
Topics
This tutorial covers the following topics:
Viewing Screenshots
Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)
Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.
Overview
In this tutorial, you are going to build a Swing application with ADF Swing that leverages ADF Business Components as a business service. Though not in the focus of this exercise, ADF Swing applications can also be built on top of business services like EJB, Web Services, TopLink, POJOs etc. The steps to develop an application with ADF Swing are similar.
First in this OBE, you create an ADF Business Component model as a persistence layer that contains the business logic and the validation rules. Using ADF Swing, you build a master-detail Swing application that displays customer information along with their placed orders. ADF Swing applications that use ADF Business Components can be deployed in a 2-tier and 3-tier architecture. For this tutorial, you will run and test the application locally using the JDeveloper embedded Java Runtime Environment (JRE).
ADF Swing is a binding layer that connects standard Swing components to the Oracle Application Development Framework (ADF) binding layer. Through ADF, applications use a consistent client API to access the various business services mentioned above. ADF Swing provides a productivity advantage to all application developers that need to build scalable client-server applications for their enterprises.
Back to Topic List
OverviewPrerequisitesCreating a Database Connection Building the Business Model with ADF Business ComponentsCreating a Master Detail ADF Swing Form Creating an Edit ADF Swing Form Summary
Page 1 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Java Database Connectivity (JDBC) is a standard application programming interface (API) that is used for connecting a Java application to relational databases. JDeveloper uses a connection navigator to maintain connection information for your application. The connection navigator makes it easy to create, manage, and test database connections.
If you haven't already created a JDBC connection to the HR schema, then perform the following steps:
1. Click the Connections tab on the Applications Navigator. If the Connections tab is not showing, choose View > Connection Navigator from the JDeveloper main menu.
Page 3 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Building the Business Model with ADF Business Components
The business model provides data access and validation for an application. When the data is managed by the business model, the data is always validated by the model, regardless of the client implementation. This cleanly separates the validation and business rules from the user interface.
The ADF Business Components model provides data access, validation services, and business logic. Storing business logic in the model layer enables you to reuse the same logic with different application client. As a recommended practice, business logic should be kept separate from the display logic, which you would implement in the ADF Swing client.
In the next few steps, you create an ADF Business Components model for the application.
Back to Topic List
Create a New Application and Projects
In JDeveloper, you always work with projects contained in an application.
The application is the highest level in the control structure. It is a view of all the objects you need while you are working. An application keeps track of your projects while you are developing your Java programs.
8. You have just created a connection to the database that will supply data for the application you build in this tutorial.
The next steps use this connection to manage the details of connecting to the database so that you can concentrate on business logic instead of JDBC calls.
Create a New Application and ProjectsCreate Business Components
Page 8 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
A JDeveloper project is an organization structure used to logically group related files. You can add multiple projects to your application to easily organize, access, modify, and reuse your source code. In the Applications Navigator, projects are displayed as the second level in the hierarchy under the application.
Note that it is considered best practices to use projects to separate the model code from the code written for the view. In this hands-on we will create one project for the ADF Business Components model, and a second one later for the ADF Swing client.
Before you create any application components, you must first create the application and project. To do this, perform the following steps:
1. Click the Applications tab to go back to the Applications Navigator.
Right-click the Applications node and select New Application from the context menu.
2. In the Create Application dialog box, enter the Application Name ADFSwing. Notice that as you enter the application
name, the directory name changes automatically.
Enter oracle as the Application Package Prefix.
Select the Java Application [Swing, ADF BC] value from the Application Template drop-down list.
Click the Manage Templates... button.
Page 9 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
In this section, you create ADF Business Components based on tables in the database. You use the hrconn database connection, which you created earlier. You create these objects in the Model project.
6.
Click Save All on the toolbar to save your work. Alternatively, you can select File | Save All from the menu.
The Applications Navigator should look like the image below.
You are now ready to create application components for the tutorial. In the next few steps, you create a model for your application.
1. In the Applications Navigator, right-click the Model project and select New from the context menu.
Page 13 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
8. JDeveloper provides several different techniques for managing components. One is to use a diagram of the components and their relationships. In this step, you can choose to have JDeveloper create a diagram of the components that you are creating.
For our example, we skip this step. Click Next to continue.
9. The final page of the Business Components Wizard shows the objects and relationships that are created when you
click Finish.
Click Finish to complete the wizard.
Page 20 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
In the next few steps, you create a Master-Detail ADF Swing Form:
Back to Topic List
Creating the Master Part
Creating the Master PartCreating the Detail PartAdding a Combo box to a Detail attribute
1. When you created the application for this tutorial, you created it with two projects: DataModel and UserInterface. The DataModel project contains the ADF Business Components that serve as the business model for your application. The UserInterface project will include the View portion of your application, which defines the User Interface components.
In the Applications Navigator, collapse the DataModel node, the Applications Navigator should appear as follows:
2. Create a new ADF Swing form by right-clicking UserInterface in the Applications Navigator and selecting New from
the context menu.
3. Expand the Client Tier node and select Empty Form from the ADF Swing Category to create a JFrame.
Page 22 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Note: Empty Form is used to create an empty Java client frame. The frame that the wizard generates will contain ADF Swing-specific application bootstrapping code. This code initializes the ADF Swing application and binds it to the ADF binding layer that accesses the ADF Business Components. As a Swing developer, you don't need to change this code.
4. Selecting a new Empty Form opens the Create ADF Swing Empty Form Wizard. Click Next to skip the Welcome
page of the Wizard (if it appears).
Page 23 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
7. Select the default generated navigation bar and delete it.
Note: The default navigation bar is generic and operates on any table or form that is added to a Java panel. For this application, you create two navigation bars that are specifically created for distinct datacontrols on the panel.
8. Click within the top part of the frame to select the Swing frame and open the Property Inspector to set Title of frame
to Swing Demo.
Page 25 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Select the Scrollbar and drag the right most blue marker to size the scrollbar to span columns 1 to 3.
11. Adding a selection of databound columns to the form.
In the Data Controls Palette, expand the DepartmentsVO1 node, select DepartmentId and drag and drop it in the cell on the second column first row (below the Scrollbar).
Page 28 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Note: You can set an ADF attribute binding on basic UI components that you insert from the Data Control Palette. Use a TextField to display plain text in a single line.
12. Repeat the previous step for DepartmentName and LocationId. Your form should look like this:
Page 29 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
13. Adding the corresponding default label to each field.
Open the Component Palette in JDeveloper (Ctrl+Shift+P) and select the ADF Swing Controls library. Drag and drop a JULabel component in the first column in front of the DepartmentId text field.
14. Repeat the previous step to add a JULabel in front of the two other text fields.
Page 30 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Note: The JULabel control can be bound to the metadata defined either on the Business Component Entity Object or View Object (display attribute) or the ADF metadata (used with EJB, POJO or Web Services controls to define display attributes).
16. In the Attribute Binding Editor, expand the HRAppModuleDataControl node, select the DepartmentsVO1 and select the DepartmentId attribute.
Click OK.
17. Repeat steps 15 and 16 (Create Binding > Label For) to map JULabel2 to DepartmentName and JULabel3 to
LocationId.
Page 32 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Use the blue markers to span it across rows 6-7 and columns 1-3.
Note: A JScrollPane provides a scrollable view of a component. When screen real estate is limited, use a scroll pane to display a component that is large or one whose size can change dynamically.
2. With the JscrollPane selected, press the toolbar icon for Grow Row
Page 37 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Now that you have built the Master-Detail Swing form, you create a listbox for the DepartmentId of the detail form so that Department Name is now displayed in place of the DepartmentId. The listbox lets the user choose one of several choices.
To create a list for the DepartmentId, perform the following steps:
1. In the Applications Navigator select the MDFormPageDef.xml node and in the Structure pane, double click the DepartmentsVo1EmployeesVO3 to open the binding editor.
2. Select the Attributes Properties tab and set the editor property for the DepartmentId to Combo Box. Then press the
[...] Edit button to create the binding for the Combo Box.
Page 45 of 64Build Rich Client Forms with ADF Swing and ADF Business Components
Now that you have built your new Master Detail Swing form, you're going to create an Edit form to display additional information related to the selected Detail record.
The next few steps take you through the testing process.
5. Click the DepartmentId column on one of the details to pop up the Department list of values.
Page 50 of 64Build Rich Client Forms with ADF Swing and ADF Business Components