tmf: Support user bookmarks in time graph
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 30 Sep 2015 22:32:15 +0000 (18:32 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 2 Oct 2015 16:37:10 +0000 (12:37 -0400)
Adds the Toggle Bookmark, Select Previous Bookmark and Select Next
Bookmark actions to the time graph viewer and the abstract time graph
view.

Adds an Add Bookmark dialog.

Adds an ITimeGraphBookmarkListener interface.

Uses the old Previous/Next Event icons for the Previous/Next Bookmark
actions, and modifies the Previous/Next Event icons.

Change-Id: Ic7e51c4cf7aab4f78b49ec7bc9e2b87faff9f325
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/57135
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
16 files changed:
tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/add_bookmark.gif [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/next_bookmark.gif [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/next_event.gif
tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/prev_bookmark.gif [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/prev_event.gif
tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/remove_bookmark.gif [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/ITmfImageConstants.java
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/dialogs/AddBookmarkDialog.java [new file with mode: 0644]
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/ITimeGraphBookmarkListener.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphBookmarkEvent.java [new file with mode: 0644]
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/TimeGraphControl.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java

diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/add_bookmark.gif b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/add_bookmark.gif
new file mode 100644 (file)
index 0000000..38f3744
Binary files /dev/null and b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/add_bookmark.gif differ
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/next_bookmark.gif b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/next_bookmark.gif
new file mode 100644 (file)
index 0000000..da6c4b6
Binary files /dev/null and b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/next_bookmark.gif differ
index da6c4b66f68e22891fa54f9aef87b1e37efae22a..c5371ffce67af2b751e3af59bbc77b148ff6d39c 100644 (file)
Binary files a/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/next_event.gif and b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/next_event.gif differ
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/prev_bookmark.gif b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/prev_bookmark.gif
new file mode 100644 (file)
index 0000000..ed3e7c2
Binary files /dev/null and b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/prev_bookmark.gif differ
index ed3e7c26eeda82c0dec1a9ca0776df484a740cb9..69c57a934ab30520c1cbfd60fb2168d405d8d976 100644 (file)
Binary files a/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/prev_event.gif and b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/prev_event.gif differ
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/remove_bookmark.gif b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/remove_bookmark.gif
new file mode 100644 (file)
index 0000000..3ac7c60
Binary files /dev/null and b/tmf/org.eclipse.tracecompass.tmf.ui/icons/elcl16/remove_bookmark.gif differ
index f78bcf6d87c814f2ea7888d3f9819cedbcb6c193..3947e3dd8f2959c56f0d6e0b51cf6e48892dd292 100755 (executable)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2014 Ericsson and others.
+ * Copyright (c) 2011, 2015 Ericsson and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -37,8 +37,10 @@ public interface ITmfImageConstants {
     String IMG_UI_SHOW_LEGEND = ICONS_PATH + "elcl16/show_legend.gif";
     String IMG_UI_NEXT_EVENT = ICONS_PATH + "elcl16/next_event.gif";
     String IMG_UI_PREV_EVENT = ICONS_PATH + "elcl16/prev_event.gif";
-//    String IMG_UI_NEXT_ITEM = ICONS_PATH + "elcl16/next_item.gif";
-//    String IMG_UI_PREV_ITEM = ICONS_PATH + "elcl16/prev_item.gif";
+    String IMG_UI_ADD_BOOKMARK = ICONS_PATH + "elcl16/add_bookmark.gif";
+    String IMG_UI_NEXT_BOOKMARK = ICONS_PATH + "elcl16/next_bookmark.gif";
+    String IMG_UI_PREVIOUS_BOOKMARK = ICONS_PATH + "elcl16/prev_bookmark.gif";
+    String IMG_UI_REMOVE_BOOKMARK = ICONS_PATH + "elcl16/remove_bookmark.gif";
     String IMG_UI_NEXT_ITEM = IMG_UI_NEXT_PAGE;
     String IMG_UI_PREV_ITEM = IMG_UI_PREV_PAGE;
     String IMG_UI_PIN_VIEW = ICONS_PATH + "elcl16/pin_view.gif";
index 435df5766d82fce8bdf48d6bd09f28bbb6ae282f..bea7f7ed1bf4154f9a4980d820b4008f3711bd8a 100644 (file)
@@ -19,6 +19,10 @@ public class Messages extends NLS {
 
     private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.tmf.ui.messages"; //$NON-NLS-1$
 
+    public static String AddBookmarkDialog_Alpha;
+    public static String AddBookmarkDialog_Color;
+    public static String AddBookmarkDialog_Message;
+    public static String AddBookmarkDialog_Title;
     public static String ManageCustomParsersDialog_ConflictMessage;
     public static String ManageCustomParsersDialog_ConflictRenameButtonLabel;
     public static String ManageCustomParsersDialog_ConflictSkipButtonLabel;
@@ -123,6 +127,10 @@ public class Messages extends NLS {
     public static String TmfTimeGraphViewer_FollowArrowForwardActionToolTipText;
     public static String TmfTimeGraphViewer_FollowArrowBackwardActionNameText;
     public static String TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText;
+    public static String TmfTimeGraphViewer_BookmarkActionAddText;
+    public static String TmfTimeGraphViewer_BookmarkActionRemoveText;
+    public static String TmfTimeGraphViewer_NextBookmarkActionText;
+    public static String TmfTimeGraphViewer_PreviousBookmarkActionText;
 
     public static String Utils_ClockCyclesUnit;
 
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/AddBookmarkDialog.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/AddBookmarkDialog.java
new file mode 100644 (file)
index 0000000..bd4a7a0
--- /dev/null
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.ui.dialogs;
+
+import org.eclipse.jface.preference.ColorSelector;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.RGBA;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Scale;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tracecompass.internal.tmf.ui.Messages;
+
+/**
+ * A dialog for soliciting a bookmark description and color from the user.
+ *
+ * @since 2.0
+ */
+public class AddBookmarkDialog extends MultiLineInputDialog {
+
+    private ColorSelector fColorSelector;
+    private Scale fAlphaScale;
+    private Label fAlphaLabel;
+    private int fAlpha = 128;
+
+    /**
+     * Constructor
+     *
+     * @param parentShell
+     *            the parent shell
+     */
+    public AddBookmarkDialog(Shell parentShell) {
+        super(parentShell, Messages.AddBookmarkDialog_Title, Messages.AddBookmarkDialog_Message, ""); //$NON-NLS-1$
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite areaComposite = (Composite) super.createDialogArea(parent);
+        Composite colorComposite = new Composite(areaComposite, SWT.NONE);
+        RowLayout layout = new RowLayout();
+        layout.center = true;
+        colorComposite.setLayout(layout);
+        colorComposite.moveBelow(getText());
+        Label colorLabel = new Label(colorComposite, SWT.NONE);
+        colorLabel.setText(Messages.AddBookmarkDialog_Color);
+        fColorSelector = new ColorSelector(colorComposite);
+        fColorSelector.setColorValue(new RGB(255, 0, 0));
+        Label alphaLabel = new Label(colorComposite, SWT.NONE);
+        alphaLabel.setText(Messages.AddBookmarkDialog_Alpha);
+        fAlphaScale = new Scale(colorComposite, SWT.NONE);
+        fAlphaScale.setMaximum(255);
+        fAlphaScale.setSelection(fAlpha);
+        fAlphaScale.setIncrement(1);
+        fAlphaScale.setPageIncrement(16);
+        fAlphaScale.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                fAlpha = fAlphaScale.getSelection();
+                fAlphaLabel.setText(Integer.toString(fAlpha));
+            }
+        });
+        fAlphaLabel = new Label(colorComposite, SWT.NONE);
+        fAlphaLabel.setText(Integer.toString(fAlpha));
+        return areaComposite;
+    }
+
+    /**
+     * Returns the color selected in this dialog.
+     *
+     * @return the color RGBA value
+     */
+    public RGBA getColorValue() {
+        RGB rgb = fColorSelector.getColorValue();
+        return new RGBA(rgb.red, rgb.green, rgb.blue, fAlpha);
+    }
+}
index ee58daeecb0ae732f600f478fa32135dbb87d16d..ef192f3b50d6b7169ded458352293bad3b8c5876 100644 (file)
 ###############################################################################
 
 # org.eclipse.tracecompass.tmf.ui.dialogs
+AddBookmarkDialog_Alpha=alpha:
+AddBookmarkDialog_Color=Color:
+AddBookmarkDialog_Message=Bookmark Description:
+AddBookmarkDialog_Title=Add Bookmark
 ManageCustomParsersDialog_ConflictMessage=Trace type ''{0} : {1}'' already exists.\nDo you want to rename to ''{2}'' or skip?
 ManageCustomParsersDialog_ConflictRenameButtonLabel=Rename
 ManageCustomParsersDialog_ConflictSkipButtonLabel=Skip
@@ -117,6 +121,10 @@ TmfTimeGraphViewer_FollowArrowForwardActionNameText=Follow Arrow Forward
 TmfTimeGraphViewer_FollowArrowForwardActionToolTipText=Follow Arrow Forward
 TmfTimeGraphViewer_FollowArrowBackwardActionNameText=Follow Arrow Backward
 TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText=Follow Arrow Backward
+TmfTimeGraphViewer_BookmarkActionAddText=Add Bookmark...
+TmfTimeGraphViewer_BookmarkActionRemoveText=Remove Bookmark
+TmfTimeGraphViewer_NextBookmarkActionText=Next Bookmark
+TmfTimeGraphViewer_PreviousBookmarkActionText=Previous Bookmark
 
 Utils_ClockCyclesUnit=\u0020cc
 
index ee0b2c0fa9927c36539c15005e3574439a5034f3..5d4a10b507052ba7d0501b4333e70c3d1e7a4301 100644 (file)
@@ -1490,6 +1490,9 @@ 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(fTimeGraphWrapper.getTimeGraphViewer().getToggleBookmarkAction());
+        manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousBookmarkAction());
+        manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextBookmarkAction());
         manager.add(fPreviousResourceAction);
         manager.add(fNextResourceAction);
         manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomInAction());
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/ITimeGraphBookmarkListener.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/ITimeGraphBookmarkListener.java
new file mode 100644 (file)
index 0000000..b019c28
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ui.widgets.timegraph;
+
+import java.util.EventListener;
+
+/**
+ * A listener which is notified when a timegraph adds or removes a bookmark.
+ *
+ * @author Patrick Tasse
+ * @since 2.0
+ */
+public interface ITimeGraphBookmarkListener extends EventListener {
+
+    /**
+     * Notifies that the timegraph has added a bookmark.
+     *
+     * @param event event object describing details
+     */
+    void bookmarkAdded(TimeGraphBookmarkEvent event);
+
+    /**
+     * Notifies that the timegraph has removed a bookmark.
+     *
+     * @param event event object describing details
+     */
+    void bookmarkRemoved(TimeGraphBookmarkEvent event);
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphBookmarkEvent.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphBookmarkEvent.java
new file mode 100644 (file)
index 0000000..640e7b4
--- /dev/null
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ui.widgets.timegraph;
+
+import java.util.EventObject;
+
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
+
+/**
+ * Bookmark event
+ *
+ * @author Patrick Tasse
+ * @since 2.0
+ */
+public class TimeGraphBookmarkEvent extends EventObject {
+
+    /**
+     * Default serial version UID for this class.
+     */
+    private static final long serialVersionUID = 8155869849072620814L;
+
+    /**
+     * The bookmark
+     */
+    private final IMarkerEvent fBookmark;
+
+    /**
+     * Standard constructor
+     *
+     * @param source
+     *            The source of this event
+     * @param bookmark
+     *            The bookmark
+     */
+    public TimeGraphBookmarkEvent(Object source, IMarkerEvent bookmark) {
+        super(source);
+        fBookmark = bookmark;
+    }
+
+    /**
+     * @return the bookmark
+     */
+    public IMarkerEvent getBookmark() {
+        return fBookmark;
+    }
+
+}
index 3cf12cda9075f41cb8bc50639e542ce5c8c688b6..fe8a4e94625746175c0dbadd5dc9a4a432d51fee 100644 (file)
 package org.eclipse.tracecompass.tmf.ui.widgets.timegraph;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.AbstractTreeViewer;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.ITableLabelProvider;
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ControlAdapter;
 import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.MenuDetectListener;
@@ -38,6 +44,8 @@ import org.eclipse.swt.events.MouseWheelListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGBA;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
@@ -51,13 +59,16 @@ import org.eclipse.swt.widgets.Slider;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.ui.ITmfImageConstants;
 import org.eclipse.tracecompass.internal.tmf.ui.Messages;
+import org.eclipse.tracecompass.internal.tmf.ui.dialogs.AddBookmarkDialog;
 import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo;
 import org.eclipse.tracecompass.tmf.ui.views.ITmfTimeAligned;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.dialogs.ShowFilterDialogAction;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeDataProviderCyclesConverter;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
@@ -66,6 +77,7 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
+import org.eclipse.ui.PlatformUI;
 
 /**
  * Generic time graph viewer implementation
@@ -85,6 +97,11 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     private static final long DEFAULT_FREQUENCY = 1000000000L;
     private static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;
 
+    private static ImageDescriptor ADD_BOOKMARK = Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ADD_BOOKMARK);
+    private static ImageDescriptor NEXT_BOOKMARK = Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_BOOKMARK);
+    private static ImageDescriptor PREVIOUS_BOOKMARK = Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREVIOUS_BOOKMARK);
+    private static ImageDescriptor REMOVE_BOOKMARK = Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_REMOVE_BOOKMARK);
+
     private long fMinTimeInterval;
     private ITimeGraphEntry fSelectedEntry;
     private long fBeginTime = SWT.DEFAULT; // The user-specified bounds start time
@@ -117,6 +134,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     private List<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<>();
     private List<ITimeGraphTimeListener> fTimeListeners = new ArrayList<>();
     private List<ITimeGraphRangeListener> fRangeListeners = new ArrayList<>();
+    private List<ITimeGraphBookmarkListener> fBookmarkListeners = new ArrayList<>();
 
     // Time format, using Epoch reference, Relative time format(default),
     // Number, or Cycles
@@ -138,6 +156,15 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     private Action fFollowArrowFwdAction;
     private Action fFollowArrowBwdAction;
     private ShowFilterDialogAction fShowFilterDialogAction;
+    private Action fToggleBookmarkAction;
+    private Action fNextBookmarkAction;
+    private Action fPreviousBookmarkAction;
+
+    /** The list of bookmarks */
+    private final List<IMarkerEvent> fBookmarks = new ArrayList<>();
+
+    /** The list of color resources created by this viewer */
+    private final List<Color> fColors = new ArrayList<>();
 
     private ListenerNotifier fListenerNotifier;
 
@@ -211,6 +238,17 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         }
     }
 
+    private final static class BookmarkComparator implements Comparator<IMarkerEvent> {
+        @Override
+        public int compare(IMarkerEvent o1, IMarkerEvent o2) {
+            int res = Long.compare(o1.getTime(), o2.getTime());
+            if (res != 0) {
+                return res;
+            }
+            return Long.compare(o1.getDuration(), o2.getDuration());
+        }
+    }
+
     /**
      * Standard constructor.
      * <p>
@@ -304,6 +342,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
             setTopIndex(0);
             fSelectionBegin = SWT.DEFAULT;
             fSelectionEnd = SWT.DEFAULT;
+            updateBookmarkActions();
             fSelectedEntry = null;
             refreshAllData(input);
         }
@@ -405,6 +444,14 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
                 super.redraw();
             }
         };
+        fDataViewer.addDisposeListener(new DisposeListener() {
+            @Override
+            public void widgetDisposed(DisposeEvent e) {
+                for (Color color : fColors) {
+                    color.dispose();
+                }
+            }
+        });
         GridLayout gl = new GridLayout(2, false);
         gl.marginHeight = fBorderWidth;
         gl.marginWidth = 0;
@@ -662,6 +709,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         }
         fTimeGraphCtrl.refreshData(traces);
         fTimeScaleCtrl.redraw();
+        updateBookmarkActions();
         adjustVerticalScrollBar();
     }
 
@@ -848,6 +896,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         ensureVisible(fSelectionEnd);
         fTimeGraphCtrl.redraw();
         fTimeScaleCtrl.redraw();
+        updateBookmarkActions();
         if ((time0 != fTime0) || (time1 != fTime1)) {
             notifyRangeListeners();
         }
@@ -866,6 +915,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
         fTimeGraphCtrl.redraw();
         fTimeScaleCtrl.redraw();
+        updateBookmarkActions();
     }
 
     private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
@@ -881,6 +931,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         boolean notifySelectedTime = (selection != fSelectionBegin || selection != fSelectionEnd);
         fSelectionBegin = selection;
         fSelectionEnd = selection;
+        updateBookmarkActions();
 
         if ((time0 != fTime0) || (time1 != fTime1)) {
             notifyRangeListeners();
@@ -1115,6 +1166,91 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         }
     }
 
+    /**
+     * Add a bookmark listener
+     *
+     * @param listener
+     *            The listener to add
+     * @since 2.0
+     */
+    public void addBookmarkListener(ITimeGraphBookmarkListener listener) {
+        fBookmarkListeners.add(listener);
+    }
+
+    /**
+     * Remove a bookmark listener
+     *
+     * @param listener
+     *            The listener to remove
+     * @since 2.0
+     */
+    public void removeBookmarkListener(ITimeGraphBookmarkListener listener) {
+        fBookmarkListeners.remove(listener);
+    }
+
+    private void fireBookmarkAdded(IMarkerEvent bookmark) {
+        TimeGraphBookmarkEvent event = new TimeGraphBookmarkEvent(this, bookmark);
+
+        for (ITimeGraphBookmarkListener listener : fBookmarkListeners) {
+            listener.bookmarkAdded(event);
+        }
+    }
+
+    private void fireBookmarkRemoved(IMarkerEvent bookmark) {
+        TimeGraphBookmarkEvent event = new TimeGraphBookmarkEvent(this, bookmark);
+
+        for (ITimeGraphBookmarkListener listener : fBookmarkListeners) {
+            listener.bookmarkRemoved(event);
+        }
+    }
+
+    /**
+     * Set the bookmarks list.
+     *
+     * @param bookmarks
+     *            The bookmarks list, or null
+     * @since 2.0
+     */
+    public void setBookmarks(List<IMarkerEvent> bookmarks) {
+        for (IMarkerEvent bookmark : fBookmarks) {
+            checkDisposeColor(bookmark.getColor());
+        }
+        fBookmarks.clear();
+        if (bookmarks != null) {
+            fBookmarks.addAll(bookmarks);
+            Collections.sort(fBookmarks, new BookmarkComparator());
+        }
+        updateBookmarkActions();
+        getTimeGraphControl().setBookmarks(bookmarks);
+    }
+
+    /**
+     * Get the bookmarks list.
+     *
+     * @return The bookmarks list
+     * @since 2.0
+     */
+    public List<IMarkerEvent> getBookmarks() {
+        return Collections.unmodifiableList(fBookmarks);
+    }
+
+    /**
+     * Dispose the color resource if and only if it was created by this viewer.
+     *
+     * @param color
+     *            the color
+     */
+    private void checkDisposeColor(Color color) {
+        for (int i = 0; i < fColors.size(); i++) {
+            /* check for identity, not equality */
+            if (fColors.get(i) == color) {
+                color.dispose();
+                fColors.remove(i);
+                break;
+            }
+        }
+    }
+
     /**
      * Callback to set a selected event in the view
      *
@@ -1853,6 +1989,146 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         return fShowFilterDialogAction;
     }
 
+    /**
+     * Get the toggle bookmark action.
+     *
+     * @return The Action object
+     * @since 2.0
+     */
+    public Action getToggleBookmarkAction() {
+        if (fToggleBookmarkAction == null) {
+            fToggleBookmarkAction = new Action() {
+                @Override
+                public void runWithEvent(Event event) {
+                    IMarkerEvent selectedBookmark = getBookmarkAtSelection();
+                    if (selectedBookmark == null) {
+                        final long time = Math.min(fSelectionBegin, fSelectionEnd);
+                        final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
+                        final AddBookmarkDialog dialog = new AddBookmarkDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+                        if (dialog.open() == Window.OK) {
+                            final String label = dialog.getValue();
+                            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, color, label, true);
+                            fBookmarks.add(bookmark);
+                            Collections.sort(fBookmarks, new BookmarkComparator());
+                            getTimeGraphControl().setBookmarks(fBookmarks);
+                            getControl().redraw();
+                            fireBookmarkAdded(bookmark);
+                        }
+                    } else {
+                        checkDisposeColor(selectedBookmark.getColor());
+                        fBookmarks.remove(selectedBookmark);
+                        getTimeGraphControl().setBookmarks(fBookmarks);
+                        getControl().redraw();
+                        fireBookmarkRemoved(selectedBookmark);
+                    }
+                    updateBookmarkActions();
+                }
+            };
+            fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
+            fToggleBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
+            fToggleBookmarkAction.setImageDescriptor(ADD_BOOKMARK);
+        }
+        return fToggleBookmarkAction;
+    }
+
+    /**
+     * Get the next bookmark action.
+     *
+     * @return The Action object
+     * @since 2.0
+     */
+    public Action getNextBookmarkAction() {
+        if (fNextBookmarkAction == null) {
+            fNextBookmarkAction = new Action() {
+                @Override
+                public void runWithEvent(Event event) {
+                    final long time = Math.min(fSelectionBegin, fSelectionEnd);
+                    final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
+                    for (IMarkerEvent bookmark : fBookmarks) {
+                        if (bookmark.getTime() > time ||
+                                (bookmark.getTime() == time && bookmark.getDuration() > duration)) {
+                            setSelectionRangeNotify(bookmark.getTime(), bookmark.getTime() + bookmark.getDuration());
+                            return;
+                        }
+                    }
+                }
+            };
+            fNextBookmarkAction.setText(Messages.TmfTimeGraphViewer_NextBookmarkActionText);
+            fNextBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_NextBookmarkActionText);
+            fNextBookmarkAction.setImageDescriptor(NEXT_BOOKMARK);
+        }
+        return fNextBookmarkAction;
+    }
+
+    /**
+     * Get the previous bookmark action.
+     *
+     * @return The Action object
+     * @since 2.0
+     */
+    public Action getPreviousBookmarkAction() {
+        if (fPreviousBookmarkAction == null) {
+            fPreviousBookmarkAction = new Action() {
+                @Override
+                public void runWithEvent(Event event) {
+                    final long time = Math.min(fSelectionBegin, fSelectionEnd);
+                    final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
+                    for (int i = fBookmarks.size() - 1; i >= 0; i--) {
+                        IMarkerEvent bookmark = fBookmarks.get(i);
+                        if (bookmark.getTime() < time ||
+                                (bookmark.getTime() == time && bookmark.getDuration() < duration)) {
+                            setSelectionRangeNotify(bookmark.getTime(), bookmark.getTime() + bookmark.getDuration());
+                            return;
+                        }
+                    }
+                }
+            };
+            fPreviousBookmarkAction.setText(Messages.TmfTimeGraphViewer_PreviousBookmarkActionText);
+            fPreviousBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousBookmarkActionText);
+            fPreviousBookmarkAction.setImageDescriptor(PREVIOUS_BOOKMARK);
+        }
+        return fPreviousBookmarkAction;
+    }
+
+    private IMarkerEvent getBookmarkAtSelection() {
+        final long time = Math.min(fSelectionBegin, fSelectionEnd);
+        final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
+        for (IMarkerEvent bookmark : fBookmarks) {
+            if (bookmark.getTime() == time && bookmark.getDuration() == duration) {
+                return bookmark;
+            }
+        }
+        return null;
+    }
+
+    private void updateBookmarkActions() {
+        if (fToggleBookmarkAction != null) {
+            if (getBookmarkAtSelection() != null) {
+                fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionRemoveText);
+                fToggleBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_BookmarkActionRemoveText);
+                fToggleBookmarkAction.setImageDescriptor(REMOVE_BOOKMARK);
+            } else {
+                fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
+                fToggleBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
+                fToggleBookmarkAction.setImageDescriptor(ADD_BOOKMARK);
+            }
+        }
+        final long time = Math.min(fSelectionBegin, fSelectionEnd);
+        final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
+        if (fPreviousBookmarkAction != null) {
+            fPreviousBookmarkAction.setEnabled(!fBookmarks.isEmpty() &&
+                    (time > fBookmarks.get(0).getTime() || (time == fBookmarks.get(0).getTime() && duration > fBookmarks.get(0).getDuration())));
+        }
+        if (fNextBookmarkAction != null) {
+            int last = fBookmarks.size() - 1;
+            fNextBookmarkAction.setEnabled(!fBookmarks.isEmpty() &&
+                    (time < fBookmarks.get(last).getTime() || (time == fBookmarks.get(last).getTime() && duration < fBookmarks.get(last).getDuration())));
+        }
+    }
+
     private void adjustHorizontalScrollBar() {
         long time0 = getTime0();
         long time1 = getTime1();
index 4e70ffdaef16c68e35d80d42993240e1b36a03da..9baee8006b44c588c4cb1c9cdf6e4df754a733b1 100644 (file)
@@ -117,6 +117,8 @@ public class TimeGraphControl extends TimeGraphBaseControl
     private static final int NO_STATUS = -1;
     private static final int STATUS_WITHOUT_CURSOR_TIME = -2;
 
+    private static final int MAX_LABEL_LENGTH = 256;
+
     /** Resource manager */
     private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
 
@@ -144,6 +146,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
     private long fTime1bak;
     private ITimeGraphPresentationProvider fTimeGraphProvider = null;
     private ItemData fItemData = null;
+    private List<IMarkerEvent> fBookmarks = null;
     private List<IMarkerEvent> fMarkers = null;
     private boolean fMarkersVisible = true;
     private List<SelectionListener> fSelectionListeners;
@@ -996,6 +999,18 @@ public class TimeGraphControl extends TimeGraphBaseControl
         return fGridLineColor;
     }
 
