Use a Custom View with the Oxygen XML Author plugin Distribution


Is it possible to create a custom view in Eclipse that can insert certain XML fragments in the documents opened with the Oxygen XML Author plugin?


Here you can find more information about the Eclipse part of the Oxygen SDK:

Use the provided Oxygen XML Author 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().
    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) 

        //Then you can do stuff like this to insert XML at cursor position
//        authPage.getDocumentController().insertXMLFragment("<testTag/>", 
//      } catch (AuthorOperationException e) {
//        // TODO Auto-generated catch block
//        e.printStackTrace();
//      }