From: Patrick Tasse Date: Wed, 28 Oct 2015 18:56:17 +0000 (-0400) Subject: tmf: Add drop-down to Next Marker action to set navigation enablement X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=6d5b0ba1f0ee934c654d05332826b6a49c6dc036;p=deliverable%2Ftracecompass.git tmf: Add drop-down to Next Marker action to set navigation enablement The Next Marker action now has the AS_DROP_DOWN_MENU style. The menu items allow to disable navigation of markers by category. The Next/Previous Marker actions now skip markers of disabled categories. The marker list is cleared immediately when switching traces in the abstract time graph view. If the trace was not a supported trace for that specific view, the marker list would never get updated. The marker actions now disabled if the time graph has no content (empty time bounds). The enablement/disablement of the Next/Previous Marker actions based on current time selection that was requested and implemented in https://git.eclipse.org/r/57135 is reverted for the following reasons: - It would now require to go through the list of markers and comparing each marker category against the set of disabled categories, just to set the action enabled state, whenever the time selection changes. - It would make the Next Marker drop down menu inaccessible if the current time selection is after the last marker. Change-Id: Idd8361ccc6a00c0bb19749019965e5389aa2692a Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/59171 Reviewed-by: Hudson CI --- 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 7475a289d1..bde2d05028 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 @@ -1582,6 +1582,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA fTimeGraphWrapper.getTimeGraphViewer().setLinks(null); fTimeGraphWrapper.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile)); fTimeGraphWrapper.getTimeGraphViewer().setMarkerCategories(getMarkerCategories()); + fTimeGraphWrapper.getTimeGraphViewer().setMarkers(null); } else { fTimeGraphWrapper.refresh(); } 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 a595f456db..f7a66f59a2 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 @@ -24,7 +24,9 @@ import java.util.List; import java.util.Set; import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; @@ -60,6 +62,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Slider; import org.eclipse.tracecompass.internal.tmf.ui.Activator; import org.eclipse.tracecompass.internal.tmf.ui.ITmfImageConstants; @@ -175,6 +178,9 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { /** The set of hidden marker categories */ private final Set fHiddenMarkerCategories = new HashSet<>(); + /** The set of skipped marker categories */ + private final Set fSkippedMarkerCategories = new HashSet<>(); + /** The list of markers */ private final List fMarkers = new ArrayList<>(); @@ -2101,7 +2107,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { */ public Action getNextMarkerAction() { if (fNextMarkerAction == null) { - fNextMarkerAction = new Action() { + fNextMarkerAction = new Action(Messages.TmfTimeGraphViewer_NextMarkerActionText, IAction.AS_DROP_DOWN_MENU) { @Override public void runWithEvent(Event event) { final long time = Math.min(fSelectionBegin, fSelectionEnd); @@ -2111,17 +2117,57 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { return; } for (IMarkerEvent marker : markers) { - if (marker.getTime() > time || - (marker.getTime() == time && marker.getDuration() > duration)) { + if ((marker.getTime() > time || + (marker.getTime() == time && marker.getDuration() > duration)) + && !fSkippedMarkerCategories.contains(marker.getCategory())) { setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration()); return; } } } }; - fNextMarkerAction.setText(Messages.TmfTimeGraphViewer_NextMarkerActionText); fNextMarkerAction.setToolTipText(Messages.TmfTimeGraphViewer_NextMarkerActionText); fNextMarkerAction.setImageDescriptor(NEXT_BOOKMARK); + fNextMarkerAction.setMenuCreator(new IMenuCreator () { + Menu menu = null; + @Override + public void dispose() { + if (menu != null) { + menu.dispose(); + menu = null; + } + } + + @Override + public Menu getMenu(Control parent) { + if (menu != null) { + menu.dispose(); + } + menu = new Menu(parent); + for (String category : fMarkerCategories) { + final Action action = new Action(category, IAction.AS_CHECK_BOX) { + @Override + public void runWithEvent(Event event) { + if (isChecked()) { + fSkippedMarkerCategories.remove(getText()); + } else { + fSkippedMarkerCategories.add(getText()); + } + updateMarkerActions(); + } + }; + action.setEnabled(!fHiddenMarkerCategories.contains(category)); + action.setChecked(action.isEnabled() && !fSkippedMarkerCategories.contains(category)); + new ActionContributionItem(action).fill(menu, -1); + } + return menu; + } + + @Override + public Menu getMenu(Menu parent) { + return null; + } + }); } return fNextMarkerAction; } @@ -2145,8 +2191,9 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { } for (int i = markers.size() - 1; i >= 0; i--) { IMarkerEvent marker = markers.get(i); - if (marker.getTime() < time || - (marker.getTime() == time && marker.getDuration() < duration)) { + if ((marker.getTime() < time || + (marker.getTime() == time && marker.getDuration() < duration)) + && !fSkippedMarkerCategories.contains(marker.getCategory())) { setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration()); return; } @@ -2208,6 +2255,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { } private void updateMarkerActions() { + boolean enabled = fTime0Bound != SWT.DEFAULT || fTime1Bound != SWT.DEFAULT; if (fToggleBookmarkAction != null) { if (getBookmarkAtSelection() != null) { fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionRemoveText); @@ -2218,21 +2266,17 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { fToggleBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_BookmarkActionAddText); fToggleBookmarkAction.setImageDescriptor(ADD_BOOKMARK); } + fToggleBookmarkAction.setEnabled(enabled); } - final long time = Math.min(fSelectionBegin, fSelectionEnd); - final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time; List markers = getTimeGraphControl().getMarkers(); if (markers == null) { markers = Collections.emptyList(); } if (fPreviousMarkerAction != null) { - fPreviousMarkerAction.setEnabled(!markers.isEmpty() && - (time > markers.get(0).getTime() || (time == markers.get(0).getTime() && duration > markers.get(0).getDuration()))); + fPreviousMarkerAction.setEnabled(enabled && !markers.isEmpty()); } if (fNextMarkerAction != null) { - int last = markers.size() - 1; - fNextMarkerAction.setEnabled(!markers.isEmpty() && - (time < markers.get(last).getTime() || (time == markers.get(last).getTime() && duration < markers.get(last).getDuration()))); + fNextMarkerAction.setEnabled(enabled && !markers.isEmpty()); } }