tmf: Preserve order of marker categories
authorPatrick Tasse <patrick.tasse@gmail.com>
Fri, 12 Feb 2016 23:15:32 +0000 (18:15 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Mon, 22 Feb 2016 16:02:29 +0000 (11:02 -0500)
Some marker event sources can have a logical order to the list of marker
categories they return in IMarkerEventSource.getMarkerCategories(). This
order should be preserved, so the categories should not be sorted
alphabetically.

Change-Id: I0423b391271fdd0803aba6bd357d7482938aad4b
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/66541
Reviewed-by: Hudson CI
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphMarkerAxis.java

index 682487763e6cebe8a56dc09523c4e6e5f9ff0e1a..6ad0a95602a4e20798a41925963f7a8e36107e27 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -1647,7 +1647,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
      * @since 2.0
      */
     private @NonNull List<String> getMarkerCategories() {
-        Set<String> categories = new HashSet<>(getViewMarkerCategories());
+        Set<String> categories = new LinkedHashSet<>(getViewMarkerCategories());
         for (IMarkerEventSource markerEventSource : getMarkerEventSources(fTrace)) {
             categories.addAll(markerEventSource.getMarkerCategories());
         }
index 6b70561934737629abe2ba9c18e6b362b89a23ea..f5dc386c5286540c3867294cce8367469e926f1f 100644 (file)
@@ -1303,11 +1303,11 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      */
     public void setMarkerCategories(List<String> categories) {
         fMarkerCategories.clear();
-        fMarkerCategories.add(IMarkerEvent.BOOKMARKS);
         if (categories != null) {
             fMarkerCategories.addAll(categories);
         }
-        Collections.sort(fMarkerCategories);
+        fMarkerCategories.add(IMarkerEvent.BOOKMARKS);
+        fMarkerAxisCtrl.setMarkerCategories(fMarkerCategories);
     }
 
     /**
index 228b6f6adc704b950a31444ffcfc4689e9cbe83a..14fd4da441053413a439c79d3e062c27f8724e94 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -29,7 +30,6 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
 
 import com.google.common.collect.LinkedHashMultimap;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
 
 /**
@@ -54,7 +54,7 @@ public class TimeGraphMarkerAxis extends TimeGraphBaseControl {
 
     private @NonNull ITimeDataProvider fTimeProvider;
     private Multimap<String, IMarkerEvent> fMarkers = LinkedHashMultimap.create();
-    private List<String> fCategories = Collections.EMPTY_LIST;
+    private @NonNull List<String> fCategories = Collections.EMPTY_LIST;
 
     /**
      * Contructor
@@ -99,6 +99,20 @@ public class TimeGraphMarkerAxis extends TimeGraphBaseControl {
         fTimeProvider = timeProvider;
     }
 
+    /**
+     * Set the list of marker categories.
+     *
+     * @param categories
+     *            The list of marker categories, or null
+     */
+    public void setMarkerCategories(List<String> categories) {
+        if (categories == null) {
+            fCategories = Collections.EMPTY_LIST;
+        } else {
+            fCategories = categories;
+        }
+    }
+
     /**
      * Set the markers list.
      *
@@ -110,11 +124,8 @@ public class TimeGraphMarkerAxis extends TimeGraphBaseControl {
         for (IMarkerEvent marker : markers) {
             map.put(marker.getCategory(), marker);
         }
-        List<String> categories = Lists.newArrayList(map.keySet());
-        Collections.sort(categories);
         Display.getDefault().asyncExec(() -> {
             fMarkers = map;
-            fCategories = categories;
             getParent().layout();
             redraw();
         });
@@ -140,7 +151,9 @@ public class TimeGraphMarkerAxis extends TimeGraphBaseControl {
         gc.fillRectangle(bounds);
 
         Rectangle rect = new Rectangle(bounds.x, bounds.y + TOP_MARGIN, bounds.width, HEIGHT);
-        for (String category : fCategories) {
+        List<String> categories = new ArrayList<>(fCategories);
+        categories.retainAll(fMarkers.keySet());
+        for (String category : categories) {
             rect.x = bounds.x;
             rect.width = nameSpace;
             drawMarkerCategory(category, rect, gc);
@@ -256,7 +269,9 @@ public class TimeGraphMarkerAxis extends TimeGraphBaseControl {
             (double) (timeSpace - RIGHT_MARGIN) / (time1 - time0);
 
         int categoryIndex = Math.max((event.y - TOP_MARGIN) / HEIGHT, 0);
-        String category = fCategories.get(categoryIndex);
+        List<String> categories = new ArrayList<>(fCategories);
+        categories.retainAll(fMarkers.keySet());
+        String category = categories.get(categoryIndex);
 
         IMarkerEvent marker = null;
         GC gc = new GC(Display.getDefault());
This page took 0.030327 seconds and 5 git commands to generate.