ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / TimeGraphTooltipHandler.java
index 0664b719566b2d9f75499c715059f465742f4457..d3e885ea5bf3be701e58adeb8c45e6bcf7cf897b 100644 (file)
-/*****************************************************************************\r
- * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *   Intel Corporation - Initial API and implementation\r
- *   Vitaly A. Provodin, Intel - Initial API and implementation\r
- *   Alvaro Sanchez-Leon - Updated for TMF\r
- *   Patrick Tasse - Refactoring\r
- *\r
- *****************************************************************************/\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
-\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.MouseAdapter;\r
-import org.eclipse.swt.events.MouseEvent;\r
-import org.eclipse.swt.events.MouseMoveListener;\r
-import org.eclipse.swt.events.MouseTrackAdapter;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Table;\r
-import org.eclipse.swt.widgets.TableColumn;\r
-import org.eclipse.swt.widgets.TableItem;\r
-\r
-/**\r
- * Handler for the tool tips in the generic time graph view.\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public class TimeGraphTooltipHandler {\r
-\r
-    private final Shell _tipShell;\r
-    private final Table _tipTable;\r
-    private Point _tipPosition;\r
-    private final ITimeDataProvider _timeDataProvider;\r
-    ITimeGraphPresentationProvider _utilImp = null;\r
-\r
-    /**\r
-     * Standard constructor\r
-     *\r
-     * @param parent\r
-     *            The parent composite object\r
-     * @param rUtilImpl\r
-     *            The presentation provider\r
-     * @param timeProv\r
-     *            The time provider\r
-     */\r
-    public TimeGraphTooltipHandler(Shell parent, ITimeGraphPresentationProvider rUtilImpl,\r
-            ITimeDataProvider timeProv) {\r
-        final Display display = parent.getDisplay();\r
-\r
-        this._utilImp = rUtilImpl;\r
-        this._timeDataProvider = timeProv;\r
-        _tipShell = new Shell(parent, SWT.ON_TOP | SWT.TOOL);\r
-        GridLayout gridLayout = new GridLayout();\r
-        gridLayout.numColumns = 2;\r
-        gridLayout.marginWidth = 2;\r
-        gridLayout.marginHeight = 2;\r
-        _tipShell.setLayout(gridLayout);\r
-        GridData data = new GridData(GridData.BEGINNING, GridData.BEGINNING,\r
-                true, true);\r
-        _tipShell.setLayoutData(data);\r
-        _tipShell.setBackground(display\r
-                .getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
-\r
-        _tipTable = new Table(_tipShell, SWT.NONE);\r
-        new TableColumn(_tipTable, SWT.NONE);\r
-        new TableColumn(_tipTable, SWT.NONE);\r
-        _tipTable.setForeground(display\r
-                .getSystemColor(SWT.COLOR_INFO_FOREGROUND));\r
-        _tipTable.setBackground(display\r
-                .getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
-        _tipTable.setHeaderVisible(false);\r
-        _tipTable.setLinesVisible(false);\r
-\r
-        // tipTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL\r
-        // | GridData.VERTICAL_ALIGN_CENTER));\r
-    }\r
-\r
-    /**\r
-     * Callback for the mouse-over tooltip\r
-     *\r
-     * @param control\r
-     *            The control object to use\r
-     */\r
-    public void activateHoverHelp(final Control control) {\r
-        //FIXME: remove old listeners\r
-        control.addMouseListener(new MouseAdapter() {\r
-            @Override\r
-            public void mouseDown(MouseEvent e) {\r
-                if (_tipShell.isVisible()) {\r
-                    _tipShell.setVisible(false);\r
-                }\r
-            }\r
-        });\r
-\r
-        control.addMouseMoveListener(new MouseMoveListener() {\r
-            @Override\r
-            public void mouseMove(MouseEvent e) {\r
-                if (_tipShell.isVisible()) {\r
-                    _tipShell.setVisible(false);\r
-                }\r
-            }\r
-        });\r
-\r
-        control.addMouseTrackListener(new MouseTrackAdapter() {\r
-            @Override\r
-            public void mouseExit(MouseEvent e) {\r
-                if (_tipShell.isVisible()) {\r
-                    _tipShell.setVisible(false);\r
-                }\r
-            }\r
-\r
-            private void addItem(String name, String value) {\r
-                TableItem line = new TableItem(_tipTable, SWT.NONE);\r
-                line.setText(0, name);\r
-                line.setText(1, value);\r
-            }\r
-\r
-            private void fillValues(Point pt, TimeGraphControl threadStates, ITimeGraphEntry entry) {\r
-                if (entry == null) {\r
-                    return;\r
-                }\r
-                if (entry.hasTimeEvents()) {\r
-                    ITimeEvent threadEvent = Utils.findEvent(entry, threadStates.getTimeAtX(pt.x), 2);\r
-                    ITimeEvent nextEvent = Utils.findEvent(entry, threadStates.getTimeAtX(pt.x), 1);\r
-                    // state name\r
-                    addItem(_utilImp.getStateTypeName(), entry.getName());\r
-                    if (threadEvent == null) {\r
-                        return;\r
-                    }\r
-                    // thread state\r
-                    String state = _utilImp.getEventName(threadEvent);\r
-                    if (state != null) {\r
-                        addItem(Messages.TmfTimeTipHandler_TRACE_STATE, state);\r
-                    }\r
-\r
-                    // This block receives a\r
-                    // list of <String, String> values to be added to the tip\r
-                    // table\r
-                    Map<String, String> eventAddOns = _utilImp.getEventHoverToolTipInfo(threadEvent);\r
-                    if (eventAddOns != null) {\r
-                        for (Iterator<String> iter = eventAddOns.keySet().iterator(); iter.hasNext();) {\r
-                            String message = (String) iter.next();\r
-                            addItem(message, eventAddOns.get(message));\r
-                        }\r
-                    }\r
-\r
-                    long eventStartTime = -1;\r
-                    long eventDuration = -1;\r
-                    long eventEndTime = -1;\r
-\r
-                    if (threadEvent != null) {\r
-                        eventStartTime = threadEvent.getTime();\r
-                        eventDuration = threadEvent.getDuration();\r
-                        if (eventDuration < 0 && nextEvent != null) {\r
-                            eventEndTime = nextEvent.getTime();\r
-                            eventDuration = eventEndTime - eventStartTime;\r
-                        } else {\r
-                            eventEndTime = eventStartTime + eventDuration;\r
-                        }\r
-                    }\r
-\r
-                    // TODO: Check if we need "format"\r
-                    //                                 TimeFormat format = TimeFormat.RELATIVE;\r
-                    Resolution res = Resolution.NANOSEC;\r
-                    if (_timeDataProvider.isCalendarFormat()) {\r
-                        //                                             format = TimeFormat.ABSOLUTE; // Absolute format\r
-                        //                                                                                                             // (calendar)\r
-                        // Add Date\r
-                        addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ?\r
-                                Utils.formatDate(eventStartTime)\r
-                                : "?"); //$NON-NLS-1$\r
-                        if (eventDuration > 0) {\r
-                            addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ?\r
-                                    Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res)\r
-                                    : "?"); //$NON-NLS-1$\r
-\r
-                            addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ?\r
-                                    Utils.formatTime(eventEndTime, TimeFormat.ABSOLUTE, res)\r
-                                    : "?"); //$NON-NLS-1$\r
-                        } else {\r
-                            addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ?\r
-                                    Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res)\r
-                                    : "?"); //$NON-NLS-1$\r
-                        }\r
-                    } else {\r
-                        if (eventDuration > 0) {\r
-                            addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ?\r
-                                    Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res)\r
-                                    : "?"); //$NON-NLS-1$\r
-\r
-                            addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ?\r
-                                    Utils.formatTime(eventEndTime, TimeFormat.RELATIVE, res)\r
-                                    : "?"); //$NON-NLS-1$\r
-                        } else {\r
-                            addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ?\r
-                                    Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res)\r
-                                    : "?"); //$NON-NLS-1$\r
-                        }\r
-                    }\r
-\r
-                    if (eventDuration > 0) {\r
-                        // Duration in relative format in any case\r
-                        addItem(Messages.TmfTimeTipHandler_DURATION, eventDuration > -1 ?\r
-                                Utils.formatTime(eventDuration, TimeFormat.RELATIVE, res)\r
-                                : "?"); //$NON-NLS-1$\r
-                    }\r
-                }\r
-            }\r
-\r
-            @Override\r
-            public void mouseHover(MouseEvent event) {\r
-                Point pt = new Point(event.x, event.y);\r
-                TimeGraphControl threadStates = (TimeGraphControl) event.widget;\r
-                ITimeGraphEntry entry = threadStates.getEntry(pt);\r
-                _tipTable.remove(0, _tipTable.getItemCount() - 1);\r
-                fillValues(pt, threadStates, entry);\r
-                if (_tipTable.getItemCount() == 0) {\r
-                    return;\r
-                }\r
-                _tipTable.getColumn(0).pack();\r
-                _tipTable.getColumn(1).pack();\r
-                _tipShell.pack();\r
-                _tipPosition = control.toDisplay(pt);\r
-                _tipShell.pack();\r
-                setHoverLocation(_tipShell, _tipPosition);\r
-                _tipShell.setVisible(true);\r
-            }\r
-        });\r
-    }\r
-\r
-    private void setHoverLocation(Shell shell, Point position) {\r
-        Rectangle displayBounds = shell.getDisplay().getBounds();\r
-        Rectangle shellBounds = shell.getBounds();\r
-        shellBounds.x = Math.max(Math.min(position.x, displayBounds.width\r
-                - shellBounds.width), 0);\r
-        shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height\r
-                - shellBounds.height), 0);\r
-        shell.setBounds(shellBounds);\r
-    }\r
-\r
+/*****************************************************************************
+ * Copyright (c) 2007, 2014 Intel Corporation, 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:
+ *   Intel Corporation - Initial API and implementation
+ *   Vitaly A. Provodin, Intel - Initial API and implementation
+ *   Alvaro Sanchez-Leon - Updated for TMF
+ *   Patrick Tasse - Refactoring
+ *****************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.NullTimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.events.MouseTrackAdapter;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Handler for the tool tips in the generic time graph view.
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public class TimeGraphTooltipHandler {
+
+    private static final int OFFSET = 16;
+
+    private Shell fTipShell;
+    private Composite fTipComposite;
+    private ITimeDataProvider fTimeDataProvider;
+    private ITimeGraphPresentationProvider fTimeGraphProvider = null;
+
+    /**
+     * Standard constructor
+     *
+     * @param graphProv
+     *            The presentation provider
+     * @param timeProv
+     *            The time provider
+     *
+     * @since 2.0
+     */
+    public TimeGraphTooltipHandler(ITimeGraphPresentationProvider graphProv,
+            ITimeDataProvider timeProv) {
+
+        this.fTimeGraphProvider = graphProv;
+        this.fTimeDataProvider = timeProv;
+    }
+
+    /**
+     * Set the time data provider
+     *
+     * @param timeDataProvider
+     *            The time data provider
+     *
+     * @since 3.2
+     */
+    public void setTimeProvider(ITimeDataProvider timeDataProvider) {
+        fTimeDataProvider = timeDataProvider;
+    }
+
+    private void createTooltipShell(Shell parent) {
+        final Display display = parent.getDisplay();
+        if (fTipShell != null && ! fTipShell.isDisposed()) {
+            fTipShell.dispose();
+        }
+        fTipShell = new Shell(parent, SWT.ON_TOP | SWT.TOOL);
+        GridLayout gridLayout = new GridLayout();
+        gridLayout.numColumns = 2;
+        gridLayout.marginWidth = 2;
+        gridLayout.marginHeight = 2;
+        fTipShell.setLayout(gridLayout);
+        fTipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
+
+        fTipComposite = new Composite(fTipShell, SWT.NONE);
+        fTipComposite.setLayout(new GridLayout(3, false));
+        setupControl(fTipComposite);
+
+    }
+
+    /**
+     * Callback for the mouse-over tooltip
+     *
+     * @param control
+     *            The control object to use
+     */
+    public void activateHoverHelp(final Control control) {
+        control.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseDown(MouseEvent e) {
+                if (fTipShell != null && ! fTipShell.isDisposed()) {
+                    fTipShell.dispose();
+                }
+            }
+        });
+
+        control.addMouseMoveListener(new MouseMoveListener() {
+            @Override
+            public void mouseMove(MouseEvent e) {
+                if (fTipShell != null && ! fTipShell.isDisposed()) {
+                    fTipShell.dispose();
+                }
+            }
+        });
+
+        control.addMouseTrackListener(new MouseTrackAdapter() {
+            @Override
+            public void mouseExit(MouseEvent e) {
+                if (fTipShell != null && ! fTipShell.isDisposed()) {
+                    Point pt = control.toDisplay(e.x, e.y);
+                    if (! fTipShell.getBounds().contains(pt)) {
+                        fTipShell.dispose();
+                    }
+                }
+            }
+
+            private void addItem(String name, String value) {
+                Label nameLabel = new Label(fTipComposite, SWT.NO_FOCUS);
+                nameLabel.setText(name);
+                setupControl(nameLabel);
+                Label separator = new Label(fTipComposite, SWT.NO_FOCUS | SWT.SEPARATOR | SWT.VERTICAL);
+                GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+                gd.heightHint = nameLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
+                separator.setLayoutData(gd);
+                setupControl(separator);
+                Label valueLabel = new Label(fTipComposite, SWT.NO_FOCUS);
+                valueLabel.setText(value);
+                setupControl(valueLabel);
+            }
+
+            private void fillValues(Point pt, TimeGraphControl timeGraphControl, ITimeGraphEntry entry) {
+                if (entry == null) {
+                    return;
+                }
+                if (entry.hasTimeEvents()) {
+                    long currPixelTime = timeGraphControl.getTimeAtX(pt.x);
+                    long nextPixelTime = timeGraphControl.getTimeAtX(pt.x + 1);
+                    if (nextPixelTime == currPixelTime) {
+                        nextPixelTime++;
+                    }
+                    ITimeEvent currEvent = Utils.findEvent(entry, currPixelTime, 0);
+                    ITimeEvent nextEvent = Utils.findEvent(entry, currPixelTime, 1);
+
+                    // if there is no current event at the start of the current pixel range,
+                    // or if the current event starts before the current pixel range,
+                    // use the next event as long as it starts within the current pixel range
+                    if ((currEvent == null || currEvent.getTime() < currPixelTime) &&
+                        (nextEvent != null && nextEvent.getTime() < nextPixelTime)) {
+                        currEvent = nextEvent;
+                        currPixelTime = nextEvent.getTime();
+                    }
+
+                    // state name
+                    String stateTypeName = fTimeGraphProvider.getStateTypeName(entry);
+                    String entryName = entry.getName();
+                    if (stateTypeName == null) {
+                        stateTypeName = fTimeGraphProvider.getStateTypeName();
+                    }
+
+                    if (!entryName.isEmpty()) {
+                        addItem(stateTypeName, entry.getName());
+                    }
+
+                    if (currEvent == null || currEvent instanceof NullTimeEvent) {
+                        return;
+                    }
+
+                    // state
+                    String state = fTimeGraphProvider.getEventName(currEvent);
+                    if (state != null) {
+                        addItem(Messages.TmfTimeTipHandler_TRACE_STATE, state);
+                    }
+
+                    // This block receives a list of <String, String> values to be added to the tip table
+                    Map<String, String> eventAddOns = fTimeGraphProvider.getEventHoverToolTipInfo(currEvent, currPixelTime);
+                    if (eventAddOns != null) {
+                        for (Iterator<String> iter = eventAddOns.keySet().iterator(); iter.hasNext();) {
+                            String message = iter.next();
+                            addItem(message, eventAddOns.get(message));
+                        }
+                    }
+                    if (fTimeGraphProvider.displayTimesInTooltip()) {
+                        long eventStartTime = -1;
+                        long eventDuration = -1;
+                        long eventEndTime = -1;
+
+                        eventStartTime = currEvent.getTime();
+                        eventDuration = currEvent.getDuration();
+                        if (eventDuration < 0 && nextEvent != null) {
+                            eventEndTime = nextEvent.getTime();
+                            eventDuration = eventEndTime - eventStartTime;
+                        } else {
+                            eventEndTime = eventStartTime + eventDuration;
+                        }
+
+                        Resolution res = Resolution.NANOSEC;
+                        TimeFormat tf = fTimeDataProvider.getTimeFormat();
+                        String startTime = "?"; //$NON-NLS-1$
+                        String duration = "?"; //$NON-NLS-1$
+                        String endTime = "?"; //$NON-NLS-1$
+                        if (fTimeDataProvider instanceof ITimeDataProviderConverter) {
+                            ITimeDataProviderConverter tdp = (ITimeDataProviderConverter) fTimeDataProvider;
+                            if (eventStartTime > -1) {
+                                eventStartTime = tdp.convertTime(eventStartTime);
+                                startTime = Utils.formatTime(eventStartTime, tf, res);
+                            }
+                            if (eventEndTime > -1) {
+                                eventEndTime = tdp.convertTime(eventEndTime);
+                                endTime = Utils.formatTime(eventEndTime, tf, res);
+                            }
+                            if (eventDuration > -1) {
+                                duration = Utils.formatDelta(eventEndTime - eventStartTime, tf, res);
+                            }
+                        } else {
+                            if (eventStartTime > -1) {
+                                startTime = Utils.formatTime(eventStartTime, tf, res);
+                            }
+                            if (eventEndTime > -1) {
+                                endTime = Utils.formatTime(eventEndTime, tf, res);
+                            }
+                            if (eventDuration > -1) {
+                                duration = Utils.formatDelta(eventDuration, tf, res);
+                            }
+                        }
+                        if (tf == TimeFormat.CALENDAR) {
+                            addItem(Messages.TmfTimeTipHandler_TRACE_DATE,
+                                    eventStartTime > -1 ? Utils.formatDate(eventStartTime) : "?"); //$NON-NLS-1$
+                        }
+                        if (eventDuration > 0) {
+                            addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, startTime);
+                            addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, endTime);
+                        } else {
+                            addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, startTime);
+                        }
+
+                        if (eventDuration > 0) {
+                            addItem(Messages.TmfTimeTipHandler_DURATION, duration);
+                        }
+                    }
+                }
+            }
+
+            private void fillValues(ILinkEvent linkEvent) {
+                addItem(Messages.TmfTimeTipHandler_LINK_SOURCE, linkEvent.getEntry().getName());
+                addItem(Messages.TmfTimeTipHandler_LINK_TARGET, linkEvent.getDestinationEntry().getName());
+
+                // This block receives a list of <String, String> values to be added to the tip table
+                Map<String, String> eventAddOns = fTimeGraphProvider.getEventHoverToolTipInfo(linkEvent);
+                if (eventAddOns != null) {
+                    for (Iterator<String> iter = eventAddOns.keySet().iterator(); iter.hasNext();) {
+                        String message = iter.next();
+                        addItem(message, eventAddOns.get(message));
+                    }
+                }
+                if (fTimeGraphProvider.displayTimesInTooltip()) {
+                    long sourceTime = linkEvent.getTime();
+                    long duration = linkEvent.getDuration();
+                    long targetTime = sourceTime + duration;
+                    if (fTimeDataProvider instanceof ITimeDataProviderConverter) {
+                        ITimeDataProviderConverter tdp = (ITimeDataProviderConverter) fTimeDataProvider;
+                        sourceTime = tdp.convertTime(sourceTime);
+                        targetTime = tdp.convertTime(targetTime);
+                        duration = targetTime - sourceTime;
+                    }
+                    Resolution res = Resolution.NANOSEC;
+                    TimeFormat tf = fTimeDataProvider.getTimeFormat();
+                    if (tf == TimeFormat.CALENDAR) {
+                        addItem(Messages.TmfTimeTipHandler_TRACE_DATE, Utils.formatDate(sourceTime));
+                    }
+                    if (duration > 0) {
+                        addItem(Messages.TmfTimeTipHandler_LINK_SOURCE_TIME, Utils.formatTime(sourceTime, tf, res));
+                        addItem(Messages.TmfTimeTipHandler_LINK_TARGET_TIME, Utils.formatTime(targetTime, tf, res));
+                        addItem(Messages.TmfTimeTipHandler_DURATION, Utils.formatDelta(duration, tf, res));
+                    } else {
+                        addItem(Messages.TmfTimeTipHandler_LINK_TIME, Utils.formatTime(sourceTime, tf, res));
+                    }
+                }
+            }
+
+            @Override
+            public void mouseHover(MouseEvent event) {
+                if ((event.stateMask & SWT.BUTTON_MASK) != 0) {
+                    return;
+                }
+                Point pt = new Point(event.x, event.y);
+                TimeGraphControl timeGraphControl = (TimeGraphControl) event.widget;
+                createTooltipShell(timeGraphControl.getShell());
+                for (Control child : fTipComposite.getChildren()) {
+                    child.dispose();
+                }
+                if ((event.stateMask & SWT.MODIFIER_MASK) != SWT.SHIFT) {
+                    ILinkEvent linkEvent = timeGraphControl.getArrow(pt);
+                    if (linkEvent != null) {
+                        fillValues(linkEvent);
+                    }
+                }
+                if (fTipComposite.getChildren().length == 0) {
+                    ITimeGraphEntry entry = timeGraphControl.getEntry(pt);
+                    fillValues(pt, timeGraphControl, entry);
+                }
+                if (fTipComposite.getChildren().length == 0) {
+                    return;
+                }
+                fTipShell.pack();
+                Point tipPosition = control.toDisplay(pt);
+                fTipShell.pack();
+                setHoverLocation(fTipShell, tipPosition);
+                fTipShell.setVisible(true);
+            }
+        });
+    }
+
+    private static void setHoverLocation(Shell shell, Point position) {
+        Rectangle displayBounds = shell.getDisplay().getBounds();
+        Rectangle shellBounds = shell.getBounds();
+        if (position.x + shellBounds.width + OFFSET > displayBounds.width && position.x - shellBounds.width - OFFSET >= 0) {
+            shellBounds.x = position.x - shellBounds.width - OFFSET;
+        } else {
+            shellBounds.x = Math.max(Math.min(position.x + OFFSET, displayBounds.width - shellBounds.width), 0);
+        }
+        if (position.y + shellBounds.height + OFFSET > displayBounds.height && position.y - shellBounds.height - OFFSET >= 0) {
+            shellBounds.y = position.y - shellBounds.height - OFFSET;
+        } else {
+            shellBounds.y = Math.max(Math.min(position.y + OFFSET, displayBounds.height - shellBounds.height), 0);
+        }
+        shell.setBounds(shellBounds);
+    }
+
+    private void setupControl(Control control) {
+        control.setForeground(fTipShell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
+        control.setBackground(fTipShell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
+
+        control.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseDown(MouseEvent e) {
+                fTipShell.dispose();
+            }
+        });
+
+        control.addMouseTrackListener(new MouseTrackAdapter() {
+            @Override
+            public void mouseExit(MouseEvent e) {
+                fTipShell.dispose();
+            }
+        });
+
+        control.addMouseMoveListener(new MouseMoveListener() {
+            @Override
+            public void mouseMove(MouseEvent e) {
+                fTipShell.dispose();
+            }
+        });
+    }
 }
This page took 0.032558 seconds and 5 git commands to generate.