This is a JavaScript-based plugin extension that allows you to contribute actions to the main menu and toolbars of Oxygen XML Editor, create custom views, interact with the application workspace, make modifications to opened documents, and add listeners for various events.
This extension can use the same API as the Workspace Access Plugin Extension, but the implementation is JavaScript-based and uses the bundled Rhyno library to create and work with Java API from the JavaScript code.
<!DOCTYPE plugin PUBLIC "-//Oxygen Plugin" "../plugin.dtd"> <plugin id="unique.id.value" name="Add Action To DITA Maps Manager popup-menu" description="Plugin adds contextual menu action to DITA Maps Manager pop-up menu." version="1.0" vendor="Syncro Soft" class="ro.sync.exml.plugin.Plugin" classLoaderType="preferReferencedResources"> <extension type="WorkspaceAccessJS" href="wsAccess.js"/> </plugin>In the example above, the JavaScript file wsAccess.js, located in the plugin folder, will be called. This JavaScript file needs to have two JavaScript methods defined inside. Methods that will be called when the application starts and when it ends:
function applicationStarted(pluginWorkspaceAccess) {
..........
}
function applicationClosing(pluginWorkspaceAccess) {
..........
}
function applicationStarted(pluginWorkspaceAccess) {
Packages.java.lang.System.err.println("Application started " + pluginWorkspaceAccess);
edChangedListener = {
/*Called when a DITA Map is opened*/
editorOpened: function (editorLocation) {
Packages.java.lang.System.err.println("\nrunning " + editorLocation);
/*Get the opened DITA Map*/
editor = pluginWorkspaceAccess.getEditorAccess(editorLocation, Packages.ro.sync.exml.workspace.api.PluginWorkspace.DITA_MAPS_EDITING_AREA);
ditaMapPage = editor.getCurrentPage();
/*Add listener called when right click is performed in the DITA Maps manager view*/
customizerObj = {
customizePopUpMenu: function (popUp, ditaMapDocumentController) {
Packages.java.lang.System.err.println("RIGHT CLICK" + popUp);
tree = ditaMapPage.getDITAMapTreeComponent();
/*Selected tree path*/
sel = tree.getSelectionPath();
if (sel != null) {
selectedElement = sel.getLastPathComponent();
/*Reference attribute*/
href = selectedElement.getAttribute("href");
if (href != null) {
try {
/*Create absolute reference*/
absoluteRef = new Packages.java.net.URL(selectedElement.getXMLBaseURL(), href.getValue());
Packages.java.lang.System.err.println("Computed absolute reference " + absoluteRef);
mi = new Packages.javax.swing.JMenuItem("Run notepad");
popUp.add(mi);
actionPerfObj = {
actionPerformed: function (e) {
try {
Packages.java.lang.Runtime.getRuntime().exec("notepad.exe " + pluginWorkspaceAccess.getUtilAccess().locateFile(absoluteRef));
}
catch (e1) {
e1.printStackTrace();
}
}
}
mi.addActionListener(new JavaAdapter(Packages.java.awt.event.ActionListener, actionPerfObj));
}
catch (e1) {
Packages.java.lang.System.err.println(e1);
}
}
}
}
}
ditaMapPage.setPopUpMenuCustomizer(new Packages.ro.sync.exml.workspace.api.editor.page.ditamap.DITAMapPopupMenuCustomizer(customizerObj));
}
}
edChangedListener = new JavaAdapter(Packages.ro.sync.exml.workspace.api.listeners.WSEditorChangeListener, edChangedListener);
pluginWorkspaceAccess.addEditorChangeListener(
edChangedListener,
Packages.ro.sync.exml.workspace.api.PluginWorkspace.DITA_MAPS_EDITING_AREA);
}
function applicationClosing(pluginWorkspaceAccess) {
Packages.java.lang.System.err.println("Application closing " + pluginWorkspaceAccess);
}