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.

image

extension.xml

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.

image

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.

image

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.

image

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".

image

The result of this is what you see below.

image

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.

image

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.

<technologyKey>General</technologyKey>

image

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

Comments:

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