tmf: Replace TmfFilterEventTypeNode with TmfFilterTraceTypeNode
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 18 Dec 2014 16:39:14 +0000 (11:39 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 4 Feb 2015 16:36:35 +0000 (11:36 -0500)
The filtering on event type is replaced with filtering on trace type.
This is done because in the upcoming change to replace field-based
filtering with aspect-based filtering, the aspect list is dependent on
the trace type and not on the event type. Furthermore filtering on event
type will still be possible since an 'Event type' aspect is available.

With this patch, the narrowing of field list based on event type for
child nodes of an EVENTTYPE node is no longer supported. In the
upcoming patch the aspect list will be narrowed based on trace type for
child nodes of a TRACETYPE node.

The handling of trace type labels "category : name" is consolidated in
utility classes TmfTraceType and TraceTypeHelper.

Change-Id: Ie911e9c63ecf7e219540e038fd82e70415e2e0ee
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/38514
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
17 files changed:
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterEventTypeNode.java [deleted file]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterTraceTypeNode.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterTreeNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/xml/TmfFilterContentHandler.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/xml/TmfFilterXMLWriter.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTrace.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTrace.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/project/model/TmfTraceType.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/project/model/TraceTypeHelper.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/ITmfTrace.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTrace.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfOpenTraceHelper.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfTraceElement.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/filter/FilterTreeLabelProvider.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/filter/FilterViewer.java

diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterEventTypeNode.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterEventTypeNode.java
deleted file mode 100644 (file)
index 9d81d97..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Patrick Tasse - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.core.filter.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-
-/**
- * Filter node for an event
- *
- * @version 1.0
- * @author Patrick Tasse
- */
-@SuppressWarnings("javadoc")
-public class TmfFilterEventTypeNode extends TmfFilterTreeNode {
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = super.hashCode();
-        result = prime * result + ((fName == null) ? 0 : fName.hashCode());
-        result = prime * result + ((fType == null) ? 0 : fType.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        TmfFilterEventTypeNode other = (TmfFilterEventTypeNode) obj;
-        if (fName == null) {
-            if (other.fName != null) {
-                return false;
-            }
-        } else if (!fName.equals(other.fName)) {
-            return false;
-        }
-        if (fType == null) {
-            if (other.fType != null) {
-                return false;
-            }
-        } else if (!fType.equals(other.fType)) {
-            return false;
-        }
-        return true;
-    }
-
-    public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
-    public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
-    public static final String NAME_ATTR = "name"; //$NON-NLS-1$
-
-    private String fType;
-    private String fName;
-
-    /**
-     * @param parent the parent node
-     */
-    public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {
-        super(parent);
-    }
-
-    @Override
-    public String getNodeName() {
-        return NODE_NAME;
-    }
-
-    /**
-     * @return the event type
-     */
-    public String getEventType() {
-        return fType;
-    }
-
-    /**
-     * @param type the event type
-     */
-    public void setEventType(String type) {
-        this.fType = type;
-    }
-
-    /**
-     * @return the category and trace type name
-     */
-    public String getName() {
-        return fName;
-    }
-
-    /**
-     * @param name the category and trace type name
-     */
-    public void setName(String name) {
-        this.fName = name;
-    }
-
-    @Override
-    public boolean matches(ITmfEvent event) {
-        boolean match = false;
-        if (fType.contains(":")) { //$NON-NLS-1$
-            // special case for custom parsers
-            if (fType.startsWith(event.getClass().getCanonicalName())) {
-                if (fType.endsWith(event.getType().getName())) {
-                    match = true;
-                }
-            }
-        } else {
-            if (event.getClass().getCanonicalName().equals(fType)) {
-                match = true;
-            }
-        }
-        if (match) {
-            // There should be at most one child
-            for (ITmfFilterTreeNode node : getChildren()) {
-                if (! node.matches(event)) {
-                    return false;
-                }
-            }
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public List<String> getValidChildren() {
-        if (getChildrenCount() == 0) {
-            return super.getValidChildren();
-        }
-        return new ArrayList<>(0); // only one child allowed
-    }
-
-    @Override
-    public String toString() {
-        StringBuffer buf = new StringBuffer();
-        buf.append("EventType is " + fName); //$NON-NLS-1$
-        if (getChildrenCount() > 0) {
-            buf.append(" and "); //$NON-NLS-1$
-        }
-        if (getChildrenCount() > 1) {
-            buf.append("( "); //$NON-NLS-1$
-        }
-        for (int i = 0; i < getChildrenCount(); i++) {
-            ITmfFilterTreeNode node = getChildren()[i];
-            buf.append(node.toString());
-            if (i < getChildrenCount() - 1) {
-                buf.append(" and "); //$NON-NLS-1$
-            }
-        }
-        if (getChildrenCount() > 1) {
-            buf.append(" )"); //$NON-NLS-1$
-        }
-        return buf.toString();
-    }
-}
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterTraceTypeNode.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterTraceTypeNode.java
new file mode 100644 (file)
index 0000000..962c660
--- /dev/null
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.filter.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+
+/**
+ * Filter node for an trace type
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterTraceTypeNode extends TmfFilterTreeNode {
+
+    public static final String NODE_NAME = "TRACETYPE"; //$NON-NLS-1$
+    public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
+    public static final String NAME_ATTR = "name"; //$NON-NLS-1$
+
+    private String fTraceTypeId;
+    private Class<? extends ITmfTrace> fTraceClass;
+    private String fName;
+
+    /**
+     * @param parent the parent node
+     */
+    public TmfFilterTraceTypeNode(ITmfFilterTreeNode parent) {
+        super(parent);
+    }
+
+    @Override
+    public String getNodeName() {
+        return NODE_NAME;
+    }
+
+    /**
+     * @return the trace type id
+     */
+    public String getTraceTypeId() {
+        return fTraceTypeId;
+    }
+
+    /**
+     * @param traceTypeId the trace type id
+     */
+    public void setTraceTypeId(String traceTypeId) {
+        this.fTraceTypeId = traceTypeId;
+    }
+
+    /**
+     * @return the trace class
+     */
+    public Class<? extends ITmfTrace> getTraceClass() {
+        return fTraceClass;
+    }
+
+    /**
+     * @param traceClass the trace class
+     */
+    public void setTraceClass(Class<? extends ITmfTrace> traceClass) {
+        this.fTraceClass = traceClass;
+    }
+
+    /**
+     * @return the category and trace type name
+     */
+    public String getName() {
+        return fName;
+    }
+
+    /**
+     * @param name the category and trace type name
+     */
+    public void setName(String name) {
+        this.fName = name;
+    }
+
+    @Override
+    public boolean matches(ITmfEvent event) {
+        boolean match = false;
+        ITmfTrace trace = event.getTrace();
+        if (trace.getClass().equals(fTraceClass)) {
+            if (fTraceTypeId != null) {
+                if (fTraceTypeId.equals(trace.getTraceTypeId())) {
+                    match = true;
+                }
+            } else {
+                match = true;
+            }
+        }
+        if (match) {
+            // There should be at most one child
+            for (ITmfFilterTreeNode node : getChildren()) {
+                if (! node.matches(event)) {
+                    return false;
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public List<String> getValidChildren() {
+        if (getChildrenCount() == 0) {
+            return super.getValidChildren();
+        }
+        return new ArrayList<>(0); // only one child allowed
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        buf.append("TraceType is " + fName); //$NON-NLS-1$
+        if (getChildrenCount() > 0) {
+            buf.append(" and "); //$NON-NLS-1$
+        }
+        if (getChildrenCount() > 1) {
+            buf.append("( "); //$NON-NLS-1$
+        }
+        for (int i = 0; i < getChildrenCount(); i++) {
+            ITmfFilterTreeNode node = getChildren()[i];
+            buf.append(node.toString());
+            if (i < getChildrenCount() - 1) {
+                buf.append(" and "); //$NON-NLS-1$
+            }
+        }
+        if (getChildrenCount() > 1) {
+            buf.append(" )"); //$NON-NLS-1$
+        }
+        return buf.toString();
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fName == null) ? 0 : fName.hashCode());
+        result = prime * result + ((fTraceTypeId == null) ? 0 : fTraceTypeId.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterTraceTypeNode other = (TmfFilterTraceTypeNode) obj;
+        if (fName == null) {
+            if (other.fName != null) {
+                return false;
+            }
+        } else if (!fName.equals(other.fName)) {
+            return false;
+        }
+        if (fTraceTypeId == null) {
+            if (other.fTraceTypeId != null) {
+                return false;
+            }
+        } else if (!fTraceTypeId.equals(other.fTraceTypeId)) {
+            return false;
+        }
+        return true;
+    }
+}
index c5b1aa9074273f56746537dde0756b59d6fc8c18..76d3bc564713794c32d0a035be349aaf144afcec 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -34,7 +34,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable
     private static final char BACKSLASH = '\\';
 
     private static final String[] VALID_CHILDREN = {
-            TmfFilterEventTypeNode.NODE_NAME,
+            TmfFilterTraceTypeNode.NODE_NAME,
             TmfFilterAndNode.NODE_NAME,
             TmfFilterOrNode.NODE_NAME,
             TmfFilterContainsNode.NODE_NAME,
index 9ed60d8f05729947206fcaf62e68a0274cedcf14..5a459fcf26e0b49b843e44a1147526a5c2e966e7 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -21,14 +21,16 @@ import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
-import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEventTypeNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesFieldNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTreeNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode.Type;
+import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
+import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
@@ -42,6 +44,12 @@ import org.xml.sax.helpers.DefaultHandler;
  */
 public class TmfFilterContentHandler extends DefaultHandler {
 
+    // Backward compatibility strings
+    private static final String EVENTTYPE_NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
+    private static final String NAME_ATTR = "name"; //$NON-NLS-1$
+    private static final String LTTNG_KERNEL_TRACE = "Common Trace Format : LTTng Kernel Trace"; //$NON-NLS-1$
+    private static final String LINUX_KERNEL_TRACE = "Common Trace Format : Linux Kernel Trace"; //$NON-NLS-1$
+
     private ITmfFilterTreeNode fRoot = null;
     private Stack<ITmfFilterTreeNode> fFilterTreeStack = null;
 
@@ -75,11 +83,16 @@ public class TmfFilterContentHandler extends DefaultHandler {
 
             node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
 
-        } else if (localName.equals(TmfFilterEventTypeNode.NODE_NAME)) {
+        } else if (localName.equals(TmfFilterTraceTypeNode.NODE_NAME)) {
 
-            node = new TmfFilterEventTypeNode(null);
-            ((TmfFilterEventTypeNode) node).setEventType(atts.getValue(TmfFilterEventTypeNode.TYPE_ATTR));
-            ((TmfFilterEventTypeNode) node).setName(atts.getValue(TmfFilterEventTypeNode.NAME_ATTR));
+            node = new TmfFilterTraceTypeNode(null);
+            String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
+            ((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
+            TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
+            if (helper != null) {
+                ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
+            }
+            ((TmfFilterTraceTypeNode) node).setName(atts.getValue(TmfFilterTraceTypeNode.NAME_ATTR));
 
         } else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
 
@@ -159,6 +172,36 @@ public class TmfFilterContentHandler extends DefaultHandler {
             }
             ((TmfFilterCompareNode) node).setValue(atts.getValue(TmfFilterCompareNode.VALUE_ATTR));
 
+        // Backward compatibility with event type filter node
+        } else if (localName.equals(EVENTTYPE_NODE_NAME)) {
+
+            node = new TmfFilterTraceTypeNode(null);
+            String label = atts.getValue(NAME_ATTR);
+            if (label != null) {
+                // Backward compatibility with renamed LTTng Kernel Trace
+                if (label.equals(LTTNG_KERNEL_TRACE)) {
+                    label = LINUX_KERNEL_TRACE;
+                }
+
+                String traceTypeId = TmfTraceType.getTraceTypeId(label);
+                TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
+                if (helper == null) {
+                    // Backward compatibility with category-less custom trace types
+                    for (TraceTypeHelper h : TmfTraceType.getTraceTypeHelpers()) {
+                        if (h.getName().equals(label)) {
+                            label = h.getLabel();
+                            helper = h;
+                            break;
+                        }
+                    }
+                }
+                if (helper != null) {
+                    ((TmfFilterTraceTypeNode) node).setTraceTypeId(helper.getTraceTypeId());
+                    ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
+                }
+                ((TmfFilterTraceTypeNode) node).setName(label);
+            }
+
         }
 
         fFilterTreeStack.push(node);
index 976c00d510df16b5a6f9498062ecddc46a3e6a5b..db9ee181dddadee2bcf98830b669ea6305a4c28d 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation
+ *   Patrick Tasse - Update filter nodes
  *******************************************************************************/
 
 package org.eclipse.tracecompass.tmf.core.filter.xml;
@@ -29,11 +30,11 @@ import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
-import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEventTypeNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesFieldNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -83,11 +84,11 @@ public class TmfFilterXMLWriter {
             TmfFilterNode node = (TmfFilterNode) treenode;
             element.setAttribute(TmfFilterNode.NAME_ATTR, node.getFilterName());
 
-        } else if (treenode instanceof TmfFilterEventTypeNode) {
+        } else if (treenode instanceof TmfFilterTraceTypeNode) {
 
-            TmfFilterEventTypeNode node = (TmfFilterEventTypeNode) treenode;
-            element.setAttribute(TmfFilterEventTypeNode.TYPE_ATTR, node.getEventType());
-            element.setAttribute(TmfFilterEventTypeNode.NAME_ATTR, node.getName());
+            TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) treenode;
+            element.setAttribute(TmfFilterTraceTypeNode.TYPE_ATTR, node.getTraceTypeId());
+            element.setAttribute(TmfFilterTraceTypeNode.NAME_ATTR, node.getName());
 
         } else if (treenode instanceof TmfFilterAndNode) {
 
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTrace.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTrace.java
new file mode 100644 (file)
index 0000000..1d0df02
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.parsers.custom;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+
+/**
+ * Base class for custom traces.
+ *
+ * @author Patrick Tasse
+ */
+public abstract class CustomTrace extends TmfTrace {
+
+    private static final char SEPARATOR = ':';
+
+    private final String fTraceTypeId;
+
+    /**
+     * Basic constructor.
+     *
+     * @param definition
+     *            Custom trace definition
+     */
+    public CustomTrace(CustomTraceDefinition definition) {
+        fTraceTypeId = buildTraceTypeId(getClass(), definition.categoryName, definition.definitionName);
+    }
+
+    /**
+     * Build the trace type id for a custom trace
+     *
+     * @param traceClass
+     *            the trace class
+     * @param category
+     *            the category
+     * @param definitionName
+     *            the definition name
+     * @return the trace type id
+     */
+    public static @NonNull String buildTraceTypeId(Class<? extends ITmfTrace> traceClass, String category, String definitionName) {
+        return traceClass.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName;
+    }
+
+    @Override
+    public String getTraceTypeId() {
+        return fTraceTypeId;
+    }
+}
index 83fbc52134035c01f0d57b4fb1a5592d2edcf68a..452b99e5dcdb7c1947e4db807eef796074df3381 100644 (file)
@@ -36,7 +36,6 @@ import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
@@ -52,7 +51,7 @@ import org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation;
  * @author Patrick Tassé
  * @since 3.0
  */
-public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexable {
+public class CustomTxtTrace extends CustomTrace implements ITmfPersistentlyIndexable {
 
     private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation(-1L);
     private static final int DEFAULT_CACHE_SIZE = 100;
@@ -70,6 +69,7 @@ public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexabl
      *            Text trace definition
      */
     public CustomTxtTrace(final CustomTxtTraceDefinition definition) {
+        super(definition);
         fDefinition = definition;
         fEventType = new CustomTxtEventType(fDefinition);
         setCacheSize(DEFAULT_CACHE_SIZE);
index 5c296ad0fb7991b3f49f1f87fb06cdd9badcd5bc..aa38c7093fb6e692ea1337c9122ac69b25cdb51d 100644 (file)
@@ -35,7 +35,6 @@ import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
@@ -60,7 +59,7 @@ import org.xml.sax.SAXParseException;
  * @author Patrick Tassé
  * @since 3.0
  */
-public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexable {
+public class CustomXmlTrace extends CustomTrace implements ITmfPersistentlyIndexable {
 
     private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation(-1L);
     private static final int DEFAULT_CACHE_SIZE = 100;
@@ -79,6 +78,7 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
      *            Trace definition
      */
     public CustomXmlTrace(final CustomXmlTraceDefinition definition) {
+        super(definition);
         fDefinition = definition;
         fEventType = new CustomXmlEventType(fDefinition);
         fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement);
index cd531c5a37783cade7edef38bc3b0a63b3996700..3dc44a1a17785a33741f9e8f658d3e2068ed4029 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2014 Ericsson, Ã‰cole Polytechnique de Montréal
+ * Copyright (c) 2011, 2015 Ericsson, Ã‰cole Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -30,6 +30,7 @@ import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTrace;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
@@ -52,8 +53,6 @@ public final class TmfTraceType {
     // Constants
     // ------------------------------------------------------------------
 
-    private static final char SEPARATOR = ':';
-
     /** Extension point ID */
     public static final String TMF_TRACE_TYPE_ID = "org.eclipse.linuxtools.tmf.core.tracetype"; //$NON-NLS-1$
 
@@ -172,20 +171,6 @@ public final class TmfTraceType {
         return typeElements.toArray(new IConfigurationElement[typeElements.size()]);
     }
 
-    /**
-     * Retrieve the TraceTypeHelper for a given trace type ID
-     *
-     * @param id
-     *            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);
-    }
-
     /**
      * Get an iterable view of the existing trace type IDs.
      *
@@ -205,24 +190,24 @@ public final class TmfTraceType {
     }
 
     /**
-     * Returns a list of "category:tracetype , ..."
+     * Returns a list of trace type labels "category : name", ...
      *
      * Returns only trace types, not experiment types
      *
-     * @return returns a list of "category:tracetype , ..."
+     * @return a list of trace type labels
      */
     public static String[] getAvailableTraceTypes() {
         return getAvailableTraceTypes(null);
     }
 
     /**
-     * Returns a list of "category:tracetype , ..." sorted by given comparator.
+     * Returns a list of trace type labels "category : name", ... sorted by given comparator.
      *
      * Returns only trace types, not experiment types
      *
      * @param comparator
      *            Comparator class (type String) or null for alphabetical order.
-     * @return sorted list according to the given comparator
+     * @return a list of trace type labels sorted according to the given comparator
      */
     public static String[] getAvailableTraceTypes(Comparator<String> comparator) {
 
@@ -232,7 +217,7 @@ public final class TmfTraceType {
         for (String key : TRACE_TYPES.keySet()) {
             TraceTypeHelper tt = TRACE_TYPES.get(key);
             if (!tt.isExperimentType()) {
-                traceTypes.add(tt.getCategoryName() + SEPARATOR + tt.getName());
+                traceTypes.add(tt.getLabel());
             }
         }
 
@@ -292,16 +277,16 @@ 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.categoryName + SEPARATOR + def.definitionName;
-            ITmfTrace trace = new CustomTxtTrace(def);
+            CustomTxtTrace trace = new CustomTxtTrace(def);
+            String traceTypeId = trace.getTraceTypeId();
             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.categoryName + SEPARATOR + def.definitionName;
-            ITmfTrace trace = new CustomXmlTrace(def);
+            CustomXmlTrace trace = new CustomXmlTrace(def);
+            String traceTypeId = trace.getTraceTypeId();
             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
@@ -340,19 +325,19 @@ public final class TmfTraceType {
      */
     public static void addCustomTraceType(Class<? extends ITmfTrace> traceClass, String category, String definitionName) {
         String traceTypeId = null;
-        ITmfTrace trace = null;
+        CustomTrace trace = null;
 
         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);
+                traceTypeId = trace.getTraceTypeId();
             }
         } 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);
+                traceTypeId = trace.getTraceTypeId();
             }
         }
 
@@ -398,7 +383,7 @@ public final class TmfTraceType {
      *            The custom parser definition name to add or replace
      */
     public static void removeCustomTraceType(Class<? extends ITmfTrace> traceClass, String category, String definitionName) {
-        String traceTypeId = traceClass.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName;
+        String traceTypeId = CustomTrace.buildTraceTypeId(traceClass, category, definitionName);
         TraceTypeHelper helper = TRACE_TYPES.remove(traceTypeId);
         if (helper != null) {
             helper.getTrace().dispose();
@@ -475,7 +460,7 @@ public final class TmfTraceType {
                 return category.getAttribute(TmfTraceType.NAME_ATTR);
             }
         }
-        return "[no category]"; //$NON-NLS-1$
+        return ""; //$NON-NLS-1$
     }
 
     /**
@@ -578,59 +563,21 @@ public final class TmfTraceType {
     }
 
     /**
-     * Find the id of a trace type by its parameters
+     * Find the id of a trace type by its label "category : name"
      *
-     * @param category
-     *            like "ctf" or "custom text"
-     * @param traceType
-     *            like "kernel"
-     * @return an id like "org.eclipse.linuxtools.blabla...
+     * @param label
+     *            the trace type label
+     * @return the trace type id
      */
-    public static String getTraceTypeId(String category, String traceType) {
+    public static String getTraceTypeId(String label) {
         for (String key : TRACE_TYPES.keySet()) {
-            if (TRACE_TYPES.get(key).getCategoryName().equals(category.trim()) && TRACE_TYPES.get(key).getName().equals(traceType.trim())) {
+            if (TRACE_TYPES.get(key).getLabel().equals(label)) {
                 return key;
             }
         }
         return null;
     }
 
-    /**
-     * Gets the custom trace type ID from the custom trace name
-     *
-     * @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 traceTypeToken[] = traceType.split(":", 2); //$NON-NLS-1$
-        if (traceTypeToken.length == 2) {
-            return getTraceTypeId(traceTypeToken[0], traceTypeToken[1]);
-        }
-        return null;
-    }
-
-    /**
-     * Is the trace a custom (user-defined) trace type. These are the traces
-     * like : text and xml defined by the custom trace wizard.
-     *
-     * @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) {
-        String traceTypeId = getCustomTraceTypeId(traceType);
-        if (traceTypeId != null) {
-            return traceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName() + SEPARATOR) ||
-                    traceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName() + SEPARATOR);
-        }
-        return false;
-    }
-
     /**
      * Checks if a trace is a valid directory trace
      * @param path
index 3ba07e4b46c47d08b7cce75db238f188f1eb38b0..ecd49eac50e8aab5a739083b02a0dd6ec6cc236d 100644 (file)
@@ -30,6 +30,8 @@ import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
  */
 public class TraceTypeHelper {
 
+    private static final String SEP = " : "; //$NON-NLS-1$
+
     private final String fName;
     private final String fCategoryName;
     private final String fTraceTypeId;
@@ -83,6 +85,18 @@ public class TraceTypeHelper {
         return fCategoryName;
     }
 
+    /**
+     * Get the trace type label "category : name".
+     *
+     * @return the trace type label
+     */
+    public String getLabel() {
+        if (fCategoryName.isEmpty()) {
+            return fName;
+        }
+        return fCategoryName + SEP + fName;
+    }
+
     /**
      * Get the trace type id
      *
index ac76479cff9afa95e9216466adbf1ebb07411639..3a3b764c96284dcce64d5ef63d8558d2b414f7b4 100644 (file)
@@ -173,10 +173,12 @@ public interface ITmfTrace extends ITmfEventProvider {
      *            the trace event type
      * @param name
      *            the trace name
+     * @param traceTypeId
+     *            the trace type id
      * @throws TmfTraceException
      *             If we couldn't open the trace
      */
-    void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type, String name) throws TmfTraceException;
+    void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type, String name, String traceTypeId) throws TmfTraceException;
 
     /**
      * Validate that the trace is of the correct type. The implementation should
@@ -211,6 +213,13 @@ public interface ITmfTrace extends ITmfEventProvider {
      */
     IResource getResource();
 
+    /**
+     * Get the trace type id
+     *
+     * @return the trace type id
+     */
+    @Nullable String getTraceTypeId();
+
     /**
      * @return the trace path
      */
index 5925751d2de94d149dd2ae1d908288cdb92c025a..c269a6fb064602ef411481f1836250d58db06036 100644 (file)
@@ -32,6 +32,7 @@ import org.eclipse.core.runtime.MultiStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
@@ -110,6 +111,9 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace, IT
     // The resource used for persistent properties for this trace
     private IResource fResource;
 
+    // The trace type id
+    private @Nullable String fTraceTypeId;
+
     // The trace path
     private String fPath;
 
@@ -210,11 +214,12 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace, IT
     // ------------------------------------------------------------------------
 
     @Override
-    public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type, String name) throws TmfTraceException {
+    public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type, String name, String traceTypeId) throws TmfTraceException {
         if (name == null) {
             throw new IllegalArgumentException();
         }
         setName(name);
+        fTraceTypeId = traceTypeId;
         initTrace(resource, path, type);
     }
 
@@ -361,6 +366,11 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace, IT
         return fResource;
     }
 
+    @Override
+    public @Nullable String getTraceTypeId() {
+        return fTraceTypeId;
+    }
+
     @Override
     public String getPath() {
         return fPath;
index b09886d71a741f6dc16ca053cfbe0be42fc45d1d..7220c77d8a804e78614c528bbb1c6f463d9f0228 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2014 Ericsson and others.
+ * Copyright (c) 2009, 2015 Ericsson and others.
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -138,7 +138,6 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
     private static final String IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID = ".import_unrecognized_traces_id"; //$NON-NLS-1$
     private static final String IMPORT_WIZARD_PRESERVE_FOLDERS_ID = ".import_preserve_folders_id"; //$NON-NLS-1$
     private static final String IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID = ".import_from_directory"; //$NON-NLS-1$
-    private static final String SEPARATOR = ":"; //$NON-NLS-1$
 
     // constant from WizardArchiveFileResourceImportPage1
     private static final String[] FILE_IMPORT_MASK = { "*.jar;*.zip;*.tar;*.tar.gz;*.tgz", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
@@ -1262,14 +1261,10 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
      * @return <code>true</code> if successful else <code>false</code>
      */
     public boolean finish() {
-        String traceTypeName = getImportTraceTypeId();
+        String traceTypeLabel = getImportTraceTypeId();
         String traceId = null;
-        if (!TRACE_TYPE_AUTO_DETECT.equals(traceTypeName)) {
-            String tokens[] = traceTypeName.split(SEPARATOR, 2);
-            if (tokens.length < 2) {
-                return false;
-            }
-            traceId = TmfTraceType.getTraceTypeId(tokens[0], tokens[1]);
+        if (!TRACE_TYPE_AUTO_DETECT.equals(traceTypeLabel)) {
+            traceId = TmfTraceType.getTraceTypeId(traceTypeLabel);
         }
 
         // Save dialog settings
index 992c297d0bbee4f9dd631b0af0e22a4d602b536a..66c55983874cc19a8371fa1474bbf8ff6df19edf 100644 (file)
@@ -254,7 +254,7 @@ public class TmfOpenTraceHelper {
         }
 
         try {
-            trace.initTrace(traceElement.getResource(), traceElement.getResource().getLocation().toOSString(), traceEvent.getClass(), traceElement.getElementPath());
+            trace.initTrace(traceElement.getResource(), traceElement.getResource().getLocation().toOSString(), traceEvent.getClass(), traceElement.getElementPath(), traceElement.getTraceType());
         } catch (final TmfTraceException e) {
             TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement, traceElement.getTypeName()),
                     Messages.TmfOpenTraceHelper_InitError + ENDL + ENDL + e);
index 4de73ea566dbc97abc3d1dbf11c563badbd4fdf4..8daf7095ed1603a01c2797c668149cd5a309298e 100644 (file)
@@ -518,7 +518,7 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF
             if (getTraceType() != null) {
                 TraceTypeHelper helper = TmfTraceType.getTraceType(getTraceType());
                 if (helper != null) {
-                    return helper.getCategoryName() + " : " + helper.getName(); //$NON-NLS-1$
+                    return helper.getLabel();
                 }
             }
             return ""; //$NON-NLS-1$
index 9b87dbb4f3066b6587a2fa01e33f1bd46b68b11d..03d3e504c850ed9f4bf2ea68b14ad5c7ad97bc2e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Yuriy Vashchuk - Initial API and implementation
+ *   Patrick Tasse - Update filter nodes
  *******************************************************************************/
 
 package org.eclipse.tracecompass.tmf.ui.views.filter;
@@ -20,10 +21,10 @@ import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode.Type;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
-import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEventTypeNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesFieldNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
 
 /**
  * This is the Label Provider for our Filter Tree
@@ -69,9 +70,9 @@ public class FilterTreeLabelProvider implements ILabelProvider {
             TmfFilterNode node = (TmfFilterNode) element;
             label = node.getNodeName() + " " + node.getFilterName(); //$NON-NLS-1$
 
-        } else if (element instanceof TmfFilterEventTypeNode) {
+        } else if (element instanceof TmfFilterTraceTypeNode) {
 
-            TmfFilterEventTypeNode node = (TmfFilterEventTypeNode) element;
+            TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) element;
             label = "WITH " + node.getNodeName() + (node.getName() != null ? " " + node.getName() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
         } else if (element instanceof TmfFilterAndNode) {
index 673420f0eb3de22aa80146a7a7ca1252f3f742e4..1b2bfb56c38a41effbeef9a57b8306fd7864f5fd 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -68,19 +68,18 @@ import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode.Type;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
-import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEventTypeNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesFieldNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTreeNode;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
-import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
-import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
+import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
 
 class FilterViewer extends Composite {
 
@@ -221,8 +220,8 @@ class FilterViewer extends Composite {
                     ITmfFilterTreeNode newNode = null;
                     if (TmfFilterNode.NODE_NAME.equals(child)) {
                         newNode = new TmfFilterNode(node, ""); //$NON-NLS-1$
-                    } else if (TmfFilterEventTypeNode.NODE_NAME.equals(child)) {
-                        newNode = new TmfFilterEventTypeNode(node);
+                    } else if (TmfFilterTraceTypeNode.NODE_NAME.equals(child)) {
+                        newNode = new TmfFilterTraceTypeNode(node);
                     } else if (TmfFilterAndNode.NODE_NAME.equals(child)) {
                         newNode = new TmfFilterAndNode(node);
                     } else if (TmfFilterOrNode.NODE_NAME.equals(child)) {
@@ -261,8 +260,8 @@ class FilterViewer extends Composite {
 
         if (node instanceof TmfFilterNode) {
             new FilterNodeComposite(fComposite, (TmfFilterNode) node);
-        } else if (node instanceof TmfFilterEventTypeNode) {
-            new FilterEventTypeNodeComposite(fComposite, (TmfFilterEventTypeNode) node);
+        } else if (node instanceof TmfFilterTraceTypeNode) {
+            new FilterTraceTypeNodeComposite(fComposite, (TmfFilterTraceTypeNode) node);
         } else if (node instanceof TmfFilterAndNode) {
             new FilterAndNodeComposite(fComposite, (TmfFilterAndNode) node);
         } else if (node instanceof TmfFilterOrNode) {
@@ -387,58 +386,17 @@ class FilterViewer extends Composite {
             return eventsTypeMap;
         }
 
-        protected String[] getFieldsList(ITmfFilterTreeNode node) {
-            ArrayList<String> fieldsList = new ArrayList<>();
-            ITmfFilterTreeNode curNode = node;
-            while (curNode != null) {
-                if (curNode instanceof TmfFilterEventTypeNode) {
-                    TmfFilterEventTypeNode eventTypeNode = (TmfFilterEventTypeNode) curNode;
-                    for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {
-                        if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(eventTypeNode.getEventType())) {
-                            try {
-                                ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
-                                ITmfEventType eventType = event.getType();
-                                if (eventType != null) {
-                                    for (String field : eventType.getRootField().getFieldNames()) {
-                                        fieldsList.add(field);
-                                    }
-                                }
-                            } catch (CoreException e) {
-                            }
-                            if (fieldsList.size() == 0) {
-                                fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP);
-                                fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE);
-                                fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE);
-                                fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE);
-                                fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT);
-                            }
-                            return fieldsList.toArray(new String[0]);
-                        }
-                    }
-                    if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) {
-                        for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
-                            if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName)) {
-                                for (OutputColumn output : def.outputs) {
-                                    fieldsList.add(output.name);
-                                }
-                                return fieldsList.toArray(new String[0]);
-                            }
-                        }
-                    }
-                    if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) {
-                        for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
-                            if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName)) {
-                                for (OutputColumn output : def.outputs) {
-                                    fieldsList.add(output.name);
-                                }
-                                return fieldsList.toArray(new String[0]);
-                            }
-                        }
-                    }
-                }
-                curNode = curNode.getParent();
+        protected Map<String, TraceTypeHelper> getTraceTypeMap() {
+            Map<String, TraceTypeHelper> traceTypeMap = new TreeMap<>();
+            for (TraceTypeHelper helper : TmfTraceType.getTraceTypeHelpers()) {
+                String text = helper.getCategoryName() + SEP + helper.getName();
+                traceTypeMap.put(text, helper);
             }
+            return traceTypeMap;
+        }
 
+        protected String[] getFieldsList() {
+            ArrayList<String> fieldsList = new ArrayList<>();
             fieldsList.add(Messages.FilterViewer_CommonCategory);
             fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP);
             fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE);
@@ -533,15 +491,15 @@ class FilterViewer extends Composite {
         }
     }
 
-    private class FilterEventTypeNodeComposite extends FilterBaseNodeComposite {
-        TmfFilterEventTypeNode fNode;
+    private class FilterTraceTypeNodeComposite extends FilterBaseNodeComposite {
+        TmfFilterTraceTypeNode fNode;
         Combo fTypeCombo;
-        Map<String, Object> fEventsTypeMap;
+        Map<String, TraceTypeHelper> fTraceTypeMap;
 
-        FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) {
+        FilterTraceTypeNodeComposite(Composite parent, TmfFilterTraceTypeNode node) {
             super(parent);
             fNode = node;
-            fEventsTypeMap = getEventsTypeMap();
+            fTraceTypeMap = getTraceTypeMap();
 
             Label label = new Label(this, SWT.NONE);
             label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
@@ -549,39 +507,18 @@ class FilterViewer extends Composite {
 
             fTypeCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
             fTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-            fTypeCombo.setItems(fEventsTypeMap.keySet().toArray(new String[0]));
-            if (fNode.getEventType() != null) {
+            fTypeCombo.setItems(fTraceTypeMap.keySet().toArray(new String[0]));
+            if (fNode.getTraceTypeId() != null) {
                 fTypeCombo.setText(fNode.getName());
             }
             fTypeCombo.addModifyListener(new ModifyListener() {
                 @Override
                 public void modifyText(ModifyEvent e) {
-                    for (Entry<String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) {
-                        if (eventTypeEntry.getKey().equals(fTypeCombo.getText())) {
-                            Object value = eventTypeEntry.getValue();
-                            if (value instanceof IConfigurationElement) {
-                                IConfigurationElement ce = (IConfigurationElement) value;
-                                fNode.setEventType(ce.getAttribute(TmfTraceType.EVENT_TYPE_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.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.categoryName + ':' + def.definitionName);
-                                fNode.setName(def.categoryName + SEP + def.definitionName);
-                            }
-                            fViewer.refresh(fNode);
-                            break;
-                        }
-                    }
+                    TraceTypeHelper helper = fTraceTypeMap.get(fTypeCombo.getText());
+                    fNode.setTraceTypeId(helper.getTraceTypeId());
+                    fNode.setTraceClass(helper.getTraceClass());
+                    fNode.setName(fTypeCombo.getText());
+                    fViewer.refresh(fNode);
                 }
             });
         }
@@ -669,7 +606,7 @@ class FilterViewer extends Composite {
 
             fFieldCombo = new Combo(this, SWT.DROP_DOWN);
             fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-            fFieldCombo.setItems(getFieldsList(fNode));
+            fFieldCombo.setItems(getFieldsList());
             fFieldCombo.setToolTipText(Messages.FilterViewer_Subfilter_ToolTip);
             if (fNode.getField() != null) {
                 fFieldCombo.setText(fNode.getField());
@@ -770,7 +707,7 @@ class FilterViewer extends Composite {
 
             fFieldCombo = new Combo(this, SWT.DROP_DOWN);
             fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-            fFieldCombo.setItems(getFieldsList(fNode));
+            fFieldCombo.setItems(getFieldsList());
             fFieldCombo.setToolTipText(Messages.FilterViewer_Subfilter_ToolTip);
             if (fNode.getField() != null) {
                 fFieldCombo.setText(fNode.getField());
@@ -870,7 +807,7 @@ class FilterViewer extends Composite {
 
             fFieldCombo = new Combo(this, SWT.DROP_DOWN);
             fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-            fFieldCombo.setItems(getFieldsList(fNode));
+            fFieldCombo.setItems(getFieldsList());
             fFieldCombo.setToolTipText(Messages.FilterViewer_Subfilter_ToolTip);
             if (fNode.getField() != null) {
                 fFieldCombo.setText(fNode.getField());
@@ -961,7 +898,7 @@ class FilterViewer extends Composite {
 
             fFieldCombo = new Combo(this, SWT.DROP_DOWN);
             fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-            fFieldCombo.setItems(getFieldsList(fNode));
+            fFieldCombo.setItems(getFieldsList());
             fFieldCombo.setToolTipText(Messages.FilterViewer_Subfilter_ToolTip);
             if (fNode.getField() != null) {
                 fFieldCombo.setText(fNode.getField());
This page took 0.065838 seconds and 5 git commands to generate.