fixed context conflict in object view; object tab context now can be defined in plugi...
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 30 Aug 2016 09:30:27 +0000 (12:30 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 30 Aug 2016 09:30:27 +0000 (12:30 +0300)
14 files changed:
src/java/netxms-eclipse/DataCollection/plugin.xml
src/java/netxms-eclipse/DataCollection/src/org/netxms/ui/eclipse/datacollection/objecttabs/LastValues.java
src/java/netxms-eclipse/ObjectView/plugin.xml
src/java/netxms-eclipse/ObjectView/schema/org.netxms.ui.eclipse.objectview.tabs.exsd
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/InterfacesTab.java
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/ObjectTab.java
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/views/TabbedObjectView.java
webui/webapp/DataCollection/plugin.xml
webui/webapp/DataCollection/src/org/netxms/ui/eclipse/datacollection/objecttabs/LastValues.java
webui/webapp/ObjectView/plugin.xml
webui/webapp/ObjectView/schema/org.netxms.ui.eclipse.objectview.tabs.exsd
webui/webapp/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/InterfacesTab.java
webui/webapp/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/ObjectTab.java
webui/webapp/ObjectView/src/org/netxms/ui/eclipse/objectview/views/TabbedObjectView.java

index ea44810..bba9d98 100644 (file)
          point="org.netxms.ui.eclipse.objectview.tabs">
       <tab
             class="org.netxms.ui.eclipse.datacollection.objecttabs.LastValues"
+            contextId="org.netxms.ui.eclipse.datacollection.context.LastValues"
             icon="icons/last_values.png"
             id="org.netxms.ui.eclipse.datacollection.objecttabs.LastValues"
             name="%tab.name.LastValues"
index 8153daf..5669bf0 100644 (file)
@@ -25,7 +25,6 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.contexts.IContextService;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.DataCollectionTarget;
 import org.netxms.ui.eclipse.datacollection.widgets.LastValuesWidget;
@@ -111,11 +110,6 @@ public class LastValues extends ObjectTab
        public void selected()
        {
                super.selected();
-               IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
-               if (contextService != null)
-               {
-                       contextService.activateContext("org.netxms.ui.eclipse.datacollection.context.LastValues"); //$NON-NLS-1$
-               }
                refresh();
        }
 }
index 9ff358c..6f2a767 100644 (file)
@@ -89,6 +89,7 @@
       </tab>
       <tab
             class="org.netxms.ui.eclipse.objectview.objecttabs.InterfacesTab"
+            contextId="org.netxms.ui.eclipse.objectview.context.InterfacesTab"
             icon="icons/interface.png"
             id="org.netxms.ui.eclipse.objectview.objecttabs.InterfacesTab"
             name="%tab.name.Interfaces"
index 585e3f3..546c7fc 100644 (file)
                </appInfo>
             </annotation>
          </attribute>
+         <attribute name="contextId" type="string">
+            <annotation>
+               <documentation>
+                  Context ID
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="identifier" basedOn="org.eclipse.ui.contexts/context/@id"/>
+               </appInfo>
+            </annotation>
+         </attribute>
       </complexType>
    </element>
 
index 3100bfa..c3ce7d6 100644 (file)
@@ -41,7 +41,6 @@ import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.contexts.IContextService;
 import org.netxms.client.objects.AbstractNode;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Interface;
@@ -436,11 +435,6 @@ public class InterfacesTab extends ObjectTab
    public void selected()
    {
       super.selected();
-      IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
-      if (contextService != null)
-      {
-         contextService.activateContext("org.netxms.ui.eclipse.objectview.context.InterfacesTab"); //$NON-NLS-1$
-      }
       refresh();
    }
 }
index eaa7892..2bb0c95 100644 (file)
@@ -28,6 +28,8 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IPluginContribution;
+import org.eclipse.ui.contexts.IContextActivation;
+import org.eclipse.ui.contexts.IContextService;
 import org.eclipse.ui.part.ViewPart;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.netxms.client.objects.AbstractObject;
@@ -49,6 +51,8 @@ public abstract class ObjectTab implements IPluginContribution
        private int order;
        private ImageDescriptor icon;
        private Image tabImage;
