|
1 /* |
|
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Variable Tracing History Dialog |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.dialog; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.Collections; |
|
23 import java.util.Comparator; |
|
24 import java.util.List; |
|
25 |
|
26 import org.eclipse.swt.SWT; |
|
27 import org.eclipse.swt.events.SelectionAdapter; |
|
28 import org.eclipse.swt.events.SelectionEvent; |
|
29 import org.eclipse.swt.graphics.Point; |
|
30 import org.eclipse.swt.layout.GridData; |
|
31 import org.eclipse.swt.layout.GridLayout; |
|
32 import org.eclipse.swt.widgets.Button; |
|
33 import org.eclipse.swt.widgets.Composite; |
|
34 import org.eclipse.swt.widgets.Event; |
|
35 import org.eclipse.swt.widgets.Group; |
|
36 import org.eclipse.swt.widgets.Label; |
|
37 import org.eclipse.swt.widgets.Listener; |
|
38 import org.eclipse.swt.widgets.Shell; |
|
39 import org.eclipse.swt.widgets.Table; |
|
40 import org.eclipse.swt.widgets.TableColumn; |
|
41 import org.eclipse.swt.widgets.TableItem; |
|
42 import org.eclipse.ui.PlatformUI; |
|
43 |
|
44 import com.nokia.traceviewer.TraceViewerHelpContextIDs; |
|
45 import com.nokia.traceviewer.action.OpenTraceLocationAction; |
|
46 import com.nokia.traceviewer.engine.TraceMetaData; |
|
47 import com.nokia.traceviewer.engine.TraceViewerGlobals; |
|
48 import com.nokia.traceviewer.engine.dataprocessor.VariableTracingEvent; |
|
49 import com.nokia.traceviewer.engine.dataprocessor.VariableTracingItem; |
|
50 |
|
51 /** |
|
52 * Variable Tracing History Dialog |
|
53 * |
|
54 */ |
|
55 public final class VariableTracingHistoryDialog extends BaseDialog { |
|
56 |
|
57 /** |
|
58 * Main UI Composite |
|
59 */ |
|
60 private Composite mainComposite; |
|
61 |
|
62 /** |
|
63 * Top UI Composite |
|
64 */ |
|
65 private Composite topComposite; |
|
66 |
|
67 /** |
|
68 * Table containing all the information |
|
69 */ |
|
70 private Table table; |
|
71 |
|
72 /** |
|
73 * Checkbox for activating trace when doubleclicking |
|
74 */ |
|
75 private Button activateTraceCheckBox; |
|
76 |
|
77 /** |
|
78 * Checkbox for activating codeline when doubleclicking |
|
79 */ |
|
80 private Button activateCodeLineCheckBox; |
|
81 |
|
82 /** |
|
83 * Tells whether we will activate trace when doubleclicking line |
|
84 */ |
|
85 private boolean activateTrace = true; |
|
86 |
|
87 /** |
|
88 * Tells whether we will activate codeline when doubleclicking line |
|
89 */ |
|
90 private boolean activateCodeLine = true; |
|
91 |
|
92 /** |
|
93 * Checks if DataReader was paused when we entered dialog -> Don't pause |
|
94 * again and don't unpause in exit |
|
95 */ |
|
96 private boolean wasPausedWhenEntered = true; |
|
97 |
|
98 /** |
|
99 * Constructor |
|
100 * |
|
101 * @param parent |
|
102 * parent shell |
|
103 */ |
|
104 public VariableTracingHistoryDialog(Shell parent) { |
|
105 super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); |
|
106 } |
|
107 |
|
108 /* |
|
109 * (non-Javadoc) |
|
110 * |
|
111 * @see org.eclipse.jface.dialogs.TrayDialog#close() |
|
112 */ |
|
113 @Override |
|
114 public boolean close() { |
|
115 boolean close = super.close(); |
|
116 if (!wasPausedWhenEntered) { |
|
117 // Unpause |
|
118 TraceViewerGlobals.getTraceViewer().getView().getActionFactory() |
|
119 .getPauseAction().run(); |
|
120 } |
|
121 return close; |
|
122 } |
|
123 |
|
124 /* |
|
125 * (non-Javadoc) |
|
126 * |
|
127 * @see com.nokia.traceviewer.dialog.BaseDialog#createShell() |
|
128 */ |
|
129 @Override |
|
130 protected void createDialogContents() { |
|
131 // Pause the datareader if it's not paused already |
|
132 wasPausedWhenEntered = TraceViewerGlobals.getTraceViewer() |
|
133 .getDataReaderAccess().getMainDataReader().isPaused(); |
|
134 if (!wasPausedWhenEntered) { |
|
135 TraceViewerGlobals.getTraceViewer().getView().getActionFactory() |
|
136 .getPauseAction().run(); |
|
137 } |
|
138 |
|
139 // Contents |
|
140 GridLayout gridLayout = new GridLayout(); |
|
141 getShell().setText( |
|
142 Messages.getString("VariableTracingHistoryDialog.ShellTitle")); //$NON-NLS-1$ |
|
143 composite.setLayout(gridLayout); |
|
144 getShell().setMinimumSize(new Point(400, 250)); |
|
145 |
|
146 // Create main composite |
|
147 createMainComposite(); |
|
148 |
|
149 // Set help |
|
150 PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(), |
|
151 TraceViewerHelpContextIDs.VARIABLE_TRACING_HISTORY); |
|
152 } |
|
153 |
|
154 /** |
|
155 * This method initializes mainComposite |
|
156 * |
|
157 */ |
|
158 private void createMainComposite() { |
|
159 // Main composite |
|
160 GridData mainCompositeGridData = new GridData(); |
|
161 mainCompositeGridData.horizontalAlignment = GridData.FILL; |
|
162 mainCompositeGridData.grabExcessHorizontalSpace = true; |
|
163 mainCompositeGridData.grabExcessVerticalSpace = true; |
|
164 mainCompositeGridData.verticalAlignment = GridData.FILL; |
|
165 mainComposite = new Composite(composite, SWT.NONE); |
|
166 mainComposite.setLayout(new GridLayout()); |
|
167 mainComposite.setLayoutData(mainCompositeGridData); |
|
168 |
|
169 // Create top composite |
|
170 createTopComposite(); |
|
171 |
|
172 // Create the table |
|
173 createTable(); |
|
174 |
|
175 // Create bottom composite |
|
176 createBottomComposite(); |
|
177 } |
|
178 |
|
179 /** |
|
180 * Creates and initializes table |
|
181 */ |
|
182 private void createTable() { |
|
183 // Layout data for table |
|
184 GridData tableGridData = new GridData(); |
|
185 tableGridData.horizontalAlignment = GridData.FILL; |
|
186 tableGridData.verticalAlignment = GridData.FILL; |
|
187 tableGridData.grabExcessHorizontalSpace = true; |
|
188 tableGridData.grabExcessVerticalSpace = true; |
|
189 tableGridData.heightHint = 300; |
|
190 |
|
191 // Create table |
|
192 table = new Table(mainComposite, SWT.BORDER | SWT.FULL_SELECTION); |
|
193 table.setHeaderVisible(true); |
|
194 table.setLayoutData(tableGridData); |
|
195 table.setLinesVisible(true); |
|
196 |
|
197 // Add double click support |
|
198 table.addListener(SWT.DefaultSelection, new Listener() { |
|
199 public void handleEvent(Event e) { |
|
200 handleDoubleClick(); |
|
201 } |
|
202 }); |
|
203 |
|
204 // Create columns |
|
205 TableColumn timestampColumn = new TableColumn(table, SWT.NONE); |
|
206 timestampColumn.setWidth(110); |
|
207 timestampColumn.setText(Messages |
|
208 .getString("VariableTracingHistoryDialog.TimestampColumnName")); //$NON-NLS-1$ |
|
209 TableColumn valueColumn = new TableColumn(table, SWT.NONE); |
|
210 valueColumn.setWidth(405); |
|
211 valueColumn.setText(Messages |
|
212 .getString("VariableTracingHistoryDialog.ValueColumnName")); //$NON-NLS-1$ |
|
213 TableColumn lineColumn = new TableColumn(table, SWT.NONE); |
|
214 lineColumn.setAlignment(SWT.CENTER); |
|
215 lineColumn.setWidth(65); |
|
216 lineColumn.setText(Messages |
|
217 .getString("VariableTracingHistoryDialog.LineNrText")); //$NON-NLS-1$ |
|
218 TableColumn hasCodeLineColumn = new TableColumn(table, SWT.NONE); |
|
219 hasCodeLineColumn.setAlignment(SWT.CENTER); |
|
220 hasCodeLineColumn |
|
221 .setText(Messages |
|
222 .getString("VariableTracingHistoryDialog.HasCodeLineColumnName")); //$NON-NLS-1$ |
|
223 hasCodeLineColumn.setWidth(80); |
|
224 |
|
225 // Insert data |
|
226 insertData(); |
|
227 } |
|
228 |
|
229 /** |
|
230 * Inserts data to table |
|
231 */ |
|
232 private void insertData() { |
|
233 // First get indices selected in the table |
|
234 int[] indices = TraceViewerGlobals.getTraceViewer().getPropertyView() |
|
235 .getSelectedVariableIndices(); |
|
236 |
|
237 // Get items from VariableTracingProcessor |
|
238 List<VariableTracingItem> variableItems = TraceViewerGlobals |
|
239 .getTraceViewer().getDataProcessorAccess() |
|
240 .getVariableTracingProcessor().getVariableTracingItems(); |
|
241 |
|
242 // Create a ArrayList of all events from selected items |
|
243 List<VariableTracingEvent> events = new ArrayList<VariableTracingEvent>(); |
|
244 for (int i = 0; i < indices.length; i++) { |
|
245 events.addAll(variableItems.get(indices[i]).getEventList()); |
|
246 } |
|
247 |
|
248 // Sort the list by line numbers |
|
249 Collections.sort(events, new Comparator<VariableTracingEvent>() { |
|
250 public int compare(VariableTracingEvent o1, VariableTracingEvent o2) { |
|
251 int val = o1.getLine(); |
|
252 int val2 = o2.getLine(); |
|
253 return val > val2 ? 1 : val < val2 ? -1 : 0; |
|
254 } |
|
255 }); |
|
256 |
|
257 // Null own timestamp from TimestampParser |
|
258 TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
259 .getTimestampParser().nullPreviousOwnTimestamp(); |
|
260 |
|
261 // Insert items |
|
262 for (int j = 0; j < events.size(); j++) { |
|
263 TableItem item = new TableItem(table, SWT.NONE); |
|
264 VariableTracingEvent event = events.get(j); |
|
265 String hasMetadata = Messages |
|
266 .getString("VariableTracingHistoryDialog.YesText"); //$NON-NLS-1$ |
|
267 |
|
268 // Calculate new timestamp |
|
269 String timestamp = TraceViewerGlobals.getTraceViewer() |
|
270 .getDataProcessorAccess().getTimestampParser() |
|
271 .processTimestampFromPlainText(event.getTimestamp(), false); |
|
272 |
|
273 // No metaData |
|
274 if (event.getTraceInformation() == null |
|
275 || TraceViewerGlobals.getDecodeProvider().getTraceMetaData( |
|
276 event.getTraceInformation()) == null |
|
277 || TraceViewerGlobals.getDecodeProvider().getTraceMetaData( |
|
278 event.getTraceInformation()).getLineNumber() == 0) { |
|
279 hasMetadata = Messages |
|
280 .getString("VariableTracingHistoryDialog.NoText"); //$NON-NLS-1$ |
|
281 } |
|
282 |
|
283 item.setText(new String[] { timestamp, |
|
284 (j + 1) + ". " + event.getParent().getName() //$NON-NLS-1$ |
|
285 + event.getValue(), |
|
286 String.valueOf(event.getLine()), hasMetadata }); |
|
287 |
|
288 // Attach event to the data part of the TableItem for easy get |
|
289 item.setData(event); |
|
290 } |
|
291 } |
|
292 |
|
293 /** |
|
294 * Handles double clicks |
|
295 */ |
|
296 void handleDoubleClick() { |
|
297 VariableTracingEvent event = (VariableTracingEvent) table |
|
298 .getSelection()[0].getData(); |
|
299 |
|
300 // Activate trace |
|
301 if (activateTrace) { |
|
302 |
|
303 // Set the line highlighted |
|
304 TraceViewerGlobals.getTraceViewer().getView().highlightLines( |
|
305 event.getLine() - 1, 0, false); |
|
306 } |
|
307 |
|
308 // Activate code line |
|
309 if (activateCodeLine) { |
|
310 if (event.getTraceInformation() != null) { |
|
311 TraceMetaData metaData = TraceViewerGlobals.getDecodeProvider() |
|
312 .getTraceMetaData(event.getTraceInformation()); |
|
313 |
|
314 if (metaData.getLineNumber() != 0) { |
|
315 // Get Action used to open trace line |
|
316 OpenTraceLocationAction action = (OpenTraceLocationAction) TraceViewerGlobals |
|
317 .getTraceViewer().getView().getActionFactory() |
|
318 .getOpenTraceLocationAction(); |
|
319 action.setMetaData(metaData, true); |
|
320 action.run(); |
|
321 } |
|
322 } |
|
323 } |
|
324 |
|
325 } |
|
326 |
|
327 /** |
|
328 * This method initializes topComposite |
|
329 * |
|
330 */ |
|
331 private void createTopComposite() { |
|
332 // Top composite |
|
333 GridData topCompositeGridData = new GridData(); |
|
334 topCompositeGridData.horizontalAlignment = GridData.FILL; |
|
335 topCompositeGridData.grabExcessHorizontalSpace = true; |
|
336 topCompositeGridData.heightHint = 90; |
|
337 topCompositeGridData.verticalSpan = 2; |
|
338 topCompositeGridData.verticalAlignment = GridData.CENTER; |
|
339 topComposite = new Composite(mainComposite, SWT.NONE); |
|
340 topComposite.setLayout(new GridLayout()); |
|
341 topComposite.setLayoutData(topCompositeGridData); |
|
342 |
|
343 // Create settings group |
|
344 createSettingsGroup(); |
|
345 } |
|
346 |
|
347 /** |
|
348 * This method initializes bottomComposite |
|
349 * |
|
350 */ |
|
351 private void createBottomComposite() { |
|
352 // Bottom composite |
|
353 GridData bottomCompositeGridData = new GridData(); |
|
354 bottomCompositeGridData.horizontalAlignment = GridData.END; |
|
355 bottomCompositeGridData.verticalAlignment = GridData.CENTER; |
|
356 Composite bottomComposite = new Composite(mainComposite, SWT.NONE); |
|
357 bottomComposite.setLayout(new GridLayout()); |
|
358 bottomComposite.setLayoutData(bottomCompositeGridData); |
|
359 } |
|
360 |
|
361 /** |
|
362 * This method initializes settingsGroup |
|
363 * |
|
364 */ |
|
365 private void createSettingsGroup() { |
|
366 // Settings group |
|
367 GridLayout settingsGroupGridLayout = new GridLayout(); |
|
368 settingsGroupGridLayout.numColumns = 2; |
|
369 settingsGroupGridLayout.horizontalSpacing = 15; |
|
370 Group settingsGroup = new Group(topComposite, SWT.NONE); |
|
371 settingsGroup.setText(Messages |
|
372 .getString("VariableTracingHistoryDialog.SettingsGroupText")); //$NON-NLS-1$ |
|
373 settingsGroup.setLayout(settingsGroupGridLayout); |
|
374 |
|
375 // Information label |
|
376 Label informationLabel = new Label(settingsGroup, SWT.NONE); |
|
377 informationLabel |
|
378 .setText(Messages |
|
379 .getString("VariableTracingHistoryDialog.InformationLabelText")); //$NON-NLS-1$ |
|
380 |
|
381 // Activate Trace checkbox |
|
382 activateTraceCheckBox = new Button(settingsGroup, SWT.CHECK); |
|
383 activateTraceCheckBox.setText(Messages |
|
384 .getString("VariableTracingHistoryDialog.ActivateTraceText")); //$NON-NLS-1$ |
|
385 activateTraceCheckBox.setSelection(activateTrace); |
|
386 |
|
387 // Filler |
|
388 new Label(settingsGroup, SWT.NONE); |
|
389 |
|
390 // Activate Codeline checkbox |
|
391 activateCodeLineCheckBox = new Button(settingsGroup, SWT.CHECK); |
|
392 activateCodeLineCheckBox |
|
393 .setText(Messages |
|
394 .getString("VariableTracingHistoryDialog.ActivateCodelineText")); //$NON-NLS-1$ |
|
395 activateCodeLineCheckBox.setSelection(true); |
|
396 } |
|
397 |
|
398 /* |
|
399 * (non-Javadoc) |
|
400 * |
|
401 * @see com.nokia.traceviewer.dialog.BaseDialog#createActionListeners() |
|
402 */ |
|
403 @Override |
|
404 public void createActionListeners() { |
|
405 // Add listener to ActivateTrace checkbox |
|
406 activateTraceCheckBox.addSelectionListener(new SelectionAdapter() { |
|
407 @Override |
|
408 public void widgetSelected(SelectionEvent event) { |
|
409 activateTrace = activateTraceCheckBox.getSelection(); |
|
410 } |
|
411 }); |
|
412 |
|
413 // Add listener to ActivateCodeLine checkbox |
|
414 activateCodeLineCheckBox.addSelectionListener(new SelectionAdapter() { |
|
415 @Override |
|
416 public void widgetSelected(SelectionEvent event) { |
|
417 activateCodeLine = activateCodeLineCheckBox.getSelection(); |
|
418 } |
|
419 }); |
|
420 } |
|
421 |
|
422 /* |
|
423 * (non-Javadoc) |
|
424 * |
|
425 * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() |
|
426 */ |
|
427 @Override |
|
428 protected void cancelPressed() { |
|
429 table.removeAll(); |
|
430 super.cancelPressed(); |
|
431 } |
|
432 |
|
433 /* |
|
434 * (non-Javadoc) |
|
435 * |
|
436 * @see org.eclipse.jface.dialogs.Dialog#okPressed() |
|
437 */ |
|
438 @Override |
|
439 protected void okPressed() { |
|
440 table.removeAll(); |
|
441 super.okPressed(); |
|
442 } |
|
443 |
|
444 /** |
|
445 * Tells is the search dialog open |
|
446 * |
|
447 * @return true if dialog is open |
|
448 */ |
|
449 public boolean isOpen() { |
|
450 boolean isOpen = false; |
|
451 if (getShell() != null && !getShell().isDisposed()) { |
|
452 isOpen = true; |
|
453 } |
|
454 return isOpen; |
|
455 } |
|
456 |
|
457 /** |
|
458 * Sets focus |
|
459 */ |
|
460 public void setFocus() { |
|
461 getShell().setFocus(); |
|
462 } |
|
463 } |