Use a Custom View with the Oxygen XML Editor plugin Distribution
Question
Is it possible to create a custom view in Eclipse that can insert certain XML fragments in the documents opened with the Oxygen XML Editor plugin?
Answer
Here you can find more information about the Eclipse part of the oXygen SDK:
https://www.oxygenxml.com/oxygen_sdk.html#oXygen_Eclipse_plugin
Use the provided Oxygen XML Editor plugin sample project as a starting point. From any custom
view/component you can have singleton access to the using the
ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace()
API.
The Java code for inserting a certain XML fragment in the currently open editor (either in the Text or Author editing modes) would look like this:
WSEditor currentEditorAccess = PluginWorkspaceProvider.getPluginWorkspace(). getCurrentEditorAccess(PluginWorkspace.MAIN_EDITING_AREA); if(currentEditorAccess.getCurrentPage() instanceof WSXMLTextEditorPage) { //Editor opened in Text page WSXMLTextEditorPage tp = (WSXMLTextEditorPage) currentEditorAccess.getCurrentPage(); //You can access an API to insert text in the XML content // tp.getDocument().insertString(tp.getCaretOffset(), "<testTag/>", null); //This is the internal StyledText implementation // tp.getTextComponent() //You can use this XPath API to find the range of an XML element. // tp.findElementsByXPath(xpathExpression) } else if(currentEditorAccess.getCurrentPage() instanceof WSAuthorEditorPage) { //Editor opened in Author page // try { WSAuthorEditorPage authPage = (WSAuthorEditorPage) currentEditorAccess.getCurrentPage(); //Then you can do stuff like this to insert XML at cursor position // authPage.getDocumentController().insertXMLFragment("<testTag/>", authPage.getCaretOffset()); // } catch (AuthorOperationException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } }