1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Patrick Tasse - Factored out from events view
12 * Francois Chouinard - Replaced Table by TmfVirtualTable
13 * Patrick Tasse - Filter implementation (inspired by www.eclipse.org/mat)
14 * Ansgar Radermacher - Support navigation to model URIs (Bug 396956)
15 * Bernd Hufmann - Updated call site and model URI implementation
16 *******************************************************************************/
18 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
;
20 import java
.io
.FileNotFoundException
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Arrays
;
23 import java
.util
.HashMap
;
24 import java
.util
.List
;
26 import java
.util
.Map
.Entry
;
27 import java
.util
.regex
.Pattern
;
28 import java
.util
.regex
.PatternSyntaxException
;
30 import org
.eclipse
.core
.resources
.IFile
;
31 import org
.eclipse
.core
.resources
.IMarker
;
32 import org
.eclipse
.core
.resources
.IResource
;
33 import org
.eclipse
.core
.resources
.IResourceVisitor
;
34 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
35 import org
.eclipse
.core
.runtime
.CoreException
;
36 import org
.eclipse
.core
.runtime
.IPath
;
37 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
38 import org
.eclipse
.core
.runtime
.IStatus
;
39 import org
.eclipse
.core
.runtime
.ListenerList
;
40 import org
.eclipse
.core
.runtime
.Path
;
41 import org
.eclipse
.core
.runtime
.Status
;
42 import org
.eclipse
.core
.runtime
.jobs
.Job
;
43 import org
.eclipse
.emf
.common
.util
.URI
;
44 import org
.eclipse
.emf
.ecore
.EValidator
;
45 import org
.eclipse
.jface
.action
.Action
;
46 import org
.eclipse
.jface
.action
.IAction
;
47 import org
.eclipse
.jface
.action
.IMenuListener
;
48 import org
.eclipse
.jface
.action
.IMenuManager
;
49 import org
.eclipse
.jface
.action
.IStatusLineManager
;
50 import org
.eclipse
.jface
.action
.MenuManager
;
51 import org
.eclipse
.jface
.action
.Separator
;
52 import org
.eclipse
.jface
.dialogs
.InputDialog
;
53 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
54 import org
.eclipse
.jface
.resource
.FontDescriptor
;
55 import org
.eclipse
.jface
.resource
.JFaceResources
;
56 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
57 import org
.eclipse
.jface
.util
.OpenStrategy
;
58 import org
.eclipse
.jface
.util
.SafeRunnable
;
59 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
60 import org
.eclipse
.jface
.viewers
.ISelection
;
61 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
62 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
63 import org
.eclipse
.jface
.viewers
.LabelProvider
;
64 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
65 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
66 import org
.eclipse
.jface
.window
.Window
;
67 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
68 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
69 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
70 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
71 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
72 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
73 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
74 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
75 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfCallsite
;
76 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
77 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
78 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
79 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
80 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
81 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
82 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
83 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
.ExecutionType
;
84 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
85 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
86 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
87 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
88 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
89 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
90 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
91 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
92 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
93 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
94 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
95 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
96 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSetting
;
97 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
98 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
99 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
100 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
101 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
;
102 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
103 import org
.eclipse
.swt
.SWT
;
104 import org
.eclipse
.swt
.custom
.SashForm
;
105 import org
.eclipse
.swt
.custom
.TableEditor
;
106 import org
.eclipse
.swt
.events
.FocusAdapter
;
107 import org
.eclipse
.swt
.events
.FocusEvent
;
108 import org
.eclipse
.swt
.events
.KeyAdapter
;
109 import org
.eclipse
.swt
.events
.KeyEvent
;
110 import org
.eclipse
.swt
.events
.MouseAdapter
;
111 import org
.eclipse
.swt
.events
.MouseEvent
;
112 import org
.eclipse
.swt
.events
.SelectionAdapter
;
113 import org
.eclipse
.swt
.events
.SelectionEvent
;
114 import org
.eclipse
.swt
.graphics
.Color
;
115 import org
.eclipse
.swt
.graphics
.Font
;
116 import org
.eclipse
.swt
.graphics
.Image
;
117 import org
.eclipse
.swt
.graphics
.Point
;
118 import org
.eclipse
.swt
.graphics
.Rectangle
;
119 import org
.eclipse
.swt
.layout
.FillLayout
;
120 import org
.eclipse
.swt
.layout
.GridData
;
121 import org
.eclipse
.swt
.layout
.GridLayout
;
122 import org
.eclipse
.swt
.widgets
.Composite
;
123 import org
.eclipse
.swt
.widgets
.Display
;
124 import org
.eclipse
.swt
.widgets
.Event
;
125 import org
.eclipse
.swt
.widgets
.Label
;
126 import org
.eclipse
.swt
.widgets
.Listener
;
127 import org
.eclipse
.swt
.widgets
.Menu
;
128 import org
.eclipse
.swt
.widgets
.MessageBox
;
129 import org
.eclipse
.swt
.widgets
.Shell
;
130 import org
.eclipse
.swt
.widgets
.TableColumn
;
131 import org
.eclipse
.swt
.widgets
.TableItem
;
132 import org
.eclipse
.swt
.widgets
.Text
;
133 import org
.eclipse
.ui
.IWorkbenchPage
;
134 import org
.eclipse
.ui
.PlatformUI
;
135 import org
.eclipse
.ui
.dialogs
.ListDialog
;
136 import org
.eclipse
.ui
.ide
.IDE
;
137 import org
.eclipse
.ui
.ide
.IGotoMarker
;
138 import org
.eclipse
.ui
.themes
.ColorUtil
;
141 * The generic TMF Events table
143 * This is a view that will list events that are read from a trace.
146 * @author Francois Chouinard
147 * @author Patrick Tasse
150 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
152 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
153 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
154 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
155 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
156 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
157 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
158 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
159 private static final Image FILTER_IMAGE
= Activator
.getDefault()
160 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
161 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
162 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
163 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
164 private static final int MAX_CACHE_SIZE
= 1000;
167 * The events table search/filter keys
170 * @author Patrick Tasse
172 public interface Key
{
174 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
177 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
180 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
183 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
186 String TIMESTAMP
= "$time"; //$NON-NLS-1$
189 String RANK
= "$rank"; //$NON-NLS-1$
192 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
194 /** Bookmark indicator */
195 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
199 * The events table search/filter state
202 * @author Patrick Tasse
204 public static enum HeaderState
{
205 /** A search is being run */
208 /** A filter is applied */
212 interface Direction
{
217 // ------------------------------------------------------------------------
219 // ------------------------------------------------------------------------
221 /** The virtual event table */
222 protected TmfVirtualTable fTable
;
224 private Composite fComposite
;
225 private SashForm fSashForm
;
226 private TmfRawEventViewer fRawViewer
;
227 private ITmfTrace fTrace
;
228 private boolean fPackDone
= false;
229 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
230 private long fSelectedRank
= 0;
231 private ITmfTimestamp fSelectedBeginTimestamp
= null;
232 private IStatusLineManager fStatusLineManager
= null;
235 private long fFilterMatchCount
;
236 private long fFilterCheckCount
;
237 private FilterThread fFilterThread
;
238 private boolean fFilterThreadResume
= false;
239 private final Object fFilterSyncObj
= new Object();
240 private SearchThread fSearchThread
;
241 private final Object fSearchSyncObj
= new Object();
244 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
246 * @see #fireSelectionChanged
248 private ListenerList selectionChangedListeners
= new ListenerList();
250 // Bookmark map <Rank, MarkerId>
251 private Map
<Long
, Long
> fBookmarksMap
= new HashMap
<Long
, Long
>();
252 private IFile fBookmarksFile
;
253 private long fPendingGotoRank
= -1;
256 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
257 private Color fGrayColor
;
258 private Color fGreenColor
;
259 private Font fBoldFont
;
261 // Table column names
262 private static final String
[] COLUMN_NAMES
= new String
[] { Messages
.TmfEventsTable_TimestampColumnHeader
,
263 Messages
.TmfEventsTable_SourceColumnHeader
, Messages
.TmfEventsTable_TypeColumnHeader
,
264 Messages
.TmfEventsTable_ReferenceColumnHeader
, Messages
.TmfEventsTable_ContentColumnHeader
};
266 private static final ColumnData
[] COLUMN_DATA
= new ColumnData
[] { new ColumnData(COLUMN_NAMES
[0], 100, SWT
.LEFT
),
267 new ColumnData(COLUMN_NAMES
[1], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[2], 100, SWT
.LEFT
),
268 new ColumnData(COLUMN_NAMES
[3], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[4], 100, SWT
.LEFT
) };
271 private final TmfEventsCache fCache
;
272 private boolean fCacheUpdateBusy
= false;
273 private boolean fCacheUpdatePending
= false;
274 private boolean fCacheUpdateCompleted
= false;
275 private final Object fCacheUpdateSyncObj
= new Object();
277 private boolean fDisposeOnClose
;
279 // ------------------------------------------------------------------------
281 // ------------------------------------------------------------------------
284 * Basic constructor, will use default column data.
287 * The parent composite UI object
289 * The size of the event table cache
291 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
292 this(parent
, cacheSize
, COLUMN_DATA
);
296 * Advanced constructor, where we also define which column data to use.
299 * The parent composite UI object
301 * The size of the event table cache
303 * The column data to use for this table
305 public TmfEventsTable(final Composite parent
, int cacheSize
, final ColumnData
[] columnData
) {
306 super("TmfEventsTable"); //$NON-NLS-1$
308 fComposite
= new Composite(parent
, SWT
.NONE
);
309 final GridLayout gl
= new GridLayout(1, false);
312 gl
.verticalSpacing
= 0;
313 fComposite
.setLayout(gl
);
315 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
316 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
318 // Create a virtual table
319 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
320 fTable
= new TmfVirtualTable(fSashForm
, style
);
322 // Set the table layout
323 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
324 fTable
.setLayoutData(layoutData
);
326 // Some cosmetic enhancements
327 fTable
.setHeaderVisible(true);
328 fTable
.setLinesVisible(true);
331 setColumnHeaders(columnData
);
333 // Set the default column field ids if this is not a subclass
334 if (Arrays
.equals(columnData
, COLUMN_DATA
)) {
335 fTable
.getColumns()[0].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
336 fTable
.getColumns()[1].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_SOURCE
);
337 fTable
.getColumns()[2].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TYPE
);
338 fTable
.getColumns()[3].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_REFERENCE
);
339 fTable
.getColumns()[4].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_CONTENT
);
342 // Set the frozen row for header row
343 fTable
.setFrozenRowCount(1);
345 // Create the header row cell editor
346 createHeaderEditor();
348 // Handle the table item selection
349 fTable
.addSelectionListener(new SelectionAdapter() {
351 public void widgetSelected(final SelectionEvent e
) {
352 if (e
.item
== null) {
355 updateStatusLine(null);
356 if (fTable
.getSelectionIndices().length
> 0) {
357 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
358 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
359 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
361 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
362 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
363 if (fTable
.getSelectionIndices().length
== 1) {
364 fSelectedBeginTimestamp
= ts
;
366 if (fSelectedBeginTimestamp
!= null) {
367 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
368 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
369 if (fTable
.getSelectionIndices().length
== 2) {
370 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
373 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
374 if (fStatusLineManager
!= null) {
375 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
380 if (fTable
.getSelectionIndices().length
== 1) {
381 fSelectedBeginTimestamp
= null;
385 if (e
.item
.getData() != null) {
386 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
388 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
393 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
394 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
395 fCache
= new TmfEventsCache(realCacheSize
, this);
397 // Handle the table item requests
398 fTable
.addListener(SWT
.SetData
, new Listener() {
401 public void handleEvent(final Event event
) {
403 final TableItem item
= (TableItem
) event
.item
;
404 int index
= event
.index
- 1; // -1 for the header row
406 if (event
.index
== 0) {
407 setHeaderRowItemData(item
);
411 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
412 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
413 setFilterStatusRowItemData(item
);
416 index
= index
- 1; // -1 for top filter status row
419 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
420 if (cachedEvent
!= null) {
421 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
425 // Else, fill the cache asynchronously (and off the UI thread)
430 fTable
.addMouseListener(new MouseAdapter() {
432 public void mouseDoubleClick(final MouseEvent event
) {
433 if (event
.button
!= 1) {
436 // Identify the selected row
437 final Point point
= new Point(event
.x
, event
.y
);
438 final TableItem item
= fTable
.getItem(point
);
440 final Rectangle imageBounds
= item
.getImageBounds(0);
441 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
442 if (imageBounds
.contains(point
)) {
443 final Long rank
= (Long
) item
.getData(Key
.RANK
);
445 toggleBookmark(rank
);
452 final Listener tooltipListener
= new Listener () {
453 Shell tooltipShell
= null;
455 public void handleEvent(final Event event
) {
456 switch (event
.type
) {
458 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
462 final Long rank
= (Long
) item
.getData(Key
.RANK
);
466 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
467 final Rectangle bounds
= item
.getImageBounds(0);
468 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
469 if (!bounds
.contains(event
.x
,event
.y
)) {
472 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
473 tooltipShell
.dispose();
475 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
476 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
477 final FillLayout layout
= new FillLayout();
478 layout
.marginWidth
= 2;
479 tooltipShell
.setLayout(layout
);
480 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
481 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: ""); //$NON-NLS-1$ //$NON-NLS-2$
482 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
483 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
485 label
.addListener(SWT
.MouseExit
, this);
486 label
.addListener(SWT
.MouseDown
, this);
487 label
.addListener(SWT
.MouseWheel
, this);
488 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
490 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
491 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
494 if (System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
495 y
+= fTable
.getHeaderHeight();
497 Point pt
= fTable
.toDisplay(event
.x
, y
);
498 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
499 pt
.y
+= item
.getBounds().height
;
500 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
501 tooltipShell
.setVisible(true);
509 if (tooltipShell
!= null) {
510 tooltipShell
.dispose();
520 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
521 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
522 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
523 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
524 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
525 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
526 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
531 ColorSettingsManager
.addColorSettingsListener(this);
533 fTable
.setItemCount(1); // +1 for header row
535 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
537 fRawViewer
.addSelectionListener(new Listener() {
539 public void handleEvent(final Event e
) {
540 if (e
.data
instanceof Long
) {
541 final long rank
= (Long
) e
.data
;
542 int index
= (int) rank
;
543 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
544 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
546 fTable
.setSelection(index
+ 1); // +1 for header row
547 fSelectedRank
= rank
;
548 updateStatusLine(null);
549 } else if (e
.data
instanceof ITmfLocation
) {
550 // DOES NOT WORK: rank undefined in context from seekLocation()
551 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
552 // TmfContext context = fTrace.seekLocation(location);
553 // fTable.setSelection((int) context.getRank());
558 final TableItem
[] selection
= fTable
.getSelection();
559 if ((selection
!= null) && (selection
.length
> 0)) {
560 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
562 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
568 fSashForm
.setWeights(new int[] { 1, 1 });
569 fRawViewer
.setVisible(false);
575 * Create a pop-up menu.
577 protected void createPopupMenu() {
578 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
581 fTable
.setVisible(true);
586 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
589 fTable
.setVisible(false);
594 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
597 fRawViewer
.setVisible(true);
599 final int index
= fTable
.getSelectionIndex();
601 fRawViewer
.selectAndReveal(index
- 1);
606 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
609 fRawViewer
.setVisible(false);
614 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
617 final TableItem items
[] = fTable
.getSelection();
618 if (items
.length
!= 1) {
621 final TableItem item
= items
[0];
623 final Object data
= item
.getData();
624 if (data
instanceof ITmfSourceLookup
) {
625 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
626 ITmfCallsite cs
= event
.getCallsite();
627 if (cs
== null || cs
.getFileName() == null) {
630 IMarker marker
= null;
632 String fileName
= cs
.getFileName();
633 final String trimmedPath
= fileName
.replaceAll("\\.\\./", ""); //$NON-NLS-1$ //$NON-NLS-2$
634 final ArrayList
<IFile
> files
= new ArrayList
<IFile
>();
635 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
637 public boolean visit(IResource resource
) throws CoreException
{
638 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
639 files
.add((IFile
) resource
);
645 if (files
.size() > 1) {
646 ListDialog dialog
= new ListDialog(getTable().getShell());
647 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
648 dialog
.setLabelProvider(new LabelProvider() {
650 public String
getText(Object element
) {
651 return ((IFile
) element
).getFullPath().toString();
654 dialog
.setInput(files
);
655 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
656 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
658 Object
[] result
= dialog
.getResult();
659 if (result
!= null && result
.length
> 0) {
660 file
= (IFile
) result
[0];
662 } else if (files
.size() == 1) {
666 marker
= file
.createMarker(IMarker
.MARKER
);
667 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
668 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
670 } else if (files
.size() == 0){
671 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
673 } catch (CoreException e
) {
680 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
684 final TableItem items
[] = fTable
.getSelection();
685 if (items
.length
!= 1) {
688 final TableItem item
= items
[0];
690 final Object eventData
= item
.getData();
691 if (eventData
instanceof ITmfModelLookup
) {
692 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
694 if (modelURI
!= null) {
695 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
698 final URI uri
= URI
.createURI(modelURI
);
699 if (uri
.isPlatformResource()) {
700 IPath path
= new Path(uri
.toPlatformString(true));
701 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
702 } else if (uri
.isFile() && !uri
.isRelative()) {
703 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
704 new Path(uri
.toFileString()));
710 * create a temporary validation marker on the
711 * model file, remove it afterwards thus,
712 * navigation works with all model editors
713 * supporting the navigation to a marker
715 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
716 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
717 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
719 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
722 catch (CoreException e
) {
726 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
733 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
736 fHeaderState
= HeaderState
.SEARCH
;
741 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
744 fHeaderState
= HeaderState
.FILTER
;
749 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
756 class ToggleBookmarkAction
extends Action
{
759 public ToggleBookmarkAction(final String text
, final long rank
) {
766 toggleBookmark(fRank
);
770 final MenuManager tablePopupMenu
= new MenuManager();
771 tablePopupMenu
.setRemoveAllWhenShown(true);
772 tablePopupMenu
.addMenuListener(new IMenuListener() {
774 public void menuAboutToShow(final IMenuManager manager
) {
775 if (fTable
.getSelectionIndex() == 0) {
776 // Right-click on header row
777 if (fHeaderState
== HeaderState
.FILTER
) {
778 tablePopupMenu
.add(showSearchBarAction
);
780 tablePopupMenu
.add(showFilterBarAction
);
784 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
785 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
787 final Rectangle imageBounds
= item
.getImageBounds(0);
788 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
789 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
790 // Right-click on left margin
791 final Long rank
= (Long
) item
.getData(Key
.RANK
);
792 if ((rank
!= null) && (fBookmarksFile
!= null)) {
793 if (fBookmarksMap
.containsKey(rank
)) {
794 tablePopupMenu
.add(new ToggleBookmarkAction(
795 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
797 tablePopupMenu
.add(new ToggleBookmarkAction(
798 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
805 // Right-click on table
806 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
807 tablePopupMenu
.add(hideTableAction
);
808 tablePopupMenu
.add(hideRawAction
);
809 } else if (!fTable
.isVisible()) {
810 tablePopupMenu
.add(showTableAction
);
811 } else if (!fRawViewer
.isVisible()) {
812 tablePopupMenu
.add(showRawAction
);
814 tablePopupMenu
.add(new Separator());
817 final Object data
= item
.getData();
818 Separator separator
= null;
819 if (data
instanceof ITmfSourceLookup
) {
820 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
821 if (event
.getCallsite() != null) {
822 tablePopupMenu
.add(openCallsiteAction
);
823 separator
= new Separator();
827 if (data
instanceof ITmfModelLookup
) {
828 ITmfModelLookup event
= (ITmfModelLookup
) data
;
829 if (event
.getModelUri() != null) {
830 tablePopupMenu
.add(openModelAction
);
831 separator
= new Separator();
834 if (separator
!= null) {
835 tablePopupMenu
.add(separator
);
840 tablePopupMenu
.add(clearFiltersAction
);
841 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
842 if (savedFilters
.length
> 0) {
843 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
844 for (final ITmfFilterTreeNode node
: savedFilters
) {
845 if (node
instanceof TmfFilterNode
) {
846 final TmfFilterNode filter
= (TmfFilterNode
) node
;
847 subMenu
.add(new Action(filter
.getFilterName()) {
855 tablePopupMenu
.add(subMenu
);
857 appendToTablePopupMenu(tablePopupMenu
, item
);
861 final MenuManager rawViewerPopupMenu
= new MenuManager();
862 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
863 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
865 public void menuAboutToShow(final IMenuManager manager
) {
866 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
867 rawViewerPopupMenu
.add(hideTableAction
);
868 rawViewerPopupMenu
.add(hideRawAction
);
869 } else if (!fTable
.isVisible()) {
870 rawViewerPopupMenu
.add(showTableAction
);
871 } else if (!fRawViewer
.isVisible()) {
872 rawViewerPopupMenu
.add(showRawAction
);
874 appendToRawPopupMenu(tablePopupMenu
);
878 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
879 fTable
.setMenu(menu
);
881 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
882 fRawViewer
.setMenu(menu
);
887 * Append an item to the event table's pop-up menu.
889 * @param tablePopupMenu
891 * @param selectedItem
894 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
895 // override to append more actions
899 * Append an item to the raw viewer's pop-up menu.
901 * @param rawViewerPopupMenu
904 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
905 // override to append more actions
909 public void dispose() {
912 ColorSettingsManager
.removeColorSettingsListener(this);
913 fComposite
.dispose();
914 if ((fTrace
!= null) && fDisposeOnClose
) {
917 fResourceManager
.dispose();
922 * Assign a layout data object to this view.
925 * The layout data to assign
927 public void setLayoutData(final Object layoutData
) {
928 fComposite
.setLayoutData(layoutData
);
932 * Get the virtual table contained in this event table.
934 * @return The TMF virtual table
936 public TmfVirtualTable
getTable() {
943 * FIXME: Add support for column selection
945 protected void setColumnHeaders(final ColumnData
[] columnData
) {
946 fTable
.setColumnHeaders(columnData
);
950 * Set a table item's data.
955 * Which trace event to link with this entry
957 * Which rank this event has in the trace/experiment
959 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
960 final ITmfEventField
[] fields
= extractItemFields(event
);
961 final String
[] content
= new String
[fields
.length
];
962 for (int i
= 0; i
< fields
.length
; i
++) {
963 content
[i
] = fields
[i
].getValue() != null ? fields
[i
].getValue().toString() : ""; //$NON-NLS-1$
965 item
.setText(content
);
967 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
968 item
.setData(Key
.RANK
, rank
);
970 boolean bookmark
= false;
971 final Long markerId
= fBookmarksMap
.get(rank
);
972 if (markerId
!= null) {
975 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
976 item
.setData(Key
.BOOKMARK
, marker
.getAttribute(IMarker
.MESSAGE
));
977 } catch (final CoreException e
) {
981 item
.setData(Key
.BOOKMARK
, null);
984 boolean searchMatch
= false;
985 boolean searchNoMatch
= false;
986 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
987 if (searchFilter
!= null) {
988 if (searchFilter
.matches(event
)) {
991 searchNoMatch
= true;
995 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
997 item
.setForeground(colorSetting
.getDimmedForegroundColor());
998 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1000 item
.setForeground(colorSetting
.getForegroundColor());
1001 item
.setBackground(colorSetting
.getBackgroundColor());
1006 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1008 item
.setImage(SEARCH_MATCH_IMAGE
);
1010 } else if (bookmark
) {
1011 item
.setImage(BOOKMARK_IMAGE
);
1013 item
.setImage((Image
) null);
1018 * Set the item data of the header row.
1021 * The item to use as table header
1023 protected void setHeaderRowItemData(final TableItem item
) {
1024 String txtKey
= null;
1025 if (fHeaderState
== HeaderState
.SEARCH
) {
1026 item
.setImage(SEARCH_IMAGE
);
1027 txtKey
= Key
.SEARCH_TXT
;
1028 } else if (fHeaderState
== HeaderState
.FILTER
) {
1029 item
.setImage(FILTER_IMAGE
);
1030 txtKey
= Key
.FILTER_TXT
;
1032 item
.setForeground(fGrayColor
);
1033 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1034 final TableColumn column
= fTable
.getColumns()[i
];
1035 final String filter
= (String
) column
.getData(txtKey
);
1036 if (filter
== null) {
1037 if (fHeaderState
== HeaderState
.SEARCH
) {
1038 item
.setText(i
, SEARCH_HINT
);
1039 } else if (fHeaderState
== HeaderState
.FILTER
) {
1040 item
.setText(i
, FILTER_HINT
);
1042 item
.setForeground(i
, fGrayColor
);
1043 item
.setFont(i
, fTable
.getFont());
1045 item
.setText(i
, filter
);
1046 item
.setForeground(i
, fGreenColor
);
1047 item
.setFont(i
, fBoldFont
);
1053 * Set the item data of the "filter status" row.
1056 * The item to use as filter status row
1058 protected void setFilterStatusRowItemData(final TableItem item
) {
1059 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1061 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1062 item
.setImage(FILTER_IMAGE
);
1064 item
.setImage(STOP_IMAGE
);
1066 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1068 item
.setText(i
, ""); //$NON-NLS-1$
1072 item
.setData(Key
.TIMESTAMP
, null);
1073 item
.setData(Key
.RANK
, null);
1074 item
.setForeground(null);
1075 item
.setBackground(null);
1079 * Create an editor for the header.
1081 protected void createHeaderEditor() {
1082 final TableEditor tableEditor
= fTable
.createTableEditor();
1083 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1084 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1085 tableEditor
.grabHorizontal
= true;
1086 tableEditor
.minimumWidth
= 50;
1088 // Handle the header row selection
1089 fTable
.addMouseListener(new MouseAdapter() {
1095 public void mouseDown(final MouseEvent event
) {
1096 if (event
.button
!= 1) {
1099 // Identify the selected row
1100 final Point point
= new Point(event
.x
, event
.y
);
1101 item
= fTable
.getItem(point
);
1103 // Header row selected
1104 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1107 if (item
.getImageBounds(0).contains(point
)) {
1108 if (fHeaderState
== HeaderState
.SEARCH
) {
1109 fHeaderState
= HeaderState
.FILTER
;
1110 } else if (fHeaderState
== HeaderState
.FILTER
) {
1111 fHeaderState
= HeaderState
.SEARCH
;
1113 fTable
.setSelection(0);
1118 // Identify the selected column
1120 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1121 final Rectangle rect
= item
.getBounds(i
);
1122 if (rect
.contains(point
)) {
1128 if (columnIndex
== -1) {
1132 column
= fTable
.getColumns()[columnIndex
];
1134 String txtKey
= null;
1135 if (fHeaderState
== HeaderState
.SEARCH
) {
1136 txtKey
= Key
.SEARCH_TXT
;
1137 } else if (fHeaderState
== HeaderState
.FILTER
) {
1138 txtKey
= Key
.FILTER_TXT
;
1141 // The control that will be the editor must be a child of the Table
1142 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1143 final String headerString
= (String
) column
.getData(txtKey
);
1144 if (headerString
!= null) {
1145 newEditor
.setText(headerString
);
1147 newEditor
.addFocusListener(new FocusAdapter() {
1149 public void focusLost(final FocusEvent e
) {
1150 final boolean changed
= updateHeader(newEditor
.getText());
1156 newEditor
.addKeyListener(new KeyAdapter() {
1158 public void keyPressed(final KeyEvent e
) {
1159 if (e
.character
== SWT
.CR
) {
1160 updateHeader(newEditor
.getText());
1162 } else if (e
.character
== SWT
.ESC
) {
1163 tableEditor
.getEditor().dispose();
1167 newEditor
.selectAll();
1168 newEditor
.setFocus();
1169 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1174 * returns true is value was changed
1176 private boolean updateHeader(final String text
) {
1177 String objKey
= null;
1178 String txtKey
= null;
1179 if (fHeaderState
== HeaderState
.SEARCH
) {
1180 objKey
= Key
.SEARCH_OBJ
;
1181 txtKey
= Key
.SEARCH_TXT
;
1182 } else if (fHeaderState
== HeaderState
.FILTER
) {
1183 objKey
= Key
.FILTER_OBJ
;
1184 txtKey
= Key
.FILTER_TXT
;
1186 if (text
.trim().length() > 0) {
1188 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1189 Pattern
.compile(regex
);
1190 if (regex
.equals(column
.getData(txtKey
))) {
1191 tableEditor
.getEditor().dispose();
1194 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1195 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1196 if (fieldId
== null) {
1197 fieldId
= column
.getText();
1199 filter
.setField(fieldId
);
1200 filter
.setRegex(regex
);
1201 column
.setData(objKey
, filter
);
1202 column
.setData(txtKey
, regex
);
1203 } catch (final PatternSyntaxException ex
) {
1204 tableEditor
.getEditor().dispose();
1205 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1206 ex
.getDescription(), ex
.getMessage());
1210 if (column
.getData(txtKey
) == null) {
1211 tableEditor
.getEditor().dispose();
1214 column
.setData(objKey
, null);
1215 column
.setData(txtKey
, null);
1220 private void applyHeader() {
1221 if (fHeaderState
== HeaderState
.SEARCH
) {
1223 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1224 for (final TableColumn col
: fTable
.getColumns()) {
1225 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1226 if (filterObj
instanceof ITmfFilterTreeNode
) {
1227 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1230 if (filter
.getChildrenCount() > 0) {
1231 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1234 fireSearchApplied(filter
);
1236 fTable
.setData(Key
.SEARCH_OBJ
, null);
1238 fireSearchApplied(null);
1240 } else if (fHeaderState
== HeaderState
.FILTER
) {
1241 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1242 for (final TableColumn col
: fTable
.getColumns()) {
1243 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1244 if (filterObj
instanceof ITmfFilterTreeNode
) {
1245 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1248 if (filter
.getChildrenCount() > 0) {
1249 applyFilter(filter
);
1255 tableEditor
.getEditor().dispose();
1259 fTable
.addKeyListener(new KeyAdapter() {
1261 public void keyPressed(final KeyEvent e
) {
1263 if (e
.character
== SWT
.ESC
) {
1267 } else if (e
.character
== SWT
.DEL
) {
1268 if (fHeaderState
== HeaderState
.SEARCH
) {
1270 for (final TableColumn column
: fTable
.getColumns()) {
1271 column
.setData(Key
.SEARCH_OBJ
, null);
1272 column
.setData(Key
.SEARCH_TXT
, null);
1274 fTable
.setData(Key
.SEARCH_OBJ
, null);
1276 fireSearchApplied(null);
1277 } else if (fHeaderState
== HeaderState
.FILTER
) {
1280 } else if (e
.character
== SWT
.CR
) {
1281 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1292 * Send an event indicating a filter has been applied.
1295 * The filter that was just applied
1297 protected void fireFilterApplied(final ITmfFilter filter
) {
1298 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1302 * Send an event indicating that a search has been applied.
1305 * The search filter that was just applied
1307 protected void fireSearchApplied(final ITmfFilter filter
) {
1308 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1312 * Start the filtering thread.
1314 protected void startFilterThread() {
1315 synchronized (fFilterSyncObj
) {
1316 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1317 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1318 if (fFilterThread
!= null) {
1319 fFilterThread
.cancel();
1320 fFilterThreadResume
= false;
1322 fFilterThread
= new FilterThread(filter
);
1323 fFilterThread
.start();
1325 fFilterThreadResume
= true;
1331 * Stop the filtering thread.
1333 protected void stopFilterThread() {
1334 synchronized (fFilterSyncObj
) {
1335 if (fFilterThread
!= null) {
1336 fFilterThread
.cancel();
1337 fFilterThread
= null;
1338 fFilterThreadResume
= false;
1347 * The filter to apply
1350 protected void applyFilter(ITmfFilter filter
) {
1353 fFilterMatchCount
= 0;
1354 fFilterCheckCount
= 0;
1355 fCache
.applyFilter(filter
);
1357 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1358 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1359 startFilterThread();
1360 fireFilterApplied(filter
);
1364 * Clear all currently active filters.
1366 protected void clearFilters() {
1367 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1372 fCache
.clearFilter();
1374 for (final TableColumn column
: fTable
.getColumns()) {
1375 column
.setData(Key
.FILTER_OBJ
, null);
1376 column
.setData(Key
.FILTER_TXT
, null);
1378 fTable
.setData(Key
.FILTER_OBJ
, null);
1379 if (fTrace
!= null) {
1380 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1382 fTable
.setItemCount(1); // +1 for header row
1384 fFilterMatchCount
= 0;
1385 fFilterCheckCount
= 0;
1386 if (fSelectedRank
>= 0) {
1387 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1389 fTable
.setSelection(0);
1391 fireFilterApplied(null);
1392 updateStatusLine(null);
1396 * Wrapper Thread object for the filtering thread.
1398 protected class FilterThread
extends Thread
{
1399 private final ITmfFilterTreeNode filter
;
1400 private TmfDataRequest request
;
1401 private boolean refreshBusy
= false;
1402 private boolean refreshPending
= false;
1403 private final Object syncObj
= new Object();
1409 * The filter this thread will be processing
1411 public FilterThread(final ITmfFilterTreeNode filter
) {
1412 super("Filter Thread"); //$NON-NLS-1$
1413 this.filter
= filter
;
1418 if (fTrace
== null) {
1421 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1422 if (nbRequested
<= 0) {
1425 request
= new TmfDataRequest(ITmfEvent
.class, (int) fFilterCheckCount
,
1426 nbRequested
, ExecutionType
.BACKGROUND
) {
1428 public void handleData(final ITmfEvent event
) {
1429 super.handleData(event
);
1430 if (request
.isCancelled()) {
1433 if (filter
.matches(event
)) {
1434 final long rank
= fFilterCheckCount
;
1435 final int index
= (int) fFilterMatchCount
;
1436 fFilterMatchCount
++;
1437 fCache
.storeEvent(event
, rank
, index
);
1439 } else if ((fFilterCheckCount
% 100) == 0) {
1442 fFilterCheckCount
++;
1445 ((ITmfDataProvider
) fTrace
).sendRequest(request
);
1447 request
.waitForCompletion();
1448 } catch (final InterruptedException e
) {
1451 synchronized (fFilterSyncObj
) {
1452 fFilterThread
= null;
1453 if (fFilterThreadResume
) {
1454 fFilterThreadResume
= false;
1455 fFilterThread
= new FilterThread(filter
);
1456 fFilterThread
.start();
1462 * Refresh the filter.
1464 public void refreshTable() {
1465 synchronized (syncObj
) {
1467 refreshPending
= true;
1472 Display
.getDefault().asyncExec(new Runnable() {
1475 if (request
.isCancelled()) {
1478 if (fTable
.isDisposed()) {
1481 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1483 synchronized (syncObj
) {
1484 refreshBusy
= false;
1485 if (refreshPending
) {
1486 refreshPending
= false;
1495 * Cancel this filtering thread.
1497 public void cancel() {
1498 if (request
!= null) {
1505 * Go to the next item of a search.
1507 protected void searchNext() {
1508 synchronized (fSearchSyncObj
) {
1509 if (fSearchThread
!= null) {
1512 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1513 if (searchFilter
== null) {
1516 final int selectionIndex
= fTable
.getSelectionIndex();
1518 if (selectionIndex
> 0) {
1519 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1521 // header row is selected, start at top event
1522 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1524 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1525 if (eventFilter
!= null) {
1526 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1528 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1529 fSearchThread
.schedule();
1534 * Go to the previous item of a search.
1536 protected void searchPrevious() {
1537 synchronized (fSearchSyncObj
) {
1538 if (fSearchThread
!= null) {
1541 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1542 if (searchFilter
== null) {
1545 final int selectionIndex
= fTable
.getSelectionIndex();
1547 if (selectionIndex
> 0) {
1548 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1550 // header row is selected, start at precedent of top event
1551 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1553 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1554 if (eventFilter
!= null) {
1555 startIndex
= startIndex
- 1; // -1 for top filter status row
1557 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1558 fSearchThread
.schedule();
1563 * Stop the search thread.
1565 protected void stopSearchThread() {
1566 fPendingGotoRank
= -1;
1567 synchronized (fSearchSyncObj
) {
1568 if (fSearchThread
!= null) {
1569 fSearchThread
.cancel();
1570 fSearchThread
= null;
1576 * Wrapper for the search thread.
1578 protected class SearchThread
extends Job
{
1580 private ITmfFilterTreeNode searchFilter
;
1581 private ITmfFilterTreeNode eventFilter
;
1582 private int startIndex
;
1583 private int direction
;
1585 private long foundRank
= -1;
1586 private TmfDataRequest request
;
1587 private ITmfTimestamp foundTimestamp
= null;
1592 * @param searchFilter
1594 * @param eventFilter
1597 * The index at which we should start searching
1598 * @param currentRank
1601 * In which direction should we search, forward or backwards
1603 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1604 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1605 final long currentRank
, final int direction
) {
1606 super(Messages
.TmfEventsTable_SearchingJobName
);
1607 this.searchFilter
= searchFilter
;
1608 this.eventFilter
= eventFilter
;
1609 this.startIndex
= startIndex
;
1610 this.rank
= currentRank
;
1611 this.direction
= direction
;
1615 protected IStatus
run(final IProgressMonitor monitor
) {
1616 if (fTrace
== null) {
1617 return Status
.OK_STATUS
;
1619 final Display display
= Display
.getDefault();
1620 if (startIndex
< 0) {
1621 rank
= (int) fTrace
.getNbEvents() - 1;
1622 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1625 int idx
= startIndex
;
1626 while (foundRank
== -1) {
1627 final CachedEvent event
= fCache
.peekEvent(idx
);
1628 if (event
== null) {
1632 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1633 foundRank
= event
.rank
;
1634 foundTimestamp
= event
.event
.getTimestamp();
1637 if (direction
== Direction
.FORWARD
) {
1643 if (foundRank
== -1) {
1644 if (direction
== Direction
.FORWARD
) {
1646 if (rank
> (fTrace
.getNbEvents() - 1)) {
1652 rank
= (int) fTrace
.getNbEvents() - 1;
1657 final int startRank
= (int) rank
;
1658 boolean wrapped
= false;
1659 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1660 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1661 if (direction
== Direction
.BACKWARD
) {
1662 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1664 request
= new TmfDataRequest(ITmfEvent
.class, (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1665 long currentRank
= rank
;
1668 public void handleData(final ITmfEvent event
) {
1669 super.handleData(event
);
1670 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1671 foundRank
= currentRank
;
1672 foundTimestamp
= event
.getTimestamp();
1673 if (direction
== Direction
.FORWARD
) {
1681 ((ITmfDataProvider
) fTrace
).sendRequest(request
);
1683 request
.waitForCompletion();
1684 if (request
.isCancelled()) {
1685 return Status
.OK_STATUS
;
1687 } catch (final InterruptedException e
) {
1688 synchronized (fSearchSyncObj
) {
1689 fSearchThread
= null;
1691 return Status
.OK_STATUS
;
1693 if (foundRank
== -1) {
1694 if (direction
== Direction
.FORWARD
) {
1696 synchronized (fSearchSyncObj
) {
1697 fSearchThread
= null;
1699 return Status
.OK_STATUS
;
1701 nbRequested
= (int) rank
;
1707 rank
= (int) fTrace
.getNbEvents() - 1;
1710 if ((rank
<= startRank
) && wrapped
) {
1711 synchronized (fSearchSyncObj
) {
1712 fSearchThread
= null;
1714 return Status
.OK_STATUS
;
1719 int index
= (int) foundRank
;
1720 if (eventFilter
!= null) {
1721 index
= fCache
.getFilteredEventIndex(foundRank
);
1723 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1725 display
.asyncExec(new Runnable() {
1728 if (monitor
.isCanceled()) {
1731 if (fTable
.isDisposed()) {
1734 fTable
.setSelection(selection
);
1735 fSelectedRank
= foundRank
;
1736 fRawViewer
.selectAndReveal(fSelectedRank
);
1737 if (foundTimestamp
!= null) {
1738 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1740 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1741 synchronized (fSearchSyncObj
) {
1742 fSearchThread
= null;
1744 updateStatusLine(null);
1747 return Status
.OK_STATUS
;
1751 protected void canceling() {
1753 synchronized (fSearchSyncObj
) {
1754 fSearchThread
= null;
1760 * Create the resources.
1762 protected void createResources() {
1763 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1764 .getForeground().getRGB()));
1765 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1766 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1772 protected void packColumns() {
1776 boolean isLinux
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
1778 TableColumn tableColumns
[] = fTable
.getColumns();
1779 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1780 final TableColumn column
= tableColumns
[i
];
1781 final int headerWidth
= column
.getWidth();
1783 // Workaround for Linux which doesn't consider the image width of
1784 // search/filter row in TableColumn.pack() after having executed
1785 // TableItem.setImage((Image)null) for other rows than search/filter row.
1786 if (isLinux
&& (i
== 0)) {
1787 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1790 if (column
.getWidth() < headerWidth
) {
1791 column
.setWidth(headerWidth
);
1798 * Extract the fields of an event (item in the table).
1801 * The event to extract from
1802 * @return The array of fields
1804 * FIXME: Add support for column selection
1806 protected ITmfEventField
[] extractItemFields(final ITmfEvent event
) {
1807 ITmfEventField
[] fields
= new TmfEventField
[0];
1808 if (event
!= null) {
1809 final String timestamp
= event
.getTimestamp().toString();
1810 final String source
= event
.getSource();
1811 final String type
= event
.getType().getName();
1812 final String reference
= event
.getReference();
1813 final String content
= event
.getContent().toString();
1814 fields
= new TmfEventField
[] {
1815 new TmfEventField(ITmfEvent
.EVENT_FIELD_TIMESTAMP
, timestamp
, null),
1816 new TmfEventField(ITmfEvent
.EVENT_FIELD_SOURCE
, source
, null),
1817 new TmfEventField(ITmfEvent
.EVENT_FIELD_TYPE
, type
, null),
1818 new TmfEventField(ITmfEvent
.EVENT_FIELD_REFERENCE
, reference
, null),
1819 new TmfEventField(ITmfEvent
.EVENT_FIELD_CONTENT
, content
, null)
1826 * Notify this table that is got the UI focus.
1828 public void setFocus() {
1833 * Assign a new trace to this event table.
1836 * The trace to assign to this event table
1837 * @param disposeOnClose
1838 * true if the trace should be disposed when the table is
1841 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1842 if ((fTrace
!= null) && fDisposeOnClose
) {
1848 fDisposeOnClose
= disposeOnClose
;
1850 // Perform the updates on the UI thread
1851 fTable
.getDisplay().syncExec(new Runnable() {
1855 fCache
.setTrace(fTrace
); // Clear the cache
1856 if (fTrace
!= null) {
1857 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1858 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1859 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1862 fFilterMatchCount
= 0;
1863 fFilterCheckCount
= 0;
1864 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1865 startFilterThread();
1869 fRawViewer
.setTrace(fTrace
);
1875 * Assign the status line manager
1877 * @param statusLineManager
1878 * The status line manager, or null to disable status line messages
1881 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
1882 if (fStatusLineManager
!= null && statusLineManager
== null) {
1883 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
1885 fStatusLineManager
= statusLineManager
;
1888 private void updateStatusLine(ITmfTimestamp delta
) {
1889 if (fStatusLineManager
!= null) {
1890 if (delta
!= null) {
1891 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
1893 fStatusLineManager
.setMessage(null);
1898 // ------------------------------------------------------------------------
1900 // ------------------------------------------------------------------------
1903 * Notify that the event cache has been updated
1906 * Also notify if the populating of the cache is complete, or
1909 public void cacheUpdated(final boolean completed
) {
1910 synchronized (fCacheUpdateSyncObj
) {
1911 if (fCacheUpdateBusy
) {
1912 fCacheUpdatePending
= true;
1913 fCacheUpdateCompleted
= completed
;
1916 fCacheUpdateBusy
= true;
1918 // Event cache is now updated. Perform update on the UI thread
1919 if (!fTable
.isDisposed()) {
1920 fTable
.getDisplay().asyncExec(new Runnable() {
1923 if (!fTable
.isDisposed()) {
1928 populateCompleted();
1930 synchronized (fCacheUpdateSyncObj
) {
1931 fCacheUpdateBusy
= false;
1932 if (fCacheUpdatePending
) {
1933 fCacheUpdatePending
= false;
1934 cacheUpdated(fCacheUpdateCompleted
);
1943 * Callback for when populating the table is complete.
1945 protected void populateCompleted() {
1946 // Nothing by default;
1949 // ------------------------------------------------------------------------
1950 // ISelectionProvider
1951 // ------------------------------------------------------------------------
1957 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
1958 selectionChangedListeners
.add(listener
);
1965 public ISelection
getSelection() {
1966 if (fTable
== null || fTable
.isDisposed()) {
1967 return StructuredSelection
.EMPTY
;
1969 List
<Object
> list
= new ArrayList
<Object
>(fTable
.getSelection().length
);
1970 for (TableItem item
: fTable
.getSelection()) {
1971 if (item
.getData() != null) {
1972 list
.add(item
.getData());
1975 return new StructuredSelection(list
);
1982 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
1983 selectionChangedListeners
.remove(listener
);
1990 public void setSelection(ISelection selection
) {
1995 * Notifies any selection changed listeners that the viewer's selection has changed.
1996 * Only listeners registered at the time this method is called are notified.
1998 * @param event a selection changed event
2000 * @see ISelectionChangedListener#selectionChanged
2003 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2004 Object
[] listeners
= selectionChangedListeners
.getListeners();
2005 for (int i
= 0; i
< listeners
.length
; ++i
) {
2006 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2007 SafeRunnable
.run(new SafeRunnable() {
2010 l
.selectionChanged(event
);
2016 // ------------------------------------------------------------------------
2017 // Bookmark handling
2018 // ------------------------------------------------------------------------
2021 * Add a bookmark to this event table.
2023 * @param bookmarksFile
2024 * The file to use for the bookmarks
2026 public void addBookmark(final IFile bookmarksFile
) {
2027 fBookmarksFile
= bookmarksFile
;
2028 final TableItem
[] selection
= fTable
.getSelection();
2029 if (selection
.length
> 0) {
2030 final TableItem tableItem
= selection
[0];
2031 if (tableItem
.getData(Key
.RANK
) != null) {
2032 final StringBuffer defaultMessage
= new StringBuffer();
2033 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2035 defaultMessage
.append(", "); //$NON-NLS-1$
2037 defaultMessage
.append(tableItem
.getText(i
));
2039 final InputDialog dialog
= new MultiLineInputDialog(
2040 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2041 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2042 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2043 defaultMessage
.toString());
2044 if (dialog
.open() == Window
.OK
) {
2045 final String message
= dialog
.getValue();
2047 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2048 if (bookmark
.exists()) {
2049 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2050 final long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2051 final int location
= (int) rank
;
2052 bookmark
.setAttribute(IMarker
.LOCATION
, (Integer
) location
);
2053 fBookmarksMap
.put(rank
, bookmark
.getId());
2056 } catch (final CoreException e
) {
2057 displayException(e
);
2066 * Remove a bookmark from this event table.
2069 * The bookmark to remove
2071 public void removeBookmark(final IMarker bookmark
) {
2072 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entrySet()) {
2073 if (entry
.getValue().equals(bookmark
.getId())) {
2074 fBookmarksMap
.remove(entry
.getKey());
2081 private void toggleBookmark(final long rank
) {
2082 if (fBookmarksFile
== null) {
2085 if (fBookmarksMap
.containsKey(rank
)) {
2086 final Long markerId
= fBookmarksMap
.remove(rank
);
2089 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2090 if (bookmark
!= null) {
2093 } catch (final CoreException e
) {
2094 displayException(e
);
2097 addBookmark(fBookmarksFile
);
2102 * Refresh the bookmarks assigned to this trace, from the contents of a
2105 * @param bookmarksFile
2106 * The bookmark file to use
2108 public void refreshBookmarks(final IFile bookmarksFile
) {
2109 fBookmarksFile
= bookmarksFile
;
2110 if (bookmarksFile
== null) {
2111 fBookmarksMap
.clear();
2116 fBookmarksMap
.clear();
2117 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2118 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2119 if (location
!= -1) {
2120 final long rank
= location
;
2121 fBookmarksMap
.put(rank
, bookmark
.getId());
2125 } catch (final CoreException e
) {
2126 displayException(e
);
2131 public void gotoMarker(final IMarker marker
) {
2132 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2135 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2136 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2137 } else if (rank
>= fTable
.getItemCount()) {
2138 fPendingGotoRank
= rank
;
2140 fSelectedRank
= rank
;
2141 fTable
.setSelection(index
+ 1); // +1 for header row
2142 updateStatusLine(null);
2146 // ------------------------------------------------------------------------
2148 // ------------------------------------------------------------------------
2151 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2155 // ------------------------------------------------------------------------
2157 // ------------------------------------------------------------------------
2160 * Handler for the trace updated signal
2163 * The incoming signal
2166 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2167 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2170 // Perform the refresh on the UI thread
2171 Display
.getDefault().asyncExec(new Runnable() {
2174 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2175 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2176 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2177 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2178 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2179 fPendingGotoRank
= -1;
2180 updateStatusLine(null);
2183 startFilterThread();
2186 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2187 fRawViewer
.refreshEventCount();
2194 * Handler for the time synch signal.
2197 * The incoming signal
2200 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2201 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2203 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2204 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2205 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2206 final TmfDataRequest subRequest
= new TmfDataRequest(ITmfEvent
.class,
2207 0, 1, ExecutionType
.FOREGROUND
) {
2209 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2212 public void handleData(final ITmfEvent event
) {
2213 super.handleData(event
);
2217 public void handleCompleted() {
2218 super.handleCompleted();
2219 if (fTrace
== null) {
2223 // Verify if the event is within the trace range and adjust if necessary
2224 ITmfTimestamp timestamp
= ts
;
2225 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2226 timestamp
= fTrace
.getStartTime();
2228 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2229 timestamp
= fTrace
.getEndTime();
2232 // Get the rank of the selected event in the table
2233 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2234 final long rank
= context
.getRank();
2236 fSelectedRank
= rank
;
2238 fTable
.getDisplay().asyncExec(new Runnable() {
2241 // Return if table is disposed
2242 if (fTable
.isDisposed()) {
2246 int index
= (int) rank
;
2247 if (fTable
.isDisposed()) {
2250 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2251 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2253 fTable
.setSelection(index
+ 1); // +1 for header row
2254 fRawViewer
.selectAndReveal(rank
);
2255 updateStatusLine(null);
2261 ((ITmfDataProvider
) fTrace
).sendRequest(subRequest
);
2265 // ------------------------------------------------------------------------
2267 // ------------------------------------------------------------------------
2270 * Display an exception in a message box
2272 * @param e the exception
2274 private static void displayException(final Exception e
) {
2275 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2276 mb
.setText(e
.getClass().getSimpleName());
2277 mb
.setMessage(e
.getMessage());
2284 public void refresh() {