Build a Java Swing Application with Oracle ADF

You can work in JDeveloper's IDE to develop and test run a Java application that is built with Oracle ADF Swing and Oracle ADF Business Components technologies.

Install the Schema: Download the schema zip file from OTN and install it. The cue cards use tables that are part of the Fusion Order Demo (FOD) schema.

Create a New Application: Use the Create Application wizard to create an application that uses the Java Desktop Application (ADF) template.

Create a Database Connection: Use the Create Database Connection dialog to create a connection to the schema.

Create Oracle ADF Business Components Objects: Use the Create Business Components from Tables wizard to create the business components that will provide access to data and implement the business logic.

Create an ADF Swing Form with Navigation: Use the Create ADF Swing Empty Form wizard to create a frame that contains code for enabling Oracle ADF data binding in the application. The frame is the databound Business Components client form that you will later run.

Create a Master Edit Form: Drag and drop a master collection from the Data Controls panel onto the client form, and then use the Create ADF Swing Edit Form wizard to create a master edit form panel for Orders records.

Create a Detail Table with Navigation: Use the Create ADF Swing Empty Panel wizard to create an empty panel. Then use the Data Controls panel to drag and drop a detail collection onto the panel to create a detail panel for viewing and browsing OrderItems records in a table format.

Add the Detail Panel to the Client Form: Complete the client form by dragging and dropping the detail panel onto the form.

Run the Application: Compile and run the application to see how the master-detail client form displays.

Customize the Form with Control Hints: Modify the view object's attributes using the Edit Attribute dialog, Control Hints section, to add meaningful labels for each attribute displayed on the master edit form.

Run the Application Again: Run the application to see how the client form displays after adding customized control hints.

 

Install the Schema

tell me more icon Installing the Schema

The steps and examples in the cue cards are based on tables that are part of the Fusion Order Demo (FOD) schema. This schema is also used as the database for the sample application that ships with Oracle JDeveloper 11g, as well as other collateral in this release. It will be convenient to have this schema installed, and you only need to do it once. If you have already installed the FOD schema, you can skip this step and go directly to the next card.   [ tell me more...]





  1. go to dialog or window icon Download the schema zip file from OTN. If you created the schema previously, go to the cue cards icon next cue card.
  2. Unzip the file to a convenient location (for example, c:\temp).
  3. From the File menu, choose Open . Open the workspace c:\temp\Infrastructure\Infrastructure.jws.
  4. If you are prompted to migrate the project, click Yes to confirm, then click OK.
  5. In the Application Navigator, expand the MasterBuildScript project. Under Resources double-click build.properties to open it in the editor.
  6. Set the appropriate values in the build.properties file ( jdeveloper.home, and all the jdbc.* and db.* settings). Keep all other properties set to their default values. The demo user must be named FOD.
    The relevant settings are:
    jdeveloper.home             The /jdeveloper directory where you have JDeveloper installed, for example, c:/JDeveloper_11/jdeveloper/
    jdbc.urlBase                    Base URL for your database, for example, jdbc:oracle:thin:@localhost
    jdbc.port                         Port number for your database, for example, 1521
    jdbc.sid                           Database System Identifier, for example, XE or ORCL
    db.adminUser                  Database user with admin privileges, for example, system
    db.demoUser.tablespace  Tablespace name where the FOD user will be installed, for example, USERS
  7. In the MasterBuildScript project, select the build.xml file.
  8. In the Structure window, right-click the refreshSchema target and choose Run Target "refreshSchema" .
  9. When prompted, enter the password for the database user with admin privileges.

    tell me more icon In the IDE

    After running the Ant task, you should see a build successful message in the JDeveloper Log window.   [ tell me more...]



 

Create a New Application and Project

tell me more icon Creating a New Application

The JDeveloper application is the highest level in the organizational structure. It stores information about the objects you are working with, while you are creating your application. It keeps track of your projects and the environment settings.   [ tell me more...]





  1. Open the Create Application wizard [ File > New > General > Applications] .
  2. To follow along with the example, enter the application name OrdersApplication.
  3. Select Java Desktop Application (ADF) in the Applica tion Template list, and click Finish .

    tell me more icon Application Templates

    Application templates provide you with a quick way to create the project structure for standard applications with the appropriate combination of technologies already specified. The new application created from the template appears in the Application Navigator already partitioned into tiered projects, with the associated technology scopes set in each project.   [ tell me more...]




    tell me more icon In the IDE

    When you complete the steps for creating a new application and project, the Projects panel in the Application Navigator should look like this:  [ tell me more...]



 

