Move Manage Custom Parsers view menu item to tracing context menu
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 13 Dec 2012 20:49:45 +0000 (15:49 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 14 Dec 2012 16:14:37 +0000 (11:14 -0500)
- The Manage Custom Parsers... command is removed from the Project
Explorer view menu, and added to the Traces folder context menu and to
the trace's Select Trace Type... context sub-menu.
- A bullet icon is added to the selected trace type's category menu item
in the Select Trace Type... context sub-menu.

Change-Id: I77156a8de320264c0fac3db623a2c9cf7831718e
Reviewed-on: https://git.eclipse.org/r/9233
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Bernd Hufmann <bhufmann@gmail.com>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
org.eclipse.linuxtools.tmf.ui/plugin.properties
org.eclipse.linuxtools.tmf.ui/plugin.xml
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectTraceTypeContributionItem.java

index b195d2f1cb80b444853e374915764f8fafc5b34b..73ae5f5b6b5b4ce1d7b428ac69e4423a93c29810 100644 (file)
@@ -102,7 +102,7 @@ command.new_experiment.description = Create Tracing Experiment
 # Custom parsers
 commands.parser.category.name = Parser Commands
 commands.parser.category.description = Parser Commands
-commands.parser.manage = Manage Custom Parsers
+commands.parser.manage = Manage Custom Parsers...
 commands.parser.manage.description = Manage Custom Parsers
  
 contenttype.trace = TMF Trace
index 7007958fef6034b841708702e8ff3cede6942873..ce6443d05fc94fb4603e61b1625b9ce07fddd837 100644 (file)
    </extension>
    <extension
          point="org.eclipse.ui.menus">
-      <menuContribution
-            locationURI="menu:org.eclipse.ui.navigator.ProjectExplorer">
-         <command
-               commandId="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers"
-               id="org.eclipse.linuxtools.tmf.ui.menu.managecustomparsers"
-               style="push">
-         </command>
-      </menuContribution>
       <menuContribution
             locationURI="popup:org.eclipse.ui.popup.any?after=additions">
          <command
                name="org.eclipse.linuxtools.tmf.ui.separator3"
                visible="true">
          </separator>
+         <command
+               commandId="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers"
+               icon="icons/etool16/customparser_wizard.gif"
+               id="org.eclipse.linuxtools.tmf.ui.menu.managecustomparsers"
+               style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <with
+                     variable="selection">
+                  <count
+                        value="1">
+                  </count>
+                  <iterate
+                        operator="and">
+                     <instanceof
+                           value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
+                     </instanceof>
+                  </iterate>
+               </with>
+            </visibleWhen>
+         </command>
          <menu
                label="%command.select_trace_type"
                mnemonic="%command.select_trace_type.mnemonic"
                   class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.SelectTraceTypeContributionItem"
                   id="org.eclipse.linuxtools.tmf.ui.command.select_trace_type.dynamic">
             </dynamic>
+            <separator
+                  name="org.eclipse.linuxtools.tmf.ui.separator6"
+                  visible="true">
+            </separator>
+            <command
+                  commandId="org.eclipse.linuxtools.tmf.ui.command.managecustomparsers"
+                  icon="icons/etool16/customparser_wizard.gif"
+                  style="push">
+            </command>
             <visibleWhen
                   checkEnabled="false">
                <with
index a7cd34f262676b12f9b45967a78a5558a22a6e19..6db3a62f1f722cd0385687dd8fb1e310abbd141e 100644 (file)
@@ -55,6 +55,20 @@ public class SelectTraceTypeContributionItem extends CompoundContributionItem {
 
     @Override
     protected IContributionItem[] getContributionItems() {
+
+        Set<String> selectedTraceTypes = new HashSet<String>();
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        IWorkbenchPage page = window.getActivePage();
+        ISelection selection = page.getSelection();
+        if (selection instanceof StructuredSelection) {
+            for (Object element : ((StructuredSelection) selection).toList()) {
+                if (element instanceof TmfTraceElement) {
+                    TmfTraceElement trace = (TmfTraceElement) element;
+                    selectedTraceTypes.add(trace.getTraceType());
+                }
+            }
+        }
+
         List<IContributionItem> list = new LinkedList<IContributionItem>();
 
         Map<String, MenuManager> categoriesMap = new HashMap<String, MenuManager>();
@@ -62,35 +76,28 @@ public class SelectTraceTypeContributionItem extends CompoundContributionItem {
                 TmfTraceType.TMF_TRACE_TYPE_ID);
         for (IConfigurationElement ce : config) {
             if (ce.getName().equals(TmfTraceType.CATEGORY_ELEM)) {
-                MenuManager subMenu = new MenuManager(ce.getAttribute(TmfTraceType.NAME_ATTR));
-                categoriesMap.put(ce.getAttribute(TmfTraceType.ID_ATTR), subMenu);
+                String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
+                ImageDescriptor icon = isSelectedCategory(categoryId, config, selectedTraceTypes) ? SELECTED_ICON : null;
+                MenuManager subMenu = new MenuManager(ce.getAttribute(TmfTraceType.NAME_ATTR), icon, null);
+                categoriesMap.put(categoryId, subMenu);
                 list.add(subMenu);
             }
         }
-        if (CustomTxtTraceDefinition.loadAll().length > 0) {
-            MenuManager subMenu = new MenuManager(CUSTOM_TXT_CATEGORY);
+        CustomTxtTraceDefinition[] customTxtTraceDefinitions = CustomTxtTraceDefinition.loadAll();
+        if (customTxtTraceDefinitions.length > 0) {
+            ImageDescriptor icon = isSelectedCategory(customTxtTraceDefinitions, selectedTraceTypes) ? SELECTED_ICON : null;
+            MenuManager subMenu = new MenuManager(CUSTOM_TXT_CATEGORY, icon, null);
             categoriesMap.put(CUSTOM_TXT_CATEGORY, subMenu);
             list.add(subMenu);
         }
-        if (CustomXmlTraceDefinition.loadAll().length > 0) {
-            MenuManager subMenu = new MenuManager(CUSTOM_XML_CATEGORY);
+        CustomXmlTraceDefinition[] customXmlTraceDefinitions = CustomXmlTraceDefinition.loadAll();
+        if (customXmlTraceDefinitions.length > 0) {
+            ImageDescriptor icon = isSelectedCategory(customXmlTraceDefinitions, selectedTraceTypes) ? SELECTED_ICON : null;
+            MenuManager subMenu = new MenuManager(CUSTOM_XML_CATEGORY, icon, null);
             categoriesMap.put(CUSTOM_XML_CATEGORY, subMenu);
             list.add(subMenu);
         }
 
-        Set<String> selectedTraceTypes = new HashSet<String>();
-        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        IWorkbenchPage page = window.getActivePage();
-        ISelection selection = page.getSelection();
-        if (selection instanceof StructuredSelection) {
-            for (Object element : ((StructuredSelection) selection).toList()) {
-                if (element instanceof TmfTraceElement) {
-                    TmfTraceElement trace = (TmfTraceElement) element;
-                    selectedTraceTypes.add(trace.getTraceType());
-                }
-            }
-        }
-
         for (IConfigurationElement ce : config) {
             if (ce.getName().equals(TmfTraceType.TYPE_ELEM)) {
                 String traceBundle = ce.getContributor().getName();
@@ -105,7 +112,7 @@ public class SelectTraceTypeContributionItem extends CompoundContributionItem {
         }
 
         // add the custom trace types
-        for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
+        for (CustomTxtTraceDefinition def : customTxtTraceDefinitions) {
             String traceBundle = Activator.getDefault().getBundle().getSymbolicName();
             String traceTypeId = CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$
             String traceIcon = DEFAULT_TRACE_ICON_PATH;
@@ -115,7 +122,7 @@ public class SelectTraceTypeContributionItem extends CompoundContributionItem {
 
             addContributionItem(list, traceBundle, traceTypeId, traceIcon, label, selected, subMenu);
         }
-        for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
+        for (CustomXmlTraceDefinition def : customXmlTraceDefinitions) {
             String traceBundle = Activator.getDefault().getBundle().getSymbolicName();
             String traceTypeId = CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$
             String traceIcon = DEFAULT_TRACE_ICON_PATH;
@@ -164,4 +171,38 @@ public class SelectTraceTypeContributionItem extends CompoundContributionItem {
             list.add(new CommandContributionItem(param));
         }
     }
+
+    private static boolean isSelectedCategory(String categoryId, IConfigurationElement[] config, Set<String> selectedTraceTypes) {
+        for (IConfigurationElement ce : config) {
+            if (ce.getName().equals(TmfTraceType.TYPE_ELEM)) {
+                String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
+                if (selectedTraceTypes.contains(traceTypeId)) {
+                    if (categoryId.equals(ce.getAttribute(TmfTraceType.CATEGORY_ATTR))) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    private static boolean isSelectedCategory(CustomTxtTraceDefinition[] customTxtTraceDefinitions, Set<String> selectedTraceTypes) {
+        for (CustomTxtTraceDefinition def : customTxtTraceDefinitions) {
+            String traceTypeId = CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$
+            if (selectedTraceTypes.contains(traceTypeId)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static boolean isSelectedCategory(CustomXmlTraceDefinition[] customXmlTraceDefinitions, Set<String> selectedTraceTypes) {
+        for (CustomXmlTraceDefinition def : customXmlTraceDefinitions) {
+            String traceTypeId = CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$
+            if (selectedTraceTypes.contains(traceTypeId)) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
This page took 0.029384 seconds and 5 git commands to generate.