From 4b3b667b238a5371df1edcec1ffb6bb446ff797d Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Mon, 25 Aug 2014 14:07:07 -0400 Subject: [PATCH] tmf: Support custom parser category in utils, properties and commands Change-Id: I0b865646d14000259d8f19f9c6a9630ed9a516ef Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/32279 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam --- .../filter/model/TmfFilterEventTypeNode.java | 4 +- .../custom/CustomTxtTraceDefinition.java | 6 +- .../custom/CustomXmlTraceDefinition.java | 6 +- .../tmf/core/project/model/TmfTraceType.java | 127 +++++++++++---- .../handlers/DropAdapterAssistant.java | 9 +- .../SelectElementTypeContributionItem.java | 67 +++----- .../model/TmfCommonProjectElement.java | 32 +--- .../project/model/TmfExperimentElement.java | 2 +- .../model/TmfNavigatorLabelProvider.java | 39 ++--- .../tmf/ui/project/model/TmfTraceElement.java | 10 +- .../tmf/ui/project/model/TmfTraceFolder.java | 3 +- .../ui/project/model/TmfTraceTypeUIUtils.java | 23 +-- .../tmf/ui/views/filter/FilterViewer.java | 152 ++++++++---------- 13 files changed, 232 insertions(+), 248 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java index ab98b3767d..55bead9a1b 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java @@ -98,14 +98,14 @@ public class TmfFilterEventTypeNode extends TmfFilterTreeNode { } /** - * @return TBD + * @return the category and trace type name */ public String getName() { return fName; } /** - * @param name TBD + * @param name the category and trace type name */ public void setName(String name) { this.fName = name; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java index b1406da073..3fcb3160ad 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java @@ -550,7 +550,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { writer.write(xmlString); } - TmfTraceType.addCustomTraceType(categoryName, definitionName); + TmfTraceType.addCustomTraceType(CustomTxtTrace.class, categoryName, definitionName); } catch (ParserConfigurationException e) { Activator.logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$ @@ -903,9 +903,9 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { writer.write(xmlString); } - TmfTraceType.removeCustomTraceType(categoryName, definitionName); + TmfTraceType.removeCustomTraceType(CustomTxtTrace.class, categoryName, definitionName); // Check if default definition needs to be reloaded - TmfTraceType.addCustomTraceType(categoryName, definitionName); + TmfTraceType.addCustomTraceType(CustomTxtTrace.class, categoryName, definitionName); } catch (ParserConfigurationException | SAXException | IOException | TransformerFactoryConfigurationError | TransformerException e) { Activator.logError("Error deleting CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java index 0568f36131..695fede026 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java @@ -410,7 +410,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { writer.write(xmlString); } - TmfTraceType.addCustomTraceType(categoryName, definitionName); + TmfTraceType.addCustomTraceType(CustomXmlTrace.class, categoryName, definitionName); } catch (ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException | IOException | SAXException e) { Activator.logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$ @@ -809,9 +809,9 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { writer.write(xmlString); } - TmfTraceType.removeCustomTraceType(categoryName, definitionName); + TmfTraceType.removeCustomTraceType(CustomXmlTrace.class, categoryName, definitionName); // Check if default definition needs to be reloaded - TmfTraceType.addCustomTraceType(categoryName, definitionName); + TmfTraceType.addCustomTraceType(CustomXmlTrace.class, categoryName, definitionName); } catch (ParserConfigurationException | SAXException | IOException | TransformerFactoryConfigurationError | TransformerException e) { Activator.logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java index c47140af29..e69ea74f02 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java @@ -24,9 +24,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace; import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition; import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace; @@ -176,7 +178,9 @@ public final class TmfTraceType { * The trace type ID * @return The corresponding TraceTypeHelper, or null if there is none for * the specified ID + * @deprecated Use {@link #getTraceType(String)} */ + @Deprecated public static TraceTypeHelper getTraceTypeHelper(String id) { return TRACE_TYPES.get(id); } @@ -287,17 +291,17 @@ public final class TmfTraceType { private static void populateCustomTraceTypes() { // add the custom trace types for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - String traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + def.definitionName; + String traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + def.categoryName + SEPARATOR + def.definitionName; ITmfTrace trace = new CustomTxtTrace(def); - TraceTypeHelper tt = new TraceTypeHelper(traceTypeId, CUSTOM_TXT_CATEGORY, def.definitionName, trace, false, TraceElementType.TRACE); + TraceTypeHelper tt = new TraceTypeHelper(traceTypeId, def.categoryName, def.definitionName, trace, false, TraceElementType.TRACE); TRACE_TYPES.put(traceTypeId, tt); // Deregister trace as signal handler because it is only used for validation TmfSignalManager.deregister(trace); } for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - String traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + def.definitionName; + String traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + def.categoryName + SEPARATOR + def.definitionName; ITmfTrace trace = new CustomXmlTrace(def); - TraceTypeHelper tt = new TraceTypeHelper(traceTypeId, CUSTOM_XML_CATEGORY, def.definitionName, trace, false, TraceElementType.TRACE); + TraceTypeHelper tt = new TraceTypeHelper(traceTypeId, def.categoryName, def.definitionName, trace, false, TraceElementType.TRACE); TRACE_TYPES.put(traceTypeId, tt); // Deregister trace as signal handler because it is only used for validation TmfSignalManager.deregister(trace); @@ -311,19 +315,40 @@ public final class TmfTraceType { * The custom parser category * @param definitionName * The custom parser definition name to add or replace + * @deprecated Use {@link #addCustomTraceType(Class, String, String)} */ + @Deprecated public static void addCustomTraceType(String category, String definitionName) { + if (category.equals(CUSTOM_TXT_CATEGORY)) { + addCustomTraceType(CustomTxtTrace.class, category, definitionName); + } else if (category.equals(CUSTOM_XML_CATEGORY)) { + addCustomTraceType(CustomXmlTrace.class, category, definitionName); + } + } + + /** + * Add or replace a custom trace type + * + * @param traceClass + * The custom trace class, either {@link CustomTxtTrace} or + * {@link CustomXmlTrace} + * @param category + * The custom parser category + * @param definitionName + * The custom parser definition name to add or replace + */ + public static void addCustomTraceType(Class traceClass, String category, String definitionName) { String traceTypeId = null; ITmfTrace trace = null; - if (category.equals(CUSTOM_TXT_CATEGORY)) { - traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + definitionName; + if (traceClass.equals(CustomTxtTrace.class)) { + traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName; CustomTxtTraceDefinition def = CustomTxtTraceDefinition.load(category, definitionName); if (def != null) { trace = new CustomTxtTrace(def); } - } else if (category.equals(CUSTOM_XML_CATEGORY)) { - traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + definitionName; + } else if (traceClass.equals(CustomXmlTrace.class)) { + traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName; CustomXmlTraceDefinition def = CustomXmlTraceDefinition.load(category, definitionName); if (def != null) { trace = new CustomXmlTrace(def); @@ -349,20 +374,33 @@ public final class TmfTraceType { * The custom parser category * @param definitionName * The custom parser definition name to add or replace + * @deprecated Use {@link #removeCustomTraceType(Class, String, String)} */ + @Deprecated public static void removeCustomTraceType(String category, String definitionName) { if (category.equals(CUSTOM_TXT_CATEGORY)) { - String traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + definitionName; - TraceTypeHelper helper = TRACE_TYPES.remove(traceTypeId); - if (helper != null) { - helper.getTrace().dispose(); - } + removeCustomTraceType(CustomTxtTrace.class, category, definitionName); } else if (category.equals(CUSTOM_XML_CATEGORY)) { - String traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + definitionName; - TraceTypeHelper helper = TRACE_TYPES.remove(traceTypeId); - if (helper != null) { - helper.getTrace().dispose(); - } + removeCustomTraceType(CustomXmlTrace.class, category, definitionName); + } + } + + /** + * Remove a custom trace type + * + * @param traceClass + * The custom trace class, either {@link CustomTxtTrace} or + * {@link CustomXmlTrace} + * @param category + * The custom parser category + * @param definitionName + * The custom parser definition name to add or replace + */ + public static void removeCustomTraceType(Class traceClass, String category, String definitionName) { + String traceTypeId = traceClass.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName; + TraceTypeHelper helper = TRACE_TYPES.remove(traceTypeId); + if (helper != null) { + helper.getTrace().dispose(); } } @@ -561,22 +599,15 @@ public final class TmfTraceType { * @param traceType * The trace type in human form (category:name) * @return the trace type ID or null if the trace is not a custom one + * @deprecated Use {@link #getTraceTypeId(String, String)} */ + @Deprecated public static String getCustomTraceTypeId(String traceType) { - String traceTypeId = null; - - // do custom trace stuff here String traceTypeToken[] = traceType.split(":", 2); //$NON-NLS-1$ if (traceTypeToken.length == 2) { - final boolean startsWithTxt = traceType.startsWith(TmfTraceType.CUSTOM_TXT_CATEGORY); - final boolean startsWithXML = traceType.startsWith(TmfTraceType.CUSTOM_XML_CATEGORY); - if (startsWithTxt) { - traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + traceTypeToken[1]; - } else if (startsWithXML) { - traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + traceTypeToken[1]; - } + return getTraceTypeId(traceTypeToken[0], traceTypeToken[1]); } - return traceTypeId; + return null; } /** @@ -586,11 +617,16 @@ public final class TmfTraceType { * @param traceType * the trace type in human form (category:name) * @return true if the trace is a custom type + * @deprecated Use {@link #getTraceTypeId(String, String)} and check prefix */ + @Deprecated public static boolean isCustomTrace(String traceType) { - final boolean startsWithTxt = traceType.startsWith(TmfTraceType.CUSTOM_TXT_CATEGORY); - final boolean startsWithXML = traceType.startsWith(TmfTraceType.CUSTOM_XML_CATEGORY); - return (startsWithTxt || startsWithXML); + String traceTypeId = getCustomTraceTypeId(traceType); + if (traceTypeId != null) { + return traceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName() + SEPARATOR) || + traceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName() + SEPARATOR); + } + return false; } /** @@ -625,4 +661,31 @@ public final class TmfTraceType { throw new IllegalArgumentException("Invalid trace type string: " + traceType); //$NON-NLS-1$ } + /** + * Get the trace type id for a resource + * + * @param resource + * the resource + * @return the trace type id or null if it is not set + * @throws CoreException + * if the trace type id cannot be accessed + * @since 3.1 + */ + public static String getTraceTypeId(IResource resource) throws CoreException { + String traceTypeId = resource.getPersistentProperties().get(TmfCommonConstants.TRACETYPE); + // Fix custom trace type id with old class name or without category name for backward compatibility + if (traceTypeId != null) { + int index = traceTypeId.lastIndexOf(':'); + if (index != -1) { + if (traceTypeId.contains(CustomTxtTrace.class.getSimpleName() + ':') && traceTypeId.indexOf(':') == index) { + traceTypeId = CustomTxtTrace.class.getCanonicalName() + ':' + + TmfTraceType.CUSTOM_TXT_CATEGORY + traceTypeId.substring(index); + } else if (traceTypeId.contains(CustomXmlTrace.class.getSimpleName() + ':') && traceTypeId.indexOf(':') == index) { + traceTypeId = CustomXmlTrace.class.getCanonicalName() + ':' + + TmfTraceType.CUSTOM_XML_CATEGORY + traceTypeId.substring(index); + } + } + } + return traceTypeId; + } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java index 2d75b98e9c..ab6f0823ac 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java @@ -20,7 +20,6 @@ import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; -import java.util.Map; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -35,7 +34,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.URIUtil; import org.eclipse.jface.operation.IRunnableWithProgress; @@ -533,8 +531,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { IPath location = resource.getLocation(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); try { - Map properties = resource.getPersistentProperties(); - String traceType = properties.get(TmfCommonConstants.TRACETYPE); + String traceType = TmfTraceType.getTraceTypeId(resource); TraceTypeHelper traceTypeHelper = TmfTraceType.getTraceType(traceType); if (resource instanceof IFolder) { @@ -631,7 +628,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { if (folder.exists()) { try { for (IResource member : folder.members()) { - if (TmfTrace.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) { + if (TmfTrace.class.getCanonicalName().equals(TmfTraceType.getTraceTypeId(member))) { member.delete(true, null); } } @@ -643,7 +640,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { private static void setTraceType(IResource traceResource) { try { - String traceType = traceResource.getPersistentProperties().get(TmfCommonConstants.TRACETYPE); + String traceType = TmfTraceType.getTraceTypeId(traceResource); TraceTypeHelper traceTypeHelper = TmfTraceType.getTraceType(traceType); if (traceTypeHelper == null) { traceTypeHelper = TmfTraceTypeUIUtils.selectTraceType(traceResource.getLocation().toOSString(), null, null); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectElementTypeContributionItem.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectElementTypeContributionItem.java index 7ee71631f2..56e911041f 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectElementTypeContributionItem.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectElementTypeContributionItem.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.eclipse.core.runtime.IConfigurationElement; @@ -173,39 +174,23 @@ public class SelectElementTypeContributionItem extends CompoundContributionItem * Add the custom txt and xml trace type to the contribution items for * traces */ - CustomTxtTraceDefinition[] customTxtTraceDefinitions = CustomTxtTraceDefinition.loadAll(); - if (customTxtTraceDefinitions.length > 0) { - ImageDescriptor icon = isSelectedCategory(customTxtTraceDefinitions, selectedTraceTypes) ? SELECTED_ICON : null; - MenuManager subMenu = new MenuManager(TmfTraceType.CUSTOM_TXT_CATEGORY, icon, null); - categoriesMap.put(TmfTraceType.CUSTOM_TXT_CATEGORY, subMenu); - list.add(subMenu); - } - CustomXmlTraceDefinition[] customXmlTraceDefinitions = CustomXmlTraceDefinition.loadAll(); - if (customXmlTraceDefinitions.length > 0) { - ImageDescriptor icon = isSelectedCategory(customXmlTraceDefinitions, selectedTraceTypes) ? SELECTED_ICON : null; - MenuManager subMenu = new MenuManager(TmfTraceType.CUSTOM_XML_CATEGORY, icon, null); - categoriesMap.put(TmfTraceType.CUSTOM_XML_CATEGORY, subMenu); - list.add(subMenu); - } - - // add the custom trace types - for (CustomTxtTraceDefinition def : customTxtTraceDefinitions) { + for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { String traceBundle = Activator.getDefault().getBundle().getSymbolicName(); - String traceTypeId = CustomTxtTrace.class.getCanonicalName() + ':' + def.definitionName; + String traceTypeId = CustomTxtTrace.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName; String traceIcon = DEFAULT_TRACE_ICON_PATH; String label = def.definitionName; boolean selected = selectedTraceTypes.contains(traceTypeId); - MenuManager subMenu = categoriesMap.get(TmfTraceType.CUSTOM_TXT_CATEGORY); + MenuManager subMenu = getCategorySubMenu(list, categoriesMap, def.categoryName, selected); addContributionItem(list, traceBundle, traceTypeId, traceIcon, label, selected, subMenu); } - for (CustomXmlTraceDefinition def : customXmlTraceDefinitions) { + for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { String traceBundle = Activator.getDefault().getBundle().getSymbolicName(); - String traceTypeId = CustomXmlTrace.class.getCanonicalName() + ':' + def.definitionName; + String traceTypeId = CustomXmlTrace.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName; String traceIcon = DEFAULT_TRACE_ICON_PATH; String label = def.definitionName; boolean selected = selectedTraceTypes.contains(traceTypeId); - MenuManager subMenu = categoriesMap.get(TmfTraceType.CUSTOM_XML_CATEGORY); + MenuManager subMenu = getCategorySubMenu(list, categoriesMap, def.categoryName, selected); addContributionItem(list, traceBundle, traceTypeId, traceIcon, label, selected, subMenu); } @@ -214,6 +199,24 @@ public class SelectElementTypeContributionItem extends CompoundContributionItem return list.toArray(new IContributionItem[list.size()]); } + private static MenuManager getCategorySubMenu(List list, + Map categoriesMap, String categoryName, boolean selected) { + for (Entry entry : categoriesMap.entrySet()) { + MenuManager subMenu = entry.getValue(); + if (subMenu.getMenuText().equals(categoryName)) { + if (selected) { + subMenu.setImageDescriptor(SELECTED_ICON); + } + return subMenu; + } + } + ImageDescriptor icon = selected ? SELECTED_ICON : null; + MenuManager subMenu = new MenuManager(categoryName, icon, null); + categoriesMap.put(categoryName, subMenu); + list.add(subMenu); + return subMenu; + } + private static void addContributionItem(List list, String traceBundle, String traceTypeId, String traceIcon, String label, boolean selected, @@ -263,24 +266,4 @@ public class SelectElementTypeContributionItem extends CompoundContributionItem } return false; } - - private static boolean isSelectedCategory(CustomTxtTraceDefinition[] customTxtTraceDefinitions, Set selectedTraceTypes) { - for (CustomTxtTraceDefinition def : customTxtTraceDefinitions) { - String traceTypeId = CustomTxtTrace.class.getCanonicalName() + ':' + def.definitionName; - 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; - if (selectedTraceTypes.contains(traceTypeId)) { - return true; - } - } - return false; - } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfCommonProjectElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfCommonProjectElement.java index 643335766b..0ab4546d31 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfCommonProjectElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfCommonProjectElement.java @@ -36,10 +36,6 @@ import org.eclipse.linuxtools.internal.tmf.ui.Activator; import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper; import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager; -import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace; -import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition; -import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace; -import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTraceDefinition; import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; @@ -114,22 +110,7 @@ public abstract class TmfCommonProjectElement extends TmfProjectModelElement { Class traceClass = null; - if (helper == null && getTraceType() != null) { - if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) { - for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - if (fTraceTypeId.equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ - traceClass = CustomTxtTrace.class; - } - } - } - if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) { - for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - if (fTraceTypeId.equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ - traceClass = CustomTxtTrace.class; - } - } - } - } else if (helper != null) { + if (helper != null) { traceClass = helper.getTraceClass(); } @@ -180,12 +161,12 @@ public abstract class TmfCommonProjectElement extends TmfProjectModelElement { } /** - * Refreshes the trace type filed by reading the trace type persistent - * property of the resource referenece. + * Refreshes the trace type field by reading the trace type persistent + * property of the resource. */ public void refreshTraceType() { try { - fTraceTypeId = getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); + fTraceTypeId = TmfTraceType.getTraceTypeId(getResource()); } catch (CoreException e) { Activator.getDefault().logError(NLS.bind(Messages.TmfCommonProjectElement_ErrorRefreshingProperty, getName()), e); } @@ -371,9 +352,10 @@ public abstract class TmfCommonProjectElement extends TmfProjectModelElement { if (trace instanceof IFolder) { IFolder folderTrace = (IFolder) trace; for (IResource member : folderTrace.members()) { - if (TmfTrace.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) { + String traceTypeId = TmfTraceType.getTraceTypeId(member); + if (TmfTrace.class.getCanonicalName().equals(traceTypeId)) { member.delete(true, null); - } else if (TmfExperiment.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) { + } else if (TmfExperiment.class.getCanonicalName().equals(traceTypeId)) { member.delete(true, null); } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java index 3af7203515..3ca82bf5b0 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java @@ -268,7 +268,7 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr IPath location = resource.getLocation(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); try { - String traceTypeId = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); + String traceTypeId = TmfTraceType.getTraceTypeId(trace.getResource()); TraceTypeHelper traceType = TmfTraceType.getTraceType(traceTypeId); if (resource instanceof IFolder) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java index de3f0bf0c6..d1d7cbb6db 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java @@ -15,7 +15,6 @@ package org.eclipse.linuxtools.tmf.ui.project.model; import java.net.URL; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ImageDescriptor; @@ -24,7 +23,6 @@ import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.StyledString.Styler; import org.eclipse.linuxtools.internal.tmf.ui.Activator; -import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType.TraceElementType; import org.eclipse.swt.graphics.Image; @@ -109,31 +107,28 @@ public class TmfNavigatorLabelProvider implements ICommonLabelProvider, IStyledL if (element instanceof TmfCommonProjectElement) { TmfCommonProjectElement trace = (TmfCommonProjectElement) element; - try { - String traceType = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); - if (traceType == null || TmfTraceType.getTraceType(traceType) == null) { - // request the label to the Eclipse platform - return fWorkspaceLabelProvider.getImage(((TmfCommonProjectElement) element).getResource()); - } + String traceType = trace.getTraceType(); + if (traceType == null || TmfTraceType.getTraceType(traceType) == null) { + // request the label to the Eclipse platform + return fWorkspaceLabelProvider.getImage(((TmfCommonProjectElement) element).getResource()); + } - IConfigurationElement traceUIAttributes = TmfTraceTypeUIUtils.getTraceUIAttributes(traceType, (element instanceof TmfTraceElement) ? TraceElementType.TRACE : TraceElementType.EXPERIMENT); - if (traceUIAttributes != null) { - String iconAttr = traceUIAttributes.getAttribute(TmfTraceTypeUIUtils.ICON_ATTR); - if (iconAttr != null) { - String name = traceUIAttributes.getContributor().getName(); - if (name != null) { - Bundle bundle = Platform.getBundle(name); - if (bundle != null) { - Image image = loadIcon(bundle, iconAttr); - if (image != null) { - return image; - } + IConfigurationElement traceUIAttributes = TmfTraceTypeUIUtils.getTraceUIAttributes(traceType, (element instanceof TmfTraceElement) ? TraceElementType.TRACE : TraceElementType.EXPERIMENT); + if (traceUIAttributes != null) { + String iconAttr = traceUIAttributes.getAttribute(TmfTraceTypeUIUtils.ICON_ATTR); + if (iconAttr != null) { + String name = traceUIAttributes.getContributor().getName(); + if (name != null) { + Bundle bundle = Platform.getBundle(name); + if (bundle != null) { + Image image = loadIcon(bundle, iconAttr); + if (image != null) { + return image; } } } - } - } catch (CoreException e) { + } if (element instanceof TmfTraceElement) { return fDefaultTraceIcon; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java index 66b06438c5..967943662c 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java @@ -204,14 +204,14 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF if (getTraceType() != null) { if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) { for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ + if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) { return new CustomTxtTrace(def); } } } if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) { for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ + if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) { return new CustomXmlTrace(def); } } @@ -240,14 +240,14 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF if (getTraceType() != null) { if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) { for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ + if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) { return new CustomTxtEvent(def); } } } if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) { for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ + if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) { return new CustomXmlEvent(def); } } @@ -450,7 +450,7 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF if (sfTraceType.equals(id)) { if (getTraceType() != null) { - TraceTypeHelper helper = TmfTraceType.getTraceTypeHelper(getTraceType()); + TraceTypeHelper helper = TmfTraceType.getTraceType(getTraceType()); if (helper != null) { return helper.getCategoryName() + " : " + helper.getName(); //$NON-NLS-1$ } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceFolder.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceFolder.java index 5e2ad50b53..d7f9dfd9e1 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceFolder.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceFolder.java @@ -22,7 +22,6 @@ import java.util.Map; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; import org.eclipse.ui.views.properties.IPropertyDescriptor; @@ -112,7 +111,7 @@ public class TmfTraceFolder extends TmfProjectModelElement implements IPropertyS for (IResource resource : members) { String name = resource.getName(); boolean isFolder = resource instanceof IFolder && - (resource.getPersistentProperty(TmfCommonConstants.TRACETYPE) == null); + (TmfTraceType.getTraceTypeId(resource) == null); ITmfProjectModelElement element = childrenMap.get(name); if (isFolder && !(element instanceof TmfTraceFolder) && !(element instanceof TmfTraceElement)) { if (TmfTraceType.isDirectoryTrace(resource.getLocationURI().getPath())) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java index 2b1e67acec..4d45d0029d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java @@ -94,8 +94,6 @@ public final class TmfTraceTypeUIUtils { /** Extension point attribute 'class' (attribute of other elements) */ public static final String CLASS_ATTR = "class"; //$NON-NLS-1$ - private static final char SEPARATOR = ':'; - private TmfTraceTypeUIUtils() { } @@ -116,7 +114,8 @@ public final class TmfTraceTypeUIUtils { * Only return the leaves of the trace types. Ignore custom trace types. */ private static boolean isUnique(TraceTypeHelper trace, List> set) { - if (isCustomTraceId(trace.getCanonicalName())) { + if (trace.getTraceClass().equals(CustomTxtTrace.class) || + trace.getTraceClass().equals(CustomXmlTrace.class)) { return true; } // check if the trace type is the leaf. we make an instance of the trace @@ -132,22 +131,6 @@ public final class TmfTraceTypeUIUtils { return count == 0; } - /** - * Is the trace type id a custom (user-defined) trace type. These are the - * traces like : text and xml defined by the custom trace wizard. - * - * @param traceTypeId - * the trace type id - * @return true if the trace is a custom type - */ - private static boolean isCustomTraceId(String traceTypeId) { - TraceTypeHelper traceType = TmfTraceType.getTraceType(traceTypeId); - if (traceType != null) { - return TmfTraceType.isCustomTrace(traceType.getCategoryName() + SEPARATOR + traceType.getName()); - } - return false; - } - private static TraceTypeHelper getTraceTypeToSet(List> candidates, Shell shell) { final Map names = new HashMap<>(); Shell shellToShow = new Shell(shell); @@ -185,7 +168,7 @@ public final class TmfTraceTypeUIUtils { display.sleep(); } } - return TmfTraceType.getTraceTypeHelper(candidatesToSet[0]); + return TmfTraceType.getTraceType(candidatesToSet[0]); } /** diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterViewer.java index fa32a8a57c..fa2456a58f 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/filter/FilterViewer.java @@ -15,9 +15,9 @@ package org.eclipse.linuxtools.tmf.ui.views.filter; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -48,6 +48,7 @@ import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode; import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode; import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode; import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterTreeNode; +import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTraceDefinition; import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn; import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtEvent; import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition; @@ -83,6 +84,8 @@ import org.eclipse.swt.widgets.TreeItem; class FilterViewer extends Composite { + private static final String SEP = " : "; //$NON-NLS-1$ + private TreeViewer fViewer; private Composite fComposite; @@ -362,6 +365,28 @@ class FilterViewer extends Composite { setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); } + protected Map getEventsTypeMap() { + Map eventsTypeMap = new TreeMap<>(); + for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { + String categoryPrefix = ""; //$NON-NLS-1$ + String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR); + if (categoryId != null) { + categoryPrefix = TmfTraceType.getCategoryName(categoryId) + SEP; + } + String text = categoryPrefix + ce.getAttribute(TmfTraceType.NAME_ATTR); + eventsTypeMap.put(text, ce); + } + for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { + String text = def.categoryName + SEP + def.definitionName; + eventsTypeMap.put(text, def); + } + for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { + String text = def.categoryName + SEP + def.definitionName; + eventsTypeMap.put(text, def); + } + return eventsTypeMap; + } + protected String[] getFieldsList(ITmfFilterTreeNode node) { ArrayList fieldsList = new ArrayList<>(); ITmfFilterTreeNode curNode = node; @@ -392,7 +417,7 @@ class FilterViewer extends Composite { } if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) { for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ + if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName)) { for (OutputColumn output : def.outputs) { fieldsList.add(output.name); } @@ -402,7 +427,7 @@ class FilterViewer extends Composite { } if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) { for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ + if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName)) { for (OutputColumn output : def.outputs) { fieldsList.add(output.name); } @@ -422,44 +447,37 @@ class FilterViewer extends Composite { fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT); fieldsList.add(""); //$NON-NLS-1$ - for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { - try { - ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); - ITmfEventType eventType = event.getType(); - if (eventType != null && eventType.getFieldNames().size() > 0) { - String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR); - if (categoryId != null) { - fieldsList.add('[' + TmfTraceType.getCategoryName(categoryId) + " : " //$NON-NLS-1$ - + ce.getAttribute(TmfTraceType.NAME_ATTR) + ']'); - } else { - fieldsList.add('[' + ce.getAttribute(TmfTraceType.NAME_ATTR) + ']'); + for (Entry eventTypeEntry : getEventsTypeMap().entrySet()) { + Object value = eventTypeEntry.getValue(); + if (value instanceof IConfigurationElement) { + IConfigurationElement ce = (IConfigurationElement) value; + try { + ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); + ITmfEventType eventType = event.getType(); + if (eventType != null && eventType.getFieldNames().size() > 0) { + String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR); + if (categoryId != null) { + fieldsList.add('[' + TmfTraceType.getCategoryName(categoryId) + SEP + + ce.getAttribute(TmfTraceType.NAME_ATTR) + ']'); + } else { + fieldsList.add('[' + ce.getAttribute(TmfTraceType.NAME_ATTR) + ']'); + } + for (String field : eventType.getFieldNames()) { + fieldsList.add(field); + } + fieldsList.add(""); //$NON-NLS-1$ } - for (String field : eventType.getFieldNames()) { - fieldsList.add(field); + } catch (CoreException e) { + } + } else if (value instanceof CustomTraceDefinition) { + CustomTraceDefinition def = (CustomTraceDefinition) value; + if (def.outputs.size() > 0) { + fieldsList.add('[' + def.categoryName + SEP + def.definitionName + ']'); + for (OutputColumn output : def.outputs) { + fieldsList.add(output.name); } fieldsList.add(""); //$NON-NLS-1$ } - } catch (CoreException e) { - } - } - for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - if (def.outputs.size() > 0) { - fieldsList.add("[" + def.categoryName + //$NON-NLS-1$ - " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - for (OutputColumn output : def.outputs) { - fieldsList.add(output.name); - } - fieldsList.add(""); //$NON-NLS-1$ - } - } - for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - if (def.outputs.size() > 0) { - fieldsList.add("[" + def.categoryName + //$NON-NLS-1$ - " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - for (OutputColumn output : def.outputs) { - fieldsList.add(output.name); - } - fieldsList.add(""); //$NON-NLS-1$ } } return fieldsList.toArray(new String[0]); @@ -533,27 +551,7 @@ class FilterViewer extends Composite { fTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fTypeCombo.setItems(fEventsTypeMap.keySet().toArray(new String[0])); if (fNode.getEventType() != null) { - for (Entry eventTypeEntry : fEventsTypeMap.entrySet()) { - Object value = eventTypeEntry.getValue(); - if (value instanceof IConfigurationElement) { - IConfigurationElement ce = (IConfigurationElement) value; - if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(fNode.getEventType())) { - fTypeCombo.setText(eventTypeEntry.getKey()); - } - } else if (value instanceof CustomTxtTraceDefinition) { - CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value; - String eventType = CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$ - if (eventType.equals(fNode.getEventType())) { - fTypeCombo.setText(eventTypeEntry.getKey()); - } - } else if (value instanceof CustomXmlTraceDefinition) { - CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value; - String eventType = CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$ - if (eventType.equals(fNode.getEventType())) { - fTypeCombo.setText(eventTypeEntry.getKey()); - } - } - } + fTypeCombo.setText(fNode.getName()); } fTypeCombo.addModifyListener(new ModifyListener() { @Override @@ -564,15 +562,21 @@ class FilterViewer extends Composite { if (value instanceof IConfigurationElement) { IConfigurationElement ce = (IConfigurationElement) value; fNode.setEventType(ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR)); - fNode.setName(ce.getAttribute(TmfTraceType.NAME_ATTR)); + String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR); + if (categoryId != null) { + fNode.setName(TmfTraceType.getCategoryName(categoryId) + SEP + + ce.getAttribute(TmfTraceType.NAME_ATTR)); + } else { + fNode.setName(ce.getAttribute(TmfTraceType.NAME_ATTR)); + } } else if (value instanceof CustomTxtTraceDefinition) { CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value; - fNode.setEventType(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$ - fNode.setName(def.definitionName); + fNode.setEventType(CustomTxtEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName); + fNode.setName(def.categoryName + SEP + def.definitionName); } else if (value instanceof CustomXmlTraceDefinition) { CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value; - fNode.setEventType(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$ - fNode.setName(def.definitionName); + fNode.setEventType(CustomXmlEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName); + fNode.setName(def.categoryName + SEP + def.definitionName); } fViewer.refresh(fNode); break; @@ -581,28 +585,6 @@ class FilterViewer extends Composite { } }); } - - protected Map getEventsTypeMap() { - Map eventsTypeMap = new LinkedHashMap<>(); - for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { - String categoryPrefix = ""; //$NON-NLS-1$ - String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR); - if (categoryId != null) { - categoryPrefix = TmfTraceType.getCategoryName(categoryId) + " : "; //$NON-NLS-1$ - } - String text = categoryPrefix + ce.getAttribute(TmfTraceType.NAME_ATTR); - eventsTypeMap.put(text, ce); - } - for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - String text = def.categoryName + " : " + def.definitionName; //$NON-NLS-1$ - eventsTypeMap.put(text, def); - } - for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - String text = def.categoryName + " : " + def.definitionName; //$NON-NLS-1$ - eventsTypeMap.put(text, def); - } - return eventsTypeMap; - } } private class FilterAndNodeComposite extends FilterBaseNodeComposite { -- 2.34.1