tmf: Add Show Markers menu for time graph viewer
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 27 Oct 2015 22:40:40 +0000 (18:40 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 29 Oct 2015 21:07:16 +0000 (17:07 -0400)
Support the dynamic Show Markers menu in time graph viewer that contains
a checked action for each of: Bookmarks category, view-specific marker
categories, and trace-specific marker categories for the current trace.

Add the menu to the abstract time graph view's view menu.

Hide markers of categories that are unchecked in the Show Markers menu.
This will also make them ignored in Next/Previous Marker navigation.

Change-Id: I31c0ee983c217a149070f8628a162fc7420222d6
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/59072
Reviewed-by: Hudson CI
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties
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/model/IMarkerEvent.java

index cc499b8aae7754f24989c1e9bf90bcb75a16b8de..a405a1c462c56e1b36e7a04d33bad5f5c3e9ffd2 100644 (file)
@@ -38,7 +38,7 @@ public class Messages extends NLS {
     public static String ManageCustomParsersDialog_NewButtonLabel;
     public static String ManageCustomParsersDialog_TextButtonLabel;
 
-    public static String MarkerEvent_Bookmark;
+    public static String MarkerEvent_Bookmarks;
 
     public static String TmfEventsTable_AddBookmarkActionText;
     public static String TmfEventsTable_ApplyPresetFilterMenuName;
@@ -134,6 +134,7 @@ public class Messages extends NLS {
     public static String TmfTimeGraphViewer_BookmarkActionRemoveText;
     public static String TmfTimeGraphViewer_NextMarkerActionText;
     public static String TmfTimeGraphViewer_PreviousMarkerActionText;
+    public static String TmfTimeGraphViewer_ShowMarkersMenuText;
 
     public static String Utils_ClockCyclesUnit;
 
index b6d41eaf1b64716ee1141104483ee850c7dce6ee..92170e71d3580db9d40eb4d8726211a3a3f3c04a 100644 (file)
@@ -85,7 +85,7 @@ TmfTimeFilterDialog_CHECK_SUBTREE=Check subtree
 TmfTimeFilterDialog_UNCHECK_SUBTREE=Uncheck subtree
 
 # org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model
-MarkerEvent_Bookmark=Bookmark
+MarkerEvent_Bookmarks=Bookmarks
 
 # org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets
 TmfTimeTipHandler_DURATION=Duration
@@ -130,6 +130,7 @@ TmfTimeGraphViewer_BookmarkActionAddText=Add Bookmark...
 TmfTimeGraphViewer_BookmarkActionRemoveText=Remove Bookmark
 TmfTimeGraphViewer_NextMarkerActionText=Next Marker
 TmfTimeGraphViewer_PreviousMarkerActionText=Previous Marker
+TmfTimeGraphViewer_ShowMarkersMenuText=Show Markers
 
 Utils_ClockCyclesUnit=\u0020cc
 
index 40ba1fed478858439ec267174d84c3771a4f4fb0..7475a289d1e22475f4f023ed9cf04c1c78ff5323 100644 (file)
@@ -22,8 +22,10 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -43,6 +45,7 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.action.Separator;
@@ -1185,7 +1188,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                             int alpha = Integer.valueOf(matcher.group(4));
                             Color color = new Color(Display.getDefault(), red, green, blue, alpha);
                             fColors.add(color);
-                            bookmarks.add(new MarkerEvent(null, Long.valueOf(time), Long.valueOf(duration), IMarkerEvent.BOOKMARK, color, label, true));
+                            bookmarks.add(new MarkerEvent(null, Long.valueOf(time), Long.valueOf(duration), IMarkerEvent.BOOKMARKS, color, label, true));
                         } catch (NumberFormatException e) {
                             Activator.getDefault().logError(e.getMessage());
                         }
@@ -1459,6 +1462,17 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         return new ArrayList<>();
     }
 
+    /**
+     * Gets the list of view-specific marker categories. Default implementation
+     * returns an empty list.
+     *
+     * @return The list of marker categories
+     * @since 2.0
+     */
+    protected @NonNull List<String> getViewMarkerCategories() {
+        return new ArrayList<>();
+    }
+
     /**
      * Gets the list of view-specific markers for a trace in a given time range.
      * Default implementation returns an empty list.
@@ -1507,6 +1521,20 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         return markers;
     }
 
+    /**
+     * Get the list of current marker categories.
+     *
+     * @return The list of marker categories
+     * @since 2.0
+     */
+    private @NonNull List<String> getMarkerCategories() {
+        Set<String> categories = new HashSet<>(getViewMarkerCategories());
+        for (IMarkerEventSource markerEventSource : getMarkerEventSources(fTrace)) {
+            categories.addAll(markerEventSource.getMarkerCategories());
+        }
+        return new ArrayList<>(categories);
+    }
+
     /**
      * Gets the list of marker event sources for a given trace.
      *
@@ -1515,7 +1543,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
      * @return The list of marker event sources
      * @since 2.0
      */
-    protected @NonNull List<IMarkerEventSource> getMarkerEventSources(ITmfTrace trace) {
+    private @NonNull List<IMarkerEventSource> getMarkerEventSources(ITmfTrace trace) {
         List<IMarkerEventSource> markerEventSources = fMarkerEventSourcesMap.get(trace);
         if (markerEventSources == null) {
             markerEventSources = checkNotNull(Collections.<IMarkerEventSource>emptyList());
@@ -1553,6 +1581,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                     fTimeGraphWrapper.setFilters(fFiltersMap.get(fTrace));
                     fTimeGraphWrapper.getTimeGraphViewer().setLinks(null);
                     fTimeGraphWrapper.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile));
+                    fTimeGraphWrapper.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
                 } else {
                     fTimeGraphWrapper.refresh();
                 }
@@ -1667,6 +1696,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
     private void contributeToActionBars() {
         IActionBars bars = getViewSite().getActionBars();
         fillLocalToolBar(bars.getToolBarManager());
+        fillLocalMenu(bars.getMenuManager());
     }
 
     /**
@@ -1683,9 +1713,11 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         manager.add(fTimeGraphWrapper.getTimeGraphViewer().getResetScaleAction());
         manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousEventAction());
         manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextEventAction());
+        manager.add(new Separator());
         manager.add(fTimeGraphWrapper.getTimeGraphViewer().getToggleBookmarkAction());
         manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousMarkerAction());
         manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextMarkerAction());
+        manager.add(new Separator());
         manager.add(fPreviousResourceAction);
         manager.add(fNextResourceAction);
         manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomInAction());
@@ -1693,6 +1725,16 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         manager.add(new Separator());
     }
 
+    /**
+     * Add actions to local menu manager
+     *
+     * @param manager the tool bar manager
+     * @since 2.0
+     */
+    protected void fillLocalMenu(IMenuManager manager) {
+        manager.add(fTimeGraphWrapper.getTimeGraphViewer().getMarkersMenu());
+    }
+
     /**
      * @since 1.0
      */
index 5ee837d0aa273fa7583445ad0277da34a366c405..a595f456db6fae19983209658483c8f5d6d96158 100644 (file)
@@ -19,10 +19,15 @@ package org.eclipse.tracecompass.tmf.ui.widgets.timegraph;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.AbstractTreeViewer;
@@ -159,10 +164,17 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     private Action fToggleBookmarkAction;
     private Action fNextMarkerAction;
     private Action fPreviousMarkerAction;
+    private MenuManager fMarkersMenu;
 
     /** The list of bookmarks */
     private final List<IMarkerEvent> fBookmarks = new ArrayList<>();
 
+    /** The list of marker categories */
+    private final List<String> fMarkerCategories = new ArrayList<>();
+
+    /** The set of hidden marker categories */
+    private final Set<String> fHiddenMarkerCategories = new HashSet<>();
+
     /** The list of markers */
     private final List<IMarkerEvent> fMarkers = new ArrayList<>();
 
@@ -453,6 +465,9 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
                 for (Color color : fColors) {
                     color.dispose();
                 }
+                if (fMarkersMenu != null) {
+                    fMarkersMenu.dispose();
+                }
             }
         });
         GridLayout gl = new GridLayout(2, false);
