tmf: Bug 457502: Prevent duplication of Stream List view filters
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 22 Jan 2015 16:24:56 +0000 (11:24 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 4 Feb 2015 17:54:18 +0000 (12:54 -0500)
Change-Id: Ia4cc06c828b09818b38cbc8178fa46073cdfcc08
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/40186
Reviewed-by: Hudson CI
17 files changed:
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/filter/TmfCollapseFilter.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/ITmfFilterTreeNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterAndNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterAspectNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterCompareNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterContainsNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterEqualsNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterMatchesNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterOrNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterRootNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterTraceTypeNode.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/model/TmfFilterTreeNode.java
org.eclipse.tracecompass.tmf.pcap.ui/src/org/eclipse/tracecompass/internal/tmf/pcap/ui/stream/StreamListView.java
org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/ColorsViewTest.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/FilterView.java

index f6870ee349860c9284758e871e9249976056837a..471bc71b1f9afde7ca3e8d0c395c5a4a7f54d8fc 100644 (file)
@@ -112,6 +112,11 @@ public class TmfCollapseFilter implements ITmfFilterTreeNode {
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public String toString(boolean explicit) {
+        return COLLAPSE_NODE_NAME + " [" + fPrevEvent + ']'; //$NON-NLS-1$
+    }
+
     @Override
     public ITmfFilterTreeNode clone() {
         return new TmfCollapseFilter();
index 87c64c57a3aaa1b7d541909e5437b1849da5dc74..73d0c35b9ec28a2369c7ac966e9df2afd569541f 100644 (file)
@@ -119,9 +119,20 @@ public interface ITmfFilterTreeNode extends ITmfFilter {
      */
     public List<String> getValidChildren();
 
+    /**
+     * <h4>Returns a string representation of the filter tree node object.</h4>
+     *
+     * @param explicit
+     *            true if ambiguous fields should explicitly include additional
+     *            information that can differentiate them from other fields with
+     *            the same name
+     *
+     * @return a string representation of the filter tree node object
+     */
+    public String toString(boolean explicit);
+
     /**
      * @return a clone of the node
      */
     public ITmfFilterTreeNode clone();
-
 }
index b9cd69e52968f04471f55c68c7a51ae401a86378..1ceb50cf403335a776ed3ebc4121617c063f8c31 100644 (file)
@@ -66,7 +66,7 @@ public class TmfFilterAndNode extends TmfFilterTreeNode {
     }
 
     @Override
-    public String toString() {
+    public String toString(boolean explicit) {
         StringBuffer buf = new StringBuffer();
         if (fNot) {
             buf.append("not "); //$NON-NLS-1$
@@ -76,7 +76,7 @@ public class TmfFilterAndNode extends TmfFilterTreeNode {
         }
         for (int i = 0; i < getChildrenCount(); i++) {
             ITmfFilterTreeNode node = getChildren()[i];
-            buf.append(node.toString());
+            buf.append(node.toString(explicit));
             if (i < getChildrenCount() - 1) {
                 buf.append(" and "); //$NON-NLS-1$
             }
index a5632cdc560c2e4d922b6d0ab408e3b36c46cda3..58ba56d8caa6ab473975d0926ff93bc9f7a531c8 100644 (file)
@@ -78,13 +78,23 @@ public abstract class TmfFilterAspectNode extends TmfFilterTreeNode {
     }
 
     /**
+     * @param explicit
+     *            true if the string representation should explicitly include
+     *            the trace type id that can differentiate it from other aspects
+     *            with the same name
+     *
      * @return The string representation of the event aspect
      */
-    public String getAspectLabel() {
+    public String getAspectLabel(boolean explicit) {
         if (fEventAspect == null) {
             return ""; //$NON-NLS-1$
         }
         StringBuilder sb = new StringBuilder(fEventAspect.getName());
+        if (explicit) {
+            sb.append('[');
+            sb.append(fTraceTypeId);
+            sb.append(']');
+        }
         if (fEventAspect instanceof TmfEventFieldAspect) {
             String field = ((TmfEventFieldAspect) fEventAspect).getFieldPath();
             if (field != null && !field.isEmpty()) {
index a52392772e4bb92c12a82d499817a4f79f28e0de..8b6ae8b51dec93345f34a17c6b78afeb518936f5 100644 (file)
@@ -224,11 +224,11 @@ public class TmfFilterCompareNode extends TmfFilterAspectNode {
     }
 
     @Override
-    public String toString() {
+    public String toString(boolean explicit) {
         String result = (fResult == 0 ? "= " : fResult < 0 ? "< " : "> "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         String open = (fType == Type.NUM ? "" : fType == Type.ALPHA ? "\"" : "["); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         String close = (fType == Type.NUM ? "" : fType == Type.ALPHA ? "\"" : "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        return getAspectLabel() + (fNot ? " not " : " ") + result + open + fValue + close; //$NON-NLS-1$ //$NON-NLS-2$
+        return getAspectLabel(explicit) + (fNot ? " not " : " ") + result + open + fValue + close; //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Override
index ca7830a2ca76c79f3138ccaea7b825a268468b94..6362cce34894547fd51932310d2fcf1dc68d3342 100644 (file)
@@ -119,8 +119,8 @@ public class TmfFilterContainsNode extends TmfFilterAspectNode {
     }
 
     @Override
-    public String toString() {
-        return getAspectLabel() + (fNot ? " not" : "") + " contains \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    public String toString(boolean explicit) {
+        return getAspectLabel(explicit) + (fNot ? " not contains " : " contains ") + (fIgnoreCase ? "ignorecase \"" : "\"") + fValue + '\"'; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
     }
 
     @Override
index ef104c5f76c448479eff7d067e537b91c4b5c934..de2d6c50c12252ec6fee1f23aeb5d3fda7470b0c 100644 (file)
@@ -114,8 +114,8 @@ public class TmfFilterEqualsNode extends TmfFilterAspectNode {
     }
 
     @Override
-    public String toString() {
-        return getAspectLabel() + (fNot ? " not" : "") + " equals \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    public String toString(boolean explicit) {
+        return getAspectLabel(explicit) + (fNot ? " not equals " : " equals ") + (fIgnoreCase ? "ignorecase \"" : "\"") + fValue + '\"'; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
     }
 
     @Override
index 025557eec15a1539cae15031d033f978f1cdcbd2..40d17357e869c9d448283b53a1971166e8f56706 100644 (file)
@@ -140,7 +140,7 @@ public class TmfFilterMatchesNode extends TmfFilterAspectNode {
     }
 
     @Override
-    public String toString() {
-        return getAspectLabel() + (isNot() ? " not" : "") + " matches \"" + getRegex() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    public String toString(boolean explicit) {
+        return getAspectLabel(explicit) + (fNot ? " not matches \"" : " matches \"") + getRegex() + '\"'; //$NON-NLS-1$ //$NON-NLS-2$
     }
 }
index 8a5d7b812723dd737af11b72027c84a2129292d4..f9fd947ca45227d68776f8d5ca0e5811bcb98bc3 100644 (file)
@@ -88,14 +88,16 @@ public class TmfFilterNode extends TmfFilterTreeNode {
     }
 
     @Override
-    public String toString() {
+    public String toString(boolean explicit) {
         StringBuffer buf = new StringBuffer();
+        buf.append(fFilterName);
+        buf.append(": "); //$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());
+            buf.append(node.toString(explicit));
             if (i < (getChildrenCount() - 1)) {
                 buf.append(" and "); //$NON-NLS-1$
             }
index 3d31711a971f1b0f1fbe6cab20404afadf0e2c50..67738cea1d07b1a11ec2c2acba14b17094e053fa 100644 (file)
@@ -66,7 +66,7 @@ public class TmfFilterOrNode extends TmfFilterTreeNode {
     }
 
     @Override
-    public String toString() {
+    public String toString(boolean explicit) {
         StringBuffer buf = new StringBuffer();
         if (fNot) {
             buf.append("not "); //$NON-NLS-1$
@@ -76,7 +76,7 @@ public class TmfFilterOrNode extends TmfFilterTreeNode {
         }
         for (int i = 0; i < getChildrenCount(); i++) {
             ITmfFilterTreeNode node = getChildren()[i];
-            buf.append(node.toString());
+            buf.append(node.toString(explicit));
             if (i < getChildrenCount() - 1) {
                 buf.append(" or "); //$NON-NLS-1$
             }
index 97000210ac86ac5107a647f7c1d4f9e6c71dc907..68d5583e3626636cf66e0fac2450d43d8d4055ed 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.eclipse.tracecompass.tmf.core.filter.model;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -60,11 +61,15 @@ public class TmfFilterRootNode extends TmfFilterTreeNode {
     }
 
     @Override
-    public String toString() {
+    public String toString(boolean explicit) {
         StringBuffer buf = new StringBuffer("root"); //$NON-NLS-1$
         if (getChildrenCount() > 0) {
             buf.append(' ');
-            buf.append(Arrays.toString(getChildren()));
+            List<String> strings = new ArrayList<>();
+            for (ITmfFilterTreeNode child : getChildren()) {
+                strings.add(child.toString(explicit));
+            }
+            buf.append(strings.toString());
         }
         return buf.toString();
     }
index e7f7183b5924bc15b7e649c51035843a9ab79140..551412275c6fe6d2805c81d6c5d7366779c30520 100644 (file)
@@ -125,9 +125,14 @@ public class TmfFilterTraceTypeNode extends TmfFilterTreeNode {
     }
 
     @Override
-    public String toString() {
+    public String toString(boolean explicit) {
         StringBuffer buf = new StringBuffer();
         buf.append("TraceType is " + fName); //$NON-NLS-1$
+        if (explicit) {
+            buf.append('[');
+            buf.append(fTraceTypeId);
+            buf.append(']');
+        }
         if (getChildrenCount() > 0) {
             buf.append(" and "); //$NON-NLS-1$
         }
@@ -136,7 +141,7 @@ public class TmfFilterTraceTypeNode extends TmfFilterTreeNode {
         }
         for (int i = 0; i < getChildrenCount(); i++) {
             ITmfFilterTreeNode node = getChildren()[i];
-            buf.append(node.toString());
+            buf.append(node.toString(explicit));
             if (i < getChildrenCount() - 1) {
                 buf.append(" and "); //$NON-NLS-1$
             }
index 5d5f129964a54b9201781077924c598fc6f22658..c16223a96e40156af6fb2a360dc1bbb3b232247f 100644 (file)
@@ -137,4 +137,9 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable
             return null;
         }
     }
+
+    @Override
+    public String toString() {
+        return toString(false);
+    }
 }
index 092e5985cbef28cf484675b24113c4aa5e615692..c7c3923640e0ec6e523155190f42e60827955a5d 100644 (file)
@@ -13,7 +13,6 @@
 
 package org.eclipse.tracecompass.internal.tmf.pcap.ui.stream;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -67,6 +66,8 @@ import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 
+import com.google.common.collect.Lists;
+
 /**
  * Class that represents the Stream List View. Such a view lists all the
  * available streams from the current experiment. <br>
@@ -418,14 +419,18 @@ public class StreamListView extends TmfView {
                         }
 
                         // Update XML
-                        List<ITmfFilterTreeNode> newFilters = new ArrayList<>();
-                        ITmfFilterTreeNode[] oldFilters = FilterManager.getSavedFilters();
-                        for (int i = 0; i < oldFilters.length; i++) {
-                            newFilters.add(oldFilters[i]);
+                        List<ITmfFilterTreeNode> filters = Lists.newArrayList(FilterManager.getSavedFilters());
+                        boolean newFilter = true;
+                        for (ITmfFilterTreeNode savedFilter : filters) {
+                            // Use toString(explicit) equality because equals() is not implemented
+                            if (savedFilter.toString(true).equals(filter.toString(true))) {
+                                newFilter = false;
+                                break;
+                            }
                         }
-                        if (!(newFilters.contains(filter))) {
-                            newFilters.add(filter);
-                            FilterManager.setSavedFilters(newFilters.toArray(new ITmfFilterTreeNode[newFilters.size()]));
+                        if (newFilter) {
+                            filters.add(filter);
+                            FilterManager.setSavedFilters(filters.toArray(new ITmfFilterTreeNode[filters.size()]));
                         }
 
                         // Update Filter View
index bb534e157919a981842e46fc7f65646a9851edc5..6f48918063bc651a628ad84f815f090aa1774a23 100644 (file)
@@ -120,6 +120,16 @@ public class ColorsViewTest {
         public ITmfFilterTreeNode clone() {
             return null;
         }
+
+        @Override
+        public String toString(boolean explicit) {
+            return toString();
+        }
+
+        @Override
+        public String toString() {
+            return getNodeName();
+        }
     }
 
     private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
index 826bf3c56da61a184152fc6fee545c99044dba0b..b1a557636b13bcaa7c75f946af3cefea8fdd5986 100644 (file)
@@ -91,7 +91,7 @@ public class FilterTreeLabelProvider implements ILabelProvider {
 
             TmfFilterContainsNode node = (TmfFilterContainsNode) element;
             label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$
-                    (node.getEventAspect() != null ? node.getAspectLabel() : Messages.FilterTreeLabelProvider_AspectHint) +
+                    (node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint) +
                     ' ' + node.getNodeName() +
                     (node.getValue() != null ? " \"" + node.getValue() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
@@ -99,7 +99,7 @@ public class FilterTreeLabelProvider implements ILabelProvider {
 
             TmfFilterEqualsNode node = (TmfFilterEqualsNode) element;
             label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$
-                    (node.getEventAspect() != null ? node.getAspectLabel() : Messages.FilterTreeLabelProvider_AspectHint) +
+                    (node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint) +
                     ' ' + node.getNodeName() +
                     (node.getValue() != null ? " \"" + node.getValue() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
@@ -107,7 +107,7 @@ public class FilterTreeLabelProvider implements ILabelProvider {
 
             TmfFilterMatchesNode node = (TmfFilterMatchesNode) element;
             label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$
-                    (node.getEventAspect() != null ? node.getAspectLabel() : Messages.FilterTreeLabelProvider_AspectHint) +
+                    (node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint) +
                     ' ' + node.getNodeName() +
                     (node.getRegex() != null ? " \"" + node.getRegex() + "\"" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
@@ -115,7 +115,7 @@ public class FilterTreeLabelProvider implements ILabelProvider {
 
             TmfFilterCompareNode node = (TmfFilterCompareNode) element;
             label = (node.isNot() ? "NOT " : "") + //$NON-NLS-1$ //$NON-NLS-2$
-                    (node.getEventAspect() != null ? node.getAspectLabel() : Messages.FilterTreeLabelProvider_AspectHint) +
+                    (node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint) +
                     (node.getResult() < 0 ? " <" : (node.getResult() > 0 ? " >" : " =")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                     (node.getType() == Type.ALPHA ? " \"" : node.getType() == Type.TIMESTAMP ? " [" : ' ') + //$NON-NLS-1$ //$NON-NLS-2$
                     (node.hasValidValue() ? node.getValue() : Messages.FilterTreeLabelProvider_ValueHint) +
index 6051ee1f1cffc2143b28c267ecd17b630094a83e..62d1a7f8942ae12c13235bc8c213173f2fd3b999 100644 (file)
@@ -110,23 +110,29 @@ public class FilterView extends TmfView {
     }
 
     /**
-     * Add a filter to the FilterView. This does not modify the XML, which must
-     * be done manually. If the filter is already in the FilterView, this is a
-     * no-op.
+     * Add a filter to the FilterView and select it. This does not modify the
+     * XML, which must be done manually. If an equivalent filter is already in
+     * the FilterView, it is not added.
      *
      * @param filter
      *            The filter to add.
      * @since 3.1
      */
     public void addFilter(ITmfFilterTreeNode filter) {
+        if (filter == null) {
+            return;
+        }
         ITmfFilterTreeNode root = fViewer.getInput();
         for (ITmfFilterTreeNode node : root.getChildren()) {
-            if (node.equals(filter)) {
+            // Use toString(explicit) equality because equals() is not implemented
+            if (node.toString(true).equals(filter.toString(true))) {
+                fViewer.setSelection(node);
                 return;
             }
         }
         root.addChild(filter);
         fViewer.setInput(root);
+        fViewer.setSelection(filter);
     }
 
     /**
This page took 0.033514 seconds and 5 git commands to generate.