From a924e2ed73d2831ed154cbaf3b2b510125ce15f2 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Fri, 12 Feb 2016 18:15:32 -0500 Subject: [PATCH] tmf: Preserve order of marker categories 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 Reviewed-on: https://git.eclipse.org/r/66541 Reviewed-by: Hudson CI Tested-by: Bernd Hufmann Reviewed-by: Bernd Hufmann --- .../timegraph/AbstractTimeGraphView.java | 4 +-- .../ui/widgets/timegraph/TimeGraphViewer.java | 4 +-- .../widgets/TimeGraphMarkerAxis.java | 29 ++++++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java index 682487763e..6ad0a95602 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java @@ -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 getMarkerCategories() { - Set categories = new HashSet<>(getViewMarkerCategories()); + Set categories = new LinkedHashSet<>(getViewMarkerCategories()); for (IMarkerEventSource markerEventSource : getMarkerEventSources(fTrace)) { categories.addAll(markerEventSource.getMarkerCategories()); } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java index 6b70561934..f5dc386c52 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java @@ -1303,11 +1303,11 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { */ public void setMarkerCategories(List categories) { fMarkerCategories.clear(); - fMarkerCategories.add(IMarkerEvent.BOOKMARKS); if (categories != null) { fMarkerCategories.addAll(categories); } - Collections.sort(fMarkerCategories); + fMarkerCategories.add(IMarkerEvent.BOOKMARKS); + fMarkerAxisCtrl.setMarkerCategories(fMarkerCategories); } /** diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphMarkerAxis.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphMarkerAxis.java index 228b6f6adc..14fd4da441 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphMarkerAxis.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphMarkerAxis.java @@ -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 fMarkers = LinkedHashMultimap.create(); - private List fCategories = Collections.EMPTY_LIST; + private @NonNull List 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 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 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 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 categories = new ArrayList<>(fCategories); + categories.retainAll(fMarkers.keySet()); + String category = categories.get(categoryIndex); IMarkerEvent marker = null; GC gc = new GC(Display.getDefault()); -- 2.34.1