|
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 * Trace Viewer view implementation |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.view; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
|
23 |
|
24 import org.eclipse.jface.action.Action; |
|
25 import org.eclipse.jface.action.IMenuListener; |
|
26 import org.eclipse.jface.action.IMenuManager; |
|
27 import org.eclipse.jface.action.MenuManager; |
|
28 import org.eclipse.jface.action.Separator; |
|
29 import org.eclipse.jface.dialogs.MessageDialog; |
|
30 import org.eclipse.jface.preference.IPreferenceNode; |
|
31 import org.eclipse.jface.preference.IPreferencePage; |
|
32 import org.eclipse.jface.preference.PreferenceDialog; |
|
33 import org.eclipse.jface.preference.PreferenceManager; |
|
34 import org.eclipse.jface.preference.PreferenceNode; |
|
35 import org.eclipse.jface.text.Document; |
|
36 import org.eclipse.jface.text.TextViewer; |
|
37 import org.eclipse.jface.viewers.StructuredSelection; |
|
38 import org.eclipse.jface.window.Window; |
|
39 import org.eclipse.swt.SWT; |
|
40 import org.eclipse.swt.custom.StyleRange; |
|
41 import org.eclipse.swt.custom.StyledText; |
|
42 import org.eclipse.swt.graphics.Font; |
|
43 import org.eclipse.swt.graphics.FontData; |
|
44 import org.eclipse.swt.layout.GridData; |
|
45 import org.eclipse.swt.layout.GridLayout; |
|
46 import org.eclipse.swt.widgets.Composite; |
|
47 import org.eclipse.swt.widgets.Control; |
|
48 import org.eclipse.swt.widgets.Listener; |
|
49 import org.eclipse.swt.widgets.Menu; |
|
50 import org.eclipse.swt.widgets.Shell; |
|
51 import org.eclipse.swt.widgets.Slider; |
|
52 import org.eclipse.ui.IActionBars; |
|
53 import org.eclipse.ui.IWorkbenchActionConstants; |
|
54 import org.eclipse.ui.PlatformUI; |
|
55 import org.eclipse.ui.part.ViewPart; |
|
56 |
|
57 import com.nokia.traceviewer.TraceViewerHelpContextIDs; |
|
58 import com.nokia.traceviewer.TraceViewerPlugin; |
|
59 import com.nokia.traceviewer.action.ActionFactory; |
|
60 import com.nokia.traceviewer.action.AddCommentToTraceAction; |
|
61 import com.nokia.traceviewer.action.EditTraceCommentAction; |
|
62 import com.nokia.traceviewer.action.OpenTraceLocationAction; |
|
63 import com.nokia.traceviewer.action.RemoveTraceCommentAction; |
|
64 import com.nokia.traceviewer.action.ShowTraceInfoAction; |
|
65 import com.nokia.traceviewer.action.TraceViewerActionUtils; |
|
66 import com.nokia.traceviewer.dialog.ProgressBarDialog; |
|
67 import com.nokia.traceviewer.dialog.SearchDialog; |
|
68 import com.nokia.traceviewer.engine.StateHolder; |
|
69 import com.nokia.traceviewer.engine.TraceMetaData; |
|
70 import com.nokia.traceviewer.engine.TraceProperties; |
|
71 import com.nokia.traceviewer.engine.TraceViewerDialog; |
|
72 import com.nokia.traceviewer.engine.TraceViewerDialogInterface; |
|
73 import com.nokia.traceviewer.engine.TraceViewerGlobals; |
|
74 import com.nokia.traceviewer.engine.TraceViewerTraceViewInterface; |
|
75 import com.nokia.traceviewer.engine.TraceViewerUtils; |
|
76 import com.nokia.traceviewer.engine.dataprocessor.DataProcessor; |
|
77 import com.nokia.traceviewer.engine.preferences.PreferenceConstants; |
|
78 import com.nokia.traceviewer.engine.preferences.TraceViewerAdvancedPreferencesPage; |
|
79 import com.nokia.traceviewer.engine.preferences.TraceViewerConnectionPreferencesPage; |
|
80 import com.nokia.traceviewer.engine.preferences.TraceViewerPreferencesPage; |
|
81 import com.nokia.traceviewer.view.listener.ScrollerSelectionListener; |
|
82 import com.nokia.traceviewer.view.listener.SelectionProperties; |
|
83 import com.nokia.traceviewer.view.listener.ViewerClickListener; |
|
84 import com.nokia.traceviewer.view.listener.ViewerKeyListener; |
|
85 import com.nokia.traceviewer.view.listener.ViewerMouseWheelListener; |
|
86 import com.nokia.traceviewer.view.listener.ViewerSelectionChangedListener; |
|
87 import com.nokia.traceviewer.view.listener.WindowResizeListener; |
|
88 |
|
89 /** |
|
90 * Trace Viewer view implementation |
|
91 */ |
|
92 public final class TraceViewerView extends ViewPart implements |
|
93 TraceViewerTraceViewInterface, TraceViewerDialogInterface, |
|
94 DataProcessor, Runnable { |
|
95 |
|
96 /** |
|
97 * Title of the view |
|
98 */ |
|
99 private static final String TRACE_VIEWER_TITLE = Messages |
|
100 .getString("TraceViewerView.ViewTitle"); //$NON-NLS-1$ |
|
101 |
|
102 /** |
|
103 * Hex prefix |
|
104 */ |
|
105 private static final String HEX_PREFIX = "0x"; //$NON-NLS-1$ |
|
106 |
|
107 /** |
|
108 * Max lines in the view |
|
109 */ |
|
110 private static final int MAX_LINES = TraceViewerGlobals.blockSize * 2; |
|
111 |
|
112 /** |
|
113 * Update interval in milliseconds |
|
114 */ |
|
115 private static final int UPDATE_INTERVAL = 100; |
|
116 |
|
117 /** |
|
118 * Normal view name |
|
119 */ |
|
120 private static final String VIEWNAME_NORMAL = TRACE_VIEWER_TITLE; |
|
121 |
|
122 /** |
|
123 * Filtered view name |
|
124 */ |
|
125 private static final String VIEWNAME_FILTERED = Messages |
|
126 .getString("TraceViewerView.FilteredText"); //$NON-NLS-1$ |
|
127 |
|
128 /** |
|
129 * Paused view name |
|
130 */ |
|
131 private static final String VIEWNAME_PAUSED = Messages |
|
132 .getString("TraceViewerView.PausedText"); //$NON-NLS-1$ |
|
133 |
|
134 /** |
|
135 * View name when storing data while triggering |
|
136 */ |
|
137 private static final String VIEWNAME_STORING = Messages |
|
138 .getString("TraceViewerView.StoringText"); //$NON-NLS-1$ |
|
139 |
|
140 /** |
|
141 * View name when trigger is armed |
|
142 */ |
|
143 private static final String VIEWNAME_ARMED = Messages |
|
144 .getString("TraceViewerView.ArmedText"); //$NON-NLS-1$ |
|
145 |
|
146 /** |
|
147 * Opened Log file name separator shown before the log file name |
|
148 */ |
|
149 private static final String LOG_FILE_NAME_SEPARATOR = " - "; //$NON-NLS-1$ |
|
150 |
|
151 /** |
|
152 * Action factory |
|
153 */ |
|
154 private ActionFactory actionFactory; |
|
155 |
|
156 /** |
|
157 * Text viewer |
|
158 */ |
|
159 private TextViewer viewer; |
|
160 |
|
161 /** |
|
162 * StyledText widget |
|
163 */ |
|
164 private StyledText widget; |
|
165 |
|
166 /** |
|
167 * String array to append to widget in next update |
|
168 */ |
|
169 private final StringBuffer newData; |
|
170 |
|
171 /** |
|
172 * String array to append to widget in next update |
|
173 */ |
|
174 private final StringBuffer scrolledData; |
|
175 |
|
176 /** |
|
177 * Timestamp of next update |
|
178 */ |
|
179 private long updateNextTime; |
|
180 |
|
181 /** |
|
182 * Slider object |
|
183 */ |
|
184 private Slider slider; |
|
185 |
|
186 /** |
|
187 * Tells from which count Viewer is showing traces from |
|
188 */ |
|
189 private int showingTracesFrom; |
|
190 |
|
191 /** |
|
192 * Start line to highlight |
|
193 */ |
|
194 private int startHighlightLine; |
|
195 |
|
196 /** |
|
197 * End line to highlight |
|
198 */ |
|
199 private int endHighlightLine; |
|
200 |
|
201 /** |
|
202 * Indicates that view name should be updated |
|
203 */ |
|
204 private boolean updateViewName; |
|
205 |
|
206 /** |
|
207 * Contains number of new traces in String buffer |
|
208 */ |
|
209 private int numberOfNewTraces; |
|
210 |
|
211 /** |
|
212 * Contains offsets of new traces in newTraces String buffer |
|
213 */ |
|
214 private final List<Integer> offsetsOfNewTraces; |
|
215 |
|
216 /** |
|
217 * Dialog factory |
|
218 */ |
|
219 private final DialogFactory dialogFactory; |
|
220 |
|
221 /** |
|
222 * Indicates that view update is on |
|
223 */ |
|
224 private boolean viewUpdateOn = true; |
|
225 |
|
226 /** |
|
227 * Inserting last block when scrolling the view |
|
228 */ |
|
229 private boolean insertingLastBlock; |
|
230 |
|
231 /** |
|
232 * The constructor. |
|
233 */ |
|
234 public TraceViewerView() { |
|
235 dialogFactory = new DialogFactory(); |
|
236 |
|
237 // Create StringBuffers |
|
238 newData = new StringBuffer(); |
|
239 scrolledData = new StringBuffer(); |
|
240 |
|
241 // Offsets of new traces are also saved |
|
242 offsetsOfNewTraces = new ArrayList<Integer>(); |
|
243 } |
|
244 |
|
245 /* |
|
246 * (non-Javadoc) |
|
247 * |
|
248 * @see |
|
249 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets |
|
250 * .Composite) |
|
251 */ |
|
252 @Override |
|
253 public void createPartControl(Composite parent) { |
|
254 actionFactory = new ActionFactory(); |
|
255 // Create layout for the shell |
|
256 createLayout(parent); |
|
257 |
|
258 // Creates the text viewer and set a document to it |
|
259 viewer = new TextViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL); |
|
260 Document document = new Document(); |
|
261 viewer.setDocument(document); |
|
262 viewer.setEditable(false); |
|
263 |
|
264 // Get styled text widget and configure it |
|
265 widget = viewer.getTextWidget(); |
|
266 setFontSize(FONT_SIZE); |
|
267 widget.getVerticalBar().setVisible(false); |
|
268 widget.getHorizontalBar().setVisible(true); |
|
269 widget |
|
270 .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, |
|
271 1)); |
|
272 |
|
273 // Create a slider |
|
274 slider = new Slider(parent, SWT.VERTICAL); |
|
275 slider.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, true, 1, |
|
276 1)); |
|
277 slider.setEnabled(false); |
|
278 |
|
279 fillMenuAndToolBar(); |
|
280 createContextMenu(); |
|
281 |
|
282 // Create listeners |
|
283 createListeners(); |
|
284 |
|
285 // Sets this view to be the dialog provider |
|
286 TraceViewerGlobals.getTraceViewer().setDialogs(this); |
|
287 |
|
288 // Sets the view reference to trace viewer engine |
|
289 TraceViewerGlobals.getTraceViewer().setTraceView(this); |
|
290 |
|
291 // Set help |
|
292 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, |
|
293 TraceViewerHelpContextIDs.MAIN_VIEW); |
|
294 |
|
295 // Set global action handler to own copy selection action |
|
296 getViewSite().getActionBars().setGlobalActionHandler( |
|
297 org.eclipse.ui.actions.ActionFactory.COPY.getId(), |
|
298 actionFactory.getCopySelectionAction()); |
|
299 |
|
300 // Set global action handler to own seach action |
|
301 getViewSite().getActionBars().setGlobalActionHandler( |
|
302 org.eclipse.ui.actions.ActionFactory.FIND.getId(), |
|
303 actionFactory.getSearchAction()); |
|
304 |
|
305 // Set global action handler to own select all action |
|
306 getViewSite().getActionBars().setGlobalActionHandler( |
|
307 org.eclipse.ui.actions.ActionFactory.SELECT_ALL.getId(), |
|
308 actionFactory.getSelectAllAction()); |
|
309 |
|
310 } |
|
311 |
|
312 /** |
|
313 * Adds action items to menu and toolbar |
|
314 */ |
|
315 private void fillMenuAndToolBar() { |
|
316 IActionBars bars = getViewSite().getActionBars(); |
|
317 actionFactory.fillMenu(bars.getMenuManager()); |
|
318 actionFactory.fillToolBar(bars.getToolBarManager()); |
|
319 } |
|
320 |
|
321 /** |
|
322 * Returns action factory |
|
323 * |
|
324 * @return action factory |
|
325 */ |
|
326 public ActionFactory getActionFactory() { |
|
327 return actionFactory; |
|
328 } |
|
329 |
|
330 /** |
|
331 * Create layout for the view |
|
332 * |
|
333 * @param parent |
|
334 * parent shell |
|
335 */ |
|
336 private void createLayout(Composite parent) { |
|
337 GridLayout layout = new GridLayout(2, false); |
|
338 layout.marginTop = 0; |
|
339 layout.marginBottom = 0; |
|
340 layout.marginHeight = 0; |
|
341 layout.marginWidth = 0; |
|
342 layout.horizontalSpacing = 0; |
|
343 parent.setLayout(layout); |
|
344 } |
|
345 |
|
346 /** |
|
347 * Create all listeners |
|
348 */ |
|
349 private void createListeners() { |
|
350 // Create scroller selection listener |
|
351 ScrollerSelectionListener slistener = new ScrollerSelectionListener( |
|
352 viewer); |
|
353 slider.addSelectionListener(slistener); |
|
354 |
|
355 // Viewer selection changed listener |
|
356 ViewerSelectionChangedListener vlistener = new ViewerSelectionChangedListener( |
|
357 slider); |
|
358 viewer.addSelectionChangedListener(vlistener); |
|
359 |
|
360 // Create viewer mouse wheel listener |
|
361 Listener mlistener = new ViewerMouseWheelListener(slider, viewer); |
|
362 widget.addListener(SWT.MouseWheel, mlistener); |
|
363 |
|
364 // Create viewer key listener |
|
365 ViewerKeyListener klistener = new ViewerKeyListener(slider, viewer, |
|
366 this); |
|
367 widget.addKeyListener(klistener); |
|
368 |
|
369 // Create window resize listener |
|
370 WindowResizeListener rlistener = new WindowResizeListener(slider, |
|
371 viewer); |
|
372 widget.addControlListener(rlistener); |
|
373 |
|
374 // Create viewer click listener |
|
375 ViewerClickListener clistener = new ViewerClickListener(viewer); |
|
376 widget.addMouseListener(clistener); |
|
377 } |
|
378 |
|
379 /** |
|
380 * Creates context menu |
|
381 */ |
|
382 private void createContextMenu() { |
|
383 // Create menu manager. |
|
384 final MenuManager menuMgr = new MenuManager(); |
|
385 menuMgr.setRemoveAllWhenShown(true); |
|
386 menuMgr.addMenuListener(new IMenuListener() { |
|
387 public void menuAboutToShow(IMenuManager mgr) { |
|
388 fillContextMenu(menuMgr); |
|
389 } |
|
390 }); |
|
391 |
|
392 // Create menu. |
|
393 Menu menu = menuMgr.createContextMenu(viewer.getControl()); |
|
394 viewer.getControl().setMenu(menu); |
|
395 |
|
396 // Register menu for extension. |
|
397 getSite().registerContextMenu(menuMgr, viewer); |
|
398 } |
|
399 |
|
400 /** |
|
401 * Fills context menu |
|
402 * |
|
403 * @param menuMgr |
|
404 * menu manager |
|
405 */ |
|
406 public void fillContextMenu(MenuManager menuMgr) { |
|
407 menuMgr.add(actionFactory.getShowTraceInfoAction()); |
|
408 menuMgr.add(actionFactory.getOpenTraceLocationAction()); |
|
409 menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
410 |
|
411 // Nothing is selected |
|
412 if (widget.getSelectionCount() == 0) { |
|
413 actionFactory.getShowTraceInfoAction().setEnabled(false); |
|
414 actionFactory.getOpenTraceLocationAction().setEnabled(false); |
|
415 |
|
416 // More than one trace selected |
|
417 } else if (widget.getSelectionText().contains("\n")) { //$NON-NLS-1$ |
|
418 actionFactory.getShowTraceInfoAction().setEnabled(false); |
|
419 actionFactory.getOpenTraceLocationAction().setEnabled(false); |
|
420 |
|
421 // One trace is selected |
|
422 } else { |
|
423 int lineNumber = showingTracesFrom |
|
424 + widget.getLineAtOffset(widget.getCaretOffset()); |
|
425 |
|
426 // Get the trace from the file |
|
427 List<TraceProperties> traceList = TraceViewerGlobals |
|
428 .getTraceViewer().getTraces(lineNumber, lineNumber); |
|
429 |
|
430 TraceProperties trace = null; |
|
431 if (traceList != null && !traceList.isEmpty()) { |
|
432 trace = traceList.get(0); |
|
433 } |
|
434 |
|
435 ShowTraceInfoAction infoAction = (ShowTraceInfoAction) actionFactory |
|
436 .getShowTraceInfoAction(); |
|
437 infoAction.setEnabled(true); |
|
438 infoAction.setTrace(trace); |
|
439 |
|
440 OpenTraceLocationAction openLocationAction = (OpenTraceLocationAction) actionFactory |
|
441 .getOpenTraceLocationAction(); |
|
442 |
|
443 // If traceInformation is found, enable open trace location action |
|
444 if (trace != null && trace.information != null) { |
|
445 TraceMetaData metaData = TraceViewerGlobals.getDecodeProvider() |
|
446 .getTraceMetaData(trace.information); |
|
447 if (metaData != null && metaData.getPath() != null) { |
|
448 openLocationAction.setEnabled(true); |
|
449 openLocationAction.setMetaData(metaData, true); |
|
450 } else { |
|
451 openLocationAction.setEnabled(false); |
|
452 } |
|
453 } else { |
|
454 openLocationAction.setEnabled(false); |
|
455 } |
|
456 |
|
457 menuMgr.add(new Separator()); |
|
458 |
|
459 // Add / Edit / Remove trace comment actions |
|
460 if (trace != null) { |
|
461 TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
462 .getTraceCommentHandler().processData(trace); |
|
463 if (trace.traceComment == null) { |
|
464 menuMgr.add(new AddCommentToTraceAction(trace.traceNumber)); |
|
465 } else { |
|
466 menuMgr.add(new EditTraceCommentAction(trace.traceNumber)); |
|
467 menuMgr |
|
468 .add(new RemoveTraceCommentAction(trace.traceNumber)); |
|
469 } |
|
470 } |
|
471 |
|
472 } |
|
473 // Separator |
|
474 menuMgr.add(new Separator()); |
|
475 |
|
476 // Copy action |
|
477 Action copyAction = actionFactory.getCopySelectionAction(); |
|
478 menuMgr.add(copyAction); |
|
479 if (widget.getSelectionCount() > 0) { |
|
480 copyAction.setEnabled(true); |
|
481 } else { |
|
482 copyAction.setEnabled(false); |
|
483 } |
|
484 } |
|
485 |
|
486 /* |
|
487 * (non-Javadoc) |
|
488 * |
|
489 * @see java.lang.Runnable#run() |
|
490 */ |
|
491 public void run() { |
|
492 if (!widget.isDisposed()) { |
|
493 |
|
494 // Set redraw off |
|
495 widget.setRedraw(false); |
|
496 |
|
497 if (TraceViewerGlobals.getTraceViewer().getStateHolder().getState() == StateHolder.State.SEARCHED) { |
|
498 slider.setSelection(startHighlightLine); |
|
499 scrollViewToLine(slider.getSelection()); |
|
500 } else if (newData.length() > 0) { |
|
501 runNormalUpdate(); |
|
502 } |
|
503 |
|
504 colorTraces(); |
|
505 |
|
506 // If view name should be updated |
|
507 if (updateViewName) { |
|
508 generateAndSetViewName(); |
|
509 } |
|
510 // Redraw |
|
511 widget.setRedraw(true); |
|
512 widget.update(); |
|
513 } |
|
514 } |
|
515 |
|
516 /** |
|
517 * Normal update sequence |
|
518 */ |
|
519 private void runNormalUpdate() { |
|
520 // Max offset is number of traces minus 1 |
|
521 int max = TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
522 .getCurrentDataReader().getTraceCount() - 1; |
|
523 |
|
524 // If previous data is not from the end, get latest blocks from file |
|
525 if (showingTracesFrom + widget.getLineCount() + numberOfNewTraces < max + 1) { |
|
526 slider.setMaximum(max); |
|
527 slider.setSelection(max); |
|
528 scrollViewToLine(max); |
|
529 setSliderProperties(max); |
|
530 } else { |
|
531 |
|
532 // If there is lot of new traces, cut down the StringBuffer already |
|
533 // in here to avoid massive insertion to text widget |
|
534 if (numberOfNewTraces > MAX_LINES + TraceViewerGlobals.blockSize) { |
|
535 int offsetOfDeletion = offsetsOfNewTraces.size() - 1 |
|
536 - (MAX_LINES / TraceViewerGlobals.blockSize); |
|
537 |
|
538 if (offsetOfDeletion >= 0 |
|
539 && offsetOfDeletion < offsetsOfNewTraces.size()) { |
|
540 newData.replace(0, offsetsOfNewTraces.get(offsetOfDeletion) |
|
541 .intValue(), ""); //$NON-NLS-1$ |
|
542 } |
|
543 } |
|
544 |
|
545 // Append the new data to current |
|
546 widget.append(newData.toString()); |
|
547 |
|
548 // Set slider properties |
|
549 setSliderProperties(max); |
|
550 |
|
551 // If there is over MAX_LINES lines, remove extra data blocks |
|
552 if (widget.getLineCount() > MAX_LINES) { |
|
553 removeDataBlocks(max); |
|
554 } // no else |
|
555 } |
|
556 |
|
557 // Clear variables and selection |
|
558 newData.setLength(0); |
|
559 numberOfNewTraces = 0; |
|
560 offsetsOfNewTraces.clear(); |
|
561 SelectionProperties.clear(); |
|
562 |
|
563 // Set the top index and caret to the end of the document |
|
564 viewer.setTopIndex(max - slider.getThumb()); |
|
565 widget.setCaretOffset(widget.getCharCount()); |
|
566 } |
|
567 |
|
568 /** |
|
569 * Removes extra data blocks |
|
570 * |
|
571 * @param max |
|
572 * number of lines alltogether |
|
573 */ |
|
574 private void removeDataBlocks(int max) { |
|
575 // Get amount of full blocks |
|
576 int fullBlocks = widget.getLineCount() / TraceViewerGlobals.blockSize; |
|
577 |
|
578 // Showing traces is starting point of total number of blocks - |
|
579 // 1 |
|
580 showingTracesFrom = (((max + 1) / TraceViewerGlobals.blockSize) - 1) |
|
581 * TraceViewerGlobals.blockSize; |
|
582 |
|
583 // Delete data from beginning of the widget |
|
584 int line = ((fullBlocks - 1) * TraceViewerGlobals.blockSize); |
|
585 int replaceTo = widget.getOffsetAtLine(line); |
|
586 widget.replaceTextRange(0, replaceTo, ""); //$NON-NLS-1$ |
|
587 } |
|
588 |
|
589 /** |
|
590 * Sets slider properties |
|
591 * |
|
592 * @param max |
|
593 * max value |
|
594 */ |
|
595 private void setSliderProperties(int max) { |
|
596 // Set Slider properties |
|
597 slider.setEnabled(max > 0); |
|
598 slider.setMaximum(max); |
|
599 slider.setSelection(max); |
|
600 slider.setThumb(getNumberOfLinesInView()); |
|
601 } |
|
602 |
|
603 /** |
|
604 * Color traces |
|
605 */ |
|
606 private void colorTraces() { |
|
607 // If coloring, color lines |
|
608 if (TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
609 .getColorer().isColoring()) { |
|
610 TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
611 .getColorer().createColorRules(); |
|
612 } |
|
613 } |
|
614 |
|
615 /** |
|
616 * Adds traces before current data |
|
617 * |
|
618 * @param traceToBeShown |
|
619 * trace to be shown |
|
620 * @param numberOfBlocks |
|
621 * number of block |
|
622 */ |
|
623 private void insertBeforeCurrentView(int numberOfBlocks, int traceToBeShown) { |
|
624 |
|
625 widget.setRedraw(false); |
|
626 // Save the caret position |
|
627 int caretPos = widget.getLineAtOffset(widget.getCaretOffset()); |
|
628 |
|
629 // Save the old data |
|
630 String oldData = getOldData(true, numberOfBlocks); |
|
631 |
|
632 // Append the old data after the new data |
|
633 if (!oldData.equals("")) { //$NON-NLS-1$ |
|
634 scrolledData.append(oldData); |
|
635 } |
|
636 |
|
637 // Set the new data to widget |
|
638 widget.setText(scrolledData.toString()); |
|
639 |
|
640 // Update showing traces variable |
|
641 showingTracesFrom = (traceToBeShown / TraceViewerGlobals.blockSize) |
|
642 * TraceViewerGlobals.blockSize; |
|
643 |
|
644 // Set view properties |
|
645 updateViewPropertiesWhenInsertingBeforeCurrentData(caretPos, |
|
646 traceToBeShown); |
|
647 |
|
648 // Empty buffer |
|
649 scrolledData.setLength(0); |
|
650 colorTraces(); |
|
651 widget.setRedraw(true); |
|
652 widget.update(); |
|
653 } |
|
654 |
|
655 /** |
|
656 * Add traces after current data |
|
657 * |
|
658 * @param traceToBeShown |
|
659 * trace to be shown |
|
660 * @param numberOfBlocks |
|
661 * number of block |
|
662 */ |
|
663 private void insertAfterCurrentView(int numberOfBlocks, int traceToBeShown) { |
|
664 |
|
665 widget.setRedraw(false); |
|
666 // Save the old data |
|
667 String oldData = getOldData(false, numberOfBlocks); |
|
668 |
|
669 // Create new StringBuffer with old and new data in it |
|
670 StringBuffer data = new StringBuffer(oldData.length() |
|
671 + scrolledData.length()); |
|
672 data.append(oldData); |
|
673 data.append(scrolledData); |
|
674 |
|
675 // Set the new data |
|
676 widget.setText(data.toString()); |
|
677 |
|
678 // Update showingTracesFrom variable |
|
679 int fullBlocksInView = (traceToBeShown + getNumberOfLinesInView() + 1) |
|
680 / TraceViewerGlobals.blockSize; |
|
681 showingTracesFrom = (fullBlocksInView * TraceViewerGlobals.blockSize) |
|
682 - TraceViewerGlobals.blockSize; |
|
683 if (showingTracesFrom < 0) { |
|
684 showingTracesFrom = 0; |
|
685 } // no else |
|
686 |
|
687 // Set view properties |
|
688 updateViewPropertiesWhenInsertingAfterCurrentData(traceToBeShown); |
|
689 |
|
690 // Empty buffer |
|
691 scrolledData.setLength(0); |
|
692 colorTraces(); |
|
693 widget.setRedraw(true); |
|
694 widget.update(); |
|
695 } |
|
696 |
|
697 /** |
|
698 * Gets old data |
|
699 * |
|
700 * @param beforeCurrentData |
|
701 * getting data to before current view |
|
702 * @param numberOfBlocks |
|
703 * number of blocks to get |
|
704 * @return old data |
|
705 */ |
|
706 private String getOldData(boolean beforeCurrentData, int numberOfBlocks) { |
|
707 String oldData = ""; //$NON-NLS-1$ |
|
708 if (numberOfBlocks == 1) { |
|
709 // More thatn 1 block of data, needs to be cut |
|
710 if (widget.getLineCount() > TraceViewerGlobals.blockSize) { |
|
711 |
|
712 // Inserting before current view |
|
713 if (beforeCurrentData) { |
|
714 oldData = widget.getText(0, widget |
|
715 .getOffsetAtLine(TraceViewerGlobals.blockSize) - 1); |
|
716 |
|
717 // Inserting after current view |
|
718 } else if (!beforeCurrentData) { |
|
719 int offsetAtBlockStart = widget |
|
720 .getOffsetAtLine(TraceViewerGlobals.blockSize); |
|
721 oldData = widget.getTextRange(offsetAtBlockStart, widget |
|
722 .getOffsetAtLine(widget.getLineCount() - 1) |
|
723 - offsetAtBlockStart); |
|
724 } |
|
725 } else { |
|
726 oldData = widget.getText(); |
|
727 } |
|
728 } |
|
729 |
|
730 return oldData; |
|
731 } |
|
732 |
|
733 /** |
|
734 * Sets view properties when inserting before current data |
|
735 * |
|
736 * @param caretPos |
|
737 * old caret position |
|
738 * @param traceToBeShown |
|
739 * trace to be shown |
|
740 */ |
|
741 private void updateViewPropertiesWhenInsertingBeforeCurrentData( |
|
742 int caretPos, int traceToBeShown) { |
|
743 StateHolder.State state = TraceViewerGlobals.getTraceViewer() |
|
744 .getStateHolder().getState(); |
|
745 // Null check |
|
746 if (state == null) { |
|
747 TraceViewerGlobals.getTraceViewer().getStateHolder().setState( |
|
748 StateHolder.State.SCROLLING_WITH_SCROLLBAR); |
|
749 state = StateHolder.State.SCROLLING_WITH_SCROLLBAR; |
|
750 } |
|
751 switch (state) { |
|
752 // Set top index when scrolling with scrollbar |
|
753 case SCROLLING_WITH_SCROLLBAR: |
|
754 |
|
755 viewer.setTopIndex((traceToBeShown % TraceViewerGlobals.blockSize)); |
|
756 break; |
|
757 // Set top index and caret offset when scrolling with arrow keys |
|
758 case SCROLLING_WITH_ARROWS: |
|
759 viewer.setTopIndex((traceToBeShown % TraceViewerGlobals.blockSize)); |
|
760 if (caretPos + TraceViewerGlobals.blockSize - 1 < widget |
|
761 .getLineCount()) { |
|
762 widget.setCaretOffset(widget.getOffsetAtLine(caretPos |
|
763 + TraceViewerGlobals.blockSize - 1)); |
|
764 } |
|
765 break; |
|
766 // Set top index and selection when searching |
|
767 case SEARCHED: |
|
768 updateViewerPropertiesAfterSearch(); |
|
769 break; |
|
770 |
|
771 // Set top index and caret offset when scrolling with page up/down |
|
772 case SCROLLING_WITH_PAGEUPDOWN: |
|
773 int topIndex = traceToBeShown % TraceViewerGlobals.blockSize - 2; |
|
774 viewer.setTopIndex(topIndex); |
|
775 int caretLine = caretPos + TraceViewerGlobals.blockSize - 1; |
|
776 if (caretLine > 0 && widget.getLineCount() > 0) { |
|
777 if (caretLine > widget.getLineCount()) { |
|
778 caretLine = widget.getLineCount() - 1; |
|
779 } |
|
780 widget.setCaretOffset(widget.getOffsetAtLine(caretLine)); |
|
781 } |
|
782 |
|
783 break; |
|
784 default: |
|
785 break; |
|
786 } |
|
787 TraceViewerGlobals.getTraceViewer().getStateHolder().setState( |
|
788 StateHolder.State.NORMAL); |
|
789 setSelection(); |
|
790 } |
|
791 |
|
792 /** |
|
793 * Sets view properties when inserting after current data |
|
794 * |
|
795 * @param traceToBeShown |
|
796 * trace to be shown |
|
797 */ |
|
798 private void updateViewPropertiesWhenInsertingAfterCurrentData( |
|
799 int traceToBeShown) { |
|
800 StateHolder.State state = TraceViewerGlobals.getTraceViewer() |
|
801 .getStateHolder().getState(); |
|
802 |
|
803 // Null check |
|
804 if (state == null) { |
|
805 TraceViewerGlobals.getTraceViewer().getStateHolder().setState( |
|
806 StateHolder.State.SCROLLING_WITH_SCROLLBAR); |
|
807 state = StateHolder.State.SCROLLING_WITH_SCROLLBAR; |
|
808 } |
|
809 |
|
810 switch (state) { |
|
811 // Set top index when scrolling with scrollbar |
|
812 case SCROLLING_WITH_SCROLLBAR: |
|
813 viewer.setTopIndex(traceToBeShown - showingTracesFrom + 1); |
|
814 break; |
|
815 |
|
816 // Set top index and caret offset when scrolling with arrow keys |
|
817 case SCROLLING_WITH_ARROWS: |
|
818 viewer.setTopIndex(traceToBeShown - showingTracesFrom - 1); |
|
819 int line = traceToBeShown - showingTracesFrom |
|
820 + getNumberOfLinesInView(); |
|
821 if (line <= widget.getLineCount() && line >= 0) { |
|
822 widget.setCaretOffset(widget.getOffsetAtLine(line)); |
|
823 } |
|
824 break; |
|
825 // Set top index and selection when searching |
|
826 case SEARCHED: |
|
827 updateViewerPropertiesAfterSearch(); |
|
828 break; |
|
829 |
|
830 // Set top index and caret offset when scrolling with page up/down |
|
831 case SCROLLING_WITH_PAGEUPDOWN: |
|
832 viewer.setTopIndex(traceToBeShown - showingTracesFrom + 1); |
|
833 int topLine = traceToBeShown - showingTracesFrom |
|
834 + getNumberOfLinesInView() - 1; |
|
835 if (topLine < widget.getLineCount()) { |
|
836 int caretOffset = widget.getOffsetAtLine(traceToBeShown |
|
837 - showingTracesFrom + getNumberOfLinesInView() - 1); |
|
838 if (caretOffset >= 0 && caretOffset < widget.getCharCount()) { |
|
839 widget.setCaretOffset(caretOffset); |
|
840 } |
|
841 } else { |
|
842 widget.setCaretOffset(widget.getCharCount() - 1); |
|
843 } |
|
844 break; |
|
845 // Unknown case, set basic top index |
|
846 case NORMAL: |
|
847 viewer.setTopIndex(traceToBeShown |
|
848 - TraceViewerGlobals.getTraceViewer().getView() |
|
849 .getShowingTracesFrom()); |
|
850 break; |
|
851 default: |
|
852 break; |
|
853 } |
|
854 |
|
855 TraceViewerGlobals.getTraceViewer().getStateHolder().setState( |
|
856 StateHolder.State.NORMAL); |
|
857 setSelection(); |
|
858 } |
|
859 |
|
860 /** |
|
861 * Sets selection to viewer |
|
862 */ |
|
863 public void setSelection() { |
|
864 if (SelectionProperties.lastClickedLine != -1) { |
|
865 |
|
866 // Calculate start offset |
|
867 int startOffset = 0; |
|
868 |
|
869 // If clicked from the totally first line |
|
870 if (SelectionProperties.firstClickedLine < showingTracesFrom) { |
|
871 startOffset = 0; |
|
872 |
|
873 // If clicked in the totally last line |
|
874 } else if (SelectionProperties.firstClickedLine > showingTracesFrom |
|
875 + widget.getLineCount()) { |
|
876 startOffset = widget.getCharCount() - 1; |
|
877 |
|
878 // Clicked between the first and last line in the viewer |
|
879 } else { |
|
880 int lineNumber = SelectionProperties.firstClickedLine |
|
881 - showingTracesFrom; |
|
882 if (lineNumber < widget.getLineCount()) { |
|
883 startOffset = widget.getOffsetAtLine(lineNumber) |
|
884 + SelectionProperties.firstClickedLineCaretOffset; |
|
885 } |
|
886 } |
|
887 |
|
888 // Calculate end offset |
|
889 int endOffset = 0; |
|
890 |
|
891 // If clicked from the totally first line |
|
892 if (SelectionProperties.lastClickedLine < showingTracesFrom) { |
|
893 endOffset = 0; |
|
894 |
|
895 // If clicked in the totally last line |
|
896 } else if (SelectionProperties.lastClickedLine >= showingTracesFrom |
|
897 + widget.getLineCount()) { |
|
898 endOffset = widget.getCharCount() - 1; |
|
899 |
|
900 // Clicked between the first and last line in the viewer |
|
901 } else { |
|
902 int lineNumber = SelectionProperties.lastClickedLine |
|
903 - showingTracesFrom; |
|
904 if (lineNumber < widget.getLineCount()) { |
|
905 endOffset = widget.getOffsetAtLine(lineNumber) |
|
906 + SelectionProperties.lastClickedLineCaretOffset; |
|
907 } |
|
908 } |
|
909 |
|
910 // Save current top index |
|
911 int topIndex = viewer.getTopIndex(); |
|
912 |
|
913 // Set the selection to the viewer |
|
914 widget.setSelection(startOffset, endOffset); |
|
915 |
|
916 // Return old top index |
|
917 viewer.setTopIndex(topIndex); |
|
918 |
|
919 // Put caret to the end |
|
920 } else if (SelectionProperties.putCaretToTheEnd) { |
|
921 SelectionProperties.putCaretToTheEnd = false; |
|
922 widget.setCaretOffset(widget.getCharCount()); |
|
923 } |
|
924 |
|
925 // Update trim |
|
926 ViewerSelectionChangedListener.handleTrimInformationUpdate(); |
|
927 } |
|
928 |
|
929 /** |
|
930 * Updates top index and selection after searching |
|
931 */ |
|
932 private void updateViewerPropertiesAfterSearch() { |
|
933 int selIndex = startHighlightLine - showingTracesFrom; |
|
934 int topIndex = selIndex - LINES_TO_LEAVE_BEFORE_FOUND_LINE; |
|
935 |
|
936 if (topIndex < 0) { |
|
937 topIndex = 0; |
|
938 } |
|
939 viewer.setTopIndex(topIndex); |
|
940 |
|
941 // Remove possible old selection values from the Selection Properties |
|
942 SelectionProperties.clear(); |
|
943 |
|
944 // Select range of traces |
|
945 if (endHighlightLine != 0) { |
|
946 SelectionProperties.firstClickedLine = startHighlightLine; |
|
947 SelectionProperties.lastClickedLine = endHighlightLine + 1; |
|
948 |
|
949 } else { |
|
950 |
|
951 // Select one line |
|
952 if (topIndex < widget.getLineCount() |
|
953 && (selIndex + 1 < widget.getLineCount())) { |
|
954 widget.setSelection(widget.getOffsetAtLine(selIndex), widget |
|
955 .getOffsetAtLine(selIndex + 1) - 1); |
|
956 } |
|
957 } |
|
958 |
|
959 // Enable search button from search dialog |
|
960 SearchDialog searchDialog = TraceViewerGlobals.getTraceViewer() |
|
961 .getDataProcessorAccess().getSearchProcessor() |
|
962 .getSearchDialog(); |
|
963 if (searchDialog != null && searchDialog.isOpen()) { |
|
964 searchDialog.enableSearchButton(); |
|
965 } |
|
966 TraceViewerGlobals.getTraceViewer().getStateHolder().setState( |
|
967 StateHolder.State.NORMAL); |
|
968 |
|
969 } |
|
970 |
|
971 /* |
|
972 * (non-Javadoc) |
|
973 * |
|
974 * @see org.eclipse.ui.IWorkbenchPart#setFocus() |
|
975 */ |
|
976 @Override |
|
977 public void setFocus() { |
|
978 viewer.getControl().setFocus(); |
|
979 } |
|
980 |
|
981 /* |
|
982 * (non-Javadoc) |
|
983 * |
|
984 * @see org.eclipse.ui.part.WorkbenchPart#dispose() |
|
985 */ |
|
986 @Override |
|
987 public void dispose() { |
|
988 super.dispose(); |
|
989 TraceViewerGlobals.getTraceViewer().shutdown(); |
|
990 } |
|
991 |
|
992 /** |
|
993 * Gets shell |
|
994 * |
|
995 * @return shell from the text viewer |
|
996 */ |
|
997 private Shell getShell() { |
|
998 Shell shell = null; |
|
999 if (viewer != null && viewer.getControl() != null |
|
1000 && viewer.getControl().getShell() != null |
|
1001 && !viewer.getControl().getShell().isDisposed()) { |
|
1002 shell = viewer.getControl().getShell(); |
|
1003 } |
|
1004 return shell; |
|
1005 } |
|
1006 |
|
1007 /* |
|
1008 * (non-Javadoc) |
|
1009 * |
|
1010 * @see |
|
1011 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#getViewer() |
|
1012 */ |
|
1013 public TextViewer getViewer() { |
|
1014 return viewer; |
|
1015 } |
|
1016 |
|
1017 /* |
|
1018 * (non-Javadoc) |
|
1019 * |
|
1020 * @seecom.nokia.traceviewer.engine.TraceViewerTraceViewInterface# |
|
1021 * getShowingTracesFrom() |
|
1022 */ |
|
1023 public int getShowingTracesFrom() { |
|
1024 return showingTracesFrom; |
|
1025 } |
|
1026 |
|
1027 /* |
|
1028 * (non-Javadoc) |
|
1029 * |
|
1030 * @see com.nokia.traceviewer.engine.DataProcessor# |
|
1031 * processData(com.nokia.traceviewer.engine.TraceProperties) |
|
1032 */ |
|
1033 public void processData(TraceProperties properties) { |
|
1034 TraceViewerGlobals.debug("processData in View", //$NON-NLS-1$ |
|
1035 TraceViewerGlobals.DebugLevel.TEST); |
|
1036 // Main if to check if trace is ok to show |
|
1037 if (!properties.traceConfiguration.isFilteredOut() |
|
1038 && properties.traceConfiguration.isShowInView() |
|
1039 && !properties.traceConfiguration.isTriggeredOut()) { |
|
1040 if (properties.traceConfiguration.isScrolledTrace()) { |
|
1041 processScrolledTrace(properties); |
|
1042 |
|
1043 // Empty new data if we are reading last block |
|
1044 if (insertingLastBlock && properties.lastTrace) { |
|
1045 newData.setLength(0); |
|
1046 insertingLastBlock = false; |
|
1047 } |
|
1048 } else if (viewUpdateOn) { |
|
1049 processNormalTrace(properties); |
|
1050 } |
|
1051 } |
|
1052 } |
|
1053 |
|
1054 /** |
|
1055 * Process normal trace |
|
1056 * |
|
1057 * @param properties |
|
1058 * trace properties |
|
1059 */ |
|
1060 private void processNormalTrace(TraceProperties properties) { |
|
1061 numberOfNewTraces++; |
|
1062 // Traces missing |
|
1063 if (properties.bTraceInformation.isTraceMissing()) { |
|
1064 newData.append(TraceViewerActionUtils.TRACES_DROPPED_MSG); |
|
1065 } |
|
1066 |
|
1067 // Append timestamp to StringBuffer |
|
1068 if (properties.timestampString != null) { |
|
1069 newData.append(properties.timestampString); |
|
1070 newData |
|
1071 .append(TraceViewerGlobals.getTraceViewer() |
|
1072 .getDataProcessorAccess().getTimestampParser() |
|
1073 .getTimeFromPreviousString( |
|
1074 properties.timeFromPreviousTrace)); |
|
1075 newData.append('\t'); |
|
1076 } |
|
1077 if (!properties.binaryTrace) { |
|
1078 newData.append(properties.traceString); |
|
1079 if (properties.traceComment != null) { |
|
1080 newData.append(TraceViewerActionUtils.COMMENT_PREFIX); |
|
1081 newData.append(properties.traceComment); |
|
1082 } |
|
1083 |
|
1084 // Binary trace |
|
1085 } else { |
|
1086 addBinaryTraceToBuffer(properties, newData); |
|
1087 } |
|
1088 |
|
1089 newData.append('\n'); |
|
1090 // Add offset of every new block to array so we know where to |
|
1091 // cut the StringBuffer |
|
1092 if (numberOfNewTraces % TraceViewerGlobals.blockSize == 1 |
|
1093 && numberOfNewTraces != 1) { |
|
1094 offsetsOfNewTraces.add(Integer.valueOf(newData.length())); |
|
1095 } |
|
1096 long time = System.currentTimeMillis(); |
|
1097 // If update interval has passed, call the view update |
|
1098 if (time > updateNextTime) { |
|
1099 updateNextTime = time + UPDATE_INTERVAL; |
|
1100 update(); |
|
1101 } |
|
1102 } |
|
1103 |
|
1104 /** |
|
1105 * Process scrolled trace |
|
1106 * |
|
1107 * @param properties |
|
1108 * trace properties |
|
1109 */ |
|
1110 private void processScrolledTrace(TraceProperties properties) { |
|
1111 // Traces missing |
|
1112 if (properties.bTraceInformation.isTraceMissing()) { |
|
1113 scrolledData.append(TraceViewerActionUtils.TRACES_DROPPED_MSG); |
|
1114 } |
|
1115 |
|
1116 // Append timestamp to StringBuffer |
|
1117 if (properties.timestampString != null) { |
|
1118 scrolledData.append(properties.timestampString); |
|
1119 scrolledData |
|
1120 .append(TraceViewerGlobals.getTraceViewer() |
|
1121 .getDataProcessorAccess().getTimestampParser() |
|
1122 .getTimeFromPreviousString( |
|
1123 properties.timeFromPreviousTrace)); |
|
1124 scrolledData.append('\t'); |
|
1125 } |
|
1126 if (!properties.binaryTrace) { |
|
1127 scrolledData.append(properties.traceString); |
|
1128 |
|
1129 if (properties.traceComment != null) { |
|
1130 scrolledData.append(TraceViewerActionUtils.COMMENT_PREFIX); |
|
1131 scrolledData.append(properties.traceComment); |
|
1132 } |
|
1133 |
|
1134 // Binary trace |
|
1135 } else { |
|
1136 addBinaryTraceToBuffer(properties, scrolledData); |
|
1137 } |
|
1138 scrolledData.append('\n'); |
|
1139 } |
|
1140 |
|
1141 /** |
|
1142 * Adds binary traces to buffer |
|
1143 * |
|
1144 * @param properties |
|
1145 * trace properties |
|
1146 * @param dataBuf |
|
1147 * data buffer to add the trace to |
|
1148 */ |
|
1149 private void addBinaryTraceToBuffer(TraceProperties properties, |
|
1150 StringBuffer dataBuf) { |
|
1151 |
|
1152 // Get the selected value |
|
1153 String type = TraceViewerPlugin.getDefault().getPreferenceStore() |
|
1154 .getString(PreferenceConstants.SHOW_UNDECODED_TRACES_TYPE); |
|
1155 |
|
1156 // Show binary trace info message |
|
1157 if (type.equals(PreferenceConstants.UNDECODED_INFO_TEXT)) { |
|
1158 String binMsg = Messages |
|
1159 .getString("TraceViewerView.BinaryTraceInformationMessage"); //$NON-NLS-1$); |
|
1160 dataBuf.append(binMsg); |
|
1161 |
|
1162 // Show binary traces as hex |
|
1163 } else if (type.equals(PreferenceConstants.UNDECODED_HEX)) { |
|
1164 |
|
1165 // Read the message to a byte array |
|
1166 String hexTrace = TraceViewerUtils.getTraceAsHexString( |
|
1167 properties.byteBuffer, properties.messageStart, |
|
1168 properties.messageLength, true); |
|
1169 dataBuf.append(hexTrace); |
|
1170 |
|
1171 // Show binary trace as ID and data |
|
1172 } else if (type.equals(PreferenceConstants.UNDECODED_ID_AND_DATA)) { |
|
1173 dataBuf.append(Messages |
|
1174 .getString("TraceViewerView.BinaryTraceText")); //$NON-NLS-1$ |
|
1175 dataBuf.append(Messages.getString("TraceViewerView.ComponentID")); //$NON-NLS-1$ |
|
1176 dataBuf.append(HEX_PREFIX); |
|
1177 dataBuf.append(Integer.toHexString(properties.information |
|
1178 .getComponentId())); |
|
1179 dataBuf.append(Messages.getString("TraceViewerView.GroupID")); //$NON-NLS-1$ |
|
1180 dataBuf.append(HEX_PREFIX); |
|
1181 dataBuf.append(Integer.toHexString(properties.information |
|
1182 .getGroupId())); |
|
1183 dataBuf.append(Messages.getString("TraceViewerView.TraceID")); //$NON-NLS-1$ |
|
1184 dataBuf.append(properties.information.getTraceId()); |
|
1185 dataBuf.append(Messages.getString("TraceViewerView.DataString")); //$NON-NLS-1$ |
|
1186 |
|
1187 // Read the message to a byte array |
|
1188 String hexTrace = TraceViewerUtils.getTraceAsHexString( |
|
1189 properties.byteBuffer, properties.dataStart, |
|
1190 properties.dataLength, true); |
|
1191 dataBuf.append(hexTrace); |
|
1192 |
|
1193 if (properties.traceComment != null) { |
|
1194 dataBuf.append(TraceViewerActionUtils.COMMENT_PREFIX); |
|
1195 dataBuf.append(properties.traceComment); |
|
1196 } |
|
1197 } |
|
1198 } |
|
1199 |
|
1200 /** |
|
1201 * Returns number of lines in view |
|
1202 * |
|
1203 * @return number of lines in view |
|
1204 */ |
|
1205 public int getNumberOfLinesInView() { |
|
1206 return viewer.getBottomIndex() - viewer.getTopIndex(); |
|
1207 } |
|
1208 |
|
1209 /* |
|
1210 * (non-Javadoc) |
|
1211 * |
|
1212 * @see com.nokia.traceviewer.engine.TraceViewerViewInterface#clearAll() |
|
1213 */ |
|
1214 public void clearAll() { |
|
1215 // Sync with UI thread |
|
1216 if (viewer != null && viewer.getControl() != null |
|
1217 && viewer.getControl().getDisplay() != null) { |
|
1218 |
|
1219 viewer.getControl().getDisplay().syncExec(new Runnable() { |
|
1220 |
|
1221 public void run() { |
|
1222 // Remove text from textviewer and disable slider |
|
1223 if (!widget.isDisposed()) { |
|
1224 widget.setText(""); //$NON-NLS-1$ |
|
1225 } |
|
1226 if (!slider.isDisposed()) { |
|
1227 slider.setEnabled(false); |
|
1228 } |
|
1229 |
|
1230 // Clear all arrays |
|
1231 newData.setLength(0); |
|
1232 scrolledData.setLength(0); |
|
1233 showingTracesFrom = 0; |
|
1234 offsetsOfNewTraces.clear(); |
|
1235 |
|
1236 // Empty the trim text |
|
1237 TraceViewerGlobals.getTrimProvider().updateText(""); //$NON-NLS-1$ |
|
1238 } |
|
1239 }); |
|
1240 } |
|
1241 |
|
1242 } |
|
1243 |
|
1244 /* |
|
1245 * (non-Javadoc) |
|
1246 * |
|
1247 * @see |
|
1248 * com.nokia.traceviewer.engine.TraceViewerViewInterface#hasUnshownData() |
|
1249 */ |
|
1250 public boolean hasUnshownData() { |
|
1251 return (newData.length() > 0); |
|
1252 } |
|
1253 |
|
1254 /* |
|
1255 * (non-Javadoc) |
|
1256 * |
|
1257 * @see com.nokia.traceviewer.engine.TraceViewerViewInterface#update() |
|
1258 */ |
|
1259 public void update() { |
|
1260 update(this); |
|
1261 } |
|
1262 |
|
1263 /** |
|
1264 * Calls syncExec with some Runnable |
|
1265 * |
|
1266 * @param r |
|
1267 * runnable object |
|
1268 */ |
|
1269 public void update(Runnable r) { |
|
1270 Control control = viewer.getControl(); |
|
1271 if ((control != null) && !(control.isDisposed())) { |
|
1272 control.getDisplay().syncExec(r); |
|
1273 } |
|
1274 } |
|
1275 |
|
1276 /* |
|
1277 * (non-Javadoc) |
|
1278 * |
|
1279 * @see |
|
1280 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#highlightLines |
|
1281 * (int, int, boolean) |
|
1282 */ |
|
1283 public void highlightLines(int startLine, int endLine, boolean syncToSource) { |
|
1284 this.startHighlightLine = startLine; |
|
1285 this.endHighlightLine = endLine; |
|
1286 TraceViewerGlobals.getTraceViewer().getStateHolder().setState( |
|
1287 StateHolder.State.SEARCHED); |
|
1288 update(); |
|
1289 |
|
1290 // Sync to source |
|
1291 if (syncToSource) { |
|
1292 viewer.getControl().getDisplay().asyncExec(new Runnable() { |
|
1293 public void run() { |
|
1294 |
|
1295 // Jump to selected trace source |
|
1296 jumpToSelectedTraceSource(); |
|
1297 } |
|
1298 }); |
|
1299 } |
|
1300 } |
|
1301 |
|
1302 /** |
|
1303 * Jumps to selected traces source if needed metadata exists |
|
1304 */ |
|
1305 private void jumpToSelectedTraceSource() { |
|
1306 // Get clicked line number |
|
1307 int clickedLine = widget.getLineAtOffset(widget.getSelectionRange().x) |
|
1308 + TraceViewerGlobals.getTraceViewer().getView() |
|
1309 .getShowingTracesFrom(); |
|
1310 |
|
1311 // Get the trace from the file |
|
1312 List<TraceProperties> traceList = TraceViewerGlobals.getTraceViewer() |
|
1313 .getTraces(clickedLine, clickedLine); |
|
1314 |
|
1315 TraceProperties trace = null; |
|
1316 if (traceList != null && !traceList.isEmpty()) { |
|
1317 trace = traceList.get(0); |
|
1318 } |
|
1319 |
|
1320 OpenTraceLocationAction openLocationAction = (OpenTraceLocationAction) actionFactory |
|
1321 .getOpenTraceLocationAction(); |
|
1322 |
|
1323 // If traceInformation is found, run open location action |
|
1324 if (trace != null && trace.information != null) { |
|
1325 TraceMetaData metaData = TraceViewerGlobals.getDecodeProvider() |
|
1326 .getTraceMetaData(trace.information); |
|
1327 if (metaData != null && metaData.getPath() != null) { |
|
1328 openLocationAction.setMetaData(metaData, false); |
|
1329 openLocationAction.run(); |
|
1330 } |
|
1331 } |
|
1332 } |
|
1333 |
|
1334 /* |
|
1335 * (non-Javadoc) |
|
1336 * |
|
1337 * @see |
|
1338 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#scrollViewToLine |
|
1339 * (int) |
|
1340 */ |
|
1341 public void scrollViewToLine(int lineNumber) { |
|
1342 if (!TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
1343 .getTriggerProcessor().isStartTriggering()) { |
|
1344 |
|
1345 // Save trace to be shown |
|
1346 int traceToBeShown = lineNumber; |
|
1347 |
|
1348 int topIndex = viewer.getTopIndex(); |
|
1349 int bottomIndex = viewer.getBottomIndex(); |
|
1350 |
|
1351 // If we need more traces to start of the view |
|
1352 if (traceToBeShown < showingTracesFrom) { |
|
1353 getMoreTracesBeforeCurrentData(traceToBeShown); |
|
1354 |
|
1355 // More trace to end of the view |
|
1356 } else if (traceToBeShown + getNumberOfLinesInView() + 2 > showingTracesFrom |
|
1357 + widget.getLineCount() |
|
1358 && TraceViewerGlobals.getTraceViewer() |
|
1359 .getDataReaderAccess().getCurrentDataReader() != null |
|
1360 && (showingTracesFrom + TraceViewerGlobals.blockSize * 2 < TraceViewerGlobals |
|
1361 .getTraceViewer().getDataReaderAccess() |
|
1362 .getCurrentDataReader().getTraceCount())) { |
|
1363 |
|
1364 getMoreTracesAfterCurrentData(traceToBeShown, bottomIndex); |
|
1365 |
|
1366 // If the trace to be shown value is different to real value |
|
1367 // shown in screen or we need to highlight search result |
|
1368 } else if ((slider.getSelection() < topIndex + showingTracesFrom |
|
1369 - 1 || slider.getSelection() > bottomIndex |
|
1370 + showingTracesFrom) |
|
1371 || TraceViewerGlobals.getTraceViewer().getStateHolder() |
|
1372 .getState() == StateHolder.State.SEARCHED) { |
|
1373 moveViewAccordingToSlider(); |
|
1374 } else { |
|
1375 TraceViewerGlobals.getTraceViewer().getStateHolder().setState( |
|
1376 StateHolder.State.NORMAL); |
|
1377 } |
|
1378 } |
|
1379 } |
|
1380 |
|
1381 /** |
|
1382 * Moves view according to slider position and highlight found text if |
|
1383 * searching |
|
1384 */ |
|
1385 private void moveViewAccordingToSlider() { |
|
1386 // If this is because of searching |
|
1387 if (TraceViewerGlobals.getTraceViewer().getStateHolder().getState() == StateHolder.State.SEARCHED) { |
|
1388 updateViewerPropertiesAfterSearch(); |
|
1389 setSelection(); |
|
1390 } else { |
|
1391 viewer.setTopIndex(slider.getSelection() - showingTracesFrom); |
|
1392 } |
|
1393 } |
|
1394 |
|
1395 /** |
|
1396 * Get more traces after the current data |
|
1397 * |
|
1398 * @param traceToBeShown |
|
1399 * trace to be shown |
|
1400 * @param bottomIndex |
|
1401 * bottom index value |
|
1402 */ |
|
1403 private void getMoreTracesAfterCurrentData(int traceToBeShown, |
|
1404 int bottomIndex) { |
|
1405 |
|
1406 int numberOfBlocks; |
|
1407 int offset; |
|
1408 |
|
1409 TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
1410 .getTimestampParser().nullPreviousTimestamp(); |
|
1411 |
|
1412 // If we need only one block |
|
1413 if (traceToBeShown < showingTracesFrom + bottomIndex |
|
1414 + TraceViewerGlobals.blockSize) { |
|
1415 numberOfBlocks = 1; |
|
1416 offset = traceToBeShown + getNumberOfLinesInView() + 2; |
|
1417 } else { |
|
1418 numberOfBlocks = 2; |
|
1419 offset = traceToBeShown + getNumberOfLinesInView() |
|
1420 - TraceViewerGlobals.blockSize + 1; |
|
1421 } |
|
1422 |
|
1423 // Check if we are getting the last block from the file |
|
1424 if (offset + (TraceViewerGlobals.blockSize * numberOfBlocks) > TraceViewerGlobals |
|
1425 .getTraceViewer().getDataReaderAccess().getCurrentDataReader() |
|
1426 .getTraceCount()) { |
|
1427 insertingLastBlock = true; |
|
1428 } else { |
|
1429 insertingLastBlock = false; |
|
1430 } |
|
1431 |
|
1432 // Start scroll reader |
|
1433 TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
1434 .startScrollReader(offset, numberOfBlocks); |
|
1435 |
|
1436 // Insert after current view |
|
1437 insertAfterCurrentView(numberOfBlocks, traceToBeShown); |
|
1438 } |
|
1439 |
|
1440 /** |
|
1441 * Get more traces before the current data |
|
1442 * |
|
1443 * @param traceToBeShown |
|
1444 * trace to be shown |
|
1445 */ |
|
1446 private void getMoreTracesBeforeCurrentData(int traceToBeShown) { |
|
1447 int numberOfBlocks; |
|
1448 TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
1449 .getTimestampParser().nullPreviousTimestamp(); |
|
1450 // If we need only one block |
|
1451 if (traceToBeShown + TraceViewerGlobals.blockSize > showingTracesFrom) { |
|
1452 numberOfBlocks = 1; |
|
1453 } else { |
|
1454 numberOfBlocks = 2; |
|
1455 } |
|
1456 |
|
1457 TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
1458 .startScrollReader(traceToBeShown, numberOfBlocks); |
|
1459 |
|
1460 // Insert before current view |
|
1461 insertBeforeCurrentView(numberOfBlocks, traceToBeShown); |
|
1462 } |
|
1463 |
|
1464 /* |
|
1465 * (non-Javadoc) |
|
1466 * |
|
1467 * @see |
|
1468 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#closeProgressBar |
|
1469 * (com.nokia.traceviewer.dialog.ProgressBarDialog) |
|
1470 */ |
|
1471 public void closeProgressBar(ProgressBarDialog dialog) { |
|
1472 update(new ProcessProgressBarUpdater(dialog)); |
|
1473 } |
|
1474 |
|
1475 /* |
|
1476 * (non-Javadoc) |
|
1477 * |
|
1478 * @see |
|
1479 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#applyColorRules |
|
1480 * (org.eclipse.swt.custom.StyleRange[]) |
|
1481 */ |
|
1482 public void applyColorRules(StyleRange[] ranges) { |
|
1483 update(new ColorRuleUpdater(ranges)); |
|
1484 |
|
1485 } |
|
1486 |
|
1487 /* |
|
1488 * (non-Javadoc) |
|
1489 * |
|
1490 * @see |
|
1491 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#updateViewName |
|
1492 * () |
|
1493 */ |
|
1494 public void updateViewName() { |
|
1495 updateViewName = true; |
|
1496 update(); |
|
1497 } |
|
1498 |
|
1499 /** |
|
1500 * Update the name of the view |
|
1501 */ |
|
1502 private void generateAndSetViewName() { |
|
1503 StringBuilder viewName = new StringBuilder(VIEWNAME_NORMAL); |
|
1504 |
|
1505 // Triggering |
|
1506 if (TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
1507 .getTriggerProcessor().isTriggering()) { |
|
1508 |
|
1509 // Trigger is armed |
|
1510 if (TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
1511 .getTriggerProcessor().isStartTriggering()) { |
|
1512 viewName.append(VIEWNAME_ARMED); |
|
1513 } else if (TraceViewerGlobals.getTraceViewer() |
|
1514 .getDataProcessorAccess().getTriggerProcessor() |
|
1515 .isStopTriggering()) { |
|
1516 viewName.append(VIEWNAME_STORING); |
|
1517 } |
|
1518 |
|
1519 } |
|
1520 // Paused |
|
1521 if (TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
1522 .getMainDataReader().isPaused()) { |
|
1523 viewName.append(VIEWNAME_PAUSED); |
|
1524 } |
|
1525 // Filtered |
|
1526 if (TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
1527 .getFilterProcessor().isFiltering()) { |
|
1528 viewName.append(VIEWNAME_FILTERED); |
|
1529 } |
|
1530 |
|
1531 // Log file opened |
|
1532 if (TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
1533 .getLogger().isLogFileOpened()) { |
|
1534 String logFilePath = TraceViewerGlobals.getTraceViewer() |
|
1535 .getDataProcessorAccess().getLogger() |
|
1536 .getOpenedLogFileName(); |
|
1537 viewName.append(LOG_FILE_NAME_SEPARATOR); |
|
1538 viewName.append(logFilePath); |
|
1539 } |
|
1540 |
|
1541 this.setPartName(viewName.toString()); |
|
1542 updateViewName = false; |
|
1543 } |
|
1544 |
|
1545 /* |
|
1546 * (non-Javadoc) |
|
1547 * |
|
1548 * @see com.nokia.traceviewer.engine.TraceViewerViewInterface#isDisposed() |
|
1549 */ |
|
1550 public boolean isDisposed() { |
|
1551 boolean disposed = false; |
|
1552 Shell shell = getShell(); |
|
1553 if (shell == null || shell.isDisposed()) { |
|
1554 disposed = true; |
|
1555 } |
|
1556 return disposed; |
|
1557 } |
|
1558 |
|
1559 /* |
|
1560 * (non-Javadoc) |
|
1561 * |
|
1562 * @see |
|
1563 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#stopViewUpdate |
|
1564 * (boolean) |
|
1565 */ |
|
1566 public void stopViewUpdate(boolean stop) { |
|
1567 viewUpdateOn = !stop; |
|
1568 |
|
1569 // If view should be refreshed |
|
1570 if (!stop) { |
|
1571 |
|
1572 // Sync with UI thread |
|
1573 viewer.getControl().getDisplay().asyncExec(new Runnable() { |
|
1574 |
|
1575 public void run() { |
|
1576 refreshTraceBlock(TraceViewerGlobals.getTraceViewer() |
|
1577 .getDataReaderAccess().getCurrentDataReader() |
|
1578 .getTraceCount()); |
|
1579 } |
|
1580 }); |
|
1581 } |
|
1582 } |
|
1583 |
|
1584 /* |
|
1585 * (non-Javadoc) |
|
1586 * |
|
1587 * @see |
|
1588 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#refreshCurrentView |
|
1589 * () |
|
1590 */ |
|
1591 public void refreshCurrentView() { |
|
1592 // Sync with UI thread |
|
1593 viewer.getControl().getDisplay().asyncExec(new Runnable() { |
|
1594 |
|
1595 public void run() { |
|
1596 refreshTraceBlock(slider.getSelection()); |
|
1597 } |
|
1598 }); |
|
1599 } |
|
1600 |
|
1601 /** |
|
1602 * Find the trace block containing given trace and refreshes it. When coming |
|
1603 * here, we should be in UI thread |
|
1604 * |
|
1605 * @param traceNumber |
|
1606 * the trace number |
|
1607 */ |
|
1608 private void refreshTraceBlock(final int traceNumber) { |
|
1609 // Set "showing traces from" variable to totally wrong and |
|
1610 // then generate a request to get last block of traces |
|
1611 showingTracesFrom = 0 - TraceViewerGlobals.blockSize * 5; |
|
1612 scrollViewToLine(traceNumber); |
|
1613 |
|
1614 } |
|
1615 |
|
1616 /* |
|
1617 * (non-Javadoc) |
|
1618 * |
|
1619 * @see |
|
1620 * com.nokia.traceviewer.engine.TraceViewerTraceViewInterface#setFontSize |
|
1621 * (int) |
|
1622 */ |
|
1623 public void setFontSize(final int size) { |
|
1624 if (widget != null && !widget.isDisposed()) { |
|
1625 // Sync with UI thread |
|
1626 viewer.getControl().getDisplay().syncExec(new Runnable() { |
|
1627 |
|
1628 public void run() { |
|
1629 // Set the font |
|
1630 Font font = new Font(viewer.getControl().getDisplay(), |
|
1631 new FontData(FONT, size, SWT.NORMAL)); |
|
1632 widget.setFont(font); |
|
1633 } |
|
1634 }); |
|
1635 } |
|
1636 } |
|
1637 |
|
1638 /* |
|
1639 * (non-Javadoc) |
|
1640 * |
|
1641 * @see |
|
1642 * com.nokia.traceviewer.engine.TraceViewerDialogInterface#showErrorMessage |
|
1643 * (java.lang.String) |
|
1644 */ |
|
1645 public void showErrorMessage(String error) { |
|
1646 MessageDialog.openError(getShell(), TRACE_VIEWER_TITLE, error); |
|
1647 } |
|
1648 |
|
1649 /* |
|
1650 * (non-Javadoc) |
|
1651 * |
|
1652 * @seecom.nokia.traceviewer.engine.TraceViewerDialogInterface# |
|
1653 * showConfirmationDialog(java.lang.String) |
|
1654 */ |
|
1655 public boolean showConfirmationDialog(String message) { |
|
1656 boolean ok = MessageDialog.openConfirm(getShell(), TRACE_VIEWER_TITLE, |
|
1657 message); |
|
1658 return ok; |
|
1659 } |
|
1660 |
|
1661 /* |
|
1662 * (non-Javadoc) |
|
1663 * |
|
1664 * @seecom.nokia.traceviewer.engine.TraceViewerDialogInterface# |
|
1665 * showInformationMessage(java.lang.String) |
|
1666 */ |
|
1667 public void showInformationMessage(String message) { |
|
1668 MessageDialog.openInformation(getShell(), TRACE_VIEWER_TITLE, message); |
|
1669 } |
|
1670 |
|
1671 /* |
|
1672 * (non-Javadoc) |
|
1673 * |
|
1674 * @see |
|
1675 * com.nokia.traceviewer.engine.TraceViewerDialogInterface#openPreferencePage |
|
1676 * ( |
|
1677 * com.nokia.traceviewer.engine.TraceViewerDialogInterface.TVPreferencePage) |
|
1678 */ |
|
1679 public boolean openPreferencePage(TVPreferencePage TVpage) { |
|
1680 boolean ret = false; |
|
1681 PreferenceManager mgr = new PreferenceManager(); |
|
1682 |
|
1683 // Create general preference page |
|
1684 IPreferencePage generalPage = new TraceViewerPreferencesPage(); |
|
1685 generalPage.setTitle(TRACE_VIEWER_TITLE); |
|
1686 IPreferenceNode generalNode = new PreferenceNode("1", generalPage); //$NON-NLS-1$ |
|
1687 mgr.addToRoot(generalNode); |
|
1688 |
|
1689 // Create advanced preference page |
|
1690 IPreferencePage advancedPage = new TraceViewerAdvancedPreferencesPage(); |
|
1691 advancedPage.setTitle(Messages |
|
1692 .getString("TraceViewerView.AdvancedPageTitle")); //$NON-NLS-1$ |
|
1693 IPreferenceNode advancedNode = new PreferenceNode("2", advancedPage); //$NON-NLS-1$ |
|
1694 mgr.addTo("1", advancedNode); //$NON-NLS-1$ |
|
1695 |
|
1696 // Create connection preference page |
|
1697 IPreferencePage connectionPage = new TraceViewerConnectionPreferencesPage(); |
|
1698 connectionPage.setTitle(Messages |
|
1699 .getString("TraceViewerView.ConnectionPageTitle")); //$NON-NLS-1$ |
|
1700 IPreferenceNode connectionNode = new PreferenceNode("3", connectionPage); //$NON-NLS-1$ |
|
1701 mgr.addTo("1", connectionNode); //$NON-NLS-1$ |
|
1702 |
|
1703 PreferenceDialog dialog = new PreferenceDialog(getShell(), mgr); |
|
1704 dialog.create(); |
|
1705 dialog.getTreeViewer().expandAll(); |
|
1706 |
|
1707 // Switch the page |
|
1708 switch (TVpage) { |
|
1709 case GENERAL: |
|
1710 dialog.getTreeViewer().setSelection( |
|
1711 new StructuredSelection(generalNode)); |
|
1712 break; |
|
1713 case ADVANCED: |
|
1714 dialog.getTreeViewer().setSelection( |
|
1715 new StructuredSelection(advancedNode)); |
|
1716 break; |
|
1717 case CONNECTION: |
|
1718 dialog.getTreeViewer().setSelection( |
|
1719 new StructuredSelection(connectionNode)); |
|
1720 break; |
|
1721 default: |
|
1722 break; |
|
1723 } |
|
1724 |
|
1725 // Open dialog and get return value |
|
1726 int ok = dialog.open(); |
|
1727 if (ok == Window.OK) { |
|
1728 ret = true; |
|
1729 } |
|
1730 |
|
1731 return ret; |
|
1732 } |
|
1733 |
|
1734 /* |
|
1735 * (non-Javadoc) |
|
1736 * |
|
1737 * @see com.nokia.traceviewer.engine.TraceViewerDialogInterface |
|
1738 * #createDialog |
|
1739 * (com.nokia.traceviewer.engine.TraceViewerDialogInterface.Dialog) |
|
1740 */ |
|
1741 public TraceViewerDialog createDialog(Dialog name) { |
|
1742 TraceViewerDialog dialog = dialogFactory.construct(name, getShell()); |
|
1743 return dialog; |
|
1744 } |
|
1745 } |