Custom Toolbar and Button for oXygen XML Editor

In the next coup­le of weeks I’d li­ke to wri­te so­me blog­posts and tu­to­ri­als about plug­in de­ve­lop­ment for the awe­so­me oXy­gen XML Editor. I’d li­ke to sha­re my ex­pe­ri­en­ces in plug­in de­ve­lop­ment sin­ce tu­to­ri­als and re­sour­ces for this to­pic are ra­re…

I’ll start off by sho­wing how to add a custom tool­bar with a simp­le but­ton to the oXy­gen main win­dow.

First of all, we need to down­load the oXy­gen plug­ins SDK from the oXy­gen Website. Create a new Java Project in your fa­vo­ri­te IDE (I’m using Eclipse), place the oxygen.jar li­bra­ry from the SDK down­load in your lib/ fol­der and add it to the build path. Also add the Javadoc, that’s qui­te hel­pful. You can al­so ac­cess the the do­cu­men­ta­ti­on on­line.

To start off with plug­in de­ve­lop­ment, read the oXy­gen ma­nu­el chap­ter about plug­in de­ve­lop­ment. Their blog al­so of­fers so­me help.

For ex­ten­ding the oXy­gen main win­dow we need to crea­te a „Workspace Access Plugin“. A plug­in al­ways con­sists of the fol­lo­wing sources:

YourDemoPlugin.java
YourDemoPluginExtension.java
plugin.xml

plugin.xml is the plug­in de­scrip­tor and you can set it up as fol­lows:

The <tool­bar> ele­ment de­fi­nes our custom tool­bar with its id at­tri­bu­te.

Next, we need YourDemoPlugin.ja­va which is for con­ve­ni­en­ce and can re­turn an in­s­tan­ce of our plug­in. Haven’t found out what el­se you can use it for…

And fi­nal­ly, YourDemoPluginExtension.ja­va is the Extension its­elf. Your PluginExtension class al­ways needs to im­ple­ment the plug­in ty­pe in­ter­face, li­ke in our ca­se, the WorkspaceAccessPluginExtension with it’s me­thods ap­p­li­ca­ti­onStar­ted() and ap­p­li­ca­tionClo­sing(). We will use ap­p­li­ca­ti­onStar­ted() to add our tool­bar and but­ton to the oXy­gen main win­dow at start­up time. Take a look at the fol­lo­wing:

We add a ToolbarComponentsCustomizer and add a custom JButton if the cur­r­ent­ly pro­ces­sed tool­bar equals our tool­bar ID in plugin.xml.

For de­mo re­a­sons I ad­ded a mess­a­ge­Dia­log with the na­me of our tool­bar. Feel free to do wha­te­ver you want with the JButton…

However, don’t for­get to add your fresh­ly crea­ted GUI com­pon­ents to the tool­bar with toolbarInfo.setComponents() and na­me your tool­bar with toolbarInfo.setTitle().

To load the plug­in in oXy­gen ex­port your Java Project as a JAR li­bra­ry and go to the oXy­gen in­stal­la­ti­on di­rec­to­ry. Open the fol­der plugins/ and crea­te your own plug­in fol­der DemoButton/. Place the plugin.xml file in­si­de, crea­te a fol­der lib/ in­si­de and place the jar file in it. Restart oXy­gen.

That’s it… 🙂

2 Kommentare

  1. Hi Tobi,

    fi­nal­ly I’ve got so­me time to try this out. And in­credi­b­ly it works! 😉
    Thank you for the good and short tu­to­ri­al! It is a good ba­se to con­ti­nue by my self.

    That is, what I found:
    – to show messa­ge diag­logs, you can use the showInformationMessage/showErrorMessage me­thod of the class StandalonePluginWorkspace.
    – to de­fi­ne a View for you plug­in, it is the sa­me pro­ce­du­re:
    – use a Element in your plugin.xml
    – addView­Com­po­nent­Custo­mi­zer me­tho­de in­s­te­ad of add­Tool­b­ar­Com­pon­ents­Custo­mi­zer
    – Difference: you can just add one JComponent to the viewIn­fo. Shure… you can add a JPanel and de­fi­ne the view by your self.
    – with show­View, show­Tool­bar, hi­de­View and hi­de­Tool­bar of StandalonePluginWorkspace you can show or hi­de your View or Toolbar.

    So next: part 2! 😉

    LG
    Nico

  2. Thanks for sharing your thoughts and ex­pe­ri­en­ces, Nico!
    Hopefully I will have time so­on to do a third part of the se­ries with stuff li­ke ge­ne­ric oxy­gen dia­logs, views, etc…
    Also check the git­hub re­po, or feel free to wri­te a guest post 😉

    Cheers,
    Toby

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.