1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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
.commands
.Command
;
31 import org
.eclipse
.core
.commands
.ExecutionException
;
32 import org
.eclipse
.core
.commands
.NotEnabledException
;
33 import org
.eclipse
.core
.commands
.NotHandledException
;
34 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
35 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
36 import org
.eclipse
.core
.expressions
.IEvaluationContext
;
37 import org
.eclipse
.core
.resources
.IFile
;
38 import org
.eclipse
.core
.resources
.IMarker
;
39 import org
.eclipse
.core
.resources
.IResource
;
40 import org
.eclipse
.core
.resources
.IResourceVisitor
;
41 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
42 import org
.eclipse
.core
.runtime
.CoreException
;
43 import org
.eclipse
.core
.runtime
.IPath
;
44 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
45 import org
.eclipse
.core
.runtime
.IStatus
;
46 import org
.eclipse
.core
.runtime
.ListenerList
;
47 import org
.eclipse
.core
.runtime
.Path
;
48 import org
.eclipse
.core
.runtime
.Status
;
49 import org
.eclipse
.core
.runtime
.jobs
.Job
;
50 import org
.eclipse
.emf
.common
.util
.URI
;
51 import org
.eclipse
.emf
.ecore
.EValidator
;
52 import org
.eclipse
.jface
.action
.Action
;
53 import org
.eclipse
.jface
.action
.IAction
;
54 import org
.eclipse
.jface
.action
.IMenuListener
;
55 import org
.eclipse
.jface
.action
.IMenuManager
;
56 import org
.eclipse
.jface
.action
.IStatusLineManager
;
57 import org
.eclipse
.jface
.action
.MenuManager
;
58 import org
.eclipse
.jface
.action
.Separator
;
59 import org
.eclipse
.jface
.dialogs
.InputDialog
;
60 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
61 import org
.eclipse
.jface
.resource
.FontDescriptor
;
62 import org
.eclipse
.jface
.resource
.JFaceResources
;
63 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
64 import org
.eclipse
.jface
.util
.OpenStrategy
;
65 import org
.eclipse
.jface
.util
.SafeRunnable
;
66 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
67 import org
.eclipse
.jface
.viewers
.ISelection
;
68 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
69 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
70 import org
.eclipse
.jface
.viewers
.LabelProvider
;
71 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
72 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
73 import org
.eclipse
.jface
.window
.Window
;
74 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
75 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
76 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
77 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
78 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfEventProvider
;
79 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
80 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
81 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfCallsite
;
82 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
83 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
84 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
85 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
86 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
87 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
88 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
89 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
90 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
91 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
92 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
93 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
94 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
95 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
96 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
97 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
98 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
99 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
100 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
101 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
102 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
103 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSetting
;
104 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
105 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
106 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
107 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
108 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
;
109 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
110 import org
.eclipse
.swt
.SWT
;
111 import org
.eclipse
.swt
.custom
.SashForm
;
112 import org
.eclipse
.swt
.custom
.TableEditor
;
113 import org
.eclipse
.swt
.events
.FocusAdapter
;
114 import org
.eclipse
.swt
.events
.FocusEvent
;
115 import org
.eclipse
.swt
.events
.KeyAdapter
;
116 import org
.eclipse
.swt
.events
.KeyEvent
;
117 import org
.eclipse
.swt
.events
.MouseAdapter
;
118 import org
.eclipse
.swt
.events
.MouseEvent
;
119 import org
.eclipse
.swt
.events
.SelectionAdapter
;
120 import org
.eclipse
.swt
.events
.SelectionEvent
;
121 import org
.eclipse
.swt
.graphics
.Color
;
122 import org
.eclipse
.swt
.graphics
.Font
;
123 import org
.eclipse
.swt
.graphics
.Image
;
124 import org
.eclipse
.swt
.graphics
.Point
;
125 import org
.eclipse
.swt
.graphics
.Rectangle
;
126 import org
.eclipse
.swt
.layout
.FillLayout
;
127 import org
.eclipse
.swt
.layout
.GridData
;
128 import org
.eclipse
.swt
.layout
.GridLayout
;
129 import org
.eclipse
.swt
.widgets
.Composite
;
130 import org
.eclipse
.swt
.widgets
.Display
;
131 import org
.eclipse
.swt
.widgets
.Event
;
132 import org
.eclipse
.swt
.widgets
.Label
;
133 import org
.eclipse
.swt
.widgets
.Listener
;
134 import org
.eclipse
.swt
.widgets
.Menu
;
135 import org
.eclipse
.swt
.widgets
.MessageBox
;
136 import org
.eclipse
.swt
.widgets
.Shell
;
137 import org
.eclipse
.swt
.widgets
.TableColumn
;
138 import org
.eclipse
.swt
.widgets
.TableItem
;
139 import org
.eclipse
.swt
.widgets
.Text
;
140 import org
.eclipse
.ui
.IWorkbenchPage
;
141 import org
.eclipse
.ui
.PlatformUI
;
142 import org
.eclipse
.ui
.commands
.ICommandService
;
143 import org
.eclipse
.ui
.dialogs
.ListDialog
;
144 import org
.eclipse
.ui
.handlers
.IHandlerService
;
145 import org
.eclipse
.ui
.ide
.IDE
;
146 import org
.eclipse
.ui
.ide
.IGotoMarker
;
147 import org
.eclipse
.ui
.themes
.ColorUtil
;
150 * The generic TMF Events table
152 * This is a view that will list events that are read from a trace.
155 * @author Francois Chouinard
156 * @author Patrick Tasse
159 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
162 * Empty string array, used by {@link #getItemStrings}.
165 protected static final String
[] EMPTY_STRING_ARRAY
= new String
[0];
167 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
168 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
169 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
170 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
171 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
172 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
173 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
174 private static final Image FILTER_IMAGE
= Activator
.getDefault()
175 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
176 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
177 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
178 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
179 private static final int MAX_CACHE_SIZE
= 1000;
182 * The events table search/filter keys
185 * @author Patrick Tasse
187 public interface Key
{
189 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
192 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
195 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
198 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
201 String TIMESTAMP
= "$time"; //$NON-NLS-1$
204 String RANK
= "$rank"; //$NON-NLS-1$
207 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
209 /** Bookmark indicator */
210 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
214 * The events table search/filter state
217 * @author Patrick Tasse
219 public static enum HeaderState
{
220 /** A search is being run */
223 /** A filter is applied */
227 interface Direction
{
232 // ------------------------------------------------------------------------
234 // ------------------------------------------------------------------------
236 /** The virtual event table */
237 protected TmfVirtualTable fTable
;
239 private Composite fComposite
;
240 private SashForm fSashForm
;
241 private TmfRawEventViewer fRawViewer
;
242 private ITmfTrace fTrace
;
243 private boolean fPackDone
= false;
244 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
245 private long fSelectedRank
= 0;
246 private ITmfTimestamp fSelectedBeginTimestamp
= null;
247 private IStatusLineManager fStatusLineManager
= null;
250 private long fFilterMatchCount
;
251 private long fFilterCheckCount
;
252 private FilterThread fFilterThread
;
253 private boolean fFilterThreadResume
= false;
254 private final Object fFilterSyncObj
= new Object();
255 private SearchThread fSearchThread
;
256 private final Object fSearchSyncObj
= new Object();
259 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
261 * @see #fireSelectionChanged
263 private ListenerList selectionChangedListeners
= new ListenerList();
265 // Bookmark map <Rank, MarkerId>
266 private Map
<Long
, Long
> fBookmarksMap
= new HashMap
<>();
267 private IFile fBookmarksFile
;
268 private long fPendingGotoRank
= -1;
271 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
272 private Color fGrayColor
;
273 private Color fGreenColor
;
274 private Font fBoldFont
;
276 // Table column names
277 private static final String
[] COLUMN_NAMES
= new String
[] { Messages
.TmfEventsTable_TimestampColumnHeader
,
278 Messages
.TmfEventsTable_SourceColumnHeader
, Messages
.TmfEventsTable_TypeColumnHeader
,
279 Messages
.TmfEventsTable_ReferenceColumnHeader
, Messages
.TmfEventsTable_ContentColumnHeader
};
281 private static final ColumnData
[] COLUMN_DATA
= new ColumnData
[] { new ColumnData(COLUMN_NAMES
[0], 100, SWT
.LEFT
),
282 new ColumnData(COLUMN_NAMES
[1], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[2], 100, SWT
.LEFT
),
283 new ColumnData(COLUMN_NAMES
[3], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[4], 100, SWT
.LEFT
) };
286 private final TmfEventsCache fCache
;
287 private boolean fCacheUpdateBusy
= false;
288 private boolean fCacheUpdatePending
= false;
289 private boolean fCacheUpdateCompleted
= false;
290 private final Object fCacheUpdateSyncObj
= new Object();
292 private boolean fDisposeOnClose
;
294 // ------------------------------------------------------------------------
296 // ------------------------------------------------------------------------
299 * Basic constructor, will use default column data.
302 * The parent composite UI object
304 * The size of the event table cache
306 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
307 this(parent
, cacheSize
, COLUMN_DATA
);
311 * Advanced constructor, where we also define which column data to use.
314 * The parent composite UI object
316 * The size of the event table cache
318 * The column data to use for this table
320 public TmfEventsTable(final Composite parent
, int cacheSize
, final ColumnData
[] columnData
) {
321 super("TmfEventsTable"); //$NON-NLS-1$
323 fComposite
= new Composite(parent
, SWT
.NONE
);
324 final GridLayout gl
= new GridLayout(1, false);
327 gl
.verticalSpacing
= 0;
328 fComposite
.setLayout(gl
);
330 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
331 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
333 // Create a virtual table
334 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
335 fTable
= new TmfVirtualTable(fSashForm
, style
);
337 // Set the table layout
338 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
339 fTable
.setLayoutData(layoutData
);
341 // Some cosmetic enhancements
342 fTable
.setHeaderVisible(true);
343 fTable
.setLinesVisible(true);
346 setColumnHeaders(columnData
);
348 // Set the default column field ids if this is not a subclass
349 if (Arrays
.equals(columnData
, COLUMN_DATA
)) {
350 fTable
.getColumns()[0].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
351 fTable
.getColumns()[1].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_SOURCE
);
352 fTable
.getColumns()[2].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TYPE
);
353 fTable
.getColumns()[3].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_REFERENCE
);
354 fTable
.getColumns()[4].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_CONTENT
);
357 // Set the frozen row for header row
358 fTable
.setFrozenRowCount(1);
360 // Create the header row cell editor
361 createHeaderEditor();
363 // Handle the table item selection
364 fTable
.addSelectionListener(new SelectionAdapter() {
366 public void widgetSelected(final SelectionEvent e
) {
367 if (e
.item
== null) {
370 updateStatusLine(null);
371 if (fTable
.getSelectionIndices().length
> 0) {
372 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
373 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
374 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
376 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
377 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
378 if (fTable
.getSelectionIndices().length
== 1) {
379 fSelectedBeginTimestamp
= ts
;
381 if (fSelectedBeginTimestamp
!= null) {
382 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
383 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
384 if (fTable
.getSelectionIndices().length
== 2) {
385 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
388 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
389 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
393 if (fTable
.getSelectionIndices().length
== 1) {
394 fSelectedBeginTimestamp
= null;
398 if (e
.item
.getData() != null) {
399 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
401 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
406 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
407 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
408 fCache
= new TmfEventsCache(realCacheSize
, this);
410 // Handle the table item requests
411 fTable
.addListener(SWT
.SetData
, new Listener() {
414 public void handleEvent(final Event event
) {
416 final TableItem item
= (TableItem
) event
.item
;
417 int index
= event
.index
- 1; // -1 for the header row
419 if (event
.index
== 0) {
420 setHeaderRowItemData(item
);
424 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
425 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
426 setFilterStatusRowItemData(item
);
429 index
= index
- 1; // -1 for top filter status row
432 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
433 if (cachedEvent
!= null) {
434 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
438 // Else, fill the cache asynchronously (and off the UI thread)
443 fTable
.addMouseListener(new MouseAdapter() {
445 public void mouseDoubleClick(final MouseEvent event
) {
446 if (event
.button
!= 1) {
449 // Identify the selected row
450 final Point point
= new Point(event
.x
, event
.y
);
451 final TableItem item
= fTable
.getItem(point
);
453 final Rectangle imageBounds
= item
.getImageBounds(0);
454 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
455 if (imageBounds
.contains(point
)) {
456 final Long rank
= (Long
) item
.getData(Key
.RANK
);
458 toggleBookmark(rank
);
465 final Listener tooltipListener
= new Listener () {
466 Shell tooltipShell
= null;
468 public void handleEvent(final Event event
) {
469 switch (event
.type
) {
471 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
475 final Long rank
= (Long
) item
.getData(Key
.RANK
);
479 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
480 final Rectangle bounds
= item
.getImageBounds(0);
481 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
482 if (!bounds
.contains(event
.x
,event
.y
)) {
485 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
486 tooltipShell
.dispose();
488 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
489 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
490 final FillLayout layout
= new FillLayout();
491 layout
.marginWidth
= 2;
492 tooltipShell
.setLayout(layout
);
493 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
494 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: ""); //$NON-NLS-1$ //$NON-NLS-2$
495 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
496 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
498 label
.addListener(SWT
.MouseExit
, this);
499 label
.addListener(SWT
.MouseDown
, this);
500 label
.addListener(SWT
.MouseWheel
, this);
501 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
503 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
504 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
507 if (System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
508 y
+= fTable
.getHeaderHeight();
510 Point pt
= fTable
.toDisplay(event
.x
, y
);
511 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
512 pt
.y
+= item
.getBounds().height
;
513 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
514 tooltipShell
.setVisible(true);
522 if (tooltipShell
!= null) {
523 tooltipShell
.dispose();
533 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
534 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
535 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
536 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
537 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
538 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
539 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
544 ColorSettingsManager
.addColorSettingsListener(this);
546 fTable
.setItemCount(1); // +1 for header row
548 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
550 fRawViewer
.addSelectionListener(new Listener() {
552 public void handleEvent(final Event e
) {
553 if (e
.data
instanceof Long
) {
554 final long rank
= (Long
) e
.data
;
555 int index
= (int) rank
;
556 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
557 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
559 fTable
.setSelection(index
+ 1); // +1 for header row
560 fSelectedRank
= rank
;
561 updateStatusLine(null);
562 } else if (e
.data
instanceof ITmfLocation
) {
563 // DOES NOT WORK: rank undefined in context from seekLocation()
564 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
565 // TmfContext context = fTrace.seekLocation(location);
566 // fTable.setSelection((int) context.getRank());
571 final TableItem
[] selection
= fTable
.getSelection();
572 if ((selection
!= null) && (selection
.length
> 0)) {
573 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
575 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
581 fSashForm
.setWeights(new int[] { 1, 1 });
582 fRawViewer
.setVisible(false);
588 * Create a pop-up menu.
590 protected void createPopupMenu() {
591 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
594 fTable
.setVisible(true);
599 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
602 fTable
.setVisible(false);
607 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
610 fRawViewer
.setVisible(true);
612 final int index
= fTable
.getSelectionIndex();
614 fRawViewer
.selectAndReveal(index
- 1);
619 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
622 fRawViewer
.setVisible(false);
627 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
630 final TableItem items
[] = fTable
.getSelection();
631 if (items
.length
!= 1) {
634 final TableItem item
= items
[0];
636 final Object data
= item
.getData();
637 if (data
instanceof ITmfSourceLookup
) {
638 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
639 ITmfCallsite cs
= event
.getCallsite();
640 if (cs
== null || cs
.getFileName() == null) {
643 IMarker marker
= null;
645 String fileName
= cs
.getFileName();
646 final String trimmedPath
= fileName
.replaceAll("\\.\\./", ""); //$NON-NLS-1$ //$NON-NLS-2$
647 final ArrayList
<IFile
> files
= new ArrayList
<>();
648 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
650 public boolean visit(IResource resource
) throws CoreException
{
651 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
652 files
.add((IFile
) resource
);
658 if (files
.size() > 1) {
659 ListDialog dialog
= new ListDialog(getTable().getShell());
660 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
661 dialog
.setLabelProvider(new LabelProvider() {
663 public String
getText(Object element
) {
664 return ((IFile
) element
).getFullPath().toString();
667 dialog
.setInput(files
);
668 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
669 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
671 Object
[] result
= dialog
.getResult();
672 if (result
!= null && result
.length
> 0) {
673 file
= (IFile
) result
[0];
675 } else if (files
.size() == 1) {
679 marker
= file
.createMarker(IMarker
.MARKER
);
680 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
681 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
683 } else if (files
.size() == 0){
684 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
686 } catch (CoreException e
) {
693 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
697 final TableItem items
[] = fTable
.getSelection();
698 if (items
.length
!= 1) {
701 final TableItem item
= items
[0];
703 final Object eventData
= item
.getData();
704 if (eventData
instanceof ITmfModelLookup
) {
705 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
707 if (modelURI
!= null) {
708 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
711 final URI uri
= URI
.createURI(modelURI
);
712 if (uri
.isPlatformResource()) {
713 IPath path
= new Path(uri
.toPlatformString(true));
714 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
715 } else if (uri
.isFile() && !uri
.isRelative()) {
716 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
717 new Path(uri
.toFileString()));
723 * create a temporary validation marker on the
724 * model file, remove it afterwards thus,
725 * navigation works with all model editors
726 * supporting the navigation to a marker
728 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
729 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
730 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
732 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
735 catch (CoreException e
) {
739 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
746 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
749 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
750 IHandlerService handlerService
= (IHandlerService
) activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
751 ICommandService cmdService
= (ICommandService
) activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
753 HashMap
<String
, Object
> parameters
= new HashMap
<>();
754 StringBuilder header
= new StringBuilder();
755 boolean needTab
= false;
756 for (TableColumn tc
: fTable
.getColumns()) {
760 header
.append(tc
.getText());
763 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
764 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
,parameters
);
765 IEvaluationContext context
= handlerService
.getCurrentState();
766 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_HEADER_ID
, header
.toString());
767 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_PARAMETER_ID
, TmfEventsTable
.this);
768 handlerService
.executeCommandInContext(cmd
, null, context
);
769 } catch (ExecutionException e
) {
771 } catch (NotDefinedException e
) {
773 } catch (NotEnabledException e
) {
775 } catch (NotHandledException e
) {
781 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
784 fHeaderState
= HeaderState
.SEARCH
;
789 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
792 fHeaderState
= HeaderState
.FILTER
;
797 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
804 class ToggleBookmarkAction
extends Action
{
807 public ToggleBookmarkAction(final String text
, final Long rank
) {
814 toggleBookmark(fRank
);
818 final MenuManager tablePopupMenu
= new MenuManager();
819 tablePopupMenu
.setRemoveAllWhenShown(true);
820 tablePopupMenu
.addMenuListener(new IMenuListener() {
822 public void menuAboutToShow(final IMenuManager manager
) {
823 if (fTable
.getSelectionIndex() == 0) {
824 // Right-click on header row
825 if (fHeaderState
== HeaderState
.FILTER
) {
826 tablePopupMenu
.add(showSearchBarAction
);
828 tablePopupMenu
.add(showFilterBarAction
);
832 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
833 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
835 final Rectangle imageBounds
= item
.getImageBounds(0);
836 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
837 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
838 // Right-click on left margin
839 final Long rank
= (Long
) item
.getData(Key
.RANK
);
840 if ((rank
!= null) && (fBookmarksFile
!= null)) {
841 if (fBookmarksMap
.containsKey(rank
)) {
842 tablePopupMenu
.add(new ToggleBookmarkAction(
843 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
845 tablePopupMenu
.add(new ToggleBookmarkAction(
846 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
853 // Right-click on table
854 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
855 tablePopupMenu
.add(hideTableAction
);
856 tablePopupMenu
.add(hideRawAction
);
857 } else if (!fTable
.isVisible()) {
858 tablePopupMenu
.add(showTableAction
);
859 } else if (!fRawViewer
.isVisible()) {
860 tablePopupMenu
.add(showRawAction
);
862 tablePopupMenu
.add(exportToTextAction
);
863 tablePopupMenu
.add(new Separator());
866 final Object data
= item
.getData();
867 Separator separator
= null;
868 if (data
instanceof ITmfSourceLookup
) {
869 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
870 if (event
.getCallsite() != null) {
871 tablePopupMenu
.add(openCallsiteAction
);
872 separator
= new Separator();
876 if (data
instanceof ITmfModelLookup
) {
877 ITmfModelLookup event
= (ITmfModelLookup
) data
;
878 if (event
.getModelUri() != null) {
879 tablePopupMenu
.add(openModelAction
);
880 separator
= new Separator();
883 if (separator
!= null) {
884 tablePopupMenu
.add(separator
);
889 tablePopupMenu
.add(clearFiltersAction
);
890 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
891 if (savedFilters
.length
> 0) {
892 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
893 for (final ITmfFilterTreeNode node
: savedFilters
) {
894 if (node
instanceof TmfFilterNode
) {
895 final TmfFilterNode filter
= (TmfFilterNode
) node
;
896 subMenu
.add(new Action(filter
.getFilterName()) {
904 tablePopupMenu
.add(subMenu
);
906 appendToTablePopupMenu(tablePopupMenu
, item
);
910 final MenuManager rawViewerPopupMenu
= new MenuManager();
911 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
912 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
914 public void menuAboutToShow(final IMenuManager manager
) {
915 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
916 rawViewerPopupMenu
.add(hideTableAction
);
917 rawViewerPopupMenu
.add(hideRawAction
);
918 } else if (!fTable
.isVisible()) {
919 rawViewerPopupMenu
.add(showTableAction
);
920 } else if (!fRawViewer
.isVisible()) {
921 rawViewerPopupMenu
.add(showRawAction
);
923 appendToRawPopupMenu(tablePopupMenu
);
927 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
928 fTable
.setMenu(menu
);
930 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
931 fRawViewer
.setMenu(menu
);
936 * Append an item to the event table's pop-up menu.
938 * @param tablePopupMenu
940 * @param selectedItem
943 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
944 // override to append more actions
948 * Append an item to the raw viewer's pop-up menu.
950 * @param rawViewerPopupMenu
953 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
954 // override to append more actions
958 public void dispose() {
961 ColorSettingsManager
.removeColorSettingsListener(this);
962 fComposite
.dispose();
963 if ((fTrace
!= null) && fDisposeOnClose
) {
966 fResourceManager
.dispose();
967 fRawViewer
.dispose();
972 * Assign a layout data object to this view.
975 * The layout data to assign
977 public void setLayoutData(final Object layoutData
) {
978 fComposite
.setLayoutData(layoutData
);
982 * Get the virtual table contained in this event table.
984 * @return The TMF virtual table
986 public TmfVirtualTable
getTable() {
993 * FIXME: Add support for column selection
995 protected void setColumnHeaders(final ColumnData
[] columnData
) {
996 fTable
.setColumnHeaders(columnData
);
1000 * Set a table item's data.
1005 * Which trace event to link with this entry
1007 * Which rank this event has in the trace/experiment
1009 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1010 item
.setText(getItemStrings(event
));
1011 item
.setData(event
);
1012 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1013 item
.setData(Key
.RANK
, rank
);
1015 boolean bookmark
= false;
1016 final Long markerId
= fBookmarksMap
.get(rank
);
1017 if (markerId
!= null) {
1020 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1021 item
.setData(Key
.BOOKMARK
, marker
.getAttribute(IMarker
.MESSAGE
));
1022 } catch (final CoreException e
) {
1023 displayException(e
);
1026 item
.setData(Key
.BOOKMARK
, null);
1029 boolean searchMatch
= false;
1030 boolean searchNoMatch
= false;
1031 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1032 if (searchFilter
!= null) {
1033 if (searchFilter
.matches(event
)) {
1036 searchNoMatch
= true;
1040 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1041 if (searchNoMatch
) {
1042 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1043 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1045 item
.setForeground(colorSetting
.getForegroundColor());
1046 item
.setBackground(colorSetting
.getBackgroundColor());
1051 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1053 item
.setImage(SEARCH_MATCH_IMAGE
);
1055 } else if (bookmark
) {
1056 item
.setImage(BOOKMARK_IMAGE
);
1058 item
.setImage((Image
) null);
1063 * Set the item data of the header row.
1066 * The item to use as table header
1068 protected void setHeaderRowItemData(final TableItem item
) {
1069 String txtKey
= null;
1070 if (fHeaderState
== HeaderState
.SEARCH
) {
1071 item
.setImage(SEARCH_IMAGE
);
1072 txtKey
= Key
.SEARCH_TXT
;
1073 } else if (fHeaderState
== HeaderState
.FILTER
) {
1074 item
.setImage(FILTER_IMAGE
);
1075 txtKey
= Key
.FILTER_TXT
;
1077 item
.setForeground(fGrayColor
);
1078 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1079 final TableColumn column
= fTable
.getColumns()[i
];
1080 final String filter
= (String
) column
.getData(txtKey
);
1081 if (filter
== null) {
1082 if (fHeaderState
== HeaderState
.SEARCH
) {
1083 item
.setText(i
, SEARCH_HINT
);
1084 } else if (fHeaderState
== HeaderState
.FILTER
) {
1085 item
.setText(i
, FILTER_HINT
);
1087 item
.setForeground(i
, fGrayColor
);
1088 item
.setFont(i
, fTable
.getFont());
1090 item
.setText(i
, filter
);
1091 item
.setForeground(i
, fGreenColor
);
1092 item
.setFont(i
, fBoldFont
);
1098 * Set the item data of the "filter status" row.
1101 * The item to use as filter status row
1103 protected void setFilterStatusRowItemData(final TableItem item
) {
1104 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1106 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1107 item
.setImage(FILTER_IMAGE
);
1109 item
.setImage(STOP_IMAGE
);
1111 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1113 item
.setText(i
, ""); //$NON-NLS-1$
1117 item
.setData(Key
.TIMESTAMP
, null);
1118 item
.setData(Key
.RANK
, null);
1119 item
.setForeground(null);
1120 item
.setBackground(null);
1124 * Create an editor for the header.
1126 protected void createHeaderEditor() {
1127 final TableEditor tableEditor
= fTable
.createTableEditor();
1128 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1129 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1130 tableEditor
.grabHorizontal
= true;
1131 tableEditor
.minimumWidth
= 50;
1133 // Handle the header row selection
1134 fTable
.addMouseListener(new MouseAdapter() {
1140 public void mouseDown(final MouseEvent event
) {
1141 if (event
.button
!= 1) {
1144 // Identify the selected row
1145 final Point point
= new Point(event
.x
, event
.y
);
1146 item
= fTable
.getItem(point
);
1148 // Header row selected
1149 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1152 if (item
.getImageBounds(0).contains(point
)) {
1153 if (fHeaderState
== HeaderState
.SEARCH
) {
1154 fHeaderState
= HeaderState
.FILTER
;
1155 } else if (fHeaderState
== HeaderState
.FILTER
) {
1156 fHeaderState
= HeaderState
.SEARCH
;
1158 fTable
.setSelection(0);
1163 // Identify the selected column
1165 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1166 final Rectangle rect
= item
.getBounds(i
);
1167 if (rect
.contains(point
)) {
1173 if (columnIndex
== -1) {
1177 column
= fTable
.getColumns()[columnIndex
];
1179 String txtKey
= null;
1180 if (fHeaderState
== HeaderState
.SEARCH
) {
1181 txtKey
= Key
.SEARCH_TXT
;
1182 } else if (fHeaderState
== HeaderState
.FILTER
) {
1183 txtKey
= Key
.FILTER_TXT
;
1186 // The control that will be the editor must be a child of the Table
1187 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1188 final String headerString
= (String
) column
.getData(txtKey
);
1189 if (headerString
!= null) {
1190 newEditor
.setText(headerString
);
1192 newEditor
.addFocusListener(new FocusAdapter() {
1194 public void focusLost(final FocusEvent e
) {
1195 final boolean changed
= updateHeader(newEditor
.getText());
1201 newEditor
.addKeyListener(new KeyAdapter() {
1203 public void keyPressed(final KeyEvent e
) {
1204 if (e
.character
== SWT
.CR
) {
1205 updateHeader(newEditor
.getText());
1208 // Set focus on the table so that the next carriage return goes to the next result
1209 TmfEventsTable
.this.getTable().setFocus();
1210 } else if (e
.character
== SWT
.ESC
) {
1211 tableEditor
.getEditor().dispose();
1215 newEditor
.selectAll();
1216 newEditor
.setFocus();
1217 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1222 * returns true is value was changed
1224 private boolean updateHeader(final String text
) {
1225 String objKey
= null;
1226 String txtKey
= null;
1227 if (fHeaderState
== HeaderState
.SEARCH
) {
1228 objKey
= Key
.SEARCH_OBJ
;
1229 txtKey
= Key
.SEARCH_TXT
;
1230 } else if (fHeaderState
== HeaderState
.FILTER
) {
1231 objKey
= Key
.FILTER_OBJ
;
1232 txtKey
= Key
.FILTER_TXT
;
1234 if (text
.trim().length() > 0) {
1236 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1237 Pattern
.compile(regex
);
1238 if (regex
.equals(column
.getData(txtKey
))) {
1239 tableEditor
.getEditor().dispose();
1242 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1243 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1244 if (fieldId
== null) {
1245 fieldId
= column
.getText();
1247 filter
.setField(fieldId
);
1248 filter
.setRegex(regex
);
1249 column
.setData(objKey
, filter
);
1250 column
.setData(txtKey
, regex
);
1251 } catch (final PatternSyntaxException ex
) {
1252 tableEditor
.getEditor().dispose();
1253 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1254 ex
.getDescription(), ex
.getMessage());
1258 if (column
.getData(txtKey
) == null) {
1259 tableEditor
.getEditor().dispose();
1262 column
.setData(objKey
, null);
1263 column
.setData(txtKey
, null);
1268 private void applyHeader() {
1269 if (fHeaderState
== HeaderState
.SEARCH
) {
1271 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1272 for (final TableColumn col
: fTable
.getColumns()) {
1273 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1274 if (filterObj
instanceof ITmfFilterTreeNode
) {
1275 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1278 if (filter
.getChildrenCount() > 0) {
1279 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1282 fireSearchApplied(filter
);
1284 fTable
.setData(Key
.SEARCH_OBJ
, null);
1286 fireSearchApplied(null);
1288 } else if (fHeaderState
== HeaderState
.FILTER
) {
1289 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1290 for (final TableColumn col
: fTable
.getColumns()) {
1291 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1292 if (filterObj
instanceof ITmfFilterTreeNode
) {
1293 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1296 if (filter
.getChildrenCount() > 0) {
1297 applyFilter(filter
);
1303 tableEditor
.getEditor().dispose();
1307 fTable
.addKeyListener(new KeyAdapter() {
1309 public void keyPressed(final KeyEvent e
) {
1311 if (e
.character
== SWT
.ESC
) {
1315 } else if (e
.character
== SWT
.DEL
) {
1316 if (fHeaderState
== HeaderState
.SEARCH
) {
1318 for (final TableColumn column
: fTable
.getColumns()) {
1319 column
.setData(Key
.SEARCH_OBJ
, null);
1320 column
.setData(Key
.SEARCH_TXT
, null);
1322 fTable
.setData(Key
.SEARCH_OBJ
, null);
1324 fireSearchApplied(null);
1325 } else if (fHeaderState
== HeaderState
.FILTER
) {
1328 } else if (e
.character
== SWT
.CR
) {
1329 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1340 * Send an event indicating a filter has been applied.
1343 * The filter that was just applied
1345 protected void fireFilterApplied(final ITmfFilter filter
) {
1346 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1350 * Send an event indicating that a search has been applied.
1353 * The search filter that was just applied
1355 protected void fireSearchApplied(final ITmfFilter filter
) {
1356 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1360 * Start the filtering thread.
1362 protected void startFilterThread() {
1363 synchronized (fFilterSyncObj
) {
1364 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1365 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1366 if (fFilterThread
!= null) {
1367 fFilterThread
.cancel();
1368 fFilterThreadResume
= false;
1370 fFilterThread
= new FilterThread(filter
);
1371 fFilterThread
.start();
1373 fFilterThreadResume
= true;
1379 * Stop the filtering thread.
1381 protected void stopFilterThread() {
1382 synchronized (fFilterSyncObj
) {
1383 if (fFilterThread
!= null) {
1384 fFilterThread
.cancel();
1385 fFilterThread
= null;
1386 fFilterThreadResume
= false;
1395 * The filter to apply
1398 protected void applyFilter(ITmfFilter filter
) {
1401 fFilterMatchCount
= 0;
1402 fFilterCheckCount
= 0;
1403 fCache
.applyFilter(filter
);
1405 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1406 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1407 startFilterThread();
1408 fireFilterApplied(filter
);
1412 * Clear all currently active filters.
1414 protected void clearFilters() {
1415 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1420 fCache
.clearFilter();
1422 for (final TableColumn column
: fTable
.getColumns()) {
1423 column
.setData(Key
.FILTER_OBJ
, null);
1424 column
.setData(Key
.FILTER_TXT
, null);
1426 fTable
.setData(Key
.FILTER_OBJ
, null);
1427 if (fTrace
!= null) {
1428 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1430 fTable
.setItemCount(1); // +1 for header row
1432 fFilterMatchCount
= 0;
1433 fFilterCheckCount
= 0;
1434 if (fSelectedRank
>= 0) {
1435 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1437 fTable
.setSelection(0);
1439 fireFilterApplied(null);
1440 updateStatusLine(null);
1444 * Wrapper Thread object for the filtering thread.
1446 protected class FilterThread
extends Thread
{
1447 private final ITmfFilterTreeNode filter
;
1448 private TmfEventRequest request
;
1449 private boolean refreshBusy
= false;
1450 private boolean refreshPending
= false;
1451 private final Object syncObj
= new Object();
1457 * The filter this thread will be processing
1459 public FilterThread(final ITmfFilterTreeNode filter
) {
1460 super("Filter Thread"); //$NON-NLS-1$
1461 this.filter
= filter
;
1466 if (fTrace
== null) {
1469 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1470 if (nbRequested
<= 0) {
1473 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1474 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1476 public void handleData(final ITmfEvent event
) {
1477 super.handleData(event
);
1478 if (request
.isCancelled()) {
1481 if (filter
.matches(event
)) {
1482 final long rank
= fFilterCheckCount
;
1483 final int index
= (int) fFilterMatchCount
;
1484 fFilterMatchCount
++;
1485 fCache
.storeEvent(event
, rank
, index
);
1487 } else if ((fFilterCheckCount
% 100) == 0) {
1490 fFilterCheckCount
++;
1493 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1495 request
.waitForCompletion();
1496 } catch (final InterruptedException e
) {
1499 synchronized (fFilterSyncObj
) {
1500 fFilterThread
= null;
1501 if (fFilterThreadResume
) {
1502 fFilterThreadResume
= false;
1503 fFilterThread
= new FilterThread(filter
);
1504 fFilterThread
.start();
1510 * Refresh the filter.
1512 public void refreshTable() {
1513 synchronized (syncObj
) {
1515 refreshPending
= true;
1520 Display
.getDefault().asyncExec(new Runnable() {
1523 if (request
.isCancelled()) {
1526 if (fTable
.isDisposed()) {
1529 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1531 synchronized (syncObj
) {
1532 refreshBusy
= false;
1533 if (refreshPending
) {
1534 refreshPending
= false;
1543 * Cancel this filtering thread.
1545 public void cancel() {
1546 if (request
!= null) {
1553 * Go to the next item of a search.
1555 protected void searchNext() {
1556 synchronized (fSearchSyncObj
) {
1557 if (fSearchThread
!= null) {
1560 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1561 if (searchFilter
== null) {
1564 final int selectionIndex
= fTable
.getSelectionIndex();
1566 if (selectionIndex
> 0) {
1567 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1569 // header row is selected, start at top event
1570 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1572 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1573 if (eventFilter
!= null) {
1574 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1576 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1577 fSearchThread
.schedule();
1582 * Go to the previous item of a search.
1584 protected void searchPrevious() {
1585 synchronized (fSearchSyncObj
) {
1586 if (fSearchThread
!= null) {
1589 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1590 if (searchFilter
== null) {
1593 final int selectionIndex
= fTable
.getSelectionIndex();
1595 if (selectionIndex
> 0) {
1596 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1598 // header row is selected, start at precedent of top event
1599 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1601 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1602 if (eventFilter
!= null) {
1603 startIndex
= startIndex
- 1; // -1 for top filter status row
1605 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1606 fSearchThread
.schedule();
1611 * Stop the search thread.
1613 protected void stopSearchThread() {
1614 fPendingGotoRank
= -1;
1615 synchronized (fSearchSyncObj
) {
1616 if (fSearchThread
!= null) {
1617 fSearchThread
.cancel();
1618 fSearchThread
= null;
1624 * Wrapper for the search thread.
1626 protected class SearchThread
extends Job
{
1628 private ITmfFilterTreeNode searchFilter
;
1629 private ITmfFilterTreeNode eventFilter
;
1630 private int startIndex
;
1631 private int direction
;
1633 private long foundRank
= -1;
1634 private TmfEventRequest request
;
1635 private ITmfTimestamp foundTimestamp
= null;
1640 * @param searchFilter
1642 * @param eventFilter
1645 * The index at which we should start searching
1646 * @param currentRank
1649 * In which direction should we search, forward or backwards
1651 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1652 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1653 final long currentRank
, final int direction
) {
1654 super(Messages
.TmfEventsTable_SearchingJobName
);
1655 this.searchFilter
= searchFilter
;
1656 this.eventFilter
= eventFilter
;
1657 this.startIndex
= startIndex
;
1658 this.rank
= currentRank
;
1659 this.direction
= direction
;
1663 protected IStatus
run(final IProgressMonitor monitor
) {
1664 if (fTrace
== null) {
1665 return Status
.OK_STATUS
;
1667 final Display display
= Display
.getDefault();
1668 if (startIndex
< 0) {
1669 rank
= (int) fTrace
.getNbEvents() - 1;
1670 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1673 int idx
= startIndex
;
1674 while (foundRank
== -1) {
1675 final CachedEvent event
= fCache
.peekEvent(idx
);
1676 if (event
== null) {
1680 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1681 foundRank
= event
.rank
;
1682 foundTimestamp
= event
.event
.getTimestamp();
1685 if (direction
== Direction
.FORWARD
) {
1691 if (foundRank
== -1) {
1692 if (direction
== Direction
.FORWARD
) {
1694 if (rank
> (fTrace
.getNbEvents() - 1)) {
1700 rank
= (int) fTrace
.getNbEvents() - 1;
1705 final int startRank
= (int) rank
;
1706 boolean wrapped
= false;
1707 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1708 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1709 if (direction
== Direction
.BACKWARD
) {
1710 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1712 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1713 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1714 long currentRank
= rank
;
1717 public void handleData(final ITmfEvent event
) {
1718 super.handleData(event
);
1719 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1720 foundRank
= currentRank
;
1721 foundTimestamp
= event
.getTimestamp();
1722 if (direction
== Direction
.FORWARD
) {
1730 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1732 request
.waitForCompletion();
1733 if (request
.isCancelled()) {
1734 return Status
.OK_STATUS
;
1736 } catch (final InterruptedException e
) {
1737 synchronized (fSearchSyncObj
) {
1738 fSearchThread
= null;
1740 return Status
.OK_STATUS
;
1742 if (foundRank
== -1) {
1743 if (direction
== Direction
.FORWARD
) {
1745 synchronized (fSearchSyncObj
) {
1746 fSearchThread
= null;
1748 return Status
.OK_STATUS
;
1750 nbRequested
= (int) rank
;
1756 rank
= (int) fTrace
.getNbEvents() - 1;
1759 if ((rank
<= startRank
) && wrapped
) {
1760 synchronized (fSearchSyncObj
) {
1761 fSearchThread
= null;
1763 return Status
.OK_STATUS
;
1768 int index
= (int) foundRank
;
1769 if (eventFilter
!= null) {
1770 index
= fCache
.getFilteredEventIndex(foundRank
);
1772 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1774 display
.asyncExec(new Runnable() {
1777 if (monitor
.isCanceled()) {
1780 if (fTable
.isDisposed()) {
1783 fTable
.setSelection(selection
);
1784 fSelectedRank
= foundRank
;
1785 fRawViewer
.selectAndReveal(fSelectedRank
);
1786 if (foundTimestamp
!= null) {
1787 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1789 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1790 synchronized (fSearchSyncObj
) {
1791 fSearchThread
= null;
1793 updateStatusLine(null);
1796 return Status
.OK_STATUS
;
1800 protected void canceling() {
1802 synchronized (fSearchSyncObj
) {
1803 fSearchThread
= null;
1809 * Create the resources.
1811 protected void createResources() {
1812 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1813 .getForeground().getRGB()));
1814 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1815 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1821 protected void packColumns() {
1825 fTable
.setRedraw(false);
1827 boolean isLinux
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
1829 TableColumn tableColumns
[] = fTable
.getColumns();
1830 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1831 final TableColumn column
= tableColumns
[i
];
1832 final int headerWidth
= column
.getWidth();
1834 // Workaround for Linux which doesn't consider the image width of
1835 // search/filter row in TableColumn.pack() after having executed
1836 // TableItem.setImage((Image)null) for other rows than search/filter row.
1837 if (isLinux
&& (i
== 0)) {
1838 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1841 if (column
.getWidth() < headerWidth
) {
1842 column
.setWidth(headerWidth
);
1846 fTable
.setRedraw(true);
1851 * Get the contents of the row in the events table corresponding to an
1852 * event. The order of the elements corresponds to the order of the columns.
1854 * TODO Use column IDs, not indexes, so that the column order can be
1858 * The event printed in this row
1859 * @return The event row entries
1862 public String
[] getItemStrings(ITmfEvent event
) {
1863 if (event
== null) {
1864 return EMPTY_STRING_ARRAY
;
1866 return new String
[] {
1867 event
.getTimestamp().toString(),
1869 event
.getType().getName(),
1870 event
.getReference(),
1871 event
.getContent().toString()
1876 * Notify this table that is got the UI focus.
1878 public void setFocus() {
1883 * Assign a new trace to this event table.
1886 * The trace to assign to this event table
1887 * @param disposeOnClose
1888 * true if the trace should be disposed when the table is
1891 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1892 if ((fTrace
!= null) && fDisposeOnClose
) {
1898 fDisposeOnClose
= disposeOnClose
;
1900 // Perform the updates on the UI thread
1901 fTable
.getDisplay().syncExec(new Runnable() {
1905 fCache
.setTrace(fTrace
); // Clear the cache
1906 if (fTrace
!= null) {
1907 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1908 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1909 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1912 fFilterMatchCount
= 0;
1913 fFilterCheckCount
= 0;
1914 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1915 startFilterThread();
1919 fRawViewer
.setTrace(fTrace
);
1925 * Assign the status line manager
1927 * @param statusLineManager
1928 * The status line manager, or null to disable status line messages
1931 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
1932 if (fStatusLineManager
!= null && statusLineManager
== null) {
1933 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
1935 fStatusLineManager
= statusLineManager
;
1938 private void updateStatusLine(ITmfTimestamp delta
) {
1939 if (fStatusLineManager
!= null) {
1940 if (delta
!= null) {
1941 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
1943 fStatusLineManager
.setMessage(null);
1948 // ------------------------------------------------------------------------
1950 // ------------------------------------------------------------------------
1953 * Notify that the event cache has been updated
1956 * Also notify if the populating of the cache is complete, or
1959 public void cacheUpdated(final boolean completed
) {
1960 synchronized (fCacheUpdateSyncObj
) {
1961 if (fCacheUpdateBusy
) {
1962 fCacheUpdatePending
= true;
1963 fCacheUpdateCompleted
= completed
;
1966 fCacheUpdateBusy
= true;
1968 // Event cache is now updated. Perform update on the UI thread
1969 if (!fTable
.isDisposed()) {
1970 fTable
.getDisplay().asyncExec(new Runnable() {
1973 if (!fTable
.isDisposed()) {
1978 populateCompleted();
1980 synchronized (fCacheUpdateSyncObj
) {
1981 fCacheUpdateBusy
= false;
1982 if (fCacheUpdatePending
) {
1983 fCacheUpdatePending
= false;
1984 cacheUpdated(fCacheUpdateCompleted
);
1993 * Callback for when populating the table is complete.
1995 protected void populateCompleted() {
1996 // Nothing by default;
1999 // ------------------------------------------------------------------------
2000 // ISelectionProvider
2001 // ------------------------------------------------------------------------
2007 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2008 selectionChangedListeners
.add(listener
);
2015 public ISelection
getSelection() {
2016 if (fTable
== null || fTable
.isDisposed()) {
2017 return StructuredSelection
.EMPTY
;
2019 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2020 for (TableItem item
: fTable
.getSelection()) {
2021 if (item
.getData() != null) {
2022 list
.add(item
.getData());
2025 return new StructuredSelection(list
);
2032 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2033 selectionChangedListeners
.remove(listener
);
2040 public void setSelection(ISelection selection
) {
2045 * Notifies any selection changed listeners that the viewer's selection has changed.
2046 * Only listeners registered at the time this method is called are notified.
2048 * @param event a selection changed event
2050 * @see ISelectionChangedListener#selectionChanged
2053 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2054 Object
[] listeners
= selectionChangedListeners
.getListeners();
2055 for (int i
= 0; i
< listeners
.length
; ++i
) {
2056 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2057 SafeRunnable
.run(new SafeRunnable() {
2060 l
.selectionChanged(event
);
2066 // ------------------------------------------------------------------------
2067 // Bookmark handling
2068 // ------------------------------------------------------------------------
2071 * Add a bookmark to this event table.
2073 * @param bookmarksFile
2074 * The file to use for the bookmarks
2076 public void addBookmark(final IFile bookmarksFile
) {
2077 fBookmarksFile
= bookmarksFile
;
2078 final TableItem
[] selection
= fTable
.getSelection();
2079 if (selection
.length
> 0) {
2080 final TableItem tableItem
= selection
[0];
2081 if (tableItem
.getData(Key
.RANK
) != null) {
2082 final StringBuffer defaultMessage
= new StringBuffer();
2083 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2085 defaultMessage
.append(", "); //$NON-NLS-1$
2087 defaultMessage
.append(tableItem
.getText(i
));
2089 final InputDialog dialog
= new MultiLineInputDialog(
2090 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2091 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2092 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2093 defaultMessage
.toString());
2094 if (dialog
.open() == Window
.OK
) {
2095 final String message
= dialog
.getValue();
2097 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2098 if (bookmark
.exists()) {
2099 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2100 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2101 final int location
= rank
.intValue();
2102 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2103 fBookmarksMap
.put(rank
, bookmark
.getId());
2106 } catch (final CoreException e
) {
2107 displayException(e
);
2116 * Remove a bookmark from this event table.
2119 * The bookmark to remove
2121 public void removeBookmark(final IMarker bookmark
) {
2122 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entrySet()) {
2123 if (entry
.getValue().equals(bookmark
.getId())) {
2124 fBookmarksMap
.remove(entry
.getKey());
2131 private void toggleBookmark(final Long rank
) {
2132 if (fBookmarksFile
== null) {
2135 if (fBookmarksMap
.containsKey(rank
)) {
2136 final Long markerId
= fBookmarksMap
.remove(rank
);
2139 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2140 if (bookmark
!= null) {
2143 } catch (final CoreException e
) {
2144 displayException(e
);
2147 addBookmark(fBookmarksFile
);
2152 * Refresh the bookmarks assigned to this trace, from the contents of a
2155 * @param bookmarksFile
2156 * The bookmark file to use
2158 public void refreshBookmarks(final IFile bookmarksFile
) {
2159 fBookmarksFile
= bookmarksFile
;
2160 if (bookmarksFile
== null) {
2161 fBookmarksMap
.clear();
2166 fBookmarksMap
.clear();
2167 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2168 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2169 if (location
!= -1) {
2170 final long rank
= location
;
2171 fBookmarksMap
.put(rank
, bookmark
.getId());
2175 } catch (final CoreException e
) {
2176 displayException(e
);
2181 public void gotoMarker(final IMarker marker
) {
2182 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2185 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2186 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2187 } else if (rank
>= fTable
.getItemCount()) {
2188 fPendingGotoRank
= rank
;
2190 fSelectedRank
= rank
;
2191 fTable
.setSelection(index
+ 1); // +1 for header row
2192 updateStatusLine(null);
2196 // ------------------------------------------------------------------------
2198 // ------------------------------------------------------------------------
2201 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2205 // ------------------------------------------------------------------------
2207 // ------------------------------------------------------------------------
2210 * Handler for the trace updated signal
2213 * The incoming signal
2216 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2217 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2220 // Perform the refresh on the UI thread
2221 Display
.getDefault().asyncExec(new Runnable() {
2224 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2225 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2226 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2227 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2228 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2229 fPendingGotoRank
= -1;
2230 updateStatusLine(null);
2233 startFilterThread();
2236 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2237 fRawViewer
.refreshEventCount();
2244 * Handler for the time synch signal.
2247 * The incoming signal
2250 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2251 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2253 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2254 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2255 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2256 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2257 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2259 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2262 public void handleData(final ITmfEvent event
) {
2263 super.handleData(event
);
2267 public void handleCompleted() {
2268 super.handleCompleted();
2269 if (fTrace
== null) {
2273 // Verify if the event is within the trace range and adjust if necessary
2274 ITmfTimestamp timestamp
= ts
;
2275 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2276 timestamp
= fTrace
.getStartTime();
2278 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2279 timestamp
= fTrace
.getEndTime();
2282 // Get the rank of the selected event in the table
2283 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2284 final long rank
= context
.getRank();
2286 fSelectedRank
= rank
;
2288 fTable
.getDisplay().asyncExec(new Runnable() {
2291 // Return if table is disposed
2292 if (fTable
.isDisposed()) {
2296 int index
= (int) rank
;
2297 if (fTable
.isDisposed()) {
2300 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2301 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2303 fTable
.setSelection(index
+ 1); // +1 for header row
2304 fRawViewer
.selectAndReveal(rank
);
2305 updateStatusLine(null);
2311 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2315 // ------------------------------------------------------------------------
2317 // ------------------------------------------------------------------------
2320 * Display an exception in a message box
2322 * @param e the exception
2324 private static void displayException(final Exception e
) {
2325 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2326 mb
.setText(e
.getClass().getSimpleName());
2327 mb
.setMessage(e
.getMessage());
2334 public void refresh() {