Create a Database Connection

tell me more icon Creating a Database Connection

You can connect to any database for which you have connection details, or install the sample schema used in the cue card examples and then establish a connection to it. If you installed the sample schema, you will be able to follow the steps in the cue cards exactly as written. If you work with your own database, you can supply your own values as needed.   [ tell me more...]





  1. Open the Create Database Connection dialog [ File > New > General > Connections > Database Connection] .
  2. Select Application Resources if it is not already selected as the Create Connection In option.
  3. Enter a name for the connection, select the connection type, and enter the username and password. To follow along with this example, use FOD for the connection name and  fod for the username.
  4. Click Test Connection to confirm that you can connect.
  5. Click OK if the connection was successful.
  6. In the Application Navigator, expand the Connections and Database nodes in the Application Resources panel to see the database objects.

    tell me more icon In the IDE

    When you complete the steps for creating a database connection, the Application Navigator should look similar to this when you expand the Application Resources panel. The database connection is now included as a resource for your application under the Connections | Database nodes.   [ tell me more...]



 

Create Oracle ADF Business Components

tell me more icon Creating Oracle ADF Business Component Objects

Oracle ADF Business Components is a model layer technology in the Oracle Application Development Framework (Oracle ADF). Oracle ADF Business Components is a fully-featured, XML-based framework for creating business services. That is, it governs interaction between the rest of the application and the data stored in the data source, providing validation, specific services, and other business logic.  [ tell me more...]





  1. In the Application Navigator, select the Model project and launch the Create Business Components from Tables wizard [ File > New > Business Tier > ADF Business Components > Business Components from Tables] .
  2. In the Initialize Business Components Project dialog, ensure that FOD is the currently selected database connection. Then click OK.

    tell me more icon Business Components Connection

    The Oracle ADF Business Components project requires a database connection that you will use to create business components from database objects. The database connection you specify will also be used by the Oracle ADF Business Components runtime to manage session facade failover and state management.  [ tell me more...]



  3. On step 1, Entity Objects, click Query to populate the A vailable list. If your schema has many tables, you may experience a short delay.
  4. Select the tables, ORDERS and ORDER_ITEMS, from the A vailable list and then click single shuttle icon to move them to the Selec ted list. (The tables are related by a foreign key so the resulting business components represent a one-to-many relationship.) Click Next .

    tell me more icon Oracle ADF Business Components from Database Tables

    The Create Business Components from Tables wizard allows you to easily create a package of business domain components (entity objects, associations, and domains) from existing database objects and optionally to create a default package of data model components (view objects, view links, and an application module) from these newly generated business domain components.  [ tell me more...]



  5. On step 2, Updatable View Objects, click shuttle all icon to move both business components, OrderItems (FOD.ORDER_ITEMS) and Orders (FOD.ORDERS), from the A vailable list to the Selec ted list. Then click Next .
  6. Click Next to skip step 3, Read-Only View Objects, which aren't needed.
  7. On step 4, Application Module, accept the default application module name and click Finish .
  8. Click the save all icon Save All to save your work.

    tell me more icon In the IDE

    After completing the Create Business Components from Tables wizard, the Model project in the Application Navigator should look similar to this:  [ tell me more...]



 

Create a Master Form in ADF Swing Form

tell me more icon Creating a Master Form in ADF Swing Form

