Monday Sep 06, 2010

Declarative Menus in JDeveloper Extensions – Part Three

Part Three: Creating Gallery menus (File / New) using a Wizard

If you came to this post directly, you may want to take a look at the previous posts first.
Part One: Introduction and Creating an Action
Part Two: Creating Context Menus

Using the JDeveloper SDK Sample project, "Create Dialog" we can take a look at how the extension.xml is setup for using a Gallery item.



The nice thing about setting up a Gallery item is that it can be done with a simple Wizard.  From the File menu, select New and look for the "Gallery Item (Wizard)" in the Extension Developer folder under Client Tier.


If you don't see the Client Tier category when the dialog first opens, make sure you are on the "All Technologies" tag and not the "Current Project Technologies" tag.

Double click on the Gallery Item option and you will see a dialog like the one below.


Enter the name of your Gallery item.  You can select the Category and Folder from the pulldown list, or type in your own. You can also select the icon that will be displayed with your menu item at this time.

NOTE:  Take a careful look at the "Wizard class" name that is being created for you.  Specifically make sure that the package name in front of the actual class name is what you want it to be.

The checkbox for adding this to the Tools Menu is something that I haven't used that much. It adds the menu item using a MenuSpec object in the code.  I'll cover how to work with the main MenuBar and ToolBar menus declaratively in Part Four of this post.

Click OK once you have all of your data entered and the wizard will add the basic lines to the extension.xml file and create a new class file based on the wizard class name that you set in the dialog.


If we look at the java class created by the wizard, you'll see two methods that manage the execution of the menu item.  

The "isAvailable" method is where you add any code that will tell the IDE when to actually show your menu item.  In the example above, you can see that this menu item is only going to be shown when there is a valid Project in the application.

The "invoke" method is where you will define the UI for your wizard or perform the action for the menu item.  In the example above, a call is made to the runDialog() method in another class that does all of the UI work. 

If we take a look at what the wizard added to the extension.xml file, we'll see that  the basic elements are added in for us.  "name" (which is pulled from the generated class), "category", and "folder".


The result of this is what you see below.


Notice however, that this only shows up in the "All Technologies" tab.  If we look at the "Current Project Technologies" tab, our menu item isn't there.


The Current Project Technologies tab is a filtered list of items. It only shows items that are related to the Technology Scopes that you are using in the current project.

If you know that your extension is working with projects that have a specific Technology Scope, Java for instance, you can set the menu item to show up in the Current Project Technologies tab when that Tech Scope is present by using the "technologyKey" element, right after the "folder" element, in the extension.xml file.  If your extension is working with any project, no matter what the tech scope may be, you can still set the technologykey to "General" and it will show up for any project.



To determine what the correct value is for the different technology scopes, just click on the "selected technologies" link at the top of the dialog and you'll see a complete list.

As usual, please post up any questions or personal experiences in the comments.

Previous parts in this topic:

Part One: Introduction and Creating an Action
Part Two: Creating Context Menus

Next Steps:

-- Part Four: Creating  Toolbar and Menubar menus

Thursday Aug 26, 2010

Declarative Menus in JDeveloper Extensions – Part Two

Part Two: Creating Context Menus

If you came to this post directly, it would be a good idea to take a look at the previous posts first.
Part One: Introduction and Creating an Action

You can create a context menu in the Navigator panel, the Explorer or Structure Panel, and the Editor window.

To create these menu items you want to first create a listener class that you can then tell the IDE to interact with.

Using the JDeveloper SDK Sample project, “First Sample” we can take a look at how the listener is defined in the extension.xml and in the Listener Class itself.




Listener class

Notice that the extension.xml file makes the reference to the Listener class, and that class goes back to the Action that we discussed in the first part of this topic. The Action is where the class is called to actually do the work when the menu item is clicked.  You can setup a Controller class to manage the command ID’s as Constants if you like.  I’ve chosen to do a direct call to the Action ID in the sample above.  Notice that the controller method is also there, just commented out.

It’s the site “idref” that determines where the context menu item will show up in the UI (Editor, Navigator, Explorer).  Of course you can have multiple Listener classes. One for each type of context menu that you want to setup.

While there isn’t a wizard for setting up Context Menus, it can still be done pretty quickly by using a bit of cut and paste from this one SDK example project.

There are multiple projects in the SDK Samples that use context menus.  To see more examples, take a look at the following projects:


As usual, please post up any questions or personal experiences in the comments.

Previous parts in this topic:

Part One: Introduction and Creating an Action

Next Steps:

-- Part Three: Creating Gallery menus  (File / New) using a Wizard

-- Part Four: Creating  Toolbar and Menubar menus

Wednesday Aug 25, 2010

Declarative Menus in JDeveloper Extensions – Part One

When creating an extension for JDeveloper, the most common way of connecting that extension to the IDE is through the menu structure.

Whether it's via a context menu, or adding a menu to the existing menu bar at the top of the IDE, it can all be done in two different ways.  In code, or declaratively in the extension.xml file

In this post, I'm going to talk about how to work with the declarative method for menu creation, as I believe it is the easiest and most flexible way to connect to the IDE.

All of the IDE commands used here, are available when working with an Extension Project type.

I will break this post into multiple sections since it's a bit of a long topic

Part One: Introduction and Creating an Action

Part Two: Creating Context menus

Part Three: Creating Gallery menus  (File / New) using a Wizard

Part Four: Creating  Toolbar and Menubar menus

The SDK example application "First Sample" does a really good job of showing how to add a menu to the following areas of the IDE:

