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

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 GitHub 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:

check­Cur­ren­tEdi­to­r­An­dCh­an­ge­But­ton­Sta­tus() is a new me­thod to check the cur­rent edi­tor on any chan­ge in the oXy­gen edi­tor pa­nes. Everytime we chan­ge the cur­rent tab in oXy­gen, clo­se a file or open a new one, the check­Cur­ren­tEdi­to­r­An­dCh­an­ge­But­ton­Sta­tus() 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.

Second, 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.

Based 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 GitHub 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 Toby,

    In or­der to make your but­ton look ex­act­ly li­ke the other Oxygen 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 JButton.
    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 Tobias,

    Will you im­ple­ment part 3 with chan­ges in com­ment above from Radu? It is rea­ly use­ful tu­to­ri­al for Oxygen 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. Unfortunately time is ra­re at the mo­ment…
    Hopefully 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.