Declarative Menus in JDeveloper Extensions – Part Two
By John 'JB' Brock on Aug 26, 2010
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.
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: