Declarative Extension building for JDeveloper with the extension.xml

Now that the Tomcat extension for JDeveloper is out there, it is time to summarize some of the new thing I learned while building this extension.

One key thing is that the extension.xml file can do a lot more than just describe your extension - it can actually save you a lot of coding needed in the past to hook up the parts of your extension to the IDE.

You can get the source of the Tomcat extension from here - and follow along.

When you look in the extension.xml file you'll see for example this part:


<action id="shay.tomcat.starttomcat">
<properties>
<property name="Name">Start Tomcat</property>
<property name="SmallIcon">res:/shay/tomcat/t002.gif</property>
<property name="LongDescription">start Tomcat</property>
</properties>
<controller-class>shay.tomcat.startTomcatController</controller-class>
<command-class>shay.tomcat.startTomcatCommand</command-class>
</action>

This define an action - an operation - in JDeveloper - you give it an id and point to the calsses that implement it.

Then you can use the above id to add menus and toolbar button that invoke the action inside JDeveloper.

See for example this part in the extension.xml for adding a menu:


<menus>
<menubar id="javax.ide.view.MAIN_WINDOW_MENUBAR_ID">
<menu id="34" after="javax.ide.HELP_MENU_ID">
<label>Tomcat</label>
<section id="Tomcat">
<item action-ref="shay.tomcat.starttomcat"/>
<item action-ref="shay.tomcat.stoptomcat"/>
<item action-ref="shay.tomcat.starttomcatdbg"/>
</section>
</menu>
</menubar>
</menus>

And this part for adding a toolbar buttons:


<toolbars>
<toolbar id="javax.ide.view.MAIN_WINDOW_TOOLBAR_ID">
<!-- Add a new section after the first section in the toolbar. -->
<section id="javax.ide.tck.toolbar.tomcatsection"
after="javax.ide.COPY_PASTE_SECTION_ID ">
<item action-ref="shay.tomcat.starttomcat"/>
<item action-ref="shay.tomcat.stoptomcat"/>
<item action-ref="shay.tomcat.starttomcatdbg"/>
</section>
</toolbar>
</toolbars>

Another thing that you can hook up in a declarative way is a new section for the tools->preferences menu.
You just create the class to implement the preferences structure and then in the extension.xml file you add:


<settings-ui-hook xmlns="http://xmlns.oracle.com/ide/extension">
<page id="shay.tomcat.tomcatpreferences" parent-idref="/preferences">
<label>Tomcat Preferences</label>
<traversable-class>shay.tomcat.TomcatPreferencesPanel</traversable-class>
</page>
</settings-ui-hook>

As you can see these hook points are quite powerful and can save some coding efforts, and they are actually part of JSR 198 - you can learn more about them in the JDeveloper online help topic "Specifying Optional JSR198 Standard and Custom Extension Points".

There are more samples of using these features in the set of examples that come with the Extension SDK. Have a look and try it out the next time you build a JDeveloper extension.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

me
I'm a Director of Product Management for the Oracle Java Development Tools.
Follow me:
Search

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