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.

image

extension.xml

image

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:

ClassSpy
CodeInteraction
Overlay

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

Comments:

Hey... Nice to see this blog... As someone involved in implementing a whole lot of this stuff, it's great to see it being captured somewhere so clearly. You're doing a great job of explaining how it all works :)

Posted by Brian Duff on August 27, 2010 at 07:47 PM PDT #

Good morning.

First of all think you for taking the time to explain how to implement extensions in JDeveloper.
I am trying to implement one but I am experiencing some issues when it comes to open a custom window if I click on a submenu element I have created.
More precisely, nothing happens.

Here is how my project is defined in JDev:
MyProject
---Application Sources
-----tools
-------addSubmenuToASqlDevPackageOnClick.xml
-------Command.java
-------Controller.java
-------SubMenuListener.java
-------ToolsAddin.java
-------JpanelToShowOnClickSubMenuelement.java
-----META-INF
-------extension.xml

Here is my submenu like when I click on a package in SQL Dev:

--MySubmenu
----ShowFileChooserWindow

Let me know if you want me to post sources.

Thinks in advance

Posted by Arix. O on January 10, 2014 at 02:52 AM PST #

Hi Arix,

Can you please provide me with the version of JDev you are working with and the operating system that you are using? It sounds like you may be using SQL Developer and not JDeveloper.

Posted by John 'JB' Brock on January 10, 2014 at 07:28 AM PST #

Hi,
I am using JDeveloper 11g on Windows 7 64bits for building a SQL Dev extension.
I used SQL Dev to see if the project deployed and ran properly.
It seems like the action I defined won't link to the item I am targeting (the one in my custom submenu).

Posted by Arix. O on January 10, 2014 at 09:53 AM PST #

Hi,

I finally resolved the issue.
In my extension.xml file I simply used className instead of action-ref.
Now when I click on the submenu I added in my DB package context menu, it does the job.

Have a good day.

Sincerly,

Arix.

Posted by Arix. O on January 14, 2014 at 03:25 AM PST #

Arix,

Glad to hear you worked it out. I wasn't able to get an answer internally before you figured it out yourself. Sorry about that.

While SQL Developer is built on JDeveloper, the extension API's can vary in a lot of places. I always recommend asking for help with specific SQL Dev issues, in the SQL Developer forums.

If an extension works properly in JDeveloper, but fails to function the same in SQL Developer, then it's most likely something like what you just found, and that will be answered the fastest in the SQL Dev forums.

Posted by John 'JB' Brock on January 15, 2014 at 07:54 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

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.


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today