Sunday, March 21, 2010

FAQ #18 - How to get started with the JDeveloper Extension SDK, Part 3


With this part, we will conclude the series of getting started with the JDeveloper Extension SDK. We will wrap up the example extension that we started in part 1 by constructing a custom editor and a custom preferences page for specifying the extension settings. Finally we will package the extension, so that it can be installed in JDeveloper through the Help | Check for Updates... feature. So, let's get to it!

Main Theme

Creating a Custom Editor

A custom editor will allow us to display data associated with an extension action in a customized view. A custom editor for the sample Application Module Verifier action is shown below.

We construct a custom editor by creating an editor class that extends the oracle.ide.editor.Editor abstract class and providing an implementation for the abstract method getGUI(). This method is actually defined in the oracle.ide.view.View class from which the Editor class is inherited. It returns the root graphical user interface component of our custom editor. You may also want to override the getEditorAttribute() method to set the characteristics of the editor such as background color, scroll bars and so on. Below is the getGUI() code for our custom editor:

In the code above we construct a oracle.javatools.ui.TransparentPanel panel called AppModuleVerifierEditorPanel, which contains the custom editor GUI. We do this after we ensure that the URL clicked by the user is related to our action since we can add other verifier actions in the future. We will not go into the details of the AppModuleVerifierEditorPanel GUI but in general it constructs a single JTabbedPane pane - called General (see picture above) - that contains two oracle.javatools.ui.HeaderPanel panels the second of which hosts a JTable table. The specific details can be found in the source code below.

It remains to hook-up the custom editor to our extension action. In order to do this, we need first to declare the custom editor in the extension.xml descriptor inside the <hooks> tag and then activate it. For the first part, add the following code to the extension.xml descriptor:

For the second part, we will invoke the custom editor by calling EditorUtil.openDefaultEditorInFrameExternal() from within the launchEditor() method of the Verifier and pass the URL of the file to view.

Finally, what is left is to generate some data to display. Since our action is related to verifying Application Modules Configurations for ADF applications, we will extract certain data from each Application Module Configuration, such as for example the data source and the locking mode. For this purpose we will use the XMLExtractor class. To build our data model - an output XML file - we will use the XMLBuilder class. Again, the specific details can be found in the source code below.

For more information about constructing a custom editor for your extension, take a look at the CustomEditor example extension, which is part of the samples downloaded along the JDeveloper Extension SDK.

Creating a Preferences Panel

We can create a preferences panel to allow the user to configure our extension via the Tools | Preferences... menu option in JDeveloper. Below is a custom preferences panel that we will add in order to configure our ADF Tools extension:

To begin, we first need to add the persistent data model for our extension preferences. We do this by right-clicking on the extension project in the Application Navigator, selecting New... and from the New Gallery dialog under the Extension Development category Data Model (HashStructureAdapter).

This will bring up the Create Data Model dialog where we can specify our extension configuration class and package.

In the configuration class that is created, we need to add a getter and a setter method for each extension setting that can be configured by the user. For example, since we will allow the user to set the ADF application root folder to be verified, we will add the following code in ADFToolsConfigData to save and retrieve the root folder:

The second step is to actually create the preferences page. We do this via the New Gallery Preferences Page wizard under the Extension Development category:

In the Create Preferences Page dialog we specify the details of the preferences page. It is here where we specify the data model that we created in the previous step:

The preferences page class that is created by the wizard overrides the base class' onEntry() and onExit() methods. We will write the necessary code in these methods to retrieve and save respectively the preferences from the data model. For our sample extension, this is shown below:

The last thing that we need to do is to write the necessary UI code to create the look and feel of the preferences page. For more information about constructing a configuration panel, refer to the ConfigPanel example extension.

Packaging the Extension

Once our extension is complete, we need to package it in a format acceptable for installation by the JDeveloper Check for Updates... feature. We do this by firstly creating a deployment profile in the Project Properties dialog and deploying the extension in a jar archive.

The name of the jar archive must include the extension version. In our example we called the jar archive ADFTools. The version of the extension can be set in the extension.xml descriptor.

To deploy the extension, right-click on the project in the Application Navigator and select Deploy. Once the extension is deployed, we need to create a bundle.xml extension installation descriptor in order to provide the necessary installation details to JDeveloper. A sample bundle.xml file is shown below:

The bundle.xml must be located in a META-INF directory. Finally, the deployed extension jar archive along with the META-INF folder and its contents - the bundle.xml descriptor - must be packaged into a .zip file. The .zip file finally can be installed via the Check for Updates... feature in JDeveloper.


With this FAQ we conclude our introduction to the JDeveloper Extension SDK. The ability to extend the IDE to integrate tasks specific to our development process is a powerful feature of JDeveloper.

Until the next time, keep on JDeveloping!



Related Posts Plugin for WordPress, Blogger...