Change ICN contentViewer's tab title in split pane mode?

615 Views Asked by At

I need to change the "title" for each document shown in ICN Viewer, dynamically, at runtime. I'll read the new viewer tab title from the document properties.

Environment: ICN 2.0.3 CM8.5 WAS 8.5.5

Code so far:

  1. I found a PARTIAL solution by hooking "ecm.model.desktop, onChange":

     aspect.after(ecm.model.desktop, 'onChange', function() {
        var contentViewer = dijit.byId('contentViewer');
        if (contentViewer) {
           var viewerTabTitleDef = new ViewerTabTitleDef ();
           contentViewer.mainTabContainer.getChildren().forEach(function(child) {
              viewerTabTitleDef.changeTitle(viewerTabTitleDef.self,
                 child.controlButton, child.contentViewerPane.viewerItem.item);
           });
           ...
    
  2. I was able to extend this for subsequent documents opened in the same viewer, and optimized by "removing()" the handler after this initial call. Here is the complete code:

     var kill = aspect.after(ecm.model.desktop, 'onChange', function() {
    
        var contentViewer = dijit.byId('contentViewer');
        // "contentViewer" will be "unknown" unless viewer invoked
        console.log('onChange: contentViewer', contentViewer);  
    
        if (contentViewer) {
           console.log("new ViewerTabTitleDef()...");
           kill.remove();
           var viewerTabTitleDef = new ViewerTabTitleDef ();
           contentViewer.mainTabContainer.getChildren().forEach(function(child) {
               // For initially opened tabs
               console.log('initially opened: child', child);
               viewerTabTitleDef.changeTitle(viewerTabTitleDef.self, child.controlButton, child.contentViewerPane.viewerItem.item);
           });
           aspect.after(contentViewer.mainTabContainer, 'addChild', function(child) {
               // For tabs added after the viewer was opened
               console.log('subsequently opened: child', child);
               viewerTabTitleDef.changeTitle(viewerTabTitleDef, child.controlButton, child.contentViewerPane.viewerItem.item);
           }, true);
        } // end if contentViewer
    
     });  // end aspect.after(onChange desktop)
    
  3. Current problem: how can I change the label for a split tab (either vertical or horizontal)?

So far, I have NOT been able to find any event for any ICN/ECM widget or object variable that I can trigger on.

2

There are 2 best solutions below

2
On BEST ANSWER

It seems you want to show a different tab-title (instead of the document title) in the navigator viewer whenever a doc is opened.

How about this?

Every document you open in the viewer is wrapped in a ecm.widget.viewer.model.ViewerItem which exposes the getHtmlName that returns the name used in the tab.

Your solution would be to implement your own getHtmlName.

Unfortunately though, the ViewerItem is constructed in the ecm.widget.viewer.ContentViewer#_open and then passed to the ecm.widget.viewer.ContentViewer#_openTab. So you'll either violate best practice by mingling with IBM private methods, or you'll go for a generic approach and just replace the ecm.widget.viewer.model.ViewerItem.prototype.getHtmlName.

3
On

(I am posting the answer on behalf of the question author, to move it to the answer section).

Many thanks to Ivo Jonker, for his suggestion to modify the widget prototype's "getHtmlName()" method. It worked!

Specifically:

  1. I'm invoking this code from an ICN plugin. I set event handlers in my plugin's base .js file, but it actually gets invoked in the new, separate viewer window.

  2. The original prototype looked like this:

     getHtmlName: function() {
         var methodName = "getHtmlName";
         this.logEntry(methodName);
    
         var displayName = this.item.getDisplayValue("{NAME}");
         if (displayName == "") {
             displayName = this.item.name;
         }
    
         var htmlName = entities.encode(displayName);
         this.logExit(methodName);
         return htmlName;
     },
    
  3. Per Ivo's suggestion, I overrode the prototype method like this:

         myPluginDojo.viewerTabTitleDef = viewerTabTitleDef;
         ...
         ecm.widget.viewer.model.ViewerItem.prototype.getHtmlName = function () {
             console.log("NEW getHtmlName()...");
             var displayName = myPluginDojo.viewerTabTitleDef.getTitle(this.item);
             return displayName;
         };