Tutorial #2: oXygen plugin development

This is part 2 of my tu­to­ri­al se­ries on oxy­gen plug­in de­ve­lop­ment. If you mis­sed part 1, read it he­re or check out the code on Git­Hub.

Part 2 of this tu­to­ri­al is about the EditorChangeListener and how we can use it to en­ab­le or dis­able our custom but­ton on dif­fe­rent file ty­pes. The code can be found in step2 branch in the Git­Hub re­po.

Let’s say, our custom but­ton should on­ly be active/enabled/clickable when the­re is an XML file ope­ned in the cur­rent oXy­gen edi­tor tab.

First, we add an EditorChangeListener with a new func­tion in all it’s chan­ge me­thods:

checkCurrentEditorAndChangeButtonStatus() is a new me­thod to check the cur­rent edi­tor on any chan­ge in the oXy­gen edi­tor pa­nes. Ever­y­ti­me we chan­ge the cur­rent tab in oXy­gen, clo­se a file or open a new one, the checkCurrentEditorAndChangeButtonStatus() is cal­led to check the cur­rent file URL:

First, we re­trei­ve the cur­rent edi­tor with the me­thod pluginWorkspaceAccess.getCurrentEditorAccess(PluginWorkspace.MAIN_EDITING_AREA) and check whe­ther we have an edi­tor ope­ned or not.

Se­cond, we re­trei­ve the file URL of the cur­rent edi­tor with currentEditor.getEditorLocation() and then check the file ex­ten­si­on for .xml en­ding.

Ba­sed on the­se checks we eit­her en­ab­le or dis­able the plug­in de­mo but­ton.

There’s al­so so­me other foo we have to chan­ge in or­der to get the­se chan­ges to work. Check out the who­le file CustomButtonPluginExtension.java in the Git­Hub re­po in branch step2.

In part 3 we will learn how to check whe­ther the file is ope­ned in author- or text-mode. Stay tu­n­ed…

4 Kommentare

  1. Hi To­by,

    In or­der to make your but­ton look ex­act­ly li­ke the other Oxy­gen tool­bar but­tons you can crea­te a but­ton using the API class
    „ro.sync.exml.workspace.api.standalone.ui.ToolbarButton“ in­s­te­ad of crea­ting a re­gu­lar JBut­ton.
    In the sa­me „„ro.sync.exml.workspace.api.standalone.ui.“ pa­cka­ge the­re other Swing-based com­pon­ents which can be used to achie­ve a con­sis­tent look and feel of the ap­p­li­ca­ti­on.


  2. Hi To­bi­as,

    Will you im­ple­ment part 3 with chan­ges in com­ment above from Ra­du? It is rea­ly use­ful tu­to­ri­al for Oxy­gen but I have no found 3-rd part of this he­re – is it not crea­ted yet?


  3. Hi Alex,
    yes, I should de­fi­na­te­ly con­ti­nue this tu­to­ri­al. Un­for­tu­n­a­te­ly time is ra­re at the mo­ment…
    Hope­ful­ly I can con­ti­nue so­on. Stay tu­n­ed…

Schreibe einen Kommentar

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