tmf.ui/timing: Update XY viewers even if there is no data
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / xycharts / TmfSimpleTooltipProvider.java
1 /**********************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.tracecompass.tmf.ui.viewers.xycharts;
13
14 import org.eclipse.swt.events.MouseEvent;
15 import org.eclipse.swt.events.MouseTrackListener;
16 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
17 import org.swtchart.IAxis;
18
19 /**
20 * Tool tip provider for TMF chart viewer. It displays the x and y
21 * value of the current mouse position.
22 *
23 * @author Bernd Hufmann
24 */
25 public class TmfSimpleTooltipProvider extends TmfBaseProvider implements MouseTrackListener {
26
27 // ------------------------------------------------------------------------
28 // Constructors
29 // ------------------------------------------------------------------------
30 /**
31 * Constructor for a tool tip provider.
32 *
33 * @param tmfChartViewer
34 * The parent chart viewer
35 */
36 public TmfSimpleTooltipProvider(ITmfChartTimeProvider tmfChartViewer) {
37 super(tmfChartViewer);
38 register();
39 }
40
41 // ------------------------------------------------------------------------
42 // TmfBaseProvider
43 // ------------------------------------------------------------------------
44 @Override
45 public void register() {
46 getChart().getPlotArea().addMouseTrackListener(this);
47 }
48
49 @Override
50 public void deregister() {
51 if ((getChartViewer().getControl() != null) && !getChartViewer().getControl().isDisposed()) {
52 getChart().getPlotArea().removeMouseTrackListener(this);
53 }
54 }
55
56 @Override
57 public void refresh() {
58 // nothing to do
59 }
60
61 // ------------------------------------------------------------------------
62 // MouseTrackListener
63 // ------------------------------------------------------------------------
64 @Override
65 public void mouseEnter(MouseEvent e) {
66 }
67
68 @Override
69 public void mouseExit(MouseEvent e) {
70 }
71
72 @Override
73 public void mouseHover(MouseEvent e) {
74 if (getChartViewer().getWindowDuration() == 0) {
75 return;
76 }
77
78 IAxis xAxis = getChart().getAxisSet().getXAxis(0);
79 IAxis yAxis = getChart().getAxisSet().getYAxis(0);
80
81 double xCoordinate = xAxis.getDataCoordinate(e.x);
82 double yCoordinate = yAxis.getDataCoordinate(e.y);
83
84 ITmfChartTimeProvider viewer = getChartViewer();
85
86 /* set tooltip of current data point */
87 StringBuffer buffer = new StringBuffer();
88 buffer.append("x="); //$NON-NLS-1$
89 buffer.append(TmfTimestamp.fromNanos((long) xCoordinate + viewer.getTimeOffset()).toString());
90 buffer.append("\n"); //$NON-NLS-1$
91 buffer.append("y="); //$NON-NLS-1$
92 buffer.append((long) yCoordinate);
93 getChart().getPlotArea().setToolTipText(buffer.toString());
94 }
95 }
This page took 0.054604 seconds and 5 git commands to generate.