Customizing titles in the dita maps manager

Post here questions and problems related to oXygen frameworks/document types.
NissenJ
Posts: 17

Customizing titles in the dita maps manager

Tue Jan 31, 2017 1:59 pm

Hi!

How can I change the displayed title in the dita maps manager from my java code? For example, I added topic numbers in the titles, which are displayed in the document, but not in the maps manager!

Thanks and regards,
Julia
Radu
Posts: 5131

Re: Customizing titles in the dita maps manager

Tue Jan 31, 2017 3:43 pm

Hi Julia,

First of all you need the latest Oxygen 18.1 as the API to control titles in the DITA Maps Manager is a very recent addition.
Oxygen has support for Java-based plugins. We have a Maven-based plugins SDK:

https://www.oxygenxml.com/oxygen_sdk.html

There is a plugin extension type called WorkspaceAccess:

https://www.oxygenxml.com/doc/versions/18.1/ug-editor/concepts/workspace-access-plugin.html

which issues callbacks to your plugin when the application starts and when it will be closed.
When the application started callback is received, you can register an editor opened listener.
So a Java-based Workspace Access plugin extension which would add a counter before each chapter would look something like this:

Code: Select all

      @Override
      public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
        pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener(){
          /**
           * @see ro.sync.exml.workspace.api.listeners.WSEditorChangeListener#editorOpened(java.net.URL)
           */
          @Override
          public void editorOpened(URL editorLocation) {
            WSEditor wsEditor = pluginWorkspaceAccess.getCurrentEditorAccess(StandalonePluginWorkspace.DITA_MAPS_EDITING_AREA);
            WSDITAMapEditorPage authorPage = (WSDITAMapEditorPage) wsEditor.getCurrentPage();

            DITAMapNodeRendererCustomizer customizer = new DITAMapNodeRendererCustomizer() {
              @Override
              public String customizeComputedTopicrefTitle(AuthorNode topicref,
                  AuthorNode targetTopicOrMap, String defaultComputedTitle) {
                if("chapter".equals(topicref.getName())){
                  AuthorParentNode parentOfTopicRef = (AuthorParentNode) topicref.getParent();
                  List<AuthorNode> nodes = parentOfTopicRef.getContentNodes();
                  return (nodes.indexOf(topicref) + 1) + " - " + defaultComputedTitle;
                } else {
                  //Default title
                  return defaultComputedTitle;
                }
              }
            };
            authorPage.addNodeRendererCustomizer(customizer);
          }
        }, PluginWorkspace.DITA_MAPS_EDITING_AREA);
      }


The WorkspaceAccess Java plugin extension also has a Javascript equivalent:

https://www.oxygenxml.com/doc/versions/18.1/ug-editor/concepts/workspace-access-plugin-js.html

The benefit would be that the Javascript does not need to be compiled and sometimes the code looks a little bit simpler.
Based on the Java code I posted above, I created a Javascript-equivalent plugin called dmmCustomizeTopicTitles in a sample GitHub repository:

https://github.com/oxygenxml/wsaccess-j ... le-plugins

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
NissenJ
Posts: 17

Re: Customizing titles in the dita maps manager

Wed Feb 01, 2017 1:48 pm

Hi Radu!

Thank you for your reply. I am currently only working with an extension bundle, but I wasn't able to transfer your solution. Do I have to make a plugin for this or is there a way to do this with my extension bundle?

Thanks and Regards,
Julia
Radu
Posts: 5131

Re: Customizing titles in the dita maps manager

Wed Feb 01, 2017 2:30 pm

Hi Julia,

My implementation details were related only to making this work as a plugin.
From the extensions bundle side, as an experiment let's say you extend the DITAMapExtensionsBundle and override the method createXMLNodeCustomizer() with some code like:

Code: Select all

  /**
   * @see ro.sync.ecss.extensions.dita.DITAExtensionsBundle#createXMLNodeCustomizer()
   */
  @Override
  public XMLNodeRendererCustomizer createXMLNodeCustomizer() {
    return new XMLNodeRendererCustomizer() {
      @Override
      public String getDescription() {
        return null;
      }
     
      @Override
      public BasicRenderingInformation getRenderingInformation(NodeRendererCustomizerContext context) {
        BasicRenderingInformation ri = new BasicRenderingInformation();
        if("chapter".equals(context.getNodeName())){
          ri.setRenderedText("AAAA");
        }

        return ri;
      }
    };
  }


If you start Oxygen with the custom extensions bundle in place, in the DITA Maps Manager all <chapter> topicrefs will display "AAAA" as their title. The context parameter allows you to access more details about the topicref on which you want to display a title.
The problem with this approach is that Oxygen does not provide you with the default title that it would have computed for the chapter. So once you take control using this renderer you need to also compute the title of the referenced topic on your own with your own code.
That's why the new plugin API approach was better, because it also gave you the title Oxygen computed for the reference and you would only need to prepend the title instead of parsing the target XML document and obtaining its title with your own code.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
NissenJ
Posts: 17

Re: Customizing titles in the dita maps manager

Wed Feb 01, 2017 3:47 pm

Hi Radu!

I tried your solution, but now only the tags change. Since my sample map only has two topics, I replaced "chapter" with "topic". Now the titles in the dita maps manager still stay the same, but the topic tag now displays "AAAA". Also in the overview instead of 'topic "topic-id" title ' it now displays 'AAAA "topic-id" title '. But I only need to customize the title! What am I doing wrong?

Concerning the problem you mentioned, computing the title of the referenced topic on my own within my code is exactly what I want to do.

Thanks and Regards,
Julia
Radu
Posts: 5131

Re: Customizing titles in the dita maps manager

Wed Feb 01, 2017 4:26 pm

Hi Julia,

Indeed a problem I forgot about is that the DITAMapExtensionsBundle extension is used both for DITA maps opened in the DITA Maps Manager and for maps opened in the main editing area. So customizing the renderer name, at least on my side, takes effect in both places:

https://www.oxygenxml.com/forum/files/customizationRenderedMapNames.png

I'm not sure why the titled in the DITA Maps Manager do not change on your side. What Oxygen version are you using?
But as the renderer controls maps opened in both places it's probably not a good option for you anyway. So you should try the plugin alternative.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
NissenJ
Posts: 17

Re: Customizing titles in the dita maps manager

Wed Feb 01, 2017 4:49 pm

Hi Radu,

thank you for your reply! I am using Oxygen 18.1. Indeed with this problem this is not a good option for me. I will take a further look into plugins in the near future and try your solution there.

Thanks and Regards,
Julia

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 0 guests