In an Oracle ADF Business Components data model, a master-detail relationship is a foreign-key association between two or more view objects. When you create master-detail forms and tables using those view objects, end users will be able to drill down from a master collection to view (and optionally edit) the related data objects in the detail collection.   [ tell me more...]





  1. In the Application Navigator, select the View project and open the Create ADF Swing Empty Form dialog [ File > New > Client Tier > ADF Swing > Empty Form] .
  2. Accept Form as the form name, and view as the package name. Confirm that Generate a Menu Bar is selected. Then click OK.

    tell me more icon Creating an ADF Swing Empty Form

    Oracle ADF Swing is a rich client technology in the Oracle Application Development Framework (Oracle ADF). Oracle ADF Swing is fully compatible with Java Swing and adds a thin layer to the client application so that standard Java components can work with the Oracle ADF data binding libraries. To enable ADF data binding in your Java client application, use the Create ADF Swing Empty Form dialog to generate a form that contains ADF-specific code.  [ tell me more...]



  3. In the Application Navigator, expand the Data Controls panel and the data control icon AppModuleDataControl node. Drag and drop the collection Data Objects icon OrdersView1 in the center of the empty form in the visual editor. Choose Add Edit Form from the context menu.

    tell me more icon Data Controls Panel and UI Controls

    The task of designing databound forms that coordinate with a back-end business service is accomplished declaratively with the Data Controls panel. The Data Controls panel affords the UI designer a hierarchical view of those business services that the application developer has registered with an instance of an Oracle ADF data control.   [ tell me more...]



  4. In the Create ADF Swing Edit Form dialog, hold down the Ctrl key and multi-select all the attributes except the following: OrderId, OrderDate, OrderStatusCode, OrderTotal. Click delete icon to delete the selected attributes. Then select OrderId, and click previous up arrow icon to move the attribute to the top of the list. Accept the default file name. Deselect Create Navigator Bar , then click OK.

    tell me more icon Creating an ADF Swing Edit Form

    The Create ADF Swing Edit Form dialog simplifies creating a databound form by generating the code for the objects of the data collection you select.   [ tell me more...]



  5. In the visual editor, click in the client form outside the top left corner of the edit form you just added.
  6. In the Structure window, make sure container icon dataPanel (which is below navBar) is selected. In the Property Inspector, Visual section, select BorderLayout from the layout dropdown list.

    tell me more icon BorderLayout and Constraints

    A Java UI container uses a special object called a layout manager to control how components in the container are located and sized each time the container is displayed. A layout manager automatically arranges the components in the container according to a particular set of rules specific to that layout manager. Layout managers allow you to specify rules and constraints for the layout of your UI in a way that will be portable across platforms.  [ tell me more...]



  7. In the Structure window, select container icon panelOrdersView1Helper1 (which is under the expanded dataPanel). Click the Constraints tab (next to the Property Inspector tab) to bring the Constraints property visual editor forward. In the Constraints property visual editor, select the topmost box.
  8. Click the save all icon Save All to save the files.
  9. In the Application Navigator, double-click javanode icon PanelOrdersView1Helper.java to open the source file for the edit form panel. In the editor window, click Design to use the Java visual editor.
  10. In the Structure window, select container icon dataPanel (FormLayout). In the Java visual editor, right-click the first cell in the first column and choose Column Properties. In the Column Properties dialog, do the following, then click OK.
    Under Alignment, select F ill .
    Under Size, select Component Size from the dropdown list, then click Default .
    Under Resize, select None .

    tell me more icon FormLayout and Column Properties

    The edit form panel you added previously is created by JDeveloper using FormLayout in the data panel, as shown in the Structure window:  [ tell me more...]



  11. In the editor window, click the javanode icon Form.java tab at the top to bring the client form forward. Click build icon Rebuild to rebuild the View project.

    tell me more icon In the IDE

    When you complete the steps for creating a master form in ADF Swing Form, the form in the Java visual editor should look similar to this:  [ tell me more...]



 

Create a Detail Table in ADF Swing Panel

tell me more icon Creating a Detail Table in ADF Swing Panel

In a master form, detail table, the role of the detail table is to display the individual data objects of the detail collection related to the current object in the master collection. The detail portion of the client form requires its own panel and layout manager, and can include a navigation bar for browsing objects in the detail collection.   [ tell me more...]





  1. In the Application Navigator, select the View project and open the Create ADF Swing Empty Panel dialog [ File > New > Client Tier > ADF Swing > Empty Form] .
  2. Enter OrderItemsPanel as the panel name, and accept view as the package name. Confirm that P anel , and both optional attributes are selected, then click OK.

    tell me more icon Creating an ADF Swing Empty Panel

    The Create ADF Swing Empty Panel/InternalFrame dialog lets you create either an empty panel or internal frame. Select P anel to create an empty panel. In the dialog, the name you enter becomes the Java class that defines the panel for containing databound UI components.  [ tell me more...]



  3. If necessary, click the Property Inspector tab to bring it in front of the Constraints property editor. In the Property Inspector, Visual section, select BorderLayout from the layout dropdown list.
  4. In the Application Navigator, expand the Data Controls panel and the data control icon AppModuleDataControl node. Then expand the same master collection of objects that you used previously, Data Objects icon OrdersView1.

    tell me more icon Collection Hierarchy in the Data Controls Panel

    The Data Controls panel affords the UI designer a hierarchical view of those business services that the application developer has registered with an instance of an Oracle ADF data control. The data control captures the master-detail relationships exposed by business service collections, and the Data Controls panel displays those relationships as parent and child nodes in the hierarchy. To create the detail portion of a master-detail page, always select a collection that constitutes a child node of the master collection node. If these parent-child nodes are not shown, then the business service that was registered with the ADF data control does not contain this relationship.  [ tell me more...]



  5. Drag and drop the detail collection Data Objects icon OrderItemsView2 in the top left corner of the empty panel in the visual editor. Choose Add Child then choose NavigationBar from the context menu.

    tell me more icon Designing the Detail Panel

    Because the detail portion of your client form will display a set of data objects in the detail collection, your panel needs to contain a collection-level UI control. The table control is ideally suited for this purpose. Each row of the table corresponds to a single data object, such as an order items record, where the attributes of each object correspond to the table columns.   [ tell me more...]



  6. In the Component Palette, Swing page, Containers panel, drag JScrollPane icon JScrollPane and drop it in the center of the remaining empty panel space in the visual editor.
  7. In the Data Controls panel, drag the same detail collection of objects, Data Objects icon OrderItemsView2, and drop it into the empty JScrollPane you just added.
  8. From the context menu, choose Add Child then choose Table to display the data objects of the detail collection in table format.
  9. Click the save all icon Save All to save the files.

    tell me more icon In the IDE

    When you complete the steps for creating a detail table in ADF Swing Panel, the panel in the Java visual editor should look similar to this:   [ tell me more...]



 

