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
.TmfContentFieldAspect
;
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
174 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
177 * Empty string array, used by {@link #getItemStrings}.
179 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
184 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
186 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
188 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
189 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
190 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
191 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
192 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
193 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
194 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
195 private static final Image FILTER_IMAGE
= Activator
.getDefault()
196 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
197 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
198 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
199 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
200 private static final int MAX_CACHE_SIZE
= 1000;
202 private static final int MARGIN_COLUMN_INDEX
= 0;
203 private static final int FILTER_SUMMARY_INDEX
= 1;
204 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
207 * The events table search/filter keys
210 * @author Patrick Tasse
212 public interface Key
{
214 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
217 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
220 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
223 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
226 String TIMESTAMP
= "$time"; //$NON-NLS-1$
229 String RANK
= "$rank"; //$NON-NLS-1$
231 /** Bookmark indicator */
232 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
234 /** Event aspect represented by this column */
235 String ASPECT
= "$aspect"; //$NON-NLS-1$
239 * The events table search/filter state
242 * @author Patrick Tasse
244 public static enum HeaderState
{
245 /** A search is being run */
248 /** A filter is applied */
252 interface Direction
{
257 // ------------------------------------------------------------------------
259 // ------------------------------------------------------------------------
261 /** The virtual event table */
262 protected TmfVirtualTable fTable
;
264 private Composite fComposite
;
265 private SashForm fSashForm
;
266 private TmfRawEventViewer fRawViewer
;
267 private ITmfTrace fTrace
;
268 volatile private boolean fPackDone
= false;
269 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
270 private long fSelectedRank
= 0;
271 private ITmfTimestamp fSelectedBeginTimestamp
= null;
272 private IStatusLineManager fStatusLineManager
= null;
275 private long fFilterMatchCount
;
276 private long fFilterCheckCount
;
277 private FilterThread fFilterThread
;
278 private boolean fFilterThreadResume
= false;
279 private final Object fFilterSyncObj
= new Object();
280 private SearchThread fSearchThread
;
281 private final Object fSearchSyncObj
= new Object();
284 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
286 * @see #fireSelectionChanged
288 private ListenerList selectionChangedListeners
= new ListenerList();
290 // Bookmark map <Rank, MarkerId>
291 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
292 private IFile fBookmarksFile
;
293 private long fPendingGotoRank
= -1;
296 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
297 private Color fGrayColor
;
298 private Color fGreenColor
;
299 private Font fBoldFont
;
301 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
304 private final TmfEventsCache fCache
;
305 private boolean fCacheUpdateBusy
= false;
306 private boolean fCacheUpdatePending
= false;
307 private boolean fCacheUpdateCompleted
= false;
308 private final Object fCacheUpdateSyncObj
= new Object();
310 private boolean fDisposeOnClose
;
312 // ------------------------------------------------------------------------
314 // ------------------------------------------------------------------------
317 * Basic constructor, using the default set of columns
320 * The parent composite UI object
322 * The size of the event table cache
324 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
325 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
329 * Legacy constructor, using ColumnData to define columns
332 * The parent composite UI object
334 * The size of the event table cache
336 * The column data array
337 * @deprecated Deprecated constructor, use
338 * {@link #TmfEventsTable(Composite, int, Collection)}
341 public TmfEventsTable(final Composite parent
, int cacheSize
,
342 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
344 * We'll do a "best-effort" to keep trace types still using this API to
345 * keep working, by defining a TmfEventTableColumn for each
346 * ColumnData they passed.
348 this(parent
, cacheSize
, convertFromColumnData(columnData
));
352 private static @NonNull Iterable
<ITmfEventAspect
> convertFromColumnData(
353 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
355 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
356 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
357 String fieldName
= col
.header
;
358 if (fieldName
!= null) {
359 builder
.add(new TmfContentFieldAspect(fieldName
, fieldName
));
362 return checkNotNull(builder
.build());
366 * Standard constructor, where we define which columns to use.
369 * The parent composite UI object
371 * The size of the event table cache
373 * The event aspects to display in this table. One column per
374 * aspect will be created.
376 * The iteration order of this collection will correspond to the
377 * initial ordering of the columns in the table.
380 public TmfEventsTable(final Composite parent
, int cacheSize
,
381 @NonNull Iterable
<ITmfEventAspect
> aspects
) {
382 super("TmfEventsTable"); //$NON-NLS-1$
384 fComposite
= new Composite(parent
, SWT
.NONE
);
385 final GridLayout gl
= new GridLayout(1, false);
388 gl
.verticalSpacing
= 0;
389 fComposite
.setLayout(gl
);
391 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
392 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
394 // Create a virtual table
395 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
396 fTable
= new TmfVirtualTable(fSashForm
, style
);
398 // Set the table layout
399 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
400 fTable
.setLayoutData(layoutData
);
402 // Some cosmetic enhancements
403 fTable
.setHeaderVisible(true);
404 fTable
.setLinesVisible(true);
407 for (ITmfEventAspect aspect
: aspects
) {
408 if (aspect
!= null) {
409 fColumns
.add(new TmfEventTableColumn(aspect
));
413 TmfMarginColumn collapseCol
= new TmfMarginColumn();
414 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
416 // Create the UI columns in the table
417 for (TmfEventTableColumn col
: fColumns
) {
418 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
419 column
.setText(col
.getHeaderName());
420 column
.setToolTipText(col
.getHeaderTooltip());
421 column
.setData(Key
.ASPECT
, col
.getEventAspect());
423 if (col
instanceof TmfMarginColumn
) {
424 column
.setResizable(false);
425 column
.addControlListener(new ControlAdapter() {
427 * Make sure that the margin column is always first
430 public void controlMoved(ControlEvent e
) {
431 int[] order
= fTable
.getColumnOrder();
432 if (order
[0] == MARGIN_COLUMN_INDEX
) {
435 for (int i
= order
.length
- 1; i
> 0; i
--) {
436 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
437 order
[i
] = order
[i
- 1];
438 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
441 fTable
.setColumnOrder(order
);
445 column
.setMoveable(true);
449 // Set the frozen row for header row
450 fTable
.setFrozenRowCount(1);
452 // Create the header row cell editor
453 createHeaderEditor();
455 // Handle the table item selection
456 fTable
.addSelectionListener(new SelectionAdapter() {
458 public void widgetSelected(final SelectionEvent e
) {
459 if (e
.item
== null) {
462 updateStatusLine(null);
463 if (fTable
.getSelectionIndices().length
> 0) {
464 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
465 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
466 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
468 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
469 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
470 if (fTable
.getSelectionIndices().length
== 1) {
471 fSelectedBeginTimestamp
= ts
;
473 if (fSelectedBeginTimestamp
!= null) {
474 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
475 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
476 if (fTable
.getSelectionIndices().length
== 2) {
477 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
480 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
481 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
485 if (fTable
.getSelectionIndices().length
== 1) {
486 fSelectedBeginTimestamp
= null;
490 if (e
.item
.getData() instanceof ITmfEvent
) {
491 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
492 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
494 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
499 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
500 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
501 fCache
= new TmfEventsCache(realCacheSize
, this);
503 // Handle the table item requests
504 fTable
.addListener(SWT
.SetData
, new Listener() {
507 public void handleEvent(final Event event
) {
509 final TableItem item
= (TableItem
) event
.item
;
510 int index
= event
.index
- 1; // -1 for the header row
512 if (event
.index
== 0) {
513 setHeaderRowItemData(item
);
517 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
518 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
519 setFilterStatusRowItemData(item
);
522 index
= index
- 1; // -1 for top filter status row
525 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
526 if (cachedEvent
!= null) {
527 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
531 // Else, fill the cache asynchronously (and off the UI thread)
536 fTable
.addMouseListener(new MouseAdapter() {
538 public void mouseDoubleClick(final MouseEvent event
) {
539 if (event
.button
!= 1) {
542 // Identify the selected row
543 final Point point
= new Point(event
.x
, event
.y
);
544 final TableItem item
= fTable
.getItem(point
);
546 final Rectangle imageBounds
= item
.getImageBounds(0);
547 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
548 if (imageBounds
.contains(point
)) {
549 final Long rank
= (Long
) item
.getData(Key
.RANK
);
551 toggleBookmark(rank
);
558 final Listener tooltipListener
= new Listener () {
559 Shell tooltipShell
= null;
561 public void handleEvent(final Event event
) {
562 switch (event
.type
) {
564 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
568 final Long rank
= (Long
) item
.getData(Key
.RANK
);
572 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
573 final Rectangle bounds
= item
.getImageBounds(0);
574 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
575 if (!bounds
.contains(event
.x
,event
.y
)) {
578 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
579 tooltipShell
.dispose();
581 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
582 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
583 final FillLayout layout
= new FillLayout();
584 layout
.marginWidth
= 2;
585 tooltipShell
.setLayout(layout
);
586 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
587 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
588 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
589 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
591 label
.addListener(SWT
.MouseExit
, this);
592 label
.addListener(SWT
.MouseDown
, this);
593 label
.addListener(SWT
.MouseWheel
, this);
594 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
596 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
597 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
601 y
+= fTable
.getHeaderHeight();
603 Point pt
= fTable
.toDisplay(event
.x
, y
);
604 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
605 pt
.y
+= item
.getBounds().height
;
606 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
607 tooltipShell
.setVisible(true);
615 if (tooltipShell
!= null) {
616 tooltipShell
.dispose();
626 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
627 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
628 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
629 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
630 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
631 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
632 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
637 ColorSettingsManager
.addColorSettingsListener(this);
639 fTable
.setItemCount(1); // +1 for header row
641 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
643 fRawViewer
.addSelectionListener(new Listener() {
645 public void handleEvent(final Event e
) {
646 if (e
.data
instanceof Long
) {
647 final long rank
= (Long
) e
.data
;
648 int index
= (int) rank
;
649 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
650 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
652 fTable
.setSelection(index
+ 1); // +1 for header row
653 fSelectedRank
= rank
;
654 updateStatusLine(null);
655 } else if (e
.data
instanceof ITmfLocation
) {
656 // DOES NOT WORK: rank undefined in context from seekLocation()
657 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
658 // TmfContext context = fTrace.seekLocation(location);
659 // fTable.setSelection((int) context.getRank());
664 final TableItem
[] selection
= fTable
.getSelection();
665 if ((selection
!= null) && (selection
.length
> 0)) {
666 TableItem item
= fTable
.getSelection()[0];
667 final TmfTimestamp ts
= (TmfTimestamp
) item
.getData(Key
.TIMESTAMP
);
669 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
671 if (item
.getData() instanceof ITmfEvent
) {
672 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) item
.getData()));
673 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(item
.getData())));
675 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
681 fSashForm
.setWeights(new int[] { 1, 1 });
682 fRawViewer
.setVisible(false);
687 // ------------------------------------------------------------------------
689 // ------------------------------------------------------------------------
692 * Create a pop-up menu.
694 protected void createPopupMenu() {
695 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
698 fTable
.setVisible(true);
703 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
706 fTable
.setVisible(false);
711 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
714 fRawViewer
.setVisible(true);
716 final int index
= fTable
.getSelectionIndex();
718 fRawViewer
.selectAndReveal(index
- 1);
723 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
726 fRawViewer
.setVisible(false);
731 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
734 final TableItem items
[] = fTable
.getSelection();
735 if (items
.length
!= 1) {
738 final TableItem item
= items
[0];
740 final Object data
= item
.getData();
741 if (data
instanceof ITmfSourceLookup
) {
742 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
743 ITmfCallsite cs
= event
.getCallsite();
744 if (cs
== null || cs
.getFileName() == null) {
747 IMarker marker
= null;
749 String fileName
= cs
.getFileName();
750 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
751 final ArrayList
<IFile
> files
= new ArrayList
<>();
752 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
754 public boolean visit(IResource resource
) throws CoreException
{
755 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
756 files
.add((IFile
) resource
);
762 if (files
.size() > 1) {
763 ListDialog dialog
= new ListDialog(getTable().getShell());
764 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
765 dialog
.setLabelProvider(new LabelProvider() {
767 public String
getText(Object element
) {
768 return ((IFile
) element
).getFullPath().toString();
771 dialog
.setInput(files
);
772 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
773 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
775 Object
[] result
= dialog
.getResult();
776 if (result
!= null && result
.length
> 0) {
777 file
= (IFile
) result
[0];
779 } else if (files
.size() == 1) {
783 marker
= file
.createMarker(IMarker
.MARKER
);
784 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
785 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
787 } else if (files
.size() == 0){
788 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
790 } catch (CoreException e
) {
797 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
801 final TableItem items
[] = fTable
.getSelection();
802 if (items
.length
!= 1) {
805 final TableItem item
= items
[0];
807 final Object eventData
= item
.getData();
808 if (eventData
instanceof ITmfModelLookup
) {
809 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
811 if (modelURI
!= null) {
812 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
815 final URI uri
= URI
.createURI(modelURI
);
816 if (uri
.isPlatformResource()) {
817 IPath path
= new Path(uri
.toPlatformString(true));
818 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
819 } else if (uri
.isFile() && !uri
.isRelative()) {
820 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
821 new Path(uri
.toFileString()));
827 * create a temporary validation marker on the
828 * model file, remove it afterwards thus,
829 * navigation works with all model editors
830 * supporting the navigation to a marker
832 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
833 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
834 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
836 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
839 catch (CoreException e
) {
843 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
850 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
853 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
854 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
855 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
856 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
857 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
859 HashMap
<String
, Object
> parameters
= new HashMap
<>();
860 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
861 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
863 IEvaluationContext context
= handlerService
.getCurrentState();
864 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
865 for (int i
: fTable
.getColumnOrder()) {
866 // Omit the margin column
867 if (i
>= EVENT_COLUMNS_START_INDEX
) {
868 exportColumns
.add(fColumns
.get(i
));
871 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
873 handlerService
.executeCommandInContext(cmd
, null, context
);
874 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
880 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
883 fHeaderState
= HeaderState
.SEARCH
;
888 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
891 fHeaderState
= HeaderState
.FILTER
;
896 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
903 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
906 applyFilter(new TmfCollapseFilter());
910 class ToggleBookmarkAction
extends Action
{
913 public ToggleBookmarkAction(final String text
, final Long rank
) {
920 toggleBookmark(fRank
);
924 final MenuManager tablePopupMenu
= new MenuManager();
925 tablePopupMenu
.setRemoveAllWhenShown(true);
926 tablePopupMenu
.addMenuListener(new IMenuListener() {
928 public void menuAboutToShow(final IMenuManager manager
) {
929 if (fTable
.getSelectionIndex() == 0) {
930 // Right-click on header row
931 if (fHeaderState
== HeaderState
.FILTER
) {
932 tablePopupMenu
.add(showSearchBarAction
);
934 tablePopupMenu
.add(showFilterBarAction
);
938 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
939 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
941 final Rectangle imageBounds
= item
.getImageBounds(0);
942 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
943 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
944 // Right-click on left margin
945 final Long rank
= (Long
) item
.getData(Key
.RANK
);
946 if ((rank
!= null) && (fBookmarksFile
!= null)) {
947 if (fBookmarksMap
.containsKey(rank
)) {
948 tablePopupMenu
.add(new ToggleBookmarkAction(
949 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
951 tablePopupMenu
.add(new ToggleBookmarkAction(
952 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
959 // Right-click on table
960 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
961 tablePopupMenu
.add(hideTableAction
);
962 tablePopupMenu
.add(hideRawAction
);
963 } else if (!fTable
.isVisible()) {
964 tablePopupMenu
.add(showTableAction
);
965 } else if (!fRawViewer
.isVisible()) {
966 tablePopupMenu
.add(showRawAction
);
968 tablePopupMenu
.add(exportToTextAction
);
969 tablePopupMenu
.add(new Separator());
972 final Object data
= item
.getData();
973 Separator separator
= null;
974 if (data
instanceof ITmfSourceLookup
) {
975 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
976 if (event
.getCallsite() != null) {
977 tablePopupMenu
.add(openCallsiteAction
);
978 separator
= new Separator();
982 if (data
instanceof ITmfModelLookup
) {
983 ITmfModelLookup event
= (ITmfModelLookup
) data
;
984 if (event
.getModelUri() != null) {
985 tablePopupMenu
.add(openModelAction
);
986 separator
= new Separator();
989 if (separator
!= null) {
990 tablePopupMenu
.add(separator
);
995 // only show collapse filter if at least one trace can be collapsed
996 boolean isCollapsible
= false;
997 if (fTrace
!= null) {
998 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
999 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1000 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1001 if (isCollapsible
) {
1007 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1008 tablePopupMenu
.add(collapseAction
);
1009 tablePopupMenu
.add(new Separator());
1012 tablePopupMenu
.add(clearFiltersAction
);
1013 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1014 if (savedFilters
.length
> 0) {
1015 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1016 for (final ITmfFilterTreeNode node
: savedFilters
) {
1017 if (node
instanceof TmfFilterNode
) {
1018 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1019 subMenu
.add(new Action(filter
.getFilterName()) {
1022 applyFilter(filter
);
1027 tablePopupMenu
.add(subMenu
);
1029 appendToTablePopupMenu(tablePopupMenu
, item
);
1033 final MenuManager rawViewerPopupMenu
= new MenuManager();
1034 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1035 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1037 public void menuAboutToShow(final IMenuManager manager
) {
1038 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1039 rawViewerPopupMenu
.add(hideTableAction
);
1040 rawViewerPopupMenu
.add(hideRawAction
);
1041 } else if (!fTable
.isVisible()) {
1042 rawViewerPopupMenu
.add(showTableAction
);
1043 } else if (!fRawViewer
.isVisible()) {
1044 rawViewerPopupMenu
.add(showRawAction
);
1046 appendToRawPopupMenu(tablePopupMenu
);
1050 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1051 fTable
.setMenu(menu
);
1053 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1054 fRawViewer
.setMenu(menu
);
1059 * Append an item to the event table's pop-up menu.
1061 * @param tablePopupMenu
1063 * @param selectedItem
1064 * The item to append
1066 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1067 // override to append more actions
1071 * Append an item to the raw viewer's pop-up menu.
1073 * @param rawViewerPopupMenu
1076 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1077 // override to append more actions
1081 public void dispose() {
1084 ColorSettingsManager
.removeColorSettingsListener(this);
1085 fComposite
.dispose();
1086 if ((fTrace
!= null) && fDisposeOnClose
) {
1089 fResourceManager
.dispose();
1090 fRawViewer
.dispose();
1095 * Assign a layout data object to this view.
1098 * The layout data to assign
1100 public void setLayoutData(final Object layoutData
) {
1101 fComposite
.setLayoutData(layoutData
);
1105 * Get the virtual table contained in this event table.
1107 * @return The TMF virtual table
1109 public TmfVirtualTable
getTable() {
1116 * @deprecated The column headers are now set at the constructor, this
1117 * shouldn't be called anymore.
1120 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1125 * Set a table item's data.
1130 * Which trace event to link with this entry
1132 * Which rank this event has in the trace/experiment
1134 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1135 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1137 // Get the actual ITmfEvent from the CachedEvent
1138 ITmfEvent tmfEvent
= event
;
1139 if (event
instanceof CachedEvent
) {
1140 tmfEvent
= ((CachedEvent
) event
).event
;
1142 item
.setText(itemStrings
);
1143 item
.setData(tmfEvent
);
1144 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1145 item
.setData(Key
.RANK
, rank
);
1147 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1148 if (!markerIds
.isEmpty()) {
1149 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1150 List
<Object
> parts
= new ArrayList
<>();
1151 if (markerIds
.size() > 1) {
1152 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1155 for (long markerId
: markerIds
) {
1156 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1157 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1159 } catch (CoreException e
) {
1160 displayException(e
);
1162 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1164 item
.setData(Key
.BOOKMARK
, null);
1167 boolean searchMatch
= false;
1168 boolean searchNoMatch
= false;
1169 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1170 if (searchFilter
!= null) {
1171 if (searchFilter
.matches(tmfEvent
)) {
1174 searchNoMatch
= true;
1178 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1179 if (searchNoMatch
) {
1180 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1181 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1183 item
.setForeground(colorSetting
.getForegroundColor());
1184 item
.setBackground(colorSetting
.getBackgroundColor());
1188 if (!markerIds
.isEmpty()) {
1189 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1191 item
.setImage(SEARCH_MATCH_IMAGE
);
1193 } else if (!markerIds
.isEmpty()) {
1194 item
.setImage(BOOKMARK_IMAGE
);
1196 item
.setImage((Image
) null);
1199 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1205 * Set the item data of the header row.
1208 * The item to use as table header
1210 protected void setHeaderRowItemData(final TableItem item
) {
1211 String txtKey
= null;
1212 if (fHeaderState
== HeaderState
.SEARCH
) {
1213 item
.setImage(SEARCH_IMAGE
);
1214 txtKey
= Key
.SEARCH_TXT
;
1215 } else if (fHeaderState
== HeaderState
.FILTER
) {
1216 item
.setImage(FILTER_IMAGE
);
1217 txtKey
= Key
.FILTER_TXT
;
1219 item
.setForeground(fGrayColor
);
1220 // Ignore collapse and image column
1221 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1222 final TableColumn column
= fTable
.getColumns()[i
];
1223 final String filter
= (String
) column
.getData(txtKey
);
1224 if (filter
== null) {
1225 if (fHeaderState
== HeaderState
.SEARCH
) {
1226 item
.setText(i
, SEARCH_HINT
);
1227 } else if (fHeaderState
== HeaderState
.FILTER
) {
1228 item
.setText(i
, FILTER_HINT
);
1230 item
.setForeground(i
, fGrayColor
);
1231 item
.setFont(i
, fTable
.getFont());
1233 item
.setText(i
, filter
);
1234 item
.setForeground(i
, fGreenColor
);
1235 item
.setFont(i
, fBoldFont
);
1241 * Set the item data of the "filter status" row.
1244 * The item to use as filter status row
1246 protected void setFilterStatusRowItemData(final TableItem item
) {
1247 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1248 if (i
== MARGIN_COLUMN_INDEX
) {
1249 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1250 item
.setImage(FILTER_IMAGE
);
1252 item
.setImage(STOP_IMAGE
);
1256 if (i
== FILTER_SUMMARY_INDEX
) {
1257 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1259 item
.setText(i
, EMPTY_STRING
);
1263 item
.setData(Key
.TIMESTAMP
, null);
1264 item
.setData(Key
.RANK
, null);
1265 item
.setForeground(null);
1266 item
.setBackground(null);
1270 * Create an editor for the header.
1272 protected void createHeaderEditor() {
1273 final TableEditor tableEditor
= fTable
.createTableEditor();
1274 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1275 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1276 tableEditor
.grabHorizontal
= true;
1277 tableEditor
.minimumWidth
= 50;
1279 // Handle the header row selection
1280 fTable
.addMouseListener(new MouseAdapter() {
1286 public void mouseDown(final MouseEvent event
) {
1287 if (event
.button
!= 1) {
1290 // Identify the selected row
1291 final Point point
= new Point(event
.x
, event
.y
);
1292 item
= fTable
.getItem(point
);
1294 // Header row selected
1295 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1298 if (item
.getImageBounds(0).contains(point
)) {
1299 if (fHeaderState
== HeaderState
.SEARCH
) {
1300 fHeaderState
= HeaderState
.FILTER
;
1301 } else if (fHeaderState
== HeaderState
.FILTER
) {
1302 fHeaderState
= HeaderState
.SEARCH
;
1304 fTable
.setSelection(0);
1309 // Identify the selected column
1311 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1312 final Rectangle rect
= item
.getBounds(i
);
1313 if (rect
.contains(point
)) {
1319 if (columnIndex
== -1) {
1323 column
= fTable
.getColumns()[columnIndex
];
1325 String txtKey
= null;
1326 if (fHeaderState
== HeaderState
.SEARCH
) {
1327 txtKey
= Key
.SEARCH_TXT
;
1328 } else if (fHeaderState
== HeaderState
.FILTER
) {
1329 txtKey
= Key
.FILTER_TXT
;
1332 // The control that will be the editor must be a child of the Table
1333 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1334 final String headerString
= (String
) column
.getData(txtKey
);
1335 if (headerString
!= null) {
1336 newEditor
.setText(headerString
);
1338 newEditor
.addFocusListener(new FocusAdapter() {
1340 public void focusLost(final FocusEvent e
) {
1341 final boolean changed
= updateHeader(newEditor
.getText());
1347 newEditor
.addKeyListener(new KeyAdapter() {
1349 public void keyPressed(final KeyEvent e
) {
1350 if (e
.character
== SWT
.CR
) {
1351 updateHeader(newEditor
.getText());
1354 // Set focus on the table so that the next carriage return goes to the next result
1355 TmfEventsTable
.this.getTable().setFocus();
1356 } else if (e
.character
== SWT
.ESC
) {
1357 tableEditor
.getEditor().dispose();
1361 newEditor
.selectAll();
1362 newEditor
.setFocus();
1363 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1368 * returns true is value was changed
1370 private boolean updateHeader(final String text
) {
1371 String objKey
= null;
1372 String txtKey
= null;
1373 if (fHeaderState
== HeaderState
.SEARCH
) {
1374 objKey
= Key
.SEARCH_OBJ
;
1375 txtKey
= Key
.SEARCH_TXT
;
1376 } else if (fHeaderState
== HeaderState
.FILTER
) {
1377 objKey
= Key
.FILTER_OBJ
;
1378 txtKey
= Key
.FILTER_TXT
;
1380 if (text
.trim().length() > 0) {
1382 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1383 Pattern
.compile(regex
);
1384 if (regex
.equals(column
.getData(txtKey
))) {
1385 tableEditor
.getEditor().dispose();
1388 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1389 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1390 filter
.setEventAspect(aspect
);
1391 filter
.setRegex(regex
);
1392 column
.setData(objKey
, filter
);
1393 column
.setData(txtKey
, regex
);
1394 } catch (final PatternSyntaxException ex
) {
1395 tableEditor
.getEditor().dispose();
1396 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1397 ex
.getDescription(), ex
.getMessage());
1401 if (column
.getData(txtKey
) == null) {
1402 tableEditor
.getEditor().dispose();
1405 column
.setData(objKey
, null);
1406 column
.setData(txtKey
, null);
1411 private void applyHeader() {
1412 if (fHeaderState
== HeaderState
.SEARCH
) {
1414 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1415 for (final TableColumn col
: fTable
.getColumns()) {
1416 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1417 if (filterObj
instanceof ITmfFilterTreeNode
) {
1418 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1421 if (filter
.getChildrenCount() > 0) {
1422 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1425 fireSearchApplied(filter
);
1427 fTable
.setData(Key
.SEARCH_OBJ
, null);
1429 fireSearchApplied(null);
1431 } else if (fHeaderState
== HeaderState
.FILTER
) {
1432 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1433 for (final TableColumn col
: fTable
.getColumns()) {
1434 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1435 if (filterObj
instanceof ITmfFilterTreeNode
) {
1436 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1439 if (filter
.getChildrenCount() > 0) {
1440 applyFilter(filter
);
1446 tableEditor
.getEditor().dispose();
1450 fTable
.addKeyListener(new KeyAdapter() {
1452 public void keyPressed(final KeyEvent e
) {
1454 if (e
.character
== SWT
.ESC
) {
1458 } else if (e
.character
== SWT
.DEL
) {
1459 if (fHeaderState
== HeaderState
.SEARCH
) {
1461 for (final TableColumn column
: fTable
.getColumns()) {
1462 column
.setData(Key
.SEARCH_OBJ
, null);
1463 column
.setData(Key
.SEARCH_TXT
, null);
1465 fTable
.setData(Key
.SEARCH_OBJ
, null);
1467 fireSearchApplied(null);
1468 } else if (fHeaderState
== HeaderState
.FILTER
) {
1471 } else if (e
.character
== SWT
.CR
) {
1472 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1483 * Send an event indicating a filter has been applied.
1486 * The filter that was just applied
1488 protected void fireFilterApplied(final ITmfFilter filter
) {
1489 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1493 * Send an event indicating that a search has been applied.
1496 * The search filter that was just applied
1498 protected void fireSearchApplied(final ITmfFilter filter
) {
1499 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1503 * Start the filtering thread.
1505 protected void startFilterThread() {
1506 synchronized (fFilterSyncObj
) {
1507 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1508 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1509 if (fFilterThread
!= null) {
1510 fFilterThread
.cancel();
1511 fFilterThreadResume
= false;
1513 fFilterThread
= new FilterThread(filter
);
1514 fFilterThread
.start();
1516 fFilterThreadResume
= true;
1522 * Stop the filtering thread.
1524 protected void stopFilterThread() {
1525 synchronized (fFilterSyncObj
) {
1526 if (fFilterThread
!= null) {
1527 fFilterThread
.cancel();
1528 fFilterThread
= null;
1529 fFilterThreadResume
= false;
1538 * The filter to apply
1540 protected void applyFilter(ITmfFilter filter
) {
1543 fFilterMatchCount
= 0;
1544 fFilterCheckCount
= 0;
1545 fCache
.applyFilter(filter
);
1547 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1548 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1549 startFilterThread();
1550 fireFilterApplied(filter
);
1554 * Clear all currently active filters.
1556 protected void clearFilters() {
1557 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1562 fCache
.clearFilter();
1564 for (final TableColumn column
: fTable
.getColumns()) {
1565 column
.setData(Key
.FILTER_OBJ
, null);
1566 column
.setData(Key
.FILTER_TXT
, null);
1568 fTable
.setData(Key
.FILTER_OBJ
, null);
1569 if (fTrace
!= null) {
1570 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1572 fTable
.setItemCount(1); // +1 for header row
1574 fFilterMatchCount
= 0;
1575 fFilterCheckCount
= 0;
1576 if (fSelectedRank
>= 0) {
1577 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1579 fTable
.setSelection(0);
1581 fireFilterApplied(null);
1582 updateStatusLine(null);
1584 // Set original width
1585 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1590 * Wrapper Thread object for the filtering thread.
1592 protected class FilterThread
extends Thread
{
1593 private final ITmfFilterTreeNode filter
;
1594 private TmfEventRequest request
;
1595 private boolean refreshBusy
= false;
1596 private boolean refreshPending
= false;
1597 private final Object syncObj
= new Object();
1603 * The filter this thread will be processing
1605 public FilterThread(final ITmfFilterTreeNode filter
) {
1606 super("Filter Thread"); //$NON-NLS-1$
1607 this.filter
= filter
;
1612 if (fTrace
== null) {
1615 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1616 if (nbRequested
<= 0) {
1619 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1620 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1622 public void handleData(final ITmfEvent event
) {
1623 super.handleData(event
);
1624 if (request
.isCancelled()) {
1627 boolean refresh
= false;
1628 if (filter
.matches(event
)) {
1629 final long rank
= fFilterCheckCount
;
1630 final int index
= (int) fFilterMatchCount
;
1631 fFilterMatchCount
++;
1632 fCache
.storeEvent(event
, rank
, index
);
1635 if (filter
instanceof TmfCollapseFilter
) {
1636 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1640 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1643 fFilterCheckCount
++;
1646 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1648 request
.waitForCompletion();
1649 } catch (final InterruptedException e
) {
1652 synchronized (fFilterSyncObj
) {
1653 fFilterThread
= null;
1654 if (fFilterThreadResume
) {
1655 fFilterThreadResume
= false;
1656 fFilterThread
= new FilterThread(filter
);
1657 fFilterThread
.start();
1663 * Refresh the filter.
1665 public void refreshTable() {
1666 synchronized (syncObj
) {
1668 refreshPending
= true;
1673 Display
.getDefault().asyncExec(new Runnable() {
1676 if (request
.isCancelled()) {
1679 if (fTable
.isDisposed()) {
1682 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1684 synchronized (syncObj
) {
1685 refreshBusy
= false;
1686 if (refreshPending
) {
1687 refreshPending
= false;
1696 * Cancel this filtering thread.
1698 public void cancel() {
1699 if (request
!= null) {
1706 * Go to the next item of a search.
1708 protected void searchNext() {
1709 synchronized (fSearchSyncObj
) {
1710 if (fSearchThread
!= null) {
1713 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1714 if (searchFilter
== null) {
1717 final int selectionIndex
= fTable
.getSelectionIndex();
1719 if (selectionIndex
> 0) {
1720 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1722 // header row is selected, start at top event
1723 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1725 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1726 if (eventFilter
!= null) {
1727 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1729 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1730 fSearchThread
.schedule();
1735 * Go to the previous item of a search.
1737 protected void searchPrevious() {
1738 synchronized (fSearchSyncObj
) {
1739 if (fSearchThread
!= null) {
1742 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1743 if (searchFilter
== null) {
1746 final int selectionIndex
= fTable
.getSelectionIndex();
1748 if (selectionIndex
> 0) {
1749 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1751 // header row is selected, start at precedent of top event
1752 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1754 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1755 if (eventFilter
!= null) {
1756 startIndex
= startIndex
- 1; // -1 for top filter status row
1758 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1759 fSearchThread
.schedule();
1764 * Stop the search thread.
1766 protected void stopSearchThread() {
1767 fPendingGotoRank
= -1;
1768 synchronized (fSearchSyncObj
) {
1769 if (fSearchThread
!= null) {
1770 fSearchThread
.cancel();
1771 fSearchThread
= null;
1777 * Wrapper for the search thread.
1779 protected class SearchThread
extends Job
{
1781 private ITmfFilterTreeNode searchFilter
;
1782 private ITmfFilterTreeNode eventFilter
;
1783 private int startIndex
;
1784 private int direction
;
1786 private long foundRank
= -1;
1787 private TmfEventRequest request
;
1788 private ITmfTimestamp foundTimestamp
= null;
1793 * @param searchFilter
1795 * @param eventFilter
1798 * The index at which we should start searching
1799 * @param currentRank
1802 * In which direction should we search, forward or backwards
1804 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1805 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1806 final long currentRank
, final int direction
) {
1807 super(Messages
.TmfEventsTable_SearchingJobName
);
1808 this.searchFilter
= searchFilter
;
1809 this.eventFilter
= eventFilter
;
1810 this.startIndex
= startIndex
;
1811 this.rank
= currentRank
;
1812 this.direction
= direction
;
1816 protected IStatus
run(final IProgressMonitor monitor
) {
1817 if (fTrace
== null) {
1818 return Status
.OK_STATUS
;
1820 final Display display
= Display
.getDefault();
1821 if (startIndex
< 0) {
1822 rank
= (int) fTrace
.getNbEvents() - 1;
1823 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1826 int idx
= startIndex
;
1827 while (foundRank
== -1) {
1828 final CachedEvent event
= fCache
.peekEvent(idx
);
1829 if (event
== null) {
1833 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1834 foundRank
= event
.rank
;
1835 foundTimestamp
= event
.event
.getTimestamp();
1838 if (direction
== Direction
.FORWARD
) {
1844 if (foundRank
== -1) {
1845 if (direction
== Direction
.FORWARD
) {
1847 if (rank
> (fTrace
.getNbEvents() - 1)) {
1853 rank
= (int) fTrace
.getNbEvents() - 1;
1858 final int startRank
= (int) rank
;
1859 boolean wrapped
= false;
1860 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1861 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1862 if (direction
== Direction
.BACKWARD
) {
1863 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1865 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1866 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1867 long currentRank
= rank
;
1870 public void handleData(final ITmfEvent event
) {
1871 super.handleData(event
);
1872 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1873 foundRank
= currentRank
;
1874 foundTimestamp
= event
.getTimestamp();
1875 if (direction
== Direction
.FORWARD
) {
1883 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1885 request
.waitForCompletion();
1886 if (request
.isCancelled()) {
1887 return Status
.OK_STATUS
;
1889 } catch (final InterruptedException e
) {
1890 synchronized (fSearchSyncObj
) {
1891 fSearchThread
= null;
1893 return Status
.OK_STATUS
;
1895 if (foundRank
== -1) {
1896 if (direction
== Direction
.FORWARD
) {
1898 synchronized (fSearchSyncObj
) {
1899 fSearchThread
= null;
1901 return Status
.OK_STATUS
;
1903 nbRequested
= (int) rank
;
1909 rank
= (int) fTrace
.getNbEvents() - 1;
1912 if ((rank
<= startRank
) && wrapped
) {
1913 synchronized (fSearchSyncObj
) {
1914 fSearchThread
= null;
1916 return Status
.OK_STATUS
;
1921 int index
= (int) foundRank
;
1922 if (eventFilter
!= null) {
1923 index
= fCache
.getFilteredEventIndex(foundRank
);
1925 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1927 display
.asyncExec(new Runnable() {
1930 if (monitor
.isCanceled()) {
1933 if (fTable
.isDisposed()) {
1936 fTable
.setSelection(selection
);
1937 fSelectedRank
= foundRank
;
1938 fRawViewer
.selectAndReveal(fSelectedRank
);
1939 if (foundTimestamp
!= null) {
1940 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1942 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1943 synchronized (fSearchSyncObj
) {
1944 fSearchThread
= null;
1946 updateStatusLine(null);
1949 return Status
.OK_STATUS
;
1953 protected void canceling() {
1955 synchronized (fSearchSyncObj
) {
1956 fSearchThread
= null;
1962 * Create the resources.
1964 protected void createResources() {
1965 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1966 .getForeground().getRGB()));
1967 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1968 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1974 protected void packColumns() {
1978 fTable
.setRedraw(false);
1980 TableColumn tableColumns
[] = fTable
.getColumns();
1981 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1982 final TableColumn column
= tableColumns
[i
];
1983 packSingleColumn(i
, column
);
1986 // Make sure that redraw is always enabled.
1987 fTable
.setRedraw(true);
1993 private void packMarginColumn() {
1994 TableColumn
[] columns
= fTable
.getColumns();
1995 if (columns
.length
> 0) {
1996 packSingleColumn(0, columns
[0]);
2000 private void packSingleColumn(int i
, final TableColumn column
) {
2001 final int headerWidth
= column
.getWidth();
2003 // Workaround for Linux which doesn't consider the image width of
2004 // search/filter row in TableColumn.pack() after having executed
2005 // TableItem.setImage((Image)null) for other rows than search/filter row.
2006 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2007 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2008 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2011 if (column
.getWidth() < headerWidth
) {
2012 column
.setWidth(headerWidth
);
2017 * Get the array of item strings (e.g., what to display in each cell of the
2018 * table row) corresponding to the columns and trace event passed in
2019 * parameter. The order of the Strings in the returned array will correspond
2020 * to the iteration order of 'columns'.
2023 * To ensure consistent results, make sure only call this within a scope
2024 * synchronized on 'columns'! If the order of 'columns' changes right after
2025 * this method is called, the returned value won't be ordered correctly
2028 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2029 if (event
== null) {
2030 return EMPTY_STRING_ARRAY
;
2032 synchronized (columns
) {
2033 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2034 for (TmfEventTableColumn column
: columns
) {
2035 ITmfEvent passedEvent
= event
;
2036 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2037 // Make sure that the event object from the trace is passed
2038 // to all columns but the TmfMarginColumn
2039 passedEvent
= ((CachedEvent
) event
).event
;
2041 if (passedEvent
== null) {
2042 itemStrings
.add(EMPTY_STRING
);
2044 itemStrings
.add(column
.getItemString(passedEvent
));
2048 return itemStrings
.toArray(new String
[0]);
2053 * Get the contents of the row in the events table corresponding to an
2054 * event. The order of the elements corresponds to the current order of the
2058 * The event printed in this row
2059 * @return The event row entries
2061 public String
[] getItemStrings(ITmfEvent event
) {
2062 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2063 for (int i
: fTable
.getColumnOrder()) {
2064 columns
.add(fColumns
.get(i
));
2066 return getItemStrings(columns
, event
);
2070 * Notify this table that is got the UI focus.
2072 public void setFocus() {
2077 * Assign a new trace to this event table.
2080 * The trace to assign to this event table
2081 * @param disposeOnClose
2082 * true if the trace should be disposed when the table is
2085 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2086 if ((fTrace
!= null) && fDisposeOnClose
) {
2092 fDisposeOnClose
= disposeOnClose
;
2094 // Perform the updates on the UI thread
2095 fTable
.getDisplay().syncExec(new Runnable() {
2099 fCache
.setTrace(fTrace
); // Clear the cache
2100 if (fTrace
!= null) {
2101 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2102 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2103 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2106 fFilterMatchCount
= 0;
2107 fFilterCheckCount
= 0;
2108 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2109 startFilterThread();
2113 fRawViewer
.setTrace(fTrace
);
2119 * Assign the status line manager
2121 * @param statusLineManager
2122 * The status line manager, or null to disable status line messages
2124 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2125 if (fStatusLineManager
!= null && statusLineManager
== null) {
2126 fStatusLineManager
.setMessage(EMPTY_STRING
);
2128 fStatusLineManager
= statusLineManager
;
2131 private void updateStatusLine(ITmfTimestamp delta
) {
2132 if (fStatusLineManager
!= null) {
2133 if (delta
!= null) {
2134 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2136 fStatusLineManager
.setMessage(null);
2141 // ------------------------------------------------------------------------
2143 // ------------------------------------------------------------------------
2146 * Notify that the event cache has been updated
2149 * Also notify if the populating of the cache is complete, or
2152 public void cacheUpdated(final boolean completed
) {
2153 synchronized (fCacheUpdateSyncObj
) {
2154 if (fCacheUpdateBusy
) {
2155 fCacheUpdatePending
= true;
2156 fCacheUpdateCompleted
= completed
;
2159 fCacheUpdateBusy
= true;
2161 // Event cache is now updated. Perform update on the UI thread
2162 if (!fTable
.isDisposed()) {
2163 fTable
.getDisplay().asyncExec(new Runnable() {
2166 if (!fTable
.isDisposed()) {
2171 populateCompleted();
2173 synchronized (fCacheUpdateSyncObj
) {
2174 fCacheUpdateBusy
= false;
2175 if (fCacheUpdatePending
) {
2176 fCacheUpdatePending
= false;
2177 cacheUpdated(fCacheUpdateCompleted
);
2186 * Callback for when populating the table is complete.
2188 protected void populateCompleted() {
2189 // Nothing by default;
2192 // ------------------------------------------------------------------------
2193 // ISelectionProvider
2194 // ------------------------------------------------------------------------
2197 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2198 selectionChangedListeners
.add(listener
);
2202 public ISelection
getSelection() {
2203 if (fTable
== null || fTable
.isDisposed()) {
2204 return StructuredSelection
.EMPTY
;
2206 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2207 for (TableItem item
: fTable
.getSelection()) {
2208 if (item
.getData() != null) {
2209 list
.add(item
.getData());
2212 return new StructuredSelection(list
);
2216 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2217 selectionChangedListeners
.remove(listener
);
2221 public void setSelection(ISelection selection
) {
2226 * Notifies any selection changed listeners that the viewer's selection has changed.
2227 * Only listeners registered at the time this method is called are notified.
2229 * @param event a selection changed event
2231 * @see ISelectionChangedListener#selectionChanged
2233 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2234 Object
[] listeners
= selectionChangedListeners
.getListeners();
2235 for (int i
= 0; i
< listeners
.length
; ++i
) {
2236 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2237 SafeRunnable
.run(new SafeRunnable() {
2240 l
.selectionChanged(event
);
2246 // ------------------------------------------------------------------------
2247 // Bookmark handling
2248 // ------------------------------------------------------------------------
2251 * Add a bookmark to this event table.
2253 * @param bookmarksFile
2254 * The file to use for the bookmarks
2256 public void addBookmark(final IFile bookmarksFile
) {
2257 fBookmarksFile
= bookmarksFile
;
2258 final TableItem
[] selection
= fTable
.getSelection();
2259 if (selection
.length
> 0) {
2260 final TableItem tableItem
= selection
[0];
2261 if (tableItem
.getData(Key
.RANK
) != null) {
2262 final StringBuffer defaultMessage
= new StringBuffer();
2263 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2265 defaultMessage
.append(", "); //$NON-NLS-1$
2267 defaultMessage
.append(tableItem
.getText(i
));
2269 final InputDialog dialog
= new MultiLineInputDialog(
2270 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2271 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2272 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2273 defaultMessage
.toString());
2274 if (dialog
.open() == Window
.OK
) {
2275 final String message
= dialog
.getValue();
2277 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2278 if (bookmark
.exists()) {
2279 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2280 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2281 final int location
= rank
.intValue();
2282 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2283 fBookmarksMap
.put(rank
, bookmark
.getId());
2286 } catch (final CoreException e
) {
2287 displayException(e
);
2296 * Remove a bookmark from this event table.
2299 * The bookmark to remove
2301 public void removeBookmark(final IMarker bookmark
) {
2302 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2303 if (entry
.getValue().equals(bookmark
.getId())) {
2304 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2311 private void toggleBookmark(final Long rank
) {
2312 if (fBookmarksFile
== null) {
2315 if (fBookmarksMap
.containsKey(rank
)) {
2316 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2319 for (long markerId
: markerIds
) {
2320 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2321 if (bookmark
!= null) {
2325 } catch (final CoreException e
) {
2326 displayException(e
);
2329 addBookmark(fBookmarksFile
);
2334 * Refresh the bookmarks assigned to this trace, from the contents of a
2337 * @param bookmarksFile
2338 * The bookmark file to use
2340 public void refreshBookmarks(final IFile bookmarksFile
) {
2341 fBookmarksFile
= bookmarksFile
;
2342 if (bookmarksFile
== null) {
2343 fBookmarksMap
.clear();
2348 fBookmarksMap
.clear();
2349 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2350 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2351 if (location
!= -1) {
2352 final long rank
= location
;
2353 fBookmarksMap
.put(rank
, bookmark
.getId());
2357 } catch (final CoreException e
) {
2358 displayException(e
);
2363 public void gotoMarker(final IMarker marker
) {
2364 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2367 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2368 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2369 } else if (rank
>= fTable
.getItemCount()) {
2370 fPendingGotoRank
= rank
;
2372 fSelectedRank
= rank
;
2373 fTable
.setSelection(index
+ 1); // +1 for header row
2374 updateStatusLine(null);
2378 // ------------------------------------------------------------------------
2380 // ------------------------------------------------------------------------
2383 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2387 // ------------------------------------------------------------------------
2389 // ------------------------------------------------------------------------
2392 * Handler for the trace updated signal
2395 * The incoming signal
2398 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2399 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2402 // Perform the refresh on the UI thread
2403 Display
.getDefault().asyncExec(new Runnable() {
2406 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2407 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2408 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2409 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2410 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2411 fPendingGotoRank
= -1;
2412 updateStatusLine(null);
2415 startFilterThread();
2418 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2419 fRawViewer
.refreshEventCount();
2426 * Handler for the time synch signal.
2429 * The incoming signal
2432 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2433 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2435 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2436 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2437 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2438 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2439 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2441 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2444 public void handleData(final ITmfEvent event
) {
2445 super.handleData(event
);
2449 public void handleSuccess() {
2450 super.handleSuccess();
2451 if (fTrace
== null) {
2455 // Verify if the event is within the trace range and adjust if necessary
2456 ITmfTimestamp timestamp
= ts
;
2457 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2458 timestamp
= fTrace
.getStartTime();
2460 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2461 timestamp
= fTrace
.getEndTime();
2464 // Get the rank of the selected event in the table
2465 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2466 final long rank
= context
.getRank();
2468 fSelectedRank
= rank
;
2470 fTable
.getDisplay().asyncExec(new Runnable() {
2473 // Return if table is disposed
2474 if (fTable
.isDisposed()) {
2478 int index
= (int) rank
;
2479 if (fTable
.isDisposed()) {
2482 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2483 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2485 fTable
.setSelection(index
+ 1); // +1 for header row
2486 fRawViewer
.selectAndReveal(rank
);
2487 updateStatusLine(null);
2493 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2497 // ------------------------------------------------------------------------
2499 // ------------------------------------------------------------------------
2502 * Display an exception in a message box
2504 * @param e the exception
2506 private static void displayException(final Exception e
) {
2507 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2508 mb
.setText(e
.getClass().getSimpleName());
2509 mb
.setMessage(e
.getMessage());
2516 public void refresh() {
2523 * Margin column for images and special text (e.g. collapse count)
2525 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2527 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2530 public String
getName() {
2531 return EMPTY_STRING
;
2535 public String
resolve(ITmfEvent event
) {
2536 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2537 return EMPTY_STRING
;
2539 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2543 public String
getHelpText() {
2544 return EMPTY_STRING
;
2551 public TmfMarginColumn() {
2552 super(MARGIN_ASPECT
);