Sunday, March 14, 2010

FAQ #17 - How to get started with the JDeveloper Extension SDK, Part 2

Introduction

In FAQ #16 - How to get started with the JDeveloper Extension SDK, Part 1 we  talked about the basics of getting started with writing your own JDeveloper extensions. In this FAQ we will expand on that knowledge to cover a few more introductory topics. Specifically we will talk about: 1) how to create a progress bar to indicate a long running action and 2) how to create and utilize a log window specific to your extension.

Main Theme

Creating a Progress Bar

You can use a progress bar in a JDeveloper extension to indicate a long running action. Since our sample ADFTools extension will iterate a base directory looking for Application Module configuration files - for the Application Module Verifier action - this is the ideal place to use it.


For more information, check-out the ProgressBar example extension, part of the extensionssdk workspace downloaded along with the JDeveloper Extension SDK. For more information about downloading the JDeveloper Extension SDK refer to FAQ #16 - How to get started with the JDeveloper Extension SDK, Part 1.

To get started, a progress bar is created by instantiating an oracle.ide.dialogs.ProgressBar class. The constructor for the ProgressBar class is documented as follows on the Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference 11g Release 1 (11.1.1) on the web:


The constructor documentation is almost self-explanatory. We need to provide the parent window of the progress bar, its title, a Runnable interface implementation and a true/false indicator of whether the task that is to be executed is determinate or not. Thus our main task becomes the implementation of the Runnable interface. For this purpose we will create a Verifier class that implements the Runnable interface by implementing the abstract run() method. In its run() method we will scan the application's root directory for Application Module configuration files. The code below shows the run() method of the Verifier class.


A few things to consider on the code above:
  • FileScanner is a generic utility class that will scan a specific root directory for a file pattern. This is done by calling its scanForFiles() method.
  • logMessage() is a class method that will log a message in our own custom JDeveloper log window. More on this later.
  • progressbar is a ProgressBar class variable that is passed to the Verifier via the setProgressBar().
  • logLink() is a class method that will log a click-able URL link in the custom log window. Again, more on this later when we will talk about the creation of our extension's log window.

Since the Verifier class can be re-used by other types of verifiers, we will also create a specialized Verifier class called ApplicationModuleVerifier. Now, we can write the plumbing code in the ApplicationModuleVerifierCommand doit() that implements the command. This code is shown below:


A few things of interest on the code above:
  •  ApplicationModuleVerifier is the Verifier-derived class specific for this command action.
  • The ProgressBar is created by specifying the IDE main window - Ide.getMainWindow() - as its parent. We also specify the ApplicationModuleVerifier we just created for its Runnable parameter.
  • We call setCancelable() on the ProgressBar to allow the user to cancel the command processing.
  • We pass the ProgressBar to the ApplicationModuleVerifier by calling its setProgressBar().
  • Finally we start the ProgressBar by calling start(). Command will then be passed to the Verifier run() method.

Creating and Utilizing a Log Window

A log window will allow us to perform log actions specific to our extension. For example, we can clear the logs without interfering with other logs made by JDeveloper.


For more information, check-out the ClickableURL example extension. We can create our own log window by creating a class that extends the oracle.ide.log.MessagePage, instantiate it and call it show() method to display it in JDeveloper. All of these are done inside the ApplicationModuleVerifierCommand's doit() as it is shown below:


Also in the code above observe the following:
  • LogManager.getLogManager().showLog() is called to show the JDeveloper Log pane
  • clearAll() is called on our log window to clear its contents
  • setMessageWindow() is called on the ApplicationModuleVerifier to pass the message pane. It will be used by the verifier to add log entries to the log pane.
Log entries are added to the custom log pane in the Verifier run() by calling the logMessage() and logLink() methods (see image above). The logLink() method is shown below. An oracle.ide.log.Href is instantiated and logged in the custom log pane. When the link is clicked the launchEditor() Verifier method is called to display it in an editor.



This pretty much wraps it up. Build the extension and run it. You should be able to see the progress bar while the action is running. You should also see the custom log window open and a number of log messages and links logged in it.


Conclusion

In this FAQ we've seen how to create a JDeveloper progress bar and a custom log pane - based on the ProgressBar and ClickableURL example extensions respectively. We've also seen how to add the plumbing code in the Command doit() method to create them and display them.

Until the next time, keep on JDeveloping!


Code

http://jdeveloperfaq.googlecode.com/files/JDeveloperFAQNo17.rar







No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...