From 587660fce293a59e58f2bb532ede76201b9f6d5e Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Thu, 13 Dec 2012 15:49:45 -0500 Subject: [PATCH] Move Manage Custom Parsers view menu item to tracing context menu - 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 IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann Reviewed-by: Patrick Tasse --- .../plugin.properties | 2 +- org.eclipse.linuxtools.tmf.ui/plugin.xml | 38 +++++++-- .../SelectTraceTypeContributionItem.java | 83 ++++++++++++++----- 3 files changed, 93 insertions(+), 30 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.properties b/org.eclipse.linuxtools.tmf.ui/plugin.properties index b195d2f1cb..73ae5f5b6b 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.properties +++ b/org.eclipse.linuxtools.tmf.ui/plugin.properties @@ -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 diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.xml b/org.eclipse.linuxtools.tmf.ui/plugin.xml index 7007958fef..ce6443d05f 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui/plugin.xml @@ -300,14 +300,6 @@ - - - - + + + + + + + + + + + + + + + + selectedTraceTypes = new HashSet(); + 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 list = new LinkedList(); Map categoriesMap = new HashMap(); @@ -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 selectedTraceTypes = new HashSet(); - 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 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 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 selectedTraceTypes) { + for (CustomXmlTraceDefinition def : customXmlTraceDefinitions) { + String traceTypeId = CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$ + if (selectedTraceTypes.contains(traceTypeId)) { + return true; + } + } + return false; + } } -- 2.34.1