Adding toolbar icons via JS plugin?
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
ttasovac
- Posts: 90
- Joined: Fri Dec 19, 2003 6:02 pm
Adding toolbar icons via JS plugin?
Hi.
Based on the example of the "Run scenarios" plugin from https://github.com/oxygenxml/wsaccess-j ... le-plugins, I've written a script which adds two buttons to the toolbar: "build" and "schema". Each button is linked to a particular transformation scenario (one XProc and one ANT). The script works (attached below for reference).
I have two questions:
All best,
Toma

Based on the example of the "Run scenarios" plugin from https://github.com/oxygenxml/wsaccess-j ... le-plugins, I've written a script which adds two buttons to the toolbar: "build" and "schema". Each button is linked to a particular transformation scenario (one XProc and one ANT). The script works (attached below for reference).
I have two questions:
- Is there a way to load custom toolbar icons via the JS plugin API?
- Is there a way to render icons visible only inside a particular project?
All best,
Toma
Code: Select all
function applicationStarted(pluginWorkspaceAccess) {
Packages.java.lang.System.err.println(
"Application started " + pluginWorkspaceAccess
);
// --------------------------------------------------
// Helper: create a button that runs a transformation
// --------------------------------------------------
function createScenarioButton(label, scenarioName) {
var button = new Packages.javax.swing.JButton(label);
var action = {
actionPerformed: function (e) {
var editorAccess =
pluginWorkspaceAccess.getCurrentEditorAccess(
Packages.ro.sync.exml.workspace.api.standalone
.StandalonePluginWorkspace.MAIN_EDITING_AREA
);
try {
var scenarios = new java.lang.reflect.Array.newInstance(
Packages.java.lang.String,
1
);
scenarios[0] = scenarioName;
editorAccess.runTransformationScenarios(scenarios, null);
} catch (e1) {
e1.printStackTrace();
}
}
};
button.addActionListener(
new JavaAdapter(
Packages.java.awt.event.ActionListener,
action
)
);
return button;
}
// --------------------------------------------------
// Toolbar customizer
// --------------------------------------------------
toolbarCustomizer = {
customizeToolbar: function (toolbarInfo) {
if ("Transformation" == toolbarInfo.getToolbarID()) {
Packages.java.lang.System.err.println(
"Customizing toolbar: " + toolbarInfo.getToolbarID()
);
var original = toolbarInfo.getComponents();
var all = new java.lang.reflect.Array.newInstance(
Packages.javax.swing.JComponent,
original.length + 2
);
for (var i = 0; i < original.length; i++) {
all[i] = original[i];
}
// Create buttons
var buildButton = createScenarioButton(
"Build",
"TEILex0: Generate documentation"
);
var schemaButton = createScenarioButton(
"Schema",
"TEILex0: ODD to RELAX NG XML"
);
// Add buttons to toolbar
all[original.length] = buildButton;
all[original.length + 1] = schemaButton;
toolbarInfo.setComponents(all);
}
}
};
toolbarCustomizer = new JavaAdapter(
Packages.ro.sync.exml.workspace.api.standalone.ToolbarComponentsCustomizer,
toolbarCustomizer
);
pluginWorkspaceAccess.addToolbarComponentsCustomizer(toolbarCustomizer);
}
function applicationClosing(pluginWorkspaceAccess) {
Packages.java.lang.System.err.println(
"Application closing " + pluginWorkspaceAccess
);
}

-
Radu
- Posts: 9601
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Adding toolbar icons via JS plugin?
Hello Toma,
As per this sample:
https://github.com/oxygenxml/wsaccess-j ... se-options
one can use a magic "jsDirURL" variable which points to the plugin folder.
Then one could use for example our APIs "ro.sync.exml.workspace.api.images.ImageUtilitiesSpecificProvider.loadIcon(URL)" to load an icon from an URL. Or use the Java Swing regular way of loading an Icon with "javax.swing.ImageIcon.ImageIcon(URL, String)".
About showing the toolbar buttons only for certain projects, we have an API "ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace.getProjectManager()" giving you access to the project context (current project URL, add a listener to listen for project changes).
In my opinion as the JS based plugin grows in complexity you might want to switch to using a Maven based Java project instead.
https://github.com/oxygenxml/sample-plu ... ace-access
Regards,
Radu
As per this sample:
https://github.com/oxygenxml/wsaccess-j ... se-options
one can use a magic "jsDirURL" variable which points to the plugin folder.
Then one could use for example our APIs "ro.sync.exml.workspace.api.images.ImageUtilitiesSpecificProvider.loadIcon(URL)" to load an icon from an URL. Or use the Java Swing regular way of loading an Icon with "javax.swing.ImageIcon.ImageIcon(URL, String)".
About showing the toolbar buttons only for certain projects, we have an API "ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace.getProjectManager()" giving you access to the project context (current project URL, add a listener to listen for project changes).
In my opinion as the JS based plugin grows in complexity you might want to switch to using a Maven based Java project instead.
https://github.com/oxygenxml/sample-plu ... ace-access
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service