From 91512088e40a75495ea13583b9cffeca1361a025 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Tue, 27 Oct 2015 18:40:40 -0400 Subject: [PATCH] tmf: Add Show Markers menu for time graph viewer 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 Reviewed-on: https://git.eclipse.org/r/59072 Reviewed-by: Hudson CI --- .../internal/tmf/ui/Messages.java | 3 +- .../internal/tmf/ui/messages.properties | 3 +- .../timegraph/AbstractTimeGraphView.java | 46 +++++++++- .../ui/widgets/timegraph/TimeGraphViewer.java | 83 ++++++++++++++++++- .../widgets/timegraph/model/IMarkerEvent.java | 4 +- 5 files changed, 129 insertions(+), 10 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java index cc499b8aae..a405a1c462 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java @@ -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; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties index b6d41eaf1b..92170e71d3 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties @@ -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 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 40ba1fed47..7475a289d1 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,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 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 getMarkerCategories() { + Set 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 getMarkerEventSources(ITmfTrace trace) { + private @NonNull List getMarkerEventSources(ITmfTrace trace) { List markerEventSources = fMarkerEventSourcesMap.get(trace); if (markerEventSources == null) { markerEventSources = checkNotNull(Collections.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 */ 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 5ee837d0aa..a595f456db 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 @@ -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 fBookmarks = new ArrayList<>(); + /** The list of marker categories */ + private final List fMarkerCategories = new ArrayList<>(); + + /** The set of hidden marker categories */ + private final Set fHiddenMarkerCategories = new HashSet<>(); + /** The list of markers */ private final List 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 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 markers = new ArrayList<>(fMarkers); - markers.addAll(fBookmarks); + List 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); } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEvent.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEvent.java index e34610ee60..087a8f0ef5 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEvent.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEvent.java @@ -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. -- 2.34.1