Complete and Run the Application

tell me more icon Completing and Running the Application

In an ADF Swing application, forms rely on the ADF panel binding object to coordinate between the exposed collections. While it is possible to create a multiform application to display the master-detail forms and tables in separate windows, relying on a single window to display the data objects of both the master and the detail collections ensures that the client form shares a single panel binding instance. The process of creating a multiform application in ADF Swing, by contrast, requires additional code to manage the panel binding instance between both windows.   [ tell me more...]





  1. In the editor window, click the java node icon Form.java document tab to bring the client form forward.
  2. In the Application Navigator, View project, drag java node icon OrderItemsPanel.java to the visual editor and drop it in the middle of the space below the master edit form.
  3. In the Select Option dialog, make sure Embed Panel is selected, then click OK.
  4. In the Application Navigator, select java node icon Form.java.
  5. In the Structure window for Form.java, Design tab, make sure orderItemsPanel1 is selected. Click the Constraints tab to bring it in front of the Property Inspector. In the Constraints visual property editor, confirm that the center box is selected.

    tell me more icon Constraints Property

    The BorderLayout layout manager arranges a container's components in one of five areas within a BorderLayout, based on the constraints property of the component: North, South, East, West, and Center.   [ tell me more...]



  6. Click build icon Rebuild to rebuild the View project.
  7. In the Application Navigator, right-click java node icon Form.java and choose R un .
  8. In the running application window, choose File then choose Exit to stop the application.

    tell me more icon In the IDE

    When you complete the steps, the client form in the Java visual editor should look similar to this:  [ tell me more...]



 

Customize Form Labels with ADF Control Hints

tell me more icon Customizing Form Labels with ADF Control Hints

Oracle ADF control hints provide a centralized mechanism for any JavaBeans-based business service (including Oracle ADF Business Components) data item to be rendered in a consistent manner across all client types. This mechanism, known as control hints, permits application developers to centralize certain UI settings across clients and thereby to control many aspects of the way the UI interacts with the data item. Because they are set at the level of the business service, using control hints can also reduce the amount of UI coding in the Swing client.   [ tell me more...]





  1. In the Application Navigator, Model project, under Application Sources | model, double-click the view object view icon OrdersView that defines the attributes for which you want to set control hints.
  2. In the overview editor for view objects, select Attributes.
  3. In the Attributes section, double-click OrderId.
  4. In the Edit Attribute dialog, select Control Hints. Enter Order Number in the Label Text field. Click OK.

    tell me more icon Control Hints

    Instead of displaying the value from the attribute's heading, such as OrderId, you can replace these with more meaningful labels for the user, such as Order Number.   [ tell me more...]



  5. Repeat the procedure to customize the control hint labels of the other attributes you have added to the master edit form, namely OrderDate, OrderStatusCode, and OrderTotal, using the label text Date of Order, Status, and Total Price, respectively.
  6. In the Application Navigator, View project, right-click java node icon Form.java and choose R un .

    tell me more icon In the IDE

    When you complete the steps for customizing labels with control hints, the Model project in the Application Navigator should look similar to this:  [ tell me more...]



 



Copyright © 1997, 2009, Oracle. All rights reserved.

false ,,,,,,,,,,,,,,,