Remove warnings and fix a windows bug with CtfTmfTrace.getName()
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / timeAnalysis / widgets / TmfTimeTipHandler.java
CommitLineData
b0d3496e
ASL
1/*****************************************************************************\r
2 * Copyright (c) 2007, Intel Corporation.\r
3 * All rights reserved. This program and the accompanying materials\r
4 * are made available under the terms of the Eclipse Public License v1.0\r
5 * which accompanies this distribution, and is available at\r
6 * http://www.eclipse.org/legal/epl-v10.html\r
7 *\r
8 * Contributors:\r
9 * Intel Corporation - Initial API and implementation\r
10 * Vitaly A. Provodin, Intel - Initial API and implementation\r
11 * Alvaro Sanchex-Leon - Udpated for TMF\r
12 *\r
13 * $Id: ThreadsTipHandler.java,v 1.5 2007/06/06 19:16:16 gnagarajan Exp $\r
14 *****************************************************************************/\r
53dd0622 15package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets;\r
b0d3496e
ASL
16\r
17import java.util.Iterator;\r
18import java.util.Map;\r
19\r
d34665f9 20import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
b0d3496e 21import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer.TimeFormat;\r
7995b722 22import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider;\r
b0d3496e
ASL
23import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent;\r
24import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r
53dd0622 25import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.Utils.Resolution;\r
b0d3496e
ASL
26import org.eclipse.swt.SWT;\r
27import org.eclipse.swt.events.MouseAdapter;\r
28import org.eclipse.swt.events.MouseEvent;\r
29import org.eclipse.swt.events.MouseTrackAdapter;\r
30import org.eclipse.swt.graphics.Point;\r
31import org.eclipse.swt.graphics.Rectangle;\r
32import org.eclipse.swt.layout.GridData;\r
33import org.eclipse.swt.layout.GridLayout;\r
34import org.eclipse.swt.widgets.Control;\r
35import org.eclipse.swt.widgets.Display;\r
36import org.eclipse.swt.widgets.Shell;\r
37import org.eclipse.swt.widgets.Table;\r
38import org.eclipse.swt.widgets.TableColumn;\r
39import org.eclipse.swt.widgets.TableItem;\r
40import org.eclipse.swt.widgets.Widget;\r
41\r
42\r
43public class TmfTimeTipHandler {\r
44\r
45 private Shell _tipShell;\r
46 private Table _tipTable;\r
47 private Item _tipItem;\r
48 private Point _tipPosition;\r
49 private ITimeDataProvider _timeDataProvider;\r
50 TmfTimeAnalysisProvider _utilImp = null;\r
51\r
52 public TmfTimeTipHandler(Shell parent, TmfTimeAnalysisProvider rUtilImpl,\r
53 ITimeDataProvider timeProv) {\r
54 final Display display = parent.getDisplay();\r
55\r
56 this._utilImp = rUtilImpl;\r
57 this._timeDataProvider = timeProv;\r
58 _tipShell = new Shell(parent, SWT.ON_TOP | SWT.TOOL);\r
59 GridLayout gridLayout = new GridLayout();\r
60 gridLayout.numColumns = 2;\r
61 gridLayout.marginWidth = 2;\r
62 gridLayout.marginHeight = 2;\r
63 _tipShell.setLayout(gridLayout);\r
64 GridData data = new GridData(GridData.BEGINNING, GridData.BEGINNING,\r
65 true, true);\r
66 _tipShell.setLayoutData(data);\r
67 _tipShell.setBackground(display\r
68 .getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
69\r
70 _tipTable = new Table(_tipShell, SWT.NONE);\r
71 _tipTable.setForeground(display\r
72 .getSystemColor(SWT.COLOR_INFO_FOREGROUND));\r
73 _tipTable.setBackground(display\r
74 .getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
75 _tipTable.setHeaderVisible(false);\r
76 _tipTable.setLinesVisible(false);\r
77\r
78 // tipTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL\r
79 // | GridData.VERTICAL_ALIGN_CENTER));\r
80 }\r
81\r
82 public void activateHoverHelp(final Control control) {\r
83 control.addMouseListener(new MouseAdapter() {\r
4e3aa37d 84 @Override\r
b0d3496e
ASL
85 public void mouseDown(MouseEvent e) {\r
86 if (_tipShell.isVisible())\r
87 _tipShell.setVisible(false);\r
88 }\r
89 });\r
90\r
91 control.addMouseTrackListener(new MouseTrackAdapter() {\r
4e3aa37d 92 @Override\r
b0d3496e
ASL
93 public void mouseExit(MouseEvent e) {\r
94 if (_tipShell.isVisible())\r
95 _tipShell.setVisible(false);\r
96 _tipItem = null;\r
97\r
98 }\r
99\r
100 private void addItem(String name, String value) {\r
101 TableItem line = new TableItem(_tipTable, SWT.NONE);\r
102 line.setText(0, name);\r
103 line.setText(1, value);\r
104 }\r
105\r
106 private void fillValues(Point pt, TmfTimeStatesCtrl threadStates,\r
107 Item item) {\r
108 if (item instanceof TraceItem) {\r
109 ITmfTimeAnalysisEntry thrd = ((TraceItem) item)._trace;\r
ce62370f
FC
110 ITimeEvent threadEvent = Utils.findEvent(thrd, threadStates.hitTimeTest(pt.x), 2);\r
111 ITimeEvent nextEvent = Utils.findEvent(thrd, threadStates.hitTimeTest(pt.x), 1);\r
b0d3496e 112 // thread name\r
7995b722 113 addItem(Messages.TmfTimeTipHandler_TRACE_NAME, thrd.getName());\r
b0d3496e 114 // class name\r
7995b722
FC
115 String traceClass = _utilImp.getTraceClassName(thrd);\r
116 if (traceClass != null) {\r
117 addItem(Messages.TmfTimeTipHandler_TRACE_CLASS_NAME, traceClass);\r
118 }\r
b0d3496e 119 // thread state\r
7995b722
FC
120 String state = _utilImp.getEventName(threadEvent);\r
121 if (state != null) {\r
122 addItem(Messages.TmfTimeTipHandler_TRACE_STATE, state);\r
123 }\r
b0d3496e
ASL
124\r
125 // This block receives a\r
126 // list of <String, String> values to be added to the tip\r
127 // table\r
ce62370f
FC
128 Map<String, String> eventAddOns = _utilImp.getEventHoverToolTipInfo(threadEvent);\r
129 if (eventAddOns != null) {\r
130 for (Iterator<String> iter = eventAddOns.keySet().iterator(); iter.hasNext();) {\r
131 String message = (String) iter.next();\r
132 addItem(message, eventAddOns.get(message));\r
133 }\r
b0d3496e
ASL
134 }\r
135\r
a5823d5f
ASL
136 long eventStartTime = -1;\r
137 long eventDuration = -1;\r
138 long eventEndTime = -1;\r
139 \r
140 if (threadEvent != null) {\r
141 eventStartTime = threadEvent.getTime();\r
142 eventDuration = threadEvent.getDuration();\r
143 if (eventDuration < 0 && nextEvent != null) {\r
144 eventEndTime = nextEvent.getTime();\r
145 eventDuration = eventEndTime - eventStartTime;\r
146 } else {\r
147 eventEndTime = eventStartTime + eventDuration;\r
148 }\r
b0d3496e
ASL
149 }\r
150\r
151// TODO: Check if we need "format" \r
152// TimeFormat format = TimeFormat.RELATIVE;\r
153 Resolution res = Resolution.NANOSEC;\r
154 if (_timeDataProvider.isCalendarFormat()) {\r
155// format = TimeFormat.ABSOLUTE; // Absolute format\r
156// // (calendar)\r
157 // Add Date\r
7995b722 158 addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ?\r
a5823d5f 159 Utils.formatDate(eventStartTime)\r
3b38ea61 160 : "?"); //$NON-NLS-1$\r
a5823d5f 161 if (eventDuration > 0) {\r
7995b722 162 addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ?\r
a5823d5f 163 Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res)\r
3b38ea61 164 : "?"); //$NON-NLS-1$\r
a5823d5f 165 \r
7995b722 166 addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ?\r
a5823d5f 167 Utils.formatTime(eventEndTime, TimeFormat.ABSOLUTE, res)\r
3b38ea61 168 : "?"); //$NON-NLS-1$\r
a5823d5f 169 } else {\r
7995b722 170 addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ?\r
a5823d5f 171 Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res)\r
3b38ea61 172 : "?"); //$NON-NLS-1$\r
a5823d5f
ASL
173 }\r
174 } else {\r
175 if (eventDuration > 0) {\r
7995b722 176 addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ?\r
a5823d5f 177 Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res)\r
3b38ea61 178 : "?"); //$NON-NLS-1$\r
a5823d5f 179 \r
7995b722 180 addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ?\r
a5823d5f 181 Utils.formatTime(eventEndTime, TimeFormat.RELATIVE, res)\r
3b38ea61 182 : "?"); //$NON-NLS-1$\r
a5823d5f 183 } else {\r
7995b722 184 addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ?\r
a5823d5f 185 Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res)\r
3b38ea61 186 : "?"); //$NON-NLS-1$\r
a5823d5f 187 }\r
b0d3496e 188 }\r
79a3a76e 189\r
a5823d5f
ASL
190 if (eventDuration > 0) {\r
191 // Duration in relative format in any case\r
7995b722 192 addItem(Messages.TmfTimeTipHandler_DURATION, eventDuration > -1 ?\r
a5823d5f 193 Utils.formatTime(eventDuration, TimeFormat.RELATIVE, res)\r
3b38ea61 194 : "?"); //$NON-NLS-1$\r
a5823d5f 195 }\r
b0d3496e
ASL
196\r
197 } else if (item instanceof GroupItem) {\r
7995b722
FC
198 addItem(Messages.TmfTimeTipHandler_TRACE_GROUP_NAME, item.toString());\r
199 addItem(Messages.TmfTimeTipHandler_NUMBER_OF_TRACES, "" + ((GroupItem) item)._traces.size()); //$NON-NLS-1$\r
b0d3496e
ASL
200 }\r
201 }\r
202\r
4e3aa37d 203 @Override\r
b0d3496e
ASL
204 public void mouseHover(MouseEvent event) {\r
205 Point pt = new Point(event.x, event.y);\r
206 Widget widget = event.widget;\r
207 Item item = null;\r
208 if (widget instanceof TmfTimeStatesCtrl) {\r
209 TmfTimeStatesCtrl threadStates = (TmfTimeStatesCtrl) widget;\r
210 item = (Item) threadStates.getItem(pt);\r
211 _tipTable.remove(0, _tipTable.getItemCount() - 1);\r
212 new TableColumn(_tipTable, SWT.NONE);\r
213 new TableColumn(_tipTable, SWT.NONE);\r
214 fillValues(pt, threadStates, item);\r
215 _tipTable.getColumn(0).setWidth(200);\r
216 _tipTable.getColumn(1).pack();\r
217 _tipTable.setSize(_tipTable.computeSize(SWT.DEFAULT, 200));\r
218 _tipShell.pack();\r
219 } else if (widget == null) {\r
220 _tipShell.setVisible(false);\r
221 _tipItem = null;\r
222 return;\r
223 }\r
224 if (item == _tipItem)\r
225 return;\r
226 _tipItem = item;\r
227 _tipPosition = control.toDisplay(pt);\r
228 _tipShell.pack();\r
229 setHoverLocation(_tipShell, _tipPosition);\r
230 _tipShell.setVisible(true);\r
231 }\r
232 });\r
233 }\r
234\r
235 private void setHoverLocation(Shell shell, Point position) {\r
236 Rectangle displayBounds = shell.getDisplay().getBounds();\r
237 Rectangle shellBounds = shell.getBounds();\r
238 shellBounds.x = Math.max(Math.min(position.x, displayBounds.width\r
239 - shellBounds.width), 0);\r
240 shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height\r
241 - shellBounds.height), 0);\r
242 shell.setBounds(shellBounds);\r
243 }\r
244\r
245}
This page took 0.052558 seconds and 5 git commands to generate.