@@ -1236,6 +1251,22 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         return Collections.unmodifiableList(fBookmarks);
     }
 
+    /**
+     * Set the list of marker categories.
+     *
+     * @param categories
+     *            The list of marker categories, or null
+     * @since 2.0
+     */
+    public void setMarkerCategories(List<String> categories) {
+        fMarkerCategories.clear();
+        fMarkerCategories.add(IMarkerEvent.BOOKMARKS);
+        if (categories != null) {
+            fMarkerCategories.addAll(categories);
+        }
+        Collections.sort(fMarkerCategories);
+    }
+
     /**
      * Set the markers list.
      *
@@ -2038,9 +2069,10 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
                             final RGBA rgba = dialog.getColorValue();
                             Color color = new Color(Display.getDefault(), rgba.rgb.red, rgba.rgb.green, rgba.rgb.blue, rgba.alpha);
                             fColors.add(color);
-                            IMarkerEvent bookmark = new MarkerEvent(null, time, duration, IMarkerEvent.BOOKMARK, color, label, true);
+                            IMarkerEvent bookmark = new MarkerEvent(null, time, duration, IMarkerEvent.BOOKMARKS, color, label, true);
                             fBookmarks.add(bookmark);
                             updateMarkerList();
+                            updateMarkerActions();
                             getControl().redraw();
                             fireBookmarkAdded(bookmark);
                         }
@@ -2048,10 +2080,10 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
                         checkDisposeColor(selectedBookmark.getColor());
                         fBookmarks.remove(selectedBookmark);
                         updateMarkerList();
+                        updateMarkerActions();
                         getControl().redraw();
                         fireBookmarkRemoved(selectedBookmark);
                     }
-                    updateMarkerActions();
                 }
             };
             fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
@@ -2128,6 +2160,42 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         return fPreviousMarkerAction;
     }
 
+    /**
+     * Get the show markers menu.
+     *
+     * @return The menu manager object
+     * @since 2.0
+     */
+    public MenuManager getMarkersMenu() {
+        if (fMarkersMenu == null) {
+            fMarkersMenu = new MenuManager(Messages.TmfTimeGraphViewer_ShowMarkersMenuText);
+            fMarkersMenu.setRemoveAllWhenShown(true);
+            fMarkersMenu.addMenuListener(new IMenuListener() {
+                @Override
+                public void menuAboutToShow(IMenuManager manager) {
+                    for (String category : fMarkerCategories) {
+                        final Action action = new Action(category, IAction.AS_CHECK_BOX) {
+                            @Override
+                            public void runWithEvent(Event event) {
+                                if (isChecked()) {
+                                    fHiddenMarkerCategories.remove(getText());
+                                } else {
+                                    fHiddenMarkerCategories.add(getText());
+                                }
+                                updateMarkerList();
+                                updateMarkerActions();
+                                getControl().redraw();
+                            }
+                        };
+                        action.setChecked(!fHiddenMarkerCategories.contains(category));
+                        manager.add(action);
+                    }
+                }
+            });
+        }
+        return fMarkersMenu;
+    }
+
     private IMarkerEvent getBookmarkAtSelection() {
         final long time = Math.min(fSelectionBegin, fSelectionEnd);
         final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
@@ -2169,8 +2237,15 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     }
 
     private void updateMarkerList() {
-        List<IMarkerEvent> markers = new ArrayList<>(fMarkers);
-        markers.addAll(fBookmarks);
+        List<IMarkerEvent> markers = new ArrayList<>();
+        for (IMarkerEvent marker : fMarkers) {
+            if (!fHiddenMarkerCategories.contains(marker.getCategory())) {
+                markers.add(marker);
+            }
+        }
+        if (!fHiddenMarkerCategories.contains(IMarkerEvent.BOOKMARKS)) {
+            markers.addAll(fBookmarks);
+        }
         Collections.sort(markers, new MarkerComparator());
         getTimeGraphControl().setMarkers(markers);
     }
index e34610ee6061f1167f6297588b86faa96df14e34..087a8f0ef5af3c01f6b6d6d8f79a4e74b4ae3920 100644 (file)
@@ -26,8 +26,8 @@ import org.eclipse.tracecompass.internal.tmf.ui.Messages;
  */
 public interface IMarkerEvent extends ITimeEvent {
 
-    /** Bookmark marker category */
-    @NonNull String BOOKMARK = checkNotNull(Messages.MarkerEvent_Bookmark);
+    /** Bookmarks marker category */
+    @NonNull String BOOKMARKS = checkNotNull(Messages.MarkerEvent_Bookmarks);
 
     /**
      * Get this marker's category.
This page took 0.032649 seconds and 5 git commands to generate.