+       private String contextId;
+   private IContextActivation context = null;
 
        /**
         * Read configuration before widget creation
@@ -68,6 +72,8 @@ public abstract class ObjectTab implements IPluginContribution
                if (name == null)
                        name = "<noname>"; //$NON-NLS-1$
                
+               contextId = ce.getAttribute("contextId");
+               
                try
                {
                        order = Integer.parseInt(ce.getAttribute("order"), 10); //$NON-NLS-1$
@@ -121,8 +127,33 @@ public abstract class ObjectTab implements IPluginContribution
                catch(RuntimeException e)
                {
                }
+
+               if ((contextId != null) && !contextId.isEmpty())
+               {
+         IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
+         if (contextService != null)
+         {
+            context = contextService.activateContext(contextId);
+         }
+               }
        }
        
+   /**
+    * Called by framework when tab is unselected.
+    */
+   public void unselected()
+   {
+      if (context == null)
+         return;
+      
+      IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
+      if (contextService != null)
+      {
+         contextService.deactivateContext(context);
+         context = null;
+      }
+   }
+   
        /**
         * Test if tab should be shown for given NetXMS object. Default implementation always returns true.
         * 
index 56ba186..57a5bf1 100644 (file)
@@ -82,6 +82,7 @@ public class TabbedObjectView extends ViewPart
        private CTabFolder tabFolder;
        private Font headerFont;
        private List<ObjectTab> tabs;
+       private ObjectTab activeTab = null;
        private ISelectionService selectionService = null;
        private ISelectionListener selectionListener = null;
        private IntermediateSelectionProvider selectionProvider;
@@ -129,15 +130,7 @@ public class TabbedObjectView extends ViewPart
                        @Override
                        public void widgetSelected(SelectionEvent e)
                        {
-                               ObjectTab tab = null;
-                               if (e.item != null)
-                               {
-                                       tab = (ObjectTab)((CTabItem)e.item).getData(); 
-                                       tab.selected();
-                                       selectionProvider.setSelectionProviderDelegate(tab.getSelectionProvider());
-                               }
-                               if (sourceProvider != null)
-                                       sourceProvider.updateProperty(SourceProvider.ACTIVE_TAB, tab);
+                               onTabSelectionChange((e.item != null) ? (ObjectTab)((CTabItem)e.item).getData() : null);
                        }
 
                        @Override
@@ -346,6 +339,8 @@ public class TabbedObjectView extends ViewPart
                                }
                                else
                                {
+                                  if (tab == activeTab)
+                                     tab.unselected();
                                        tab.hide();
                                        tab.changeObject(null);
                                }
@@ -357,8 +352,7 @@ public class TabbedObjectView extends ViewPart
                                {
                                        tabFolder.setSelection(0);
                                        ObjectTab tab = (ObjectTab)tabFolder.getItem(0).getData();
-                                       tab.selected();
-                                       selectionProvider.setSelectionProviderDelegate(tab.getSelectionProvider());
+                                       onTabSelectionChange(tab);
                                }
                                catch(IllegalArgumentException e)
                                {
@@ -444,12 +438,39 @@ public class TabbedObjectView extends ViewPart
                        if (tab.getLocalId().equals(tabId))
                        {
                                tabFolder.setSelection(i);
-                               tab.selected();
-                               selectionProvider.setSelectionProviderDelegate(tab.getSelectionProvider());
+                               onTabSelectionChange(tab);
                                break;
                        }
                }
        }
+       
+       /**
+        * Handler for tab selection change
+        * 
+        * @param tab new selection
+        */
+       private void onTabSelectionChange(ObjectTab tab)
+       {
+          if (activeTab == tab)
+             return;
+          
+          if (activeTab != null)
+             activeTab.unselected();
+
+          if (tab != null)
+          {
+         tab.selected();
+         selectionProvider.setSelectionProviderDelegate(tab.getSelectionProvider());
+          }
+          else
+          {
+             selectionProvider.setSelectionProviderDelegate(null);
+          }
+          
+          activeTab = tab;
+      if (sourceProvider != null)
+         sourceProvider.updateProperty(SourceProvider.ACTIVE_TAB, tab);
+       }
 
        /* (non-Javadoc)
         * @see org.eclipse.ui.part.WorkbenchPart#dispose()
index ea44810..bba9d98 100644 (file)
          point="org.netxms.ui.eclipse.objectview.tabs">
       <tab
             class="org.netxms.ui.eclipse.datacollection.objecttabs.LastValues"
+            contextId="org.netxms.ui.eclipse.datacollection.context.LastValues"
             icon="icons/last_values.png"
             id="org.netxms.ui.eclipse.datacollection.objecttabs.LastValues"
             name="%tab.name.LastValues"
index 8153daf..5669bf0 100644 (file)
@@ -25,7 +25,6 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.contexts.IContextService;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.DataCollectionTarget;
 import org.netxms.ui.eclipse.datacollection.widgets.LastValuesWidget;
@@ -111,11 +110,6 @@ public class LastValues extends ObjectTab
        public void selected()
        {
                super.selected();
-               IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
-               if (contextService != null)
-               {
-                       contextService.activateContext("org.netxms.ui.eclipse.datacollection.context.LastValues"); //$NON-NLS-1$
-               }
                refresh();
        }
 }
index ad25361..6f2a767 100644 (file)
             description="Toggle Filter"
             id="org.netxms.ui.eclipse.objectview.commands.show_filter"
             name="Toggle Filter">
+         <state
+               class="org.eclipse.jface.commands.ToggleState"
+               id="org.netxms.ui.eclipse.objectview.commands.show_filter.state">
+         </state>
          <defaultHandler
                class="org.netxms.ui.eclipse.objectview.actions.ToggleFilterHandler">
             <parameter
                   value="default">
             </parameter>
          </defaultHandler>
-         <state
-               class="org.eclipse.jface.commands.ToggleState"
-               id="org.netxms.ui.eclipse.objectview.commands.show_filter.state">
-         </state>
       </command>
    </extension>
    
@@ -89,6 +89,7 @@
       </tab>
       <tab
             class="org.netxms.ui.eclipse.objectview.objecttabs.InterfacesTab"
+            contextId="org.netxms.ui.eclipse.objectview.context.InterfacesTab"
             icon="icons/interface.png"
             id="org.netxms.ui.eclipse.objectview.objecttabs.InterfacesTab"
             name="%tab.name.Interfaces"
          point="org.eclipse.ui.contexts">
       <context
             id="org.netxms.ui.eclipse.objectview.context.InterfacesTab"
-            name="Interfaces Tab">
+            name="Interfaces Tab"
+            parentId="org.eclipse.ui.contexts.window">
       </context>
    </extension>
    <extension
index 585e3f3..546c7fc 100644 (file)
                </appInfo>
             </annotation>
          </attribute>
+         <attribute name="contextId" type="string">
+            <annotation>
+               <documentation>
+                  Context ID
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="identifier" basedOn="org.eclipse.ui.contexts/context/@id"/>
+               </appInfo>
+            </annotation>
+         </attribute>
       </complexType>
    </element>
 
index d5ba400..2b7449c 100644 (file)
@@ -39,7 +39,6 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.contexts.IContextService;
 import org.netxms.client.objects.AbstractNode;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Interface;
@@ -81,7 +80,7 @@ public class InterfacesTab extends ObjectTab
        public static final int COLUMN_STATUS = 19;
        public static final int COLUMN_8021X_PAE_STATE = 20;
        public static final int COLUMN_8021X_BACKEND_STATE = 21;
-       
+
        private SortableTableViewer viewer;
        private InterfaceListLabelProvider labelProvider;
        private Action actionExportToCsv;
@@ -163,6 +162,7 @@ public class InterfacesTab extends ObjectTab
              Messages.get().InterfacesTab_Col8021xPAE, 
              Messages.get().InterfacesTab_Col8021xBackend 
                };
+               
                final int[] widths = { 60, 150, 150, 150, 70, 70, 70, 70, 90, 150, 100, 90, 150, 100, 90, 80, 80, 80, 80, 80, 80, 80 };
                viewer = new SortableTableViewer(interfacesArea, names, widths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
                labelProvider = new InterfaceListLabelProvider();
@@ -338,11 +338,6 @@ public class InterfacesTab extends ObjectTab
    public void selected()
    {
       super.selected();
-      IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
-      if (contextService != null)
-      {
-         contextService.activateContext("org.netxms.ui.eclipse.objectview.context.InterfacesTab"); //$NON-NLS-1$
-      }
       refresh();
    }
 }
index eaa7892..2bb0c95 100644 (file)
@@ -28,6 +28,8 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IPluginContribution;
+import org.eclipse.ui.contexts.IContextActivation;
+import org.eclipse.ui.contexts.IContextService;
 import org.eclipse.ui.part.ViewPart;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.netxms.client.objects.AbstractObject;
@@ -49,6 +51,8 @@ public abstract class ObjectTab implements IPluginContribution
        private int order;
        private ImageDescriptor icon;
        private Image tabImage;
+       private String contextId;
+   private IContextActivation context = null;
 
        /**
         * Read configuration before widget creation
@@ -68,6 +72,8 @@ public abstract class ObjectTab implements IPluginContribution
                if (name == null)
                        name = "<noname>"; //$NON-NLS-1$
                
+               contextId = ce.getAttribute("contextId");
+               
                try
                {
                        order = Integer.parseInt(ce.getAttribute("order"), 10); //$NON-NLS-1$
@@ -121,8 +127,33 @@ public abstract class ObjectTab implements IPluginContribution
                catch(RuntimeException e)
                {
                }
+
+               if ((contextId != null) && !contextId.isEmpty())
+               {
+         IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
+         if (contextService != null)
+         {
+            context = contextService.activateContext(contextId);
+         }
+               }
        }
        
+   /**
+    * Called by framework when tab is unselected.
+    */
+   public void unselected()
+   {
+      if (context == null)
+         return;
+      
+      IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
+      if (contextService != null)
+      {
+         contextService.deactivateContext(context);
+         context = null;
+      }
+   }
+   
        /**
         * Test if tab should be shown for given NetXMS object. Default implementation always returns true.
         * 
index e4b5a7d..f355f53 100644 (file)
@@ -82,6 +82,7 @@ public class TabbedObjectView extends ViewPart
        private CTabFolder tabFolder;
        private Font headerFont;
        private List<ObjectTab> tabs;
+       private ObjectTab activeTab = null;
        private ISelectionService selectionService = null;
        private ISelectionListener selectionListener = null;
        private IntermediateSelectionProvider selectionProvider;
@@ -128,15 +129,7 @@ public class TabbedObjectView extends ViewPart
                        @Override
                        public void widgetSelected(SelectionEvent e)
                        {
-                               ObjectTab tab = null;
-                               if (e.item != null)
-                               {
-                                       tab = (ObjectTab)((CTabItem)e.item).getData(); 
-                                       tab.selected();
-                                       selectionProvider.setSelectionProviderDelegate(tab.getSelectionProvider());
-                               }
-                               if (sourceProvider != null)
-                                       sourceProvider.updateProperty(SourceProvider.ACTIVE_TAB, tab);
+                               onTabSelectionChange((e.item != null) ? (ObjectTab)((CTabItem)e.item).getData() : null);
                        }
 
                        @Override
@@ -345,6 +338,8 @@ public class TabbedObjectView extends ViewPart
                                }
                                else
                                {
+                                  if (tab == activeTab)
+                                     tab.unselected();
                                        tab.hide();
                                        tab.changeObject(null);
                                }
@@ -356,8 +351,7 @@ public class TabbedObjectView extends ViewPart
                                {
                                        tabFolder.setSelection(0);
                                        ObjectTab tab = (ObjectTab)tabFolder.getItem(0).getData();
-                                       tab.selected();
-                                       selectionProvider.setSelectionProviderDelegate(tab.getSelectionProvider());
+                                       onTabSelectionChange(tab);
                                }
                                catch(IllegalArgumentException e)
                                {
@@ -443,12 +437,39 @@ public class TabbedObjectView extends ViewPart
                        if (tab.getLocalId().equals(tabId))
                        {
                                tabFolder.setSelection(i);
-                               tab.selected();
-                               selectionProvider.setSelectionProviderDelegate(tab.getSelectionProvider());
+                               onTabSelectionChange(tab);
                                break;
                        }
                }
        }
+       
+       /**
+        * Handler for tab selection change
+        * 
+        * @param tab new selection
+        */
+       private void onTabSelectionChange(ObjectTab tab)
+       {
+          if (activeTab == tab)
+             return;
+          
+          if (activeTab != null)
+             activeTab.unselected();
+
+          if (tab != null)
+          {
+         tab.selected();
+         selectionProvider.setSelectionProviderDelegate(tab.getSelectionProvider());
+          }
+          else
+          {
+             selectionProvider.setSelectionProviderDelegate(null);
+          }
+          
+          activeTab = tab;
+      if (sourceProvider != null)
+         sourceProvider.updateProperty(SourceProvider.ACTIVE_TAB, tab);
+       }
 
        /* (non-Javadoc)
         * @see org.eclipse.ui.part.WorkbenchPart#dispose()