Context Menu for:

Explorer (Structure pane)


New Gallery






The above examples show the proper syntax for working with all of the different kinds of menus.  However, they don't give you the information about how to find the ID for the menu areas that you want to add to, or how to nest menus.  We'll go into more detail about how to do these things as well as take a general look at how everything is tied together.

Getting Started (creating an action)

The first thing you need to do when working with menus, is to create the action section that will define what the menu item will do.  All of the menu items will reference this action to get the actual work done.  This is made very simple in JDev 11g by using the "File -> New" Wizard to add an Action to the existing extension project.

Right-Click on your extension project name in the Navigator pane and select New.  In the resulting Wizard, make sure the "All Technologies" tab is selected and then click on the Extension Development folder under the Client Tier  category.


Double click on the Action item and fill out the dialog with the information about your new Action.


You can select an Icon for your menu item from the OracleIcons group here, or you can add an icon to the project at a later time and then reference it in the extension.xml file later.

Once you have created your action, it will look like this in the extension.xml file


Next Steps: 

-- Part Two: Creating Context menus

-- Part Three: Creating Gallery menus  (File / New) using a Wizard

-- Part Four: Creating  Toolbar and Menubar menus

Monday Jul 26, 2010

What's New in JDeveloper 11gR2 Extension Development

With the release of JDeveloper 11gR2, the entire Extension Framework has been reworked so that extensions are now implemented as OSGi modules. Extensions written for previous versions of JDeveloper will not work with this release until you do some modifications to your code.

What does this mean to extension developers?

Lazy Loading

The biggest impact is when and how an extension is loaded.  Jdeveloper use to load all extensions at the same time when JDeveloper was first started.  We now take advantage of something called Lazy Loading.  Extensions are only loaded when the developer needs them.  This allows JDeveloper to have a much faster startup time, and also a lower memory footprint while running since extensions that you don't need, are not loaded.

Trigger Hooks

With this release, there is the introduction of Trigger-Hooks in the extension.xml file.  This is separate from the older Hooks element.  Because an extension isn't loaded automatically by calling the Addin.initialize() method any longer, you need to add an action or event to the trigger-hooks section so the IDE knows when to load your extension.
You can take a look at the trigger-hooks wiki to see the existing trigger-hooks available in this release.

Separate Classloaders

With the use of OSGi, comes the use of a separate classloader for each extension.  You may have to change how your extension sets it's dependencies. The classpath element in extension.xml is no longer used. You set the dependencies in the Manfest.MF files instead.

Run and Debug from the IDE

There is an extra step now for running or debugging your extension from within the IDE.  Before you click on the Run Extension or Debug Extension options, you must click on "Deploy to Target Platform" first.  This rebuilds the Manifest.MF files with any changes to your project.  This will become a little smoother in a future release, but for now, you just have to do this one extra step.

JDeveloper Extension Development Guide

With such a significant change to the framework, we had to update the documentation to go with it of course.  A completely new Extension Developer Guide has been written for this release.  It's a great place to start.

What's next?

Those are the major changes for the Extension Framework in this release. They are quite significant.  I will be posting another entry shortly where I will walk through the steps of taking an existing extension project, and migrating it to work with the new OSGi enabled framework.  Stay tuned for more.

As always, please feel free to post any questions or personal experiences in the comments. I'm sure everyone's experiences with migrating existing extensions will be of benefit to all of us.

Wednesday Jul 21, 2010

JDeveloper Role files – What are they?

[Read More]

Friday Jul 16, 2010

Where to start when writing JDev Extensions

For many of us, it's that first step that seems to be the hardest to get past when starting something new.  When it comes to JDev Extension development it really isn't any different.  It took a while to compile a lot of those sites that give you the beginners perspective and not just a lot of code samples that someone with experience could only use.

Below is a short list of some of the more beginners resources that I came across over the last couple of months.  If you have others, please add them in the comments.

1) The search field in the IDE itself is probably the best resource that I stumbled across in JDev.  It does far more then just search the existing code.  It looks at the JavaDocs, online Help, Oracle Technology Network and more.  Definitely give this a try.

2) Shay Shmeltzer's blog is a wealth of info for both beginner and more advanced extension developers.  A must have bookmark

3) The intro video for JDeveloper 11gR1 Extension SDK is a good place to start.  The intro video for 11gR2 is also available.

4) The JDeveloper FAQ blog by Nick Haralabidis has a three part series on writing your first JDev Extension.  The series is found in blog's #16 - #18.

5) The Extension SDK samples themselves.  There are approx. 30 sample application that come with the SDK that you install via the JDev Update Center.  These samples contain a lot of info beyond just what they say they do in the description.  I've gone through all of them over the last month and will post a spreadsheet shortly that shows a lot more about what each sample can provide some insights to.

6) The JDeveloper and ADF Forum.  If all else fails, ask for help in the JDeveloper forum.  There are a lot of great minds that follow this forum.  They are friendly and helpful.  If you do post up a new question, make sure you add an "extension" tag to the post, so that it's easier for others to learn from your questions in the future.

Hope these beginners resource help others get going with developing extensions for JDeveloper. If you have some of your own, please add them in the comments.

Wednesday Jul 14, 2010

How to find the IdRef for most menu commands

[Read More]

Monday Jul 12, 2010

It has to start somewhere...

[Read More]

profile image
My name is John 'JB' Brock.
This Blog will focus on tips and tricks for working with the JDeveloper Extension SDK.
I hope to bring clarity to some of the mysteries around developing extensions for JDeveloper.


« July 2016