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, 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 java
.io
.FileNotFoundException
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collection
;
23 import java
.util
.HashMap
;
24 import java
.util
.LinkedList
;
25 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
.jdt
.annotation
.NonNull
;
53 import org
.eclipse
.jface
.action
.Action
;
54 import org
.eclipse
.jface
.action
.IAction
;
55 import org
.eclipse
.jface
.action
.IMenuListener
;
56 import org
.eclipse
.jface
.action
.IMenuManager
;
57 import org
.eclipse
.jface
.action
.IStatusLineManager
;
58 import org
.eclipse
.jface
.action
.MenuManager
;
59 import org
.eclipse
.jface
.action
.Separator
;
60 import org
.eclipse
.jface
.dialogs
.InputDialog
;
61 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
62 import org
.eclipse
.jface
.resource
.FontDescriptor
;
63 import org
.eclipse
.jface
.resource
.JFaceResources
;
64 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
65 import org
.eclipse
.jface
.util
.OpenStrategy
;
66 import org
.eclipse
.jface
.util
.SafeRunnable
;
67 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
68 import org
.eclipse
.jface
.viewers
.ISelection
;
69 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
70 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
71 import org
.eclipse
.jface
.viewers
.LabelProvider
;
72 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
73 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
74 import org
.eclipse
.jface
.window
.Window
;
75 import org
.eclipse
.swt
.SWT
;
76 import org
.eclipse
.swt
.custom
.SashForm
;
77 import org
.eclipse
.swt
.custom
.TableEditor
;
78 import org
.eclipse
.swt
.events
.ControlAdapter
;
79 import org
.eclipse
.swt
.events
.ControlEvent
;
80 import org
.eclipse
.swt
.events
.FocusAdapter
;
81 import org
.eclipse
.swt
.events
.FocusEvent
;
82 import org
.eclipse
.swt
.events
.KeyAdapter
;
83 import org
.eclipse
.swt
.events
.KeyEvent
;
84 import org
.eclipse
.swt
.events
.MouseAdapter
;
85 import org
.eclipse
.swt
.events
.MouseEvent
;
86 import org
.eclipse
.swt
.events
.SelectionAdapter
;
87 import org
.eclipse
.swt
.events
.SelectionEvent
;
88 import org
.eclipse
.swt
.graphics
.Color
;
89 import org
.eclipse
.swt
.graphics
.Font
;
90 import org
.eclipse
.swt
.graphics
.Image
;
91 import org
.eclipse
.swt
.graphics
.Point
;
92 import org
.eclipse
.swt
.graphics
.Rectangle
;
93 import org
.eclipse
.swt
.layout
.FillLayout
;
94 import org
.eclipse
.swt
.layout
.GridData
;
95 import org
.eclipse
.swt
.layout
.GridLayout
;
96 import org
.eclipse
.swt
.widgets
.Composite
;
97 import org
.eclipse
.swt
.widgets
.Display
;
98 import org
.eclipse
.swt
.widgets
.Event
;
99 import org
.eclipse
.swt
.widgets
.Label
;
100 import org
.eclipse
.swt
.widgets
.Listener
;
101 import org
.eclipse
.swt
.widgets
.Menu
;
102 import org
.eclipse
.swt
.widgets
.MessageBox
;
103 import org
.eclipse
.swt
.widgets
.Shell
;
104 import org
.eclipse
.swt
.widgets
.TableColumn
;
105 import org
.eclipse
.swt
.widgets
.TableItem
;
106 import org
.eclipse
.swt
.widgets
.Text
;
107 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
108 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
109 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
110 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
111 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
112 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
113 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
114 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
115 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
116 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfEventFieldAspect
;
117 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
118 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
119 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
120 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
121 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
122 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
123 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
124 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
141 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
142 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
143 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
144 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
145 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
146 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
147 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
148 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
149 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
150 import org
.eclipse
.ui
.IWorkbenchPage
;
151 import org
.eclipse
.ui
.PlatformUI
;
152 import org
.eclipse
.ui
.commands
.ICommandService
;
153 import org
.eclipse
.ui
.dialogs
.ListDialog
;
154 import org
.eclipse
.ui
.handlers
.IHandlerService
;
155 import org
.eclipse
.ui
.ide
.IDE
;
156 import org
.eclipse
.ui
.ide
.IGotoMarker
;
157 import org
.eclipse
.ui
.themes
.ColorUtil
;
159 import com
.google
.common
.base
.Joiner
;
160 import com
.google
.common
.collect
.HashMultimap
;
161 import com
.google
.common
.collect
.ImmutableList
;
162 import com
.google
.common
.collect
.Multimap
;
165 * The generic TMF Events table
167 * This is a view that will list events that are read from a trace.
169 * @author Francois Chouinard
170 * @author Patrick Tasse
173 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
176 * Empty string array, used by {@link #getItemStrings}.
179 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
185 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
187 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
189 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
190 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
191 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
192 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
193 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
194 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
195 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
196 private static final Image FILTER_IMAGE
= Activator
.getDefault()
197 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
198 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
199 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
200 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
201 private static final int MAX_CACHE_SIZE
= 1000;
203 private static final int MARGIN_COLUMN_INDEX
= 0;
204 private static final int FILTER_SUMMARY_INDEX
= 1;
205 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
208 * The events table search/filter keys
211 * @author Patrick Tasse
213 public interface Key
{
215 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
218 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
221 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
224 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
227 String TIMESTAMP
= "$time"; //$NON-NLS-1$
230 String RANK
= "$rank"; //$NON-NLS-1$
233 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
235 /** Bookmark indicator */
236 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
240 * The events table search/filter state
243 * @author Patrick Tasse
245 public static enum HeaderState
{
246 /** A search is being run */
249 /** A filter is applied */
253 interface Direction
{
258 // ------------------------------------------------------------------------
260 // ------------------------------------------------------------------------
262 /** The virtual event table */
263 protected TmfVirtualTable fTable
;
265 private Composite fComposite
;
266 private SashForm fSashForm
;
267 private TmfRawEventViewer fRawViewer
;
268 private ITmfTrace fTrace
;
269 volatile private boolean fPackDone
= false;
270 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
271 private long fSelectedRank
= 0;
272 private ITmfTimestamp fSelectedBeginTimestamp
= null;
273 private IStatusLineManager fStatusLineManager
= null;
276 private long fFilterMatchCount
;
277 private long fFilterCheckCount
;
278 private FilterThread fFilterThread
;
279 private boolean fFilterThreadResume
= false;
280 private final Object fFilterSyncObj
= new Object();
281 private SearchThread fSearchThread
;
282 private final Object fSearchSyncObj
= new Object();
285 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
287 * @see #fireSelectionChanged
289 private ListenerList selectionChangedListeners
= new ListenerList();
291 // Bookmark map <Rank, MarkerId>
292 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
293 private IFile fBookmarksFile
;
294 private long fPendingGotoRank
= -1;
297 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
298 private Color fGrayColor
;
299 private Color fGreenColor
;
300 private Font fBoldFont
;
302 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
305 private final TmfEventsCache fCache
;
306 private boolean fCacheUpdateBusy
= false;
307 private boolean fCacheUpdatePending
= false;
308 private boolean fCacheUpdateCompleted
= false;
309 private final Object fCacheUpdateSyncObj
= new Object();
311 private boolean fDisposeOnClose
;
313 // ------------------------------------------------------------------------
315 // ------------------------------------------------------------------------
318 * Basic constructor, using the default set of columns
321 * The parent composite UI object
323 * The size of the event table cache
325 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
326 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
330 * Legacy constructor, using ColumnData to define columns
333 * The parent composite UI object
335 * The size of the event table cache
338 * @deprecated Deprecated constructor, use
339 * {@link #TmfEventsTable(Composite, int, Collection)}
342 public TmfEventsTable(final Composite parent
, int cacheSize
,
343 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
345 * We'll do a "best-effort" to keep trace types still using this API to
346 * keep working, by defining a TmfEventTableFieldColumn for each
347 * ColumnData they passed.
349 this(parent
, cacheSize
, convertFromColumnData(columnData
));
353 private static Iterable
<ITmfEventAspect
> convertFromColumnData(
354 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
356 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
357 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
358 String fieldName
= col
.header
;
359 if (fieldName
!= null) {
360 builder
.add(new TmfEventFieldAspect(fieldName
, fieldName
));
363 return builder
.build();
367 * Standard constructor, where we define which columns to use.
370 * The parent composite UI object
372 * The size of the event table cache
374 * The event aspects to display in this table. One column per
375 * aspect will be created.
377 * The iteration order of this collection will correspond to the
378 * initial ordering of the columns in the table.
382 public TmfEventsTable(final Composite parent
, int cacheSize
,
383 Iterable
<ITmfEventAspect
> aspects
) {
384 super("TmfEventsTable"); //$NON-NLS-1$
386 fComposite
= new Composite(parent
, SWT
.NONE
);
387 final GridLayout gl
= new GridLayout(1, false);
390 gl
.verticalSpacing
= 0;
391 fComposite
.setLayout(gl
);
393 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
394 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
396 // Create a virtual table
397 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
398 fTable
= new TmfVirtualTable(fSashForm
, style
);
400 // Set the table layout
401 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
402 fTable
.setLayoutData(layoutData
);
404 // Some cosmetic enhancements
405 fTable
.setHeaderVisible(true);
406 fTable
.setLinesVisible(true);
409 if (aspects
!= null) {
410 for (ITmfEventAspect aspect
: aspects
) {
411 if (aspect
!= null) {
412 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
.FIELD_ID
, col
.getFilterFieldId());
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 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
672 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
678 fSashForm
.setWeights(new int[] { 1, 1 });
679 fRawViewer
.setVisible(false);
684 // ------------------------------------------------------------------------
686 // ------------------------------------------------------------------------
689 * Create a pop-up menu.
691 protected void createPopupMenu() {
692 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
695 fTable
.setVisible(true);
700 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
703 fTable
.setVisible(false);
708 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
711 fRawViewer
.setVisible(true);
713 final int index
= fTable
.getSelectionIndex();
715 fRawViewer
.selectAndReveal(index
- 1);
720 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
723 fRawViewer
.setVisible(false);
728 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
731 final TableItem items
[] = fTable
.getSelection();
732 if (items
.length
!= 1) {
735 final TableItem item
= items
[0];
737 final Object data
= item
.getData();
738 if (data
instanceof ITmfSourceLookup
) {
739 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
740 ITmfCallsite cs
= event
.getCallsite();
741 if (cs
== null || cs
.getFileName() == null) {
744 IMarker marker
= null;
746 String fileName
= cs
.getFileName();
747 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
748 final ArrayList
<IFile
> files
= new ArrayList
<>();
749 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
751 public boolean visit(IResource resource
) throws CoreException
{
752 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
753 files
.add((IFile
) resource
);
759 if (files
.size() > 1) {
760 ListDialog dialog
= new ListDialog(getTable().getShell());
761 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
762 dialog
.setLabelProvider(new LabelProvider() {
764 public String
getText(Object element
) {
765 return ((IFile
) element
).getFullPath().toString();
768 dialog
.setInput(files
);
769 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
770 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
772 Object
[] result
= dialog
.getResult();
773 if (result
!= null && result
.length
> 0) {
774 file
= (IFile
) result
[0];
776 } else if (files
.size() == 1) {
780 marker
= file
.createMarker(IMarker
.MARKER
);
781 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
782 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
784 } else if (files
.size() == 0){
785 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
787 } catch (CoreException e
) {
794 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
798 final TableItem items
[] = fTable
.getSelection();
799 if (items
.length
!= 1) {
802 final TableItem item
= items
[0];
804 final Object eventData
= item
.getData();
805 if (eventData
instanceof ITmfModelLookup
) {
806 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
808 if (modelURI
!= null) {
809 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
812 final URI uri
= URI
.createURI(modelURI
);
813 if (uri
.isPlatformResource()) {
814 IPath path
= new Path(uri
.toPlatformString(true));
815 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
816 } else if (uri
.isFile() && !uri
.isRelative()) {
817 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
818 new Path(uri
.toFileString()));
824 * create a temporary validation marker on the
825 * model file, remove it afterwards thus,
826 * navigation works with all model editors
827 * supporting the navigation to a marker
829 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
830 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
831 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
833 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
836 catch (CoreException e
) {
840 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
847 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
850 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
851 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
852 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
853 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
854 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
856 HashMap
<String
, Object
> parameters
= new HashMap
<>();
857 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
858 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
860 IEvaluationContext context
= handlerService
.getCurrentState();
861 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
862 for (int i
: fTable
.getColumnOrder()) {
863 // Omit the margin column
864 if (i
>= EVENT_COLUMNS_START_INDEX
) {
865 exportColumns
.add(fColumns
.get(i
));
868 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
870 handlerService
.executeCommandInContext(cmd
, null, context
);
871 } catch (ExecutionException e
) {
873 } catch (NotDefinedException e
) {
875 } catch (NotEnabledException e
) {
877 } catch (NotHandledException e
) {
883 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
886 fHeaderState
= HeaderState
.SEARCH
;
891 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
894 fHeaderState
= HeaderState
.FILTER
;
899 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
906 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
909 applyFilter(new TmfCollapseFilter());
913 class ToggleBookmarkAction
extends Action
{
916 public ToggleBookmarkAction(final String text
, final Long rank
) {
923 toggleBookmark(fRank
);
927 final MenuManager tablePopupMenu
= new MenuManager();
928 tablePopupMenu
.setRemoveAllWhenShown(true);
929 tablePopupMenu
.addMenuListener(new IMenuListener() {
931 public void menuAboutToShow(final IMenuManager manager
) {
932 if (fTable
.getSelectionIndex() == 0) {
933 // Right-click on header row
934 if (fHeaderState
== HeaderState
.FILTER
) {
935 tablePopupMenu
.add(showSearchBarAction
);
937 tablePopupMenu
.add(showFilterBarAction
);
941 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
942 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
944 final Rectangle imageBounds
= item
.getImageBounds(0);
945 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
946 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
947 // Right-click on left margin
948 final Long rank
= (Long
) item
.getData(Key
.RANK
);
949 if ((rank
!= null) && (fBookmarksFile
!= null)) {
950 if (fBookmarksMap
.containsKey(rank
)) {
951 tablePopupMenu
.add(new ToggleBookmarkAction(
952 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
954 tablePopupMenu
.add(new ToggleBookmarkAction(
955 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
962 // Right-click on table
963 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
964 tablePopupMenu
.add(hideTableAction
);
965 tablePopupMenu
.add(hideRawAction
);
966 } else if (!fTable
.isVisible()) {
967 tablePopupMenu
.add(showTableAction
);
968 } else if (!fRawViewer
.isVisible()) {
969 tablePopupMenu
.add(showRawAction
);
971 tablePopupMenu
.add(exportToTextAction
);
972 tablePopupMenu
.add(new Separator());
975 final Object data
= item
.getData();
976 Separator separator
= null;
977 if (data
instanceof ITmfSourceLookup
) {
978 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
979 if (event
.getCallsite() != null) {
980 tablePopupMenu
.add(openCallsiteAction
);
981 separator
= new Separator();
985 if (data
instanceof ITmfModelLookup
) {
986 ITmfModelLookup event
= (ITmfModelLookup
) data
;
987 if (event
.getModelUri() != null) {
988 tablePopupMenu
.add(openModelAction
);
989 separator
= new Separator();
992 if (separator
!= null) {
993 tablePopupMenu
.add(separator
);
998 // only show collapse filter if at least one trace can be collapsed
999 boolean isCollapsible
= false;
1000 if (fTrace
!= null) {
1001 ITmfTrace traces
[] = TmfTraceManager
.getTraceSet(fTrace
);
1002 for (ITmfTrace trace
: traces
) {
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
);
1140 item
.setText(itemStrings
);
1141 item
.setData(event
);
1142 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1143 item
.setData(Key
.RANK
, rank
);
1145 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1146 if (!markerIds
.isEmpty()) {
1147 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1148 List
<Object
> parts
= new ArrayList
<>();
1149 if (markerIds
.size() > 1) {
1150 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1153 for (long markerId
: markerIds
) {
1154 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1155 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1157 } catch (CoreException e
) {
1158 displayException(e
);
1160 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1162 item
.setData(Key
.BOOKMARK
, null);
1165 boolean searchMatch
= false;
1166 boolean searchNoMatch
= false;
1167 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1168 if (searchFilter
!= null) {
1169 if (searchFilter
.matches(event
)) {
1172 searchNoMatch
= true;
1176 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1177 if (searchNoMatch
) {
1178 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1179 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1181 item
.setForeground(colorSetting
.getForegroundColor());
1182 item
.setBackground(colorSetting
.getBackgroundColor());
1186 if (!markerIds
.isEmpty()) {
1187 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1189 item
.setImage(SEARCH_MATCH_IMAGE
);
1191 } else if (!markerIds
.isEmpty()) {
1192 item
.setImage(BOOKMARK_IMAGE
);
1194 item
.setImage((Image
) null);
1197 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1203 * Set the item data of the header row.
1206 * The item to use as table header
1208 protected void setHeaderRowItemData(final TableItem item
) {
1209 String txtKey
= null;
1210 if (fHeaderState
== HeaderState
.SEARCH
) {
1211 item
.setImage(SEARCH_IMAGE
);
1212 txtKey
= Key
.SEARCH_TXT
;
1213 } else if (fHeaderState
== HeaderState
.FILTER
) {
1214 item
.setImage(FILTER_IMAGE
);
1215 txtKey
= Key
.FILTER_TXT
;
1217 item
.setForeground(fGrayColor
);
1218 // Ignore collapse and image column
1219 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1220 final TableColumn column
= fTable
.getColumns()[i
];
1221 final String filter
= (String
) column
.getData(txtKey
);
1222 if (filter
== null) {
1223 if (fHeaderState
== HeaderState
.SEARCH
) {
1224 item
.setText(i
, SEARCH_HINT
);
1225 } else if (fHeaderState
== HeaderState
.FILTER
) {
1226 item
.setText(i
, FILTER_HINT
);
1228 item
.setForeground(i
, fGrayColor
);
1229 item
.setFont(i
, fTable
.getFont());
1231 item
.setText(i
, filter
);
1232 item
.setForeground(i
, fGreenColor
);
1233 item
.setFont(i
, fBoldFont
);
1239 * Set the item data of the "filter status" row.
1242 * The item to use as filter status row
1244 protected void setFilterStatusRowItemData(final TableItem item
) {
1245 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1246 if (i
== MARGIN_COLUMN_INDEX
) {
1247 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1248 item
.setImage(FILTER_IMAGE
);
1250 item
.setImage(STOP_IMAGE
);
1254 if (i
== FILTER_SUMMARY_INDEX
) {
1255 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1257 item
.setText(i
, EMPTY_STRING
);
1261 item
.setData(Key
.TIMESTAMP
, null);
1262 item
.setData(Key
.RANK
, null);
1263 item
.setForeground(null);
1264 item
.setBackground(null);
1268 * Create an editor for the header.
1270 protected void createHeaderEditor() {
1271 final TableEditor tableEditor
= fTable
.createTableEditor();
1272 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1273 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1274 tableEditor
.grabHorizontal
= true;
1275 tableEditor
.minimumWidth
= 50;
1277 // Handle the header row selection
1278 fTable
.addMouseListener(new MouseAdapter() {
1284 public void mouseDown(final MouseEvent event
) {
1285 if (event
.button
!= 1) {
1288 // Identify the selected row
1289 final Point point
= new Point(event
.x
, event
.y
);
1290 item
= fTable
.getItem(point
);
1292 // Header row selected
1293 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1296 if (item
.getImageBounds(0).contains(point
)) {
1297 if (fHeaderState
== HeaderState
.SEARCH
) {
1298 fHeaderState
= HeaderState
.FILTER
;
1299 } else if (fHeaderState
== HeaderState
.FILTER
) {
1300 fHeaderState
= HeaderState
.SEARCH
;
1302 fTable
.setSelection(0);
1307 // Identify the selected column
1309 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1310 final Rectangle rect
= item
.getBounds(i
);
1311 if (rect
.contains(point
)) {
1317 if (columnIndex
== -1) {
1321 column
= fTable
.getColumns()[columnIndex
];
1323 String txtKey
= null;
1324 if (fHeaderState
== HeaderState
.SEARCH
) {
1325 txtKey
= Key
.SEARCH_TXT
;
1326 } else if (fHeaderState
== HeaderState
.FILTER
) {
1327 txtKey
= Key
.FILTER_TXT
;
1330 // The control that will be the editor must be a child of the Table
1331 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1332 final String headerString
= (String
) column
.getData(txtKey
);
1333 if (headerString
!= null) {
1334 newEditor
.setText(headerString
);
1336 newEditor
.addFocusListener(new FocusAdapter() {
1338 public void focusLost(final FocusEvent e
) {
1339 final boolean changed
= updateHeader(newEditor
.getText());
1345 newEditor
.addKeyListener(new KeyAdapter() {
1347 public void keyPressed(final KeyEvent e
) {
1348 if (e
.character
== SWT
.CR
) {
1349 updateHeader(newEditor
.getText());
1352 // Set focus on the table so that the next carriage return goes to the next result
1353 TmfEventsTable
.this.getTable().setFocus();
1354 } else if (e
.character
== SWT
.ESC
) {
1355 tableEditor
.getEditor().dispose();
1359 newEditor
.selectAll();
1360 newEditor
.setFocus();
1361 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1366 * returns true is value was changed
1368 private boolean updateHeader(final String text
) {
1369 String objKey
= null;
1370 String txtKey
= null;
1371 if (fHeaderState
== HeaderState
.SEARCH
) {
1372 objKey
= Key
.SEARCH_OBJ
;
1373 txtKey
= Key
.SEARCH_TXT
;
1374 } else if (fHeaderState
== HeaderState
.FILTER
) {
1375 objKey
= Key
.FILTER_OBJ
;
1376 txtKey
= Key
.FILTER_TXT
;
1378 if (text
.trim().length() > 0) {
1380 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1381 Pattern
.compile(regex
);
1382 if (regex
.equals(column
.getData(txtKey
))) {
1383 tableEditor
.getEditor().dispose();
1386 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1387 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1388 if (fieldId
== null) {
1389 fieldId
= column
.getText();
1391 filter
.setField(fieldId
);
1392 filter
.setRegex(regex
);
1393 column
.setData(objKey
, filter
);
1394 column
.setData(txtKey
, regex
);
1395 } catch (final PatternSyntaxException ex
) {
1396 tableEditor
.getEditor().dispose();
1397 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1398 ex
.getDescription(), ex
.getMessage());
1402 if (column
.getData(txtKey
) == null) {
1403 tableEditor
.getEditor().dispose();
1406 column
.setData(objKey
, null);
1407 column
.setData(txtKey
, null);
1412 private void applyHeader() {
1413 if (fHeaderState
== HeaderState
.SEARCH
) {
1415 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1416 for (final TableColumn col
: fTable
.getColumns()) {
1417 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1418 if (filterObj
instanceof ITmfFilterTreeNode
) {
1419 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1422 if (filter
.getChildrenCount() > 0) {
1423 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1426 fireSearchApplied(filter
);
1428 fTable
.setData(Key
.SEARCH_OBJ
, null);
1430 fireSearchApplied(null);
1432 } else if (fHeaderState
== HeaderState
.FILTER
) {
1433 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1434 for (final TableColumn col
: fTable
.getColumns()) {
1435 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1436 if (filterObj
instanceof ITmfFilterTreeNode
) {
1437 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1440 if (filter
.getChildrenCount() > 0) {
1441 applyFilter(filter
);
1447 tableEditor
.getEditor().dispose();
1451 fTable
.addKeyListener(new KeyAdapter() {
1453 public void keyPressed(final KeyEvent e
) {
1455 if (e
.character
== SWT
.ESC
) {
1459 } else if (e
.character
== SWT
.DEL
) {
1460 if (fHeaderState
== HeaderState
.SEARCH
) {
1462 for (final TableColumn column
: fTable
.getColumns()) {
1463 column
.setData(Key
.SEARCH_OBJ
, null);
1464 column
.setData(Key
.SEARCH_TXT
, null);
1466 fTable
.setData(Key
.SEARCH_OBJ
, null);
1468 fireSearchApplied(null);
1469 } else if (fHeaderState
== HeaderState
.FILTER
) {
1472 } else if (e
.character
== SWT
.CR
) {
1473 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1484 * Send an event indicating a filter has been applied.
1487 * The filter that was just applied
1489 protected void fireFilterApplied(final ITmfFilter filter
) {
1490 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1494 * Send an event indicating that a search has been applied.
1497 * The search filter that was just applied
1499 protected void fireSearchApplied(final ITmfFilter filter
) {
1500 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1504 * Start the filtering thread.
1506 protected void startFilterThread() {
1507 synchronized (fFilterSyncObj
) {
1508 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1509 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1510 if (fFilterThread
!= null) {
1511 fFilterThread
.cancel();
1512 fFilterThreadResume
= false;
1514 fFilterThread
= new FilterThread(filter
);
1515 fFilterThread
.start();
1517 fFilterThreadResume
= true;
1523 * Stop the filtering thread.
1525 protected void stopFilterThread() {
1526 synchronized (fFilterSyncObj
) {
1527 if (fFilterThread
!= null) {
1528 fFilterThread
.cancel();
1529 fFilterThread
= null;
1530 fFilterThreadResume
= false;
1539 * The filter to apply
1542 protected void applyFilter(ITmfFilter filter
) {
1545 fFilterMatchCount
= 0;
1546 fFilterCheckCount
= 0;
1547 fCache
.applyFilter(filter
);
1549 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1550 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1551 startFilterThread();
1552 fireFilterApplied(filter
);
1556 * Clear all currently active filters.
1558 protected void clearFilters() {
1559 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1564 fCache
.clearFilter();
1566 for (final TableColumn column
: fTable
.getColumns()) {
1567 column
.setData(Key
.FILTER_OBJ
, null);
1568 column
.setData(Key
.FILTER_TXT
, null);
1570 fTable
.setData(Key
.FILTER_OBJ
, null);
1571 if (fTrace
!= null) {
1572 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1574 fTable
.setItemCount(1); // +1 for header row
1576 fFilterMatchCount
= 0;
1577 fFilterCheckCount
= 0;
1578 if (fSelectedRank
>= 0) {
1579 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1581 fTable
.setSelection(0);
1583 fireFilterApplied(null);
1584 updateStatusLine(null);
1586 // Set original width
1587 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1592 * Wrapper Thread object for the filtering thread.
1594 protected class FilterThread
extends Thread
{
1595 private final ITmfFilterTreeNode filter
;
1596 private TmfEventRequest request
;
1597 private boolean refreshBusy
= false;
1598 private boolean refreshPending
= false;
1599 private final Object syncObj
= new Object();
1605 * The filter this thread will be processing
1607 public FilterThread(final ITmfFilterTreeNode filter
) {
1608 super("Filter Thread"); //$NON-NLS-1$
1609 this.filter
= filter
;
1614 if (fTrace
== null) {
1617 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1618 if (nbRequested
<= 0) {
1621 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1622 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1624 public void handleData(final ITmfEvent event
) {
1625 super.handleData(event
);
1626 if (request
.isCancelled()) {
1629 boolean refresh
= false;
1630 if (filter
.matches(event
)) {
1631 final long rank
= fFilterCheckCount
;
1632 final int index
= (int) fFilterMatchCount
;
1633 fFilterMatchCount
++;
1634 fCache
.storeEvent(event
, rank
, index
);
1637 if (filter
instanceof TmfCollapseFilter
) {
1638 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1642 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1645 fFilterCheckCount
++;
1648 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1650 request
.waitForCompletion();
1651 } catch (final InterruptedException e
) {
1654 synchronized (fFilterSyncObj
) {
1655 fFilterThread
= null;
1656 if (fFilterThreadResume
) {
1657 fFilterThreadResume
= false;
1658 fFilterThread
= new FilterThread(filter
);
1659 fFilterThread
.start();
1665 * Refresh the filter.
1667 public void refreshTable() {
1668 synchronized (syncObj
) {
1670 refreshPending
= true;
1675 Display
.getDefault().asyncExec(new Runnable() {
1678 if (request
.isCancelled()) {
1681 if (fTable
.isDisposed()) {
1684 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1686 synchronized (syncObj
) {
1687 refreshBusy
= false;
1688 if (refreshPending
) {
1689 refreshPending
= false;
1698 * Cancel this filtering thread.
1700 public void cancel() {
1701 if (request
!= null) {
1708 * Go to the next item of a search.
1710 protected void searchNext() {
1711 synchronized (fSearchSyncObj
) {
1712 if (fSearchThread
!= null) {
1715 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1716 if (searchFilter
== null) {
1719 final int selectionIndex
= fTable
.getSelectionIndex();
1721 if (selectionIndex
> 0) {
1722 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1724 // header row is selected, start at top event
1725 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1727 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1728 if (eventFilter
!= null) {
1729 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1731 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1732 fSearchThread
.schedule();
1737 * Go to the previous item of a search.
1739 protected void searchPrevious() {
1740 synchronized (fSearchSyncObj
) {
1741 if (fSearchThread
!= null) {
1744 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1745 if (searchFilter
== null) {
1748 final int selectionIndex
= fTable
.getSelectionIndex();
1750 if (selectionIndex
> 0) {
1751 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1753 // header row is selected, start at precedent of top event
1754 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1756 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1757 if (eventFilter
!= null) {
1758 startIndex
= startIndex
- 1; // -1 for top filter status row
1760 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1761 fSearchThread
.schedule();
1766 * Stop the search thread.
1768 protected void stopSearchThread() {
1769 fPendingGotoRank
= -1;
1770 synchronized (fSearchSyncObj
) {
1771 if (fSearchThread
!= null) {
1772 fSearchThread
.cancel();
1773 fSearchThread
= null;
1779 * Wrapper for the search thread.
1781 protected class SearchThread
extends Job
{
1783 private ITmfFilterTreeNode searchFilter
;
1784 private ITmfFilterTreeNode eventFilter
;
1785 private int startIndex
;
1786 private int direction
;
1788 private long foundRank
= -1;
1789 private TmfEventRequest request
;
1790 private ITmfTimestamp foundTimestamp
= null;
1795 * @param searchFilter
1797 * @param eventFilter
1800 * The index at which we should start searching
1801 * @param currentRank
1804 * In which direction should we search, forward or backwards
1806 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1807 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1808 final long currentRank
, final int direction
) {
1809 super(Messages
.TmfEventsTable_SearchingJobName
);
1810 this.searchFilter
= searchFilter
;
1811 this.eventFilter
= eventFilter
;
1812 this.startIndex
= startIndex
;
1813 this.rank
= currentRank
;
1814 this.direction
= direction
;
1818 protected IStatus
run(final IProgressMonitor monitor
) {
1819 if (fTrace
== null) {
1820 return Status
.OK_STATUS
;
1822 final Display display
= Display
.getDefault();
1823 if (startIndex
< 0) {
1824 rank
= (int) fTrace
.getNbEvents() - 1;
1825 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1828 int idx
= startIndex
;
1829 while (foundRank
== -1) {
1830 final CachedEvent event
= fCache
.peekEvent(idx
);
1831 if (event
== null) {
1835 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1836 foundRank
= event
.rank
;
1837 foundTimestamp
= event
.event
.getTimestamp();
1840 if (direction
== Direction
.FORWARD
) {
1846 if (foundRank
== -1) {
1847 if (direction
== Direction
.FORWARD
) {
1849 if (rank
> (fTrace
.getNbEvents() - 1)) {
1855 rank
= (int) fTrace
.getNbEvents() - 1;
1860 final int startRank
= (int) rank
;
1861 boolean wrapped
= false;
1862 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1863 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1864 if (direction
== Direction
.BACKWARD
) {
1865 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1867 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1868 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1869 long currentRank
= rank
;
1872 public void handleData(final ITmfEvent event
) {
1873 super.handleData(event
);
1874 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1875 foundRank
= currentRank
;
1876 foundTimestamp
= event
.getTimestamp();
1877 if (direction
== Direction
.FORWARD
) {
1885 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1887 request
.waitForCompletion();
1888 if (request
.isCancelled()) {
1889 return Status
.OK_STATUS
;
1891 } catch (final InterruptedException e
) {
1892 synchronized (fSearchSyncObj
) {
1893 fSearchThread
= null;
1895 return Status
.OK_STATUS
;
1897 if (foundRank
== -1) {
1898 if (direction
== Direction
.FORWARD
) {
1900 synchronized (fSearchSyncObj
) {
1901 fSearchThread
= null;
1903 return Status
.OK_STATUS
;
1905 nbRequested
= (int) rank
;
1911 rank
= (int) fTrace
.getNbEvents() - 1;
1914 if ((rank
<= startRank
) && wrapped
) {
1915 synchronized (fSearchSyncObj
) {
1916 fSearchThread
= null;
1918 return Status
.OK_STATUS
;
1923 int index
= (int) foundRank
;
1924 if (eventFilter
!= null) {
1925 index
= fCache
.getFilteredEventIndex(foundRank
);
1927 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1929 display
.asyncExec(new Runnable() {
1932 if (monitor
.isCanceled()) {
1935 if (fTable
.isDisposed()) {
1938 fTable
.setSelection(selection
);
1939 fSelectedRank
= foundRank
;
1940 fRawViewer
.selectAndReveal(fSelectedRank
);
1941 if (foundTimestamp
!= null) {
1942 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1944 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1945 synchronized (fSearchSyncObj
) {
1946 fSearchThread
= null;
1948 updateStatusLine(null);
1951 return Status
.OK_STATUS
;
1955 protected void canceling() {
1957 synchronized (fSearchSyncObj
) {
1958 fSearchThread
= null;
1964 * Create the resources.
1966 protected void createResources() {
1967 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1968 .getForeground().getRGB()));
1969 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1970 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1976 protected void packColumns() {
1980 fTable
.setRedraw(false);
1982 TableColumn tableColumns
[] = fTable
.getColumns();
1983 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1984 final TableColumn column
= tableColumns
[i
];
1985 packSingleColumn(i
, column
);
1988 // Make sure that redraw is always enabled.
1989 fTable
.setRedraw(true);
1995 private void packMarginColumn() {
1996 TableColumn
[] columns
= fTable
.getColumns();
1997 if (columns
.length
> 0) {
1998 packSingleColumn(0, columns
[0]);
2002 private void packSingleColumn(int i
, final TableColumn column
) {
2003 final int headerWidth
= column
.getWidth();
2005 // Workaround for Linux which doesn't consider the image width of
2006 // search/filter row in TableColumn.pack() after having executed
2007 // TableItem.setImage((Image)null) for other rows than search/filter row.
2008 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2009 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2010 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2013 if (column
.getWidth() < headerWidth
) {
2014 column
.setWidth(headerWidth
);
2019 * Get the array of item strings (e.g., what to display in each cell of the
2020 * table row) corresponding to the columns and trace event passed in
2021 * parameter. The order of the Strings in the returned array will correspond
2022 * to the iteration order of 'columns'.
2025 * To ensure consistent results, make sure only call this within a scope
2026 * synchronized on 'columns'! If the order of 'columns' changes right after
2027 * this method is called, the returned value won't be ordered correctly
2030 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2031 if (event
== null) {
2032 return EMPTY_STRING_ARRAY
;
2034 synchronized (columns
) {
2035 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2036 for (TmfEventTableColumn column
: columns
) {
2037 ITmfEvent passedEvent
= event
;
2038 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2039 // Make sure that the event object from the trace is passed
2040 // to all columns but the TmfMarginColumn
2041 passedEvent
= ((CachedEvent
) event
).event
;
2043 if (passedEvent
== null) {
2044 itemStrings
.add(EMPTY_STRING
);
2046 itemStrings
.add(column
.getItemString(passedEvent
));
2050 return itemStrings
.toArray(new String
[0]);
2055 * Get the contents of the row in the events table corresponding to an
2056 * event. The order of the elements corresponds to the current order of the
2060 * The event printed in this row
2061 * @return The event row entries
2064 public String
[] getItemStrings(ITmfEvent event
) {
2065 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2066 for (int i
: fTable
.getColumnOrder()) {
2067 columns
.add(fColumns
.get(i
));
2069 return getItemStrings(columns
, event
);
2073 * Notify this table that is got the UI focus.
2075 public void setFocus() {
2080 * Assign a new trace to this event table.
2083 * The trace to assign to this event table
2084 * @param disposeOnClose
2085 * true if the trace should be disposed when the table is
2088 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2089 if ((fTrace
!= null) && fDisposeOnClose
) {
2095 fDisposeOnClose
= disposeOnClose
;
2097 // Perform the updates on the UI thread
2098 fTable
.getDisplay().syncExec(new Runnable() {
2102 fCache
.setTrace(fTrace
); // Clear the cache
2103 if (fTrace
!= null) {
2104 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2105 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2106 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2109 fFilterMatchCount
= 0;
2110 fFilterCheckCount
= 0;
2111 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2112 startFilterThread();
2116 fRawViewer
.setTrace(fTrace
);
2122 * Assign the status line manager
2124 * @param statusLineManager
2125 * The status line manager, or null to disable status line messages
2128 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2129 if (fStatusLineManager
!= null && statusLineManager
== null) {
2130 fStatusLineManager
.setMessage(EMPTY_STRING
);
2132 fStatusLineManager
= statusLineManager
;
2135 private void updateStatusLine(ITmfTimestamp delta
) {
2136 if (fStatusLineManager
!= null) {
2137 if (delta
!= null) {
2138 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2140 fStatusLineManager
.setMessage(null);
2145 // ------------------------------------------------------------------------
2147 // ------------------------------------------------------------------------
2150 * Notify that the event cache has been updated
2153 * Also notify if the populating of the cache is complete, or
2156 public void cacheUpdated(final boolean completed
) {
2157 synchronized (fCacheUpdateSyncObj
) {
2158 if (fCacheUpdateBusy
) {
2159 fCacheUpdatePending
= true;
2160 fCacheUpdateCompleted
= completed
;
2163 fCacheUpdateBusy
= true;
2165 // Event cache is now updated. Perform update on the UI thread
2166 if (!fTable
.isDisposed()) {
2167 fTable
.getDisplay().asyncExec(new Runnable() {
2170 if (!fTable
.isDisposed()) {
2175 populateCompleted();
2177 synchronized (fCacheUpdateSyncObj
) {
2178 fCacheUpdateBusy
= false;
2179 if (fCacheUpdatePending
) {
2180 fCacheUpdatePending
= false;
2181 cacheUpdated(fCacheUpdateCompleted
);
2190 * Callback for when populating the table is complete.
2192 protected void populateCompleted() {
2193 // Nothing by default;
2196 // ------------------------------------------------------------------------
2197 // ISelectionProvider
2198 // ------------------------------------------------------------------------
2204 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2205 selectionChangedListeners
.add(listener
);
2212 public ISelection
getSelection() {
2213 if (fTable
== null || fTable
.isDisposed()) {
2214 return StructuredSelection
.EMPTY
;
2216 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2217 for (TableItem item
: fTable
.getSelection()) {
2218 if (item
.getData() != null) {
2219 list
.add(item
.getData());
2222 return new StructuredSelection(list
);
2229 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2230 selectionChangedListeners
.remove(listener
);
2237 public void setSelection(ISelection selection
) {
2242 * Notifies any selection changed listeners that the viewer's selection has changed.
2243 * Only listeners registered at the time this method is called are notified.
2245 * @param event a selection changed event
2247 * @see ISelectionChangedListener#selectionChanged
2250 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2251 Object
[] listeners
= selectionChangedListeners
.getListeners();
2252 for (int i
= 0; i
< listeners
.length
; ++i
) {
2253 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2254 SafeRunnable
.run(new SafeRunnable() {
2257 l
.selectionChanged(event
);
2263 // ------------------------------------------------------------------------
2264 // Bookmark handling
2265 // ------------------------------------------------------------------------
2268 * Add a bookmark to this event table.
2270 * @param bookmarksFile
2271 * The file to use for the bookmarks
2273 public void addBookmark(final IFile bookmarksFile
) {
2274 fBookmarksFile
= bookmarksFile
;
2275 final TableItem
[] selection
= fTable
.getSelection();
2276 if (selection
.length
> 0) {
2277 final TableItem tableItem
= selection
[0];
2278 if (tableItem
.getData(Key
.RANK
) != null) {
2279 final StringBuffer defaultMessage
= new StringBuffer();
2280 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2282 defaultMessage
.append(", "); //$NON-NLS-1$
2284 defaultMessage
.append(tableItem
.getText(i
));
2286 final InputDialog dialog
= new MultiLineInputDialog(
2287 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2288 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2289 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2290 defaultMessage
.toString());
2291 if (dialog
.open() == Window
.OK
) {
2292 final String message
= dialog
.getValue();
2294 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2295 if (bookmark
.exists()) {
2296 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2297 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2298 final int location
= rank
.intValue();
2299 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2300 fBookmarksMap
.put(rank
, bookmark
.getId());
2303 } catch (final CoreException e
) {
2304 displayException(e
);
2313 * Remove a bookmark from this event table.
2316 * The bookmark to remove
2318 public void removeBookmark(final IMarker bookmark
) {
2319 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2320 if (entry
.getValue().equals(bookmark
.getId())) {
2321 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2328 private void toggleBookmark(final Long rank
) {
2329 if (fBookmarksFile
== null) {
2332 if (fBookmarksMap
.containsKey(rank
)) {
2333 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2336 for (long markerId
: markerIds
) {
2337 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2338 if (bookmark
!= null) {
2342 } catch (final CoreException e
) {
2343 displayException(e
);
2346 addBookmark(fBookmarksFile
);
2351 * Refresh the bookmarks assigned to this trace, from the contents of a
2354 * @param bookmarksFile
2355 * The bookmark file to use
2357 public void refreshBookmarks(final IFile bookmarksFile
) {
2358 fBookmarksFile
= bookmarksFile
;
2359 if (bookmarksFile
== null) {
2360 fBookmarksMap
.clear();
2365 fBookmarksMap
.clear();
2366 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2367 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2368 if (location
!= -1) {
2369 final long rank
= location
;
2370 fBookmarksMap
.put(rank
, bookmark
.getId());
2374 } catch (final CoreException e
) {
2375 displayException(e
);
2380 public void gotoMarker(final IMarker marker
) {
2381 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2384 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2385 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2386 } else if (rank
>= fTable
.getItemCount()) {
2387 fPendingGotoRank
= rank
;
2389 fSelectedRank
= rank
;
2390 fTable
.setSelection(index
+ 1); // +1 for header row
2391 updateStatusLine(null);
2395 // ------------------------------------------------------------------------
2397 // ------------------------------------------------------------------------
2400 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2404 // ------------------------------------------------------------------------
2406 // ------------------------------------------------------------------------
2409 * Handler for the trace updated signal
2412 * The incoming signal
2415 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2416 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2419 // Perform the refresh on the UI thread
2420 Display
.getDefault().asyncExec(new Runnable() {
2423 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2424 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2425 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2426 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2427 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2428 fPendingGotoRank
= -1;
2429 updateStatusLine(null);
2432 startFilterThread();
2435 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2436 fRawViewer
.refreshEventCount();
2443 * Handler for the time synch signal.
2446 * The incoming signal
2449 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2450 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2452 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2453 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2454 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2455 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2456 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2458 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2461 public void handleData(final ITmfEvent event
) {
2462 super.handleData(event
);
2466 public void handleCompleted() {
2467 super.handleCompleted();
2468 if (fTrace
== null) {
2472 // Verify if the event is within the trace range and adjust if necessary
2473 ITmfTimestamp timestamp
= ts
;
2474 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2475 timestamp
= fTrace
.getStartTime();
2477 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2478 timestamp
= fTrace
.getEndTime();
2481 // Get the rank of the selected event in the table
2482 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2483 final long rank
= context
.getRank();
2485 fSelectedRank
= rank
;
2487 fTable
.getDisplay().asyncExec(new Runnable() {
2490 // Return if table is disposed
2491 if (fTable
.isDisposed()) {
2495 int index
= (int) rank
;
2496 if (fTable
.isDisposed()) {
2499 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2500 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2502 fTable
.setSelection(index
+ 1); // +1 for header row
2503 fRawViewer
.selectAndReveal(rank
);
2504 updateStatusLine(null);
2510 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2514 // ------------------------------------------------------------------------
2516 // ------------------------------------------------------------------------
2519 * Display an exception in a message box
2521 * @param e the exception
2523 private static void displayException(final Exception e
) {
2524 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2525 mb
.setText(e
.getClass().getSimpleName());
2526 mb
.setMessage(e
.getMessage());
2533 public void refresh() {
2540 * Margin column for images and special text (e.g. collapse count)
2542 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2544 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2547 public String
getName() {
2548 return EMPTY_STRING
;
2552 public String
resolve(ITmfEvent event
) {
2553 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2554 return EMPTY_STRING
;
2556 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2560 public String
getHelpText() {
2561 return EMPTY_STRING
;
2565 public String
getFilterId() {
2573 public TmfMarginColumn() {
2574 super(MARGIN_ASPECT
);