1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 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, replaced Table by TmfVirtualTable
11 * Patrick Tasse - Factored out from events view,
12 * Filter implementation (inspired by www.eclipse.org/mat)
13 * Ansgar Radermacher - Support navigation to model URIs (Bug 396956)
14 * Bernd Hufmann - Updated call site and model URI implementation
15 * Alexandre Montplaisir - Update to new column API
16 *******************************************************************************/
18 package org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
;
20 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
22 import java
.io
.FileNotFoundException
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Collection
;
25 import java
.util
.HashMap
;
26 import java
.util
.LinkedList
;
27 import java
.util
.List
;
28 import java
.util
.Map
.Entry
;
29 import java
.util
.regex
.Pattern
;
30 import java
.util
.regex
.PatternSyntaxException
;
32 import org
.eclipse
.core
.commands
.Command
;
33 import org
.eclipse
.core
.commands
.ExecutionException
;
34 import org
.eclipse
.core
.commands
.NotEnabledException
;
35 import org
.eclipse
.core
.commands
.NotHandledException
;
36 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
37 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
38 import org
.eclipse
.core
.expressions
.IEvaluationContext
;
39 import org
.eclipse
.core
.resources
.IFile
;
40 import org
.eclipse
.core
.resources
.IMarker
;
41 import org
.eclipse
.core
.resources
.IResource
;
42 import org
.eclipse
.core
.resources
.IResourceVisitor
;
43 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
44 import org
.eclipse
.core
.runtime
.CoreException
;
45 import org
.eclipse
.core
.runtime
.IPath
;
46 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
47 import org
.eclipse
.core
.runtime
.IStatus
;
48 import org
.eclipse
.core
.runtime
.ListenerList
;
49 import org
.eclipse
.core
.runtime
.Path
;
50 import org
.eclipse
.core
.runtime
.Status
;
51 import org
.eclipse
.core
.runtime
.jobs
.Job
;
52 import org
.eclipse
.emf
.common
.util
.URI
;
53 import org
.eclipse
.emf
.ecore
.EValidator
;
54 import org
.eclipse
.jdt
.annotation
.NonNull
;
55 import org
.eclipse
.jface
.action
.Action
;
56 import org
.eclipse
.jface
.action
.IAction
;
57 import org
.eclipse
.jface
.action
.IMenuListener
;
58 import org
.eclipse
.jface
.action
.IMenuManager
;
59 import org
.eclipse
.jface
.action
.IStatusLineManager
;
60 import org
.eclipse
.jface
.action
.MenuManager
;
61 import org
.eclipse
.jface
.action
.Separator
;
62 import org
.eclipse
.jface
.dialogs
.InputDialog
;
63 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
64 import org
.eclipse
.jface
.resource
.FontDescriptor
;
65 import org
.eclipse
.jface
.resource
.JFaceResources
;
66 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
67 import org
.eclipse
.jface
.util
.OpenStrategy
;
68 import org
.eclipse
.jface
.util
.SafeRunnable
;
69 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
70 import org
.eclipse
.jface
.viewers
.ISelection
;
71 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
72 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
73 import org
.eclipse
.jface
.viewers
.LabelProvider
;
74 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
75 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
76 import org
.eclipse
.jface
.window
.Window
;
77 import org
.eclipse
.swt
.SWT
;
78 import org
.eclipse
.swt
.custom
.SashForm
;
79 import org
.eclipse
.swt
.custom
.TableEditor
;
80 import org
.eclipse
.swt
.events
.ControlAdapter
;
81 import org
.eclipse
.swt
.events
.ControlEvent
;
82 import org
.eclipse
.swt
.events
.FocusAdapter
;
83 import org
.eclipse
.swt
.events
.FocusEvent
;
84 import org
.eclipse
.swt
.events
.KeyAdapter
;
85 import org
.eclipse
.swt
.events
.KeyEvent
;
86 import org
.eclipse
.swt
.events
.MouseAdapter
;
87 import org
.eclipse
.swt
.events
.MouseEvent
;
88 import org
.eclipse
.swt
.events
.SelectionAdapter
;
89 import org
.eclipse
.swt
.events
.SelectionEvent
;
90 import org
.eclipse
.swt
.graphics
.Color
;
91 import org
.eclipse
.swt
.graphics
.Font
;
92 import org
.eclipse
.swt
.graphics
.Image
;
93 import org
.eclipse
.swt
.graphics
.Point
;
94 import org
.eclipse
.swt
.graphics
.Rectangle
;
95 import org
.eclipse
.swt
.layout
.FillLayout
;
96 import org
.eclipse
.swt
.layout
.GridData
;
97 import org
.eclipse
.swt
.layout
.GridLayout
;
98 import org
.eclipse
.swt
.widgets
.Composite
;
99 import org
.eclipse
.swt
.widgets
.Display
;
100 import org
.eclipse
.swt
.widgets
.Event
;
101 import org
.eclipse
.swt
.widgets
.Label
;
102 import org
.eclipse
.swt
.widgets
.Listener
;
103 import org
.eclipse
.swt
.widgets
.Menu
;
104 import org
.eclipse
.swt
.widgets
.MessageBox
;
105 import org
.eclipse
.swt
.widgets
.Shell
;
106 import org
.eclipse
.swt
.widgets
.TableColumn
;
107 import org
.eclipse
.swt
.widgets
.TableItem
;
108 import org
.eclipse
.swt
.widgets
.Text
;
109 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
110 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
111 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
112 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
113 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
114 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
115 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
116 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
117 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
118 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfEventFieldAspect
;
119 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
120 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
121 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
122 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
123 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
124 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
141 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
142 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
143 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
144 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
145 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
146 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
147 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
148 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
149 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
150 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
151 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
152 import org
.eclipse
.ui
.IWorkbenchPage
;
153 import org
.eclipse
.ui
.PlatformUI
;
154 import org
.eclipse
.ui
.commands
.ICommandService
;
155 import org
.eclipse
.ui
.dialogs
.ListDialog
;
156 import org
.eclipse
.ui
.handlers
.IHandlerService
;
157 import org
.eclipse
.ui
.ide
.IDE
;
158 import org
.eclipse
.ui
.ide
.IGotoMarker
;
159 import org
.eclipse
.ui
.themes
.ColorUtil
;
161 import com
.google
.common
.base
.Joiner
;
162 import com
.google
.common
.collect
.HashMultimap
;
163 import com
.google
.common
.collect
.ImmutableList
;
164 import com
.google
.common
.collect
.Multimap
;
167 * The generic TMF Events table
169 * This is a view that will list events that are read from a trace.
171 * @author Francois Chouinard
172 * @author Patrick Tasse
175 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
178 * Empty string array, used by {@link #getItemStrings}.
181 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
187 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
189 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
191 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
192 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
193 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
194 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
195 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
196 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
197 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
198 private static final Image FILTER_IMAGE
= Activator
.getDefault()
199 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
200 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
201 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
202 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
203 private static final int MAX_CACHE_SIZE
= 1000;
205 private static final int MARGIN_COLUMN_INDEX
= 0;
206 private static final int FILTER_SUMMARY_INDEX
= 1;
207 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
210 * The events table search/filter keys
213 * @author Patrick Tasse
215 public interface Key
{
217 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
220 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
223 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
226 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
229 String TIMESTAMP
= "$time"; //$NON-NLS-1$
232 String RANK
= "$rank"; //$NON-NLS-1$
234 /** Bookmark indicator */
235 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
237 /** Event aspect represented by this column */
238 String ASPECT
= "$aspect"; //$NON-NLS-1$
242 * The events table search/filter state
245 * @author Patrick Tasse
247 public static enum HeaderState
{
248 /** A search is being run */
251 /** A filter is applied */
255 interface Direction
{
260 // ------------------------------------------------------------------------
262 // ------------------------------------------------------------------------
264 /** The virtual event table */
265 protected TmfVirtualTable fTable
;
267 private Composite fComposite
;
268 private SashForm fSashForm
;
269 private TmfRawEventViewer fRawViewer
;
270 private ITmfTrace fTrace
;
271 volatile private boolean fPackDone
= false;
272 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
273 private long fSelectedRank
= 0;
274 private ITmfTimestamp fSelectedBeginTimestamp
= null;
275 private IStatusLineManager fStatusLineManager
= null;
278 private long fFilterMatchCount
;
279 private long fFilterCheckCount
;
280 private FilterThread fFilterThread
;
281 private boolean fFilterThreadResume
= false;
282 private final Object fFilterSyncObj
= new Object();
283 private SearchThread fSearchThread
;
284 private final Object fSearchSyncObj
= new Object();
287 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
289 * @see #fireSelectionChanged
291 private ListenerList selectionChangedListeners
= new ListenerList();
293 // Bookmark map <Rank, MarkerId>
294 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
295 private IFile fBookmarksFile
;
296 private long fPendingGotoRank
= -1;
299 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
300 private Color fGrayColor
;
301 private Color fGreenColor
;
302 private Font fBoldFont
;
304 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
307 private final TmfEventsCache fCache
;
308 private boolean fCacheUpdateBusy
= false;
309 private boolean fCacheUpdatePending
= false;
310 private boolean fCacheUpdateCompleted
= false;
311 private final Object fCacheUpdateSyncObj
= new Object();
313 private boolean fDisposeOnClose
;
315 // ------------------------------------------------------------------------
317 // ------------------------------------------------------------------------
320 * Basic constructor, using the default set of columns
323 * The parent composite UI object
325 * The size of the event table cache
327 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
328 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
332 * Legacy constructor, using ColumnData to define columns
335 * The parent composite UI object
337 * The size of the event table cache
340 * @deprecated Deprecated constructor, use
341 * {@link #TmfEventsTable(Composite, int, Collection)}
344 public TmfEventsTable(final Composite parent
, int cacheSize
,
345 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
347 * We'll do a "best-effort" to keep trace types still using this API to
348 * keep working, by defining a TmfEventTableFieldColumn for each
349 * ColumnData they passed.
351 this(parent
, cacheSize
, convertFromColumnData(columnData
));
355 private static @NonNull Iterable
<ITmfEventAspect
> convertFromColumnData(
356 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
358 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
359 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
360 String fieldName
= col
.header
;
361 if (fieldName
!= null) {
362 builder
.add(new TmfEventFieldAspect(fieldName
, fieldName
));
365 return checkNotNull(builder
.build());
369 * Standard constructor, where we define which columns to use.
372 * The parent composite UI object
374 * The size of the event table cache
376 * The event aspects to display in this table. One column per
377 * aspect will be created.
379 * The iteration order of this collection will correspond to the
380 * initial ordering of the columns in the table.
384 public TmfEventsTable(final Composite parent
, int cacheSize
,
385 @NonNull Iterable
<ITmfEventAspect
> aspects
) {
386 super("TmfEventsTable"); //$NON-NLS-1$
388 fComposite
= new Composite(parent
, SWT
.NONE
);
389 final GridLayout gl
= new GridLayout(1, false);
392 gl
.verticalSpacing
= 0;
393 fComposite
.setLayout(gl
);
395 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
396 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
398 // Create a virtual table
399 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
400 fTable
= new TmfVirtualTable(fSashForm
, style
);
402 // Set the table layout
403 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
404 fTable
.setLayoutData(layoutData
);
406 // Some cosmetic enhancements
407 fTable
.setHeaderVisible(true);
408 fTable
.setLinesVisible(true);
411 for (ITmfEventAspect aspect
: aspects
) {
412 if (aspect
!= null) {
413 fColumns
.add(new TmfEventTableColumn(aspect
));
417 TmfMarginColumn collapseCol
= new TmfMarginColumn();
418 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
420 // Create the UI columns in the table
421 for (TmfEventTableColumn col
: fColumns
) {
422 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
423 column
.setText(col
.getHeaderName());
424 column
.setToolTipText(col
.getHeaderTooltip());
425 column
.setData(Key
.ASPECT
, col
.getEventAspect());
427 if (col
instanceof TmfMarginColumn
) {
428 column
.setResizable(false);
429 column
.addControlListener(new ControlAdapter() {
431 * Make sure that the margin column is always first
434 public void controlMoved(ControlEvent e
) {
435 int[] order
= fTable
.getColumnOrder();
436 if (order
[0] == MARGIN_COLUMN_INDEX
) {
439 for (int i
= order
.length
- 1; i
> 0; i
--) {
440 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
441 order
[i
] = order
[i
- 1];
442 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
445 fTable
.setColumnOrder(order
);
449 column
.setMoveable(true);
453 // Set the frozen row for header row
454 fTable
.setFrozenRowCount(1);
456 // Create the header row cell editor
457 createHeaderEditor();
459 // Handle the table item selection
460 fTable
.addSelectionListener(new SelectionAdapter() {
462 public void widgetSelected(final SelectionEvent e
) {
463 if (e
.item
== null) {
466 updateStatusLine(null);
467 if (fTable
.getSelectionIndices().length
> 0) {
468 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
469 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
470 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
472 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
473 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
474 if (fTable
.getSelectionIndices().length
== 1) {
475 fSelectedBeginTimestamp
= ts
;
477 if (fSelectedBeginTimestamp
!= null) {
478 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
479 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
480 if (fTable
.getSelectionIndices().length
== 2) {
481 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
484 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
485 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
489 if (fTable
.getSelectionIndices().length
== 1) {
490 fSelectedBeginTimestamp
= null;
494 if (e
.item
.getData() instanceof ITmfEvent
) {
495 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
496 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
498 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
503 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
504 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
505 fCache
= new TmfEventsCache(realCacheSize
, this);
507 // Handle the table item requests
508 fTable
.addListener(SWT
.SetData
, new Listener() {
511 public void handleEvent(final Event event
) {
513 final TableItem item
= (TableItem
) event
.item
;
514 int index
= event
.index
- 1; // -1 for the header row
516 if (event
.index
== 0) {
517 setHeaderRowItemData(item
);
521 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
522 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
523 setFilterStatusRowItemData(item
);
526 index
= index
- 1; // -1 for top filter status row
529 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
530 if (cachedEvent
!= null) {
531 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
535 // Else, fill the cache asynchronously (and off the UI thread)
540 fTable
.addMouseListener(new MouseAdapter() {
542 public void mouseDoubleClick(final MouseEvent event
) {
543 if (event
.button
!= 1) {
546 // Identify the selected row
547 final Point point
= new Point(event
.x
, event
.y
);
548 final TableItem item
= fTable
.getItem(point
);
550 final Rectangle imageBounds
= item
.getImageBounds(0);
551 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
552 if (imageBounds
.contains(point
)) {
553 final Long rank
= (Long
) item
.getData(Key
.RANK
);
555 toggleBookmark(rank
);
562 final Listener tooltipListener
= new Listener () {
563 Shell tooltipShell
= null;
565 public void handleEvent(final Event event
) {
566 switch (event
.type
) {
568 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
572 final Long rank
= (Long
) item
.getData(Key
.RANK
);
576 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
577 final Rectangle bounds
= item
.getImageBounds(0);
578 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
579 if (!bounds
.contains(event
.x
,event
.y
)) {
582 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
583 tooltipShell
.dispose();
585 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
586 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
587 final FillLayout layout
= new FillLayout();
588 layout
.marginWidth
= 2;
589 tooltipShell
.setLayout(layout
);
590 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
591 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
592 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
593 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
595 label
.addListener(SWT
.MouseExit
, this);
596 label
.addListener(SWT
.MouseDown
, this);
597 label
.addListener(SWT
.MouseWheel
, this);
598 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
600 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
601 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
605 y
+= fTable
.getHeaderHeight();
607 Point pt
= fTable
.toDisplay(event
.x
, y
);
608 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
609 pt
.y
+= item
.getBounds().height
;
610 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
611 tooltipShell
.setVisible(true);
619 if (tooltipShell
!= null) {
620 tooltipShell
.dispose();
630 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
631 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
632 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
633 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
634 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
635 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
636 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
641 ColorSettingsManager
.addColorSettingsListener(this);
643 fTable
.setItemCount(1); // +1 for header row
645 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
647 fRawViewer
.addSelectionListener(new Listener() {
649 public void handleEvent(final Event e
) {
650 if (e
.data
instanceof Long
) {
651 final long rank
= (Long
) e
.data
;
652 int index
= (int) rank
;
653 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
654 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
656 fTable
.setSelection(index
+ 1); // +1 for header row
657 fSelectedRank
= rank
;
658 updateStatusLine(null);
659 } else if (e
.data
instanceof ITmfLocation
) {
660 // DOES NOT WORK: rank undefined in context from seekLocation()
661 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
662 // TmfContext context = fTrace.seekLocation(location);
663 // fTable.setSelection((int) context.getRank());
668 final TableItem
[] selection
= fTable
.getSelection();
669 if ((selection
!= null) && (selection
.length
> 0)) {
670 TableItem item
= fTable
.getSelection()[0];
671 final TmfTimestamp ts
= (TmfTimestamp
) item
.getData(Key
.TIMESTAMP
);
673 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
675 if (item
.getData() instanceof ITmfEvent
) {
676 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) item
.getData()));
677 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(item
.getData())));
679 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
685 fSashForm
.setWeights(new int[] { 1, 1 });
686 fRawViewer
.setVisible(false);
691 // ------------------------------------------------------------------------
693 // ------------------------------------------------------------------------
696 * Create a pop-up menu.
698 protected void createPopupMenu() {
699 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
702 fTable
.setVisible(true);
707 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
710 fTable
.setVisible(false);
715 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
718 fRawViewer
.setVisible(true);
720 final int index
= fTable
.getSelectionIndex();
722 fRawViewer
.selectAndReveal(index
- 1);
727 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
730 fRawViewer
.setVisible(false);
735 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
738 final TableItem items
[] = fTable
.getSelection();
739 if (items
.length
!= 1) {
742 final TableItem item
= items
[0];
744 final Object data
= item
.getData();
745 if (data
instanceof ITmfSourceLookup
) {
746 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
747 ITmfCallsite cs
= event
.getCallsite();
748 if (cs
== null || cs
.getFileName() == null) {
751 IMarker marker
= null;
753 String fileName
= cs
.getFileName();
754 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
755 final ArrayList
<IFile
> files
= new ArrayList
<>();
756 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
758 public boolean visit(IResource resource
) throws CoreException
{
759 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
760 files
.add((IFile
) resource
);
766 if (files
.size() > 1) {
767 ListDialog dialog
= new ListDialog(getTable().getShell());
768 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
769 dialog
.setLabelProvider(new LabelProvider() {
771 public String
getText(Object element
) {
772 return ((IFile
) element
).getFullPath().toString();
775 dialog
.setInput(files
);
776 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
777 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
779 Object
[] result
= dialog
.getResult();
780 if (result
!= null && result
.length
> 0) {
781 file
= (IFile
) result
[0];
783 } else if (files
.size() == 1) {
787 marker
= file
.createMarker(IMarker
.MARKER
);
788 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
789 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
791 } else if (files
.size() == 0){
792 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
794 } catch (CoreException e
) {
801 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
805 final TableItem items
[] = fTable
.getSelection();
806 if (items
.length
!= 1) {
809 final TableItem item
= items
[0];
811 final Object eventData
= item
.getData();
812 if (eventData
instanceof ITmfModelLookup
) {
813 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
815 if (modelURI
!= null) {
816 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
819 final URI uri
= URI
.createURI(modelURI
);
820 if (uri
.isPlatformResource()) {
821 IPath path
= new Path(uri
.toPlatformString(true));
822 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
823 } else if (uri
.isFile() && !uri
.isRelative()) {
824 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
825 new Path(uri
.toFileString()));
831 * create a temporary validation marker on the
832 * model file, remove it afterwards thus,
833 * navigation works with all model editors
834 * supporting the navigation to a marker
836 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
837 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
838 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
840 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
843 catch (CoreException e
) {
847 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
854 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
857 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
858 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
859 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
860 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
861 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
863 HashMap
<String
, Object
> parameters
= new HashMap
<>();
864 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
865 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
867 IEvaluationContext context
= handlerService
.getCurrentState();
868 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
869 for (int i
: fTable
.getColumnOrder()) {
870 // Omit the margin column
871 if (i
>= EVENT_COLUMNS_START_INDEX
) {
872 exportColumns
.add(fColumns
.get(i
));
875 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
877 handlerService
.executeCommandInContext(cmd
, null, context
);
878 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
884 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
887 fHeaderState
= HeaderState
.SEARCH
;
892 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
895 fHeaderState
= HeaderState
.FILTER
;
900 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
907 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
910 applyFilter(new TmfCollapseFilter());
914 class ToggleBookmarkAction
extends Action
{
917 public ToggleBookmarkAction(final String text
, final Long rank
) {
924 toggleBookmark(fRank
);
928 final MenuManager tablePopupMenu
= new MenuManager();
929 tablePopupMenu
.setRemoveAllWhenShown(true);
930 tablePopupMenu
.addMenuListener(new IMenuListener() {
932 public void menuAboutToShow(final IMenuManager manager
) {
933 if (fTable
.getSelectionIndex() == 0) {
934 // Right-click on header row
935 if (fHeaderState
== HeaderState
.FILTER
) {
936 tablePopupMenu
.add(showSearchBarAction
);
938 tablePopupMenu
.add(showFilterBarAction
);
942 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
943 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
945 final Rectangle imageBounds
= item
.getImageBounds(0);
946 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
947 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
948 // Right-click on left margin
949 final Long rank
= (Long
) item
.getData(Key
.RANK
);
950 if ((rank
!= null) && (fBookmarksFile
!= null)) {
951 if (fBookmarksMap
.containsKey(rank
)) {
952 tablePopupMenu
.add(new ToggleBookmarkAction(
953 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
955 tablePopupMenu
.add(new ToggleBookmarkAction(
956 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
963 // Right-click on table
964 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
965 tablePopupMenu
.add(hideTableAction
);
966 tablePopupMenu
.add(hideRawAction
);
967 } else if (!fTable
.isVisible()) {
968 tablePopupMenu
.add(showTableAction
);
969 } else if (!fRawViewer
.isVisible()) {
970 tablePopupMenu
.add(showRawAction
);
972 tablePopupMenu
.add(exportToTextAction
);
973 tablePopupMenu
.add(new Separator());
976 final Object data
= item
.getData();
977 Separator separator
= null;
978 if (data
instanceof ITmfSourceLookup
) {
979 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
980 if (event
.getCallsite() != null) {
981 tablePopupMenu
.add(openCallsiteAction
);
982 separator
= new Separator();
986 if (data
instanceof ITmfModelLookup
) {
987 ITmfModelLookup event
= (ITmfModelLookup
) data
;
988 if (event
.getModelUri() != null) {
989 tablePopupMenu
.add(openModelAction
);
990 separator
= new Separator();
993 if (separator
!= null) {
994 tablePopupMenu
.add(separator
);
999 // only show collapse filter if at least one trace can be collapsed
1000 boolean isCollapsible
= false;
1001 if (fTrace
!= null) {
1002 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
1003 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1004 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1005 if (isCollapsible
) {
1011 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1012 tablePopupMenu
.add(collapseAction
);
1013 tablePopupMenu
.add(new Separator());
1016 tablePopupMenu
.add(clearFiltersAction
);
1017 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1018 if (savedFilters
.length
> 0) {
1019 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1020 for (final ITmfFilterTreeNode node
: savedFilters
) {
1021 if (node
instanceof TmfFilterNode
) {
1022 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1023 subMenu
.add(new Action(filter
.getFilterName()) {
1026 applyFilter(filter
);
1031 tablePopupMenu
.add(subMenu
);
1033 appendToTablePopupMenu(tablePopupMenu
, item
);
1037 final MenuManager rawViewerPopupMenu
= new MenuManager();
1038 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1039 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1041 public void menuAboutToShow(final IMenuManager manager
) {
1042 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1043 rawViewerPopupMenu
.add(hideTableAction
);
1044 rawViewerPopupMenu
.add(hideRawAction
);
1045 } else if (!fTable
.isVisible()) {
1046 rawViewerPopupMenu
.add(showTableAction
);
1047 } else if (!fRawViewer
.isVisible()) {
1048 rawViewerPopupMenu
.add(showRawAction
);
1050 appendToRawPopupMenu(tablePopupMenu
);
1054 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1055 fTable
.setMenu(menu
);
1057 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1058 fRawViewer
.setMenu(menu
);
1063 * Append an item to the event table's pop-up menu.
1065 * @param tablePopupMenu
1067 * @param selectedItem
1068 * The item to append
1070 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1071 // override to append more actions
1075 * Append an item to the raw viewer's pop-up menu.
1077 * @param rawViewerPopupMenu
1080 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1081 // override to append more actions
1085 public void dispose() {
1088 ColorSettingsManager
.removeColorSettingsListener(this);
1089 fComposite
.dispose();
1090 if ((fTrace
!= null) && fDisposeOnClose
) {
1093 fResourceManager
.dispose();
1094 fRawViewer
.dispose();
1099 * Assign a layout data object to this view.
1102 * The layout data to assign
1104 public void setLayoutData(final Object layoutData
) {
1105 fComposite
.setLayoutData(layoutData
);
1109 * Get the virtual table contained in this event table.
1111 * @return The TMF virtual table
1113 public TmfVirtualTable
getTable() {
1120 * @deprecated The column headers are now set at the constructor, this
1121 * shouldn't be called anymore.
1124 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1129 * Set a table item's data.
1134 * Which trace event to link with this entry
1136 * Which rank this event has in the trace/experiment
1138 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1139 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1141 // Get the actual ITmfEvent from the CachedEvent
1142 ITmfEvent tmfEvent
= event
;
1143 if (event
instanceof CachedEvent
) {
1144 tmfEvent
= ((CachedEvent
) event
).event
;
1146 item
.setText(itemStrings
);
1147 item
.setData(tmfEvent
);
1148 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1149 item
.setData(Key
.RANK
, rank
);
1151 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1152 if (!markerIds
.isEmpty()) {
1153 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1154 List
<Object
> parts
= new ArrayList
<>();
1155 if (markerIds
.size() > 1) {
1156 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1159 for (long markerId
: markerIds
) {
1160 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1161 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1163 } catch (CoreException e
) {
1164 displayException(e
);
1166 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1168 item
.setData(Key
.BOOKMARK
, null);
1171 boolean searchMatch
= false;
1172 boolean searchNoMatch
= false;
1173 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1174 if (searchFilter
!= null) {
1175 if (searchFilter
.matches(tmfEvent
)) {
1178 searchNoMatch
= true;
1182 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1183 if (searchNoMatch
) {
1184 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1185 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1187 item
.setForeground(colorSetting
.getForegroundColor());
1188 item
.setBackground(colorSetting
.getBackgroundColor());
1192 if (!markerIds
.isEmpty()) {
1193 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1195 item
.setImage(SEARCH_MATCH_IMAGE
);
1197 } else if (!markerIds
.isEmpty()) {
1198 item
.setImage(BOOKMARK_IMAGE
);
1200 item
.setImage((Image
) null);
1203 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1209 * Set the item data of the header row.
1212 * The item to use as table header
1214 protected void setHeaderRowItemData(final TableItem item
) {
1215 String txtKey
= null;
1216 if (fHeaderState
== HeaderState
.SEARCH
) {
1217 item
.setImage(SEARCH_IMAGE
);
1218 txtKey
= Key
.SEARCH_TXT
;
1219 } else if (fHeaderState
== HeaderState
.FILTER
) {
1220 item
.setImage(FILTER_IMAGE
);
1221 txtKey
= Key
.FILTER_TXT
;
1223 item
.setForeground(fGrayColor
);
1224 // Ignore collapse and image column
1225 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1226 final TableColumn column
= fTable
.getColumns()[i
];
1227 final String filter
= (String
) column
.getData(txtKey
);
1228 if (filter
== null) {
1229 if (fHeaderState
== HeaderState
.SEARCH
) {
1230 item
.setText(i
, SEARCH_HINT
);
1231 } else if (fHeaderState
== HeaderState
.FILTER
) {
1232 item
.setText(i
, FILTER_HINT
);
1234 item
.setForeground(i
, fGrayColor
);
1235 item
.setFont(i
, fTable
.getFont());
1237 item
.setText(i
, filter
);
1238 item
.setForeground(i
, fGreenColor
);
1239 item
.setFont(i
, fBoldFont
);
1245 * Set the item data of the "filter status" row.
1248 * The item to use as filter status row
1250 protected void setFilterStatusRowItemData(final TableItem item
) {
1251 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1252 if (i
== MARGIN_COLUMN_INDEX
) {
1253 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1254 item
.setImage(FILTER_IMAGE
);
1256 item
.setImage(STOP_IMAGE
);
1260 if (i
== FILTER_SUMMARY_INDEX
) {
1261 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1263 item
.setText(i
, EMPTY_STRING
);
1267 item
.setData(Key
.TIMESTAMP
, null);
1268 item
.setData(Key
.RANK
, null);
1269 item
.setForeground(null);
1270 item
.setBackground(null);
1274 * Create an editor for the header.
1276 protected void createHeaderEditor() {
1277 final TableEditor tableEditor
= fTable
.createTableEditor();
1278 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1279 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1280 tableEditor
.grabHorizontal
= true;
1281 tableEditor
.minimumWidth
= 50;
1283 // Handle the header row selection
1284 fTable
.addMouseListener(new MouseAdapter() {
1290 public void mouseDown(final MouseEvent event
) {
1291 if (event
.button
!= 1) {
1294 // Identify the selected row
1295 final Point point
= new Point(event
.x
, event
.y
);
1296 item
= fTable
.getItem(point
);
1298 // Header row selected
1299 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1302 if (item
.getImageBounds(0).contains(point
)) {
1303 if (fHeaderState
== HeaderState
.SEARCH
) {
1304 fHeaderState
= HeaderState
.FILTER
;
1305 } else if (fHeaderState
== HeaderState
.FILTER
) {
1306 fHeaderState
= HeaderState
.SEARCH
;
1308 fTable
.setSelection(0);
1313 // Identify the selected column
1315 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1316 final Rectangle rect
= item
.getBounds(i
);
1317 if (rect
.contains(point
)) {
1323 if (columnIndex
== -1) {
1327 column
= fTable
.getColumns()[columnIndex
];
1329 String txtKey
= null;
1330 if (fHeaderState
== HeaderState
.SEARCH
) {
1331 txtKey
= Key
.SEARCH_TXT
;
1332 } else if (fHeaderState
== HeaderState
.FILTER
) {
1333 txtKey
= Key
.FILTER_TXT
;
1336 // The control that will be the editor must be a child of the Table
1337 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1338 final String headerString
= (String
) column
.getData(txtKey
);
1339 if (headerString
!= null) {
1340 newEditor
.setText(headerString
);
1342 newEditor
.addFocusListener(new FocusAdapter() {
1344 public void focusLost(final FocusEvent e
) {
1345 final boolean changed
= updateHeader(newEditor
.getText());
1351 newEditor
.addKeyListener(new KeyAdapter() {
1353 public void keyPressed(final KeyEvent e
) {
1354 if (e
.character
== SWT
.CR
) {
1355 updateHeader(newEditor
.getText());
1358 // Set focus on the table so that the next carriage return goes to the next result
1359 TmfEventsTable
.this.getTable().setFocus();
1360 } else if (e
.character
== SWT
.ESC
) {
1361 tableEditor
.getEditor().dispose();
1365 newEditor
.selectAll();
1366 newEditor
.setFocus();
1367 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1372 * returns true is value was changed
1374 private boolean updateHeader(final String text
) {
1375 String objKey
= null;
1376 String txtKey
= null;
1377 if (fHeaderState
== HeaderState
.SEARCH
) {
1378 objKey
= Key
.SEARCH_OBJ
;
1379 txtKey
= Key
.SEARCH_TXT
;
1380 } else if (fHeaderState
== HeaderState
.FILTER
) {
1381 objKey
= Key
.FILTER_OBJ
;
1382 txtKey
= Key
.FILTER_TXT
;
1384 if (text
.trim().length() > 0) {
1386 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1387 Pattern
.compile(regex
);
1388 if (regex
.equals(column
.getData(txtKey
))) {
1389 tableEditor
.getEditor().dispose();
1392 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1393 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1394 filter
.setEventAspect(aspect
);
1395 filter
.setRegex(regex
);
1396 column
.setData(objKey
, filter
);
1397 column
.setData(txtKey
, regex
);
1398 } catch (final PatternSyntaxException ex
) {
1399 tableEditor
.getEditor().dispose();
1400 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1401 ex
.getDescription(), ex
.getMessage());
1405 if (column
.getData(txtKey
) == null) {
1406 tableEditor
.getEditor().dispose();
1409 column
.setData(objKey
, null);
1410 column
.setData(txtKey
, null);
1415 private void applyHeader() {
1416 if (fHeaderState
== HeaderState
.SEARCH
) {
1418 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1419 for (final TableColumn col
: fTable
.getColumns()) {
1420 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1421 if (filterObj
instanceof ITmfFilterTreeNode
) {
1422 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1425 if (filter
.getChildrenCount() > 0) {
1426 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1429 fireSearchApplied(filter
);
1431 fTable
.setData(Key
.SEARCH_OBJ
, null);
1433 fireSearchApplied(null);
1435 } else if (fHeaderState
== HeaderState
.FILTER
) {
1436 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1437 for (final TableColumn col
: fTable
.getColumns()) {
1438 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1439 if (filterObj
instanceof ITmfFilterTreeNode
) {
1440 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1443 if (filter
.getChildrenCount() > 0) {
1444 applyFilter(filter
);
1450 tableEditor
.getEditor().dispose();
1454 fTable
.addKeyListener(new KeyAdapter() {
1456 public void keyPressed(final KeyEvent e
) {
1458 if (e
.character
== SWT
.ESC
) {
1462 } else if (e
.character
== SWT
.DEL
) {
1463 if (fHeaderState
== HeaderState
.SEARCH
) {
1465 for (final TableColumn column
: fTable
.getColumns()) {
1466 column
.setData(Key
.SEARCH_OBJ
, null);
1467 column
.setData(Key
.SEARCH_TXT
, null);
1469 fTable
.setData(Key
.SEARCH_OBJ
, null);
1471 fireSearchApplied(null);
1472 } else if (fHeaderState
== HeaderState
.FILTER
) {
1475 } else if (e
.character
== SWT
.CR
) {
1476 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1487 * Send an event indicating a filter has been applied.
1490 * The filter that was just applied
1492 protected void fireFilterApplied(final ITmfFilter filter
) {
1493 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1497 * Send an event indicating that a search has been applied.
1500 * The search filter that was just applied
1502 protected void fireSearchApplied(final ITmfFilter filter
) {
1503 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1507 * Start the filtering thread.
1509 protected void startFilterThread() {
1510 synchronized (fFilterSyncObj
) {
1511 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1512 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1513 if (fFilterThread
!= null) {
1514 fFilterThread
.cancel();
1515 fFilterThreadResume
= false;
1517 fFilterThread
= new FilterThread(filter
);
1518 fFilterThread
.start();
1520 fFilterThreadResume
= true;
1526 * Stop the filtering thread.
1528 protected void stopFilterThread() {
1529 synchronized (fFilterSyncObj
) {
1530 if (fFilterThread
!= null) {
1531 fFilterThread
.cancel();
1532 fFilterThread
= null;
1533 fFilterThreadResume
= false;
1542 * The filter to apply
1545 protected void applyFilter(ITmfFilter filter
) {
1548 fFilterMatchCount
= 0;
1549 fFilterCheckCount
= 0;
1550 fCache
.applyFilter(filter
);
1552 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1553 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1554 startFilterThread();
1555 fireFilterApplied(filter
);
1559 * Clear all currently active filters.
1561 protected void clearFilters() {
1562 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1567 fCache
.clearFilter();
1569 for (final TableColumn column
: fTable
.getColumns()) {
1570 column
.setData(Key
.FILTER_OBJ
, null);
1571 column
.setData(Key
.FILTER_TXT
, null);
1573 fTable
.setData(Key
.FILTER_OBJ
, null);
1574 if (fTrace
!= null) {
1575 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1577 fTable
.setItemCount(1); // +1 for header row
1579 fFilterMatchCount
= 0;
1580 fFilterCheckCount
= 0;
1581 if (fSelectedRank
>= 0) {
1582 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1584 fTable
.setSelection(0);
1586 fireFilterApplied(null);
1587 updateStatusLine(null);
1589 // Set original width
1590 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1595 * Wrapper Thread object for the filtering thread.
1597 protected class FilterThread
extends Thread
{
1598 private final ITmfFilterTreeNode filter
;
1599 private TmfEventRequest request
;
1600 private boolean refreshBusy
= false;
1601 private boolean refreshPending
= false;
1602 private final Object syncObj
= new Object();
1608 * The filter this thread will be processing
1610 public FilterThread(final ITmfFilterTreeNode filter
) {
1611 super("Filter Thread"); //$NON-NLS-1$
1612 this.filter
= filter
;
1617 if (fTrace
== null) {
1620 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1621 if (nbRequested
<= 0) {
1624 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1625 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1627 public void handleData(final ITmfEvent event
) {
1628 super.handleData(event
);
1629 if (request
.isCancelled()) {
1632 boolean refresh
= false;
1633 if (filter
.matches(event
)) {
1634 final long rank
= fFilterCheckCount
;
1635 final int index
= (int) fFilterMatchCount
;
1636 fFilterMatchCount
++;
1637 fCache
.storeEvent(event
, rank
, index
);
1640 if (filter
instanceof TmfCollapseFilter
) {
1641 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1645 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1648 fFilterCheckCount
++;
1651 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1653 request
.waitForCompletion();
1654 } catch (final InterruptedException e
) {
1657 synchronized (fFilterSyncObj
) {
1658 fFilterThread
= null;
1659 if (fFilterThreadResume
) {
1660 fFilterThreadResume
= false;
1661 fFilterThread
= new FilterThread(filter
);
1662 fFilterThread
.start();
1668 * Refresh the filter.
1670 public void refreshTable() {
1671 synchronized (syncObj
) {
1673 refreshPending
= true;
1678 Display
.getDefault().asyncExec(new Runnable() {
1681 if (request
.isCancelled()) {
1684 if (fTable
.isDisposed()) {
1687 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1689 synchronized (syncObj
) {
1690 refreshBusy
= false;
1691 if (refreshPending
) {
1692 refreshPending
= false;
1701 * Cancel this filtering thread.
1703 public void cancel() {
1704 if (request
!= null) {
1711 * Go to the next item of a search.
1713 protected void searchNext() {
1714 synchronized (fSearchSyncObj
) {
1715 if (fSearchThread
!= null) {
1718 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1719 if (searchFilter
== null) {
1722 final int selectionIndex
= fTable
.getSelectionIndex();
1724 if (selectionIndex
> 0) {
1725 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1727 // header row is selected, start at top event
1728 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1730 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1731 if (eventFilter
!= null) {
1732 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1734 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1735 fSearchThread
.schedule();
1740 * Go to the previous item of a search.
1742 protected void searchPrevious() {
1743 synchronized (fSearchSyncObj
) {
1744 if (fSearchThread
!= null) {
1747 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1748 if (searchFilter
== null) {
1751 final int selectionIndex
= fTable
.getSelectionIndex();
1753 if (selectionIndex
> 0) {
1754 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1756 // header row is selected, start at precedent of top event
1757 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1759 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1760 if (eventFilter
!= null) {
1761 startIndex
= startIndex
- 1; // -1 for top filter status row
1763 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1764 fSearchThread
.schedule();
1769 * Stop the search thread.
1771 protected void stopSearchThread() {
1772 fPendingGotoRank
= -1;
1773 synchronized (fSearchSyncObj
) {
1774 if (fSearchThread
!= null) {
1775 fSearchThread
.cancel();
1776 fSearchThread
= null;
1782 * Wrapper for the search thread.
1784 protected class SearchThread
extends Job
{
1786 private ITmfFilterTreeNode searchFilter
;
1787 private ITmfFilterTreeNode eventFilter
;
1788 private int startIndex
;
1789 private int direction
;
1791 private long foundRank
= -1;
1792 private TmfEventRequest request
;
1793 private ITmfTimestamp foundTimestamp
= null;
1798 * @param searchFilter
1800 * @param eventFilter
1803 * The index at which we should start searching
1804 * @param currentRank
1807 * In which direction should we search, forward or backwards
1809 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1810 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1811 final long currentRank
, final int direction
) {
1812 super(Messages
.TmfEventsTable_SearchingJobName
);
1813 this.searchFilter
= searchFilter
;
1814 this.eventFilter
= eventFilter
;
1815 this.startIndex
= startIndex
;
1816 this.rank
= currentRank
;
1817 this.direction
= direction
;
1821 protected IStatus
run(final IProgressMonitor monitor
) {
1822 if (fTrace
== null) {
1823 return Status
.OK_STATUS
;
1825 final Display display
= Display
.getDefault();
1826 if (startIndex
< 0) {
1827 rank
= (int) fTrace
.getNbEvents() - 1;
1828 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1831 int idx
= startIndex
;
1832 while (foundRank
== -1) {
1833 final CachedEvent event
= fCache
.peekEvent(idx
);
1834 if (event
== null) {
1838 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1839 foundRank
= event
.rank
;
1840 foundTimestamp
= event
.event
.getTimestamp();
1843 if (direction
== Direction
.FORWARD
) {
1849 if (foundRank
== -1) {
1850 if (direction
== Direction
.FORWARD
) {
1852 if (rank
> (fTrace
.getNbEvents() - 1)) {
1858 rank
= (int) fTrace
.getNbEvents() - 1;
1863 final int startRank
= (int) rank
;
1864 boolean wrapped
= false;
1865 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1866 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1867 if (direction
== Direction
.BACKWARD
) {
1868 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1870 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1871 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1872 long currentRank
= rank
;
1875 public void handleData(final ITmfEvent event
) {
1876 super.handleData(event
);
1877 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1878 foundRank
= currentRank
;
1879 foundTimestamp
= event
.getTimestamp();
1880 if (direction
== Direction
.FORWARD
) {
1888 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1890 request
.waitForCompletion();
1891 if (request
.isCancelled()) {
1892 return Status
.OK_STATUS
;
1894 } catch (final InterruptedException e
) {
1895 synchronized (fSearchSyncObj
) {
1896 fSearchThread
= null;
1898 return Status
.OK_STATUS
;
1900 if (foundRank
== -1) {
1901 if (direction
== Direction
.FORWARD
) {
1903 synchronized (fSearchSyncObj
) {
1904 fSearchThread
= null;
1906 return Status
.OK_STATUS
;
1908 nbRequested
= (int) rank
;
1914 rank
= (int) fTrace
.getNbEvents() - 1;
1917 if ((rank
<= startRank
) && wrapped
) {
1918 synchronized (fSearchSyncObj
) {
1919 fSearchThread
= null;
1921 return Status
.OK_STATUS
;
1926 int index
= (int) foundRank
;
1927 if (eventFilter
!= null) {
1928 index
= fCache
.getFilteredEventIndex(foundRank
);
1930 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1932 display
.asyncExec(new Runnable() {
1935 if (monitor
.isCanceled()) {
1938 if (fTable
.isDisposed()) {
1941 fTable
.setSelection(selection
);
1942 fSelectedRank
= foundRank
;
1943 fRawViewer
.selectAndReveal(fSelectedRank
);
1944 if (foundTimestamp
!= null) {
1945 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1947 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1948 synchronized (fSearchSyncObj
) {
1949 fSearchThread
= null;
1951 updateStatusLine(null);
1954 return Status
.OK_STATUS
;
1958 protected void canceling() {
1960 synchronized (fSearchSyncObj
) {
1961 fSearchThread
= null;
1967 * Create the resources.
1969 protected void createResources() {
1970 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1971 .getForeground().getRGB()));
1972 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1973 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1979 protected void packColumns() {
1983 fTable
.setRedraw(false);
1985 TableColumn tableColumns
[] = fTable
.getColumns();
1986 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1987 final TableColumn column
= tableColumns
[i
];
1988 packSingleColumn(i
, column
);
1991 // Make sure that redraw is always enabled.
1992 fTable
.setRedraw(true);
1998 private void packMarginColumn() {
1999 TableColumn
[] columns
= fTable
.getColumns();
2000 if (columns
.length
> 0) {
2001 packSingleColumn(0, columns
[0]);
2005 private void packSingleColumn(int i
, final TableColumn column
) {
2006 final int headerWidth
= column
.getWidth();
2008 // Workaround for Linux which doesn't consider the image width of
2009 // search/filter row in TableColumn.pack() after having executed
2010 // TableItem.setImage((Image)null) for other rows than search/filter row.
2011 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2012 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2013 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2016 if (column
.getWidth() < headerWidth
) {
2017 column
.setWidth(headerWidth
);
2022 * Get the array of item strings (e.g., what to display in each cell of the
2023 * table row) corresponding to the columns and trace event passed in
2024 * parameter. The order of the Strings in the returned array will correspond
2025 * to the iteration order of 'columns'.
2028 * To ensure consistent results, make sure only call this within a scope
2029 * synchronized on 'columns'! If the order of 'columns' changes right after
2030 * this method is called, the returned value won't be ordered correctly
2033 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2034 if (event
== null) {
2035 return EMPTY_STRING_ARRAY
;
2037 synchronized (columns
) {
2038 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2039 for (TmfEventTableColumn column
: columns
) {
2040 ITmfEvent passedEvent
= event
;
2041 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2042 // Make sure that the event object from the trace is passed
2043 // to all columns but the TmfMarginColumn
2044 passedEvent
= ((CachedEvent
) event
).event
;
2046 if (passedEvent
== null) {
2047 itemStrings
.add(EMPTY_STRING
);
2049 itemStrings
.add(column
.getItemString(passedEvent
));
2053 return itemStrings
.toArray(new String
[0]);
2058 * Get the contents of the row in the events table corresponding to an
2059 * event. The order of the elements corresponds to the current order of the
2063 * The event printed in this row
2064 * @return The event row entries
2067 public String
[] getItemStrings(ITmfEvent event
) {
2068 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2069 for (int i
: fTable
.getColumnOrder()) {
2070 columns
.add(fColumns
.get(i
));
2072 return getItemStrings(columns
, event
);
2076 * Notify this table that is got the UI focus.
2078 public void setFocus() {
2083 * Assign a new trace to this event table.
2086 * The trace to assign to this event table
2087 * @param disposeOnClose
2088 * true if the trace should be disposed when the table is
2091 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2092 if ((fTrace
!= null) && fDisposeOnClose
) {
2098 fDisposeOnClose
= disposeOnClose
;
2100 // Perform the updates on the UI thread
2101 fTable
.getDisplay().syncExec(new Runnable() {
2105 fCache
.setTrace(fTrace
); // Clear the cache
2106 if (fTrace
!= null) {
2107 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2108 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2109 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2112 fFilterMatchCount
= 0;
2113 fFilterCheckCount
= 0;
2114 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2115 startFilterThread();
2119 fRawViewer
.setTrace(fTrace
);
2125 * Assign the status line manager
2127 * @param statusLineManager
2128 * The status line manager, or null to disable status line messages
2131 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2132 if (fStatusLineManager
!= null && statusLineManager
== null) {
2133 fStatusLineManager
.setMessage(EMPTY_STRING
);
2135 fStatusLineManager
= statusLineManager
;
2138 private void updateStatusLine(ITmfTimestamp delta
) {
2139 if (fStatusLineManager
!= null) {
2140 if (delta
!= null) {
2141 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2143 fStatusLineManager
.setMessage(null);
2148 // ------------------------------------------------------------------------
2150 // ------------------------------------------------------------------------
2153 * Notify that the event cache has been updated
2156 * Also notify if the populating of the cache is complete, or
2159 public void cacheUpdated(final boolean completed
) {
2160 synchronized (fCacheUpdateSyncObj
) {
2161 if (fCacheUpdateBusy
) {
2162 fCacheUpdatePending
= true;
2163 fCacheUpdateCompleted
= completed
;
2166 fCacheUpdateBusy
= true;
2168 // Event cache is now updated. Perform update on the UI thread
2169 if (!fTable
.isDisposed()) {
2170 fTable
.getDisplay().asyncExec(new Runnable() {
2173 if (!fTable
.isDisposed()) {
2178 populateCompleted();
2180 synchronized (fCacheUpdateSyncObj
) {
2181 fCacheUpdateBusy
= false;
2182 if (fCacheUpdatePending
) {
2183 fCacheUpdatePending
= false;
2184 cacheUpdated(fCacheUpdateCompleted
);
2193 * Callback for when populating the table is complete.
2195 protected void populateCompleted() {
2196 // Nothing by default;
2199 // ------------------------------------------------------------------------
2200 // ISelectionProvider
2201 // ------------------------------------------------------------------------
2207 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2208 selectionChangedListeners
.add(listener
);
2215 public ISelection
getSelection() {
2216 if (fTable
== null || fTable
.isDisposed()) {
2217 return StructuredSelection
.EMPTY
;
2219 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2220 for (TableItem item
: fTable
.getSelection()) {
2221 if (item
.getData() != null) {
2222 list
.add(item
.getData());
2225 return new StructuredSelection(list
);
2232 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2233 selectionChangedListeners
.remove(listener
);
2240 public void setSelection(ISelection selection
) {
2245 * Notifies any selection changed listeners that the viewer's selection has changed.
2246 * Only listeners registered at the time this method is called are notified.
2248 * @param event a selection changed event
2250 * @see ISelectionChangedListener#selectionChanged
2253 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2254 Object
[] listeners
= selectionChangedListeners
.getListeners();
2255 for (int i
= 0; i
< listeners
.length
; ++i
) {
2256 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2257 SafeRunnable
.run(new SafeRunnable() {
2260 l
.selectionChanged(event
);
2266 // ------------------------------------------------------------------------
2267 // Bookmark handling
2268 // ------------------------------------------------------------------------
2271 * Add a bookmark to this event table.
2273 * @param bookmarksFile
2274 * The file to use for the bookmarks
2276 public void addBookmark(final IFile bookmarksFile
) {
2277 fBookmarksFile
= bookmarksFile
;
2278 final TableItem
[] selection
= fTable
.getSelection();
2279 if (selection
.length
> 0) {
2280 final TableItem tableItem
= selection
[0];
2281 if (tableItem
.getData(Key
.RANK
) != null) {
2282 final StringBuffer defaultMessage
= new StringBuffer();
2283 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2285 defaultMessage
.append(", "); //$NON-NLS-1$
2287 defaultMessage
.append(tableItem
.getText(i
));
2289 final InputDialog dialog
= new MultiLineInputDialog(
2290 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2291 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2292 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2293 defaultMessage
.toString());
2294 if (dialog
.open() == Window
.OK
) {
2295 final String message
= dialog
.getValue();
2297 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2298 if (bookmark
.exists()) {
2299 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2300 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2301 final int location
= rank
.intValue();
2302 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2303 fBookmarksMap
.put(rank
, bookmark
.getId());
2306 } catch (final CoreException e
) {
2307 displayException(e
);
2316 * Remove a bookmark from this event table.
2319 * The bookmark to remove
2321 public void removeBookmark(final IMarker bookmark
) {
2322 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2323 if (entry
.getValue().equals(bookmark
.getId())) {
2324 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2331 private void toggleBookmark(final Long rank
) {
2332 if (fBookmarksFile
== null) {
2335 if (fBookmarksMap
.containsKey(rank
)) {
2336 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2339 for (long markerId
: markerIds
) {
2340 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2341 if (bookmark
!= null) {
2345 } catch (final CoreException e
) {
2346 displayException(e
);
2349 addBookmark(fBookmarksFile
);
2354 * Refresh the bookmarks assigned to this trace, from the contents of a
2357 * @param bookmarksFile
2358 * The bookmark file to use
2360 public void refreshBookmarks(final IFile bookmarksFile
) {
2361 fBookmarksFile
= bookmarksFile
;
2362 if (bookmarksFile
== null) {
2363 fBookmarksMap
.clear();
2368 fBookmarksMap
.clear();
2369 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2370 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2371 if (location
!= -1) {
2372 final long rank
= location
;
2373 fBookmarksMap
.put(rank
, bookmark
.getId());
2377 } catch (final CoreException e
) {
2378 displayException(e
);
2383 public void gotoMarker(final IMarker marker
) {
2384 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2387 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2388 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2389 } else if (rank
>= fTable
.getItemCount()) {
2390 fPendingGotoRank
= rank
;
2392 fSelectedRank
= rank
;
2393 fTable
.setSelection(index
+ 1); // +1 for header row
2394 updateStatusLine(null);
2398 // ------------------------------------------------------------------------
2400 // ------------------------------------------------------------------------
2403 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2407 // ------------------------------------------------------------------------
2409 // ------------------------------------------------------------------------
2412 * Handler for the trace updated signal
2415 * The incoming signal
2418 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2419 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2422 // Perform the refresh on the UI thread
2423 Display
.getDefault().asyncExec(new Runnable() {
2426 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2427 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2428 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2429 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2430 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2431 fPendingGotoRank
= -1;
2432 updateStatusLine(null);
2435 startFilterThread();
2438 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2439 fRawViewer
.refreshEventCount();
2446 * Handler for the time synch signal.
2449 * The incoming signal
2452 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2453 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2455 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2456 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2457 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2458 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2459 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2461 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2464 public void handleData(final ITmfEvent event
) {
2465 super.handleData(event
);
2469 public void handleSuccess() {
2470 super.handleSuccess();
2471 if (fTrace
== null) {
2475 // Verify if the event is within the trace range and adjust if necessary
2476 ITmfTimestamp timestamp
= ts
;
2477 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2478 timestamp
= fTrace
.getStartTime();
2480 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2481 timestamp
= fTrace
.getEndTime();
2484 // Get the rank of the selected event in the table
2485 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2486 final long rank
= context
.getRank();
2488 fSelectedRank
= rank
;
2490 fTable
.getDisplay().asyncExec(new Runnable() {
2493 // Return if table is disposed
2494 if (fTable
.isDisposed()) {
2498 int index
= (int) rank
;
2499 if (fTable
.isDisposed()) {
2502 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2503 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2505 fTable
.setSelection(index
+ 1); // +1 for header row
2506 fRawViewer
.selectAndReveal(rank
);
2507 updateStatusLine(null);
2513 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2517 // ------------------------------------------------------------------------
2519 // ------------------------------------------------------------------------
2522 * Display an exception in a message box
2524 * @param e the exception
2526 private static void displayException(final Exception e
) {
2527 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2528 mb
.setText(e
.getClass().getSimpleName());
2529 mb
.setMessage(e
.getMessage());
2536 public void refresh() {
2543 * Margin column for images and special text (e.g. collapse count)
2545 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2547 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2550 public String
getName() {
2551 return EMPTY_STRING
;
2555 public String
resolve(ITmfEvent event
) {
2556 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2557 return EMPTY_STRING
;
2559 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2563 public String
getHelpText() {
2564 return EMPTY_STRING
;
2571 public TmfMarginColumn() {
2572 super(MARGIN_ASPECT
);