+    /**
+     * Set the bookmarks list.
+     *
+     * @param bookmarks
+     *            The bookmarks list, or null
+     * @since 2.0
+     */
+    public void setBookmarks(List<IMarkerEvent> bookmarks) {
+        fBookmarks = bookmarks;
+        fTimeGraphScale.setBookmarks(bookmarks);
+    }
+
     /**
      * Set the markers list.
      *
@@ -1417,12 +1432,18 @@ public class TimeGraphControl extends TimeGraphBaseControl
         // draw the background markers
         drawMarkers(bounds, fTimeProvider, fMarkers, false, nameSpace, gc);
 
+        // draw the background bookmarks
+        drawMarkers(bounds, fTimeProvider, fBookmarks, false, nameSpace, gc);
+
         // draw the items
         drawItems(bounds, fTimeProvider, fItemData.fExpandedItems, fTopIndex, nameSpace, gc);
 
         // draw the foreground markers
         drawMarkers(bounds, fTimeProvider, fMarkers, true, nameSpace, gc);
 
+        // draw the foreground bookmarks
+        drawMarkers(bounds, fTimeProvider, fBookmarks, true, nameSpace, gc);
+
         // draw the links (arrows)
         drawLinks(bounds, fTimeProvider, fItemData.fLinks, nameSpace, gc);
 
@@ -1642,8 +1663,9 @@ public class TimeGraphControl extends TimeGraphBaseControl
         gc.setAlpha(255);
         String label = marker.getLabel();
         if (label != null && marker.getEntry() != null) {
+            label = label.substring(0, Math.min(label.indexOf('\n') != -1 ? label.indexOf('\n') : label.length(), MAX_LABEL_LENGTH));
             gc.setForeground(marker.getColor());
-            Utils.drawText(gc, label, rect.x - gc.stringExtent(label).x, rect.y, true);
+            Utils.drawText(gc, label, rect.x - gc.textExtent(label).x, rect.y, true);
         }
     }
 
index 646ab1e659fd220b21bc82b8411581fe94dd20c7..a44994856425d6c5cafc47bfa9ccd9fe491abba1 100644 (file)
@@ -114,6 +114,8 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
     private static final int NO_BUTTON = 0;
     private static final int LEFT_BUTTON = 1;
 
+    private static final int MAX_LABEL_LENGTH = 256;
+
     private ITimeDataProvider fTimeProvider;
     private int fDragState = NO_BUTTON;
     private int fDragX0 = 0;
@@ -123,6 +125,7 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
     private boolean fIsInUpdate;
     private int fHeight;
     private List<Integer> fTickList = new ArrayList<>();
+    private List<IMarkerEvent> fBookmarks = null;
     private List<IMarkerEvent> fMarkers = null;
     private boolean fMarkersVisible = true;
 
@@ -216,6 +219,17 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
         return fTickList;
     }
 
+    /**
+     * Set the bookmarks list.
+     *
+     * @param bookmarks
+     *            The bookmarks list, or null
+     * @since 2.0
+     */
+    public void setBookmarks(List<IMarkerEvent> bookmarks) {
+        fBookmarks = bookmarks;
+    }
+
     /**
      * Set the markers list.
      *
@@ -470,15 +484,26 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
         fTickList = tickList;
 
         // draw marker labels
-        if (fMarkersVisible && fMarkers != null) {
-            for (IMarkerEvent marker : fMarkers) {
-                String label = marker.getLabel();
-                if (label != null && marker.getEntry() == null) {
-                    int x = rect.x + leftSpace + (int) (Math.floor((marker.getTime() - time0) * pixelsPerNanoSec));
-                    y = rect.y + rect.height - gc.stringExtent(label).y + 1;
-                    gc.setForeground(marker.getColor());
-                    Utils.drawText(gc, label, x, y, true);
-                }
+        if (fMarkersVisible) {
+            drawMarkerLabels(fMarkers, rect, gc, time0, leftSpace, pixelsPerNanoSec);
+        }
+
+        // draw bookmark labels
+        drawMarkerLabels(fBookmarks, rect, gc, time0, leftSpace, pixelsPerNanoSec);
+    }
+
+    private static void drawMarkerLabels(List<IMarkerEvent> markerEvents, Rectangle rect, GC gc, long time0, int leftSpace, double pixelsPerNanoSec) {
+        if (markerEvents == null) {
+            return;
+        }
+        for (IMarkerEvent markerEvent : markerEvents) {
+            String label = markerEvent.getLabel();
+            if (label != null && markerEvent.getEntry() == null) {
+                label = label.substring(0, Math.min(label.indexOf('\n') != -1 ? label.indexOf('\n') : label.length(), MAX_LABEL_LENGTH));
+                int x = rect.x + leftSpace + (int) (Math.floor((markerEvent.getTime() - time0) * pixelsPerNanoSec));
+                int y = rect.y + rect.height - gc.stringExtent(" ").y + 2; //$NON-NLS-1$
+                gc.setForeground(markerEvent.getColor());
+                Utils.drawText(gc, label, x, y, true);
             }
         }
     }
This page took 0.051072 seconds and 5 git commands to generate.