Implementing addMenuBarCustomizer
Posted: Thu Apr 02, 2015 5:00 am
Hi Everyone,
I would like to create a plugin that allows for pre-processing of XML documents before transforming them into DITA topics. My thought was to add a set of menu items to act on the document that is currently open. I am using eclipse with oxygen-sdk-16.1.2-all connected to Oxygen Author using this guidance - https://www.oxygenxml.com/doc/ug-editor ... lugin.html.
So Oxygen Author opens while running eclipse in debug mode, but no menu item is added. Here are the classes I'm writing (at this point they are pretty basic I'm getting back into Java after several years). Any advise would be greatly appreciated. Thank you!
*************************************************
package gehc;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension;
import ro.sync.exml.workspace.api.standalone.MenuBarCustomizer;
import ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.net.URL;
public class CustomGEHCPluginExtension implements WorkspaceAccessPluginExtension {
private StandalonePluginWorkspace instance = null;
private boolean runPlugin;
public boolean applicationClosing() {
try{
} finally {
return true;
}
}
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addMenuBarCustomizer(new MenuBarCustomizer() {
final Action showSettingsWindow = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
Integer i = 0;
//processor.showSettingsDialog();
}
};
public void customizeMainMenu(JMenuBar mainMenuBar) {
JMenu menuCMS = new JMenu();
final JMenuItem oneMenuItem = new JMenuItem(showSettingsWindow);
oneMenuItem.setText("GEHC");
menuCMS.add(oneMenuItem);
menuCMS.setText("GEHC");
mainMenuBar.add(menuCMS, mainMenuBar.getMenuCount() - 1);
}
});
}
}
*************************************************
package gehc;
import ro.sync.exml.plugin.Plugin;
import ro.sync.exml.plugin.PluginDescriptor;
public class CustomGEHCPlugin extends Plugin {
/**
* The static plugin instance.
*/
private static CustomGEHCPlugin instance = null;
/**
* Constructs the plugin.
*
* @param descriptor The plugin descriptor
*/
public CustomGEHCPlugin(PluginDescriptor descriptor) {
super(descriptor);
if (instance != null) {
throw new IllegalStateException("Already instantiated!");
}
instance = this;
}
/**
* Get the plugin instance.
*
* @return the shared plugin instance.
*/
public static CustomGEHCPlugin getInstance() {
return instance;
}
}
I would like to create a plugin that allows for pre-processing of XML documents before transforming them into DITA topics. My thought was to add a set of menu items to act on the document that is currently open. I am using eclipse with oxygen-sdk-16.1.2-all connected to Oxygen Author using this guidance - https://www.oxygenxml.com/doc/ug-editor ... lugin.html.
So Oxygen Author opens while running eclipse in debug mode, but no menu item is added. Here are the classes I'm writing (at this point they are pretty basic I'm getting back into Java after several years). Any advise would be greatly appreciated. Thank you!
*************************************************
package gehc;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension;
import ro.sync.exml.workspace.api.standalone.MenuBarCustomizer;
import ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.net.URL;
public class CustomGEHCPluginExtension implements WorkspaceAccessPluginExtension {
private StandalonePluginWorkspace instance = null;
private boolean runPlugin;
public boolean applicationClosing() {
try{
} finally {
return true;
}
}
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addMenuBarCustomizer(new MenuBarCustomizer() {
final Action showSettingsWindow = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
Integer i = 0;
//processor.showSettingsDialog();
}
};
public void customizeMainMenu(JMenuBar mainMenuBar) {
JMenu menuCMS = new JMenu();
final JMenuItem oneMenuItem = new JMenuItem(showSettingsWindow);
oneMenuItem.setText("GEHC");
menuCMS.add(oneMenuItem);
menuCMS.setText("GEHC");
mainMenuBar.add(menuCMS, mainMenuBar.getMenuCount() - 1);
}
});
}
}
*************************************************
package gehc;
import ro.sync.exml.plugin.Plugin;
import ro.sync.exml.plugin.PluginDescriptor;
public class CustomGEHCPlugin extends Plugin {
/**
* The static plugin instance.
*/
private static CustomGEHCPlugin instance = null;
/**
* Constructs the plugin.
*
* @param descriptor The plugin descriptor
*/
public CustomGEHCPlugin(PluginDescriptor descriptor) {
super(descriptor);
if (instance != null) {
throw new IllegalStateException("Already instantiated!");
}
instance = this;
}
/**
* Get the plugin instance.
*
* @return the shared plugin instance.
*/
public static CustomGEHCPlugin getInstance() {
return instance;
}
}