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 static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
22 import java
.io
.FileNotFoundException
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Collection
;
25 import java
.util
.HashMap
;
26 import java
.util
.LinkedList
;
27 import java
.util
.List
;
28 import java
.util
.Map
.Entry
;
29 import java
.util
.regex
.Pattern
;
30 import java
.util
.regex
.PatternSyntaxException
;
32 import org
.eclipse
.core
.commands
.Command
;
33 import org
.eclipse
.core
.commands
.ExecutionException
;
34 import org
.eclipse
.core
.commands
.NotEnabledException
;
35 import org
.eclipse
.core
.commands
.NotHandledException
;
36 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
37 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
38 import org
.eclipse
.core
.expressions
.IEvaluationContext
;
39 import org
.eclipse
.core
.resources
.IFile
;
40 import org
.eclipse
.core
.resources
.IMarker
;
41 import org
.eclipse
.core
.resources
.IResource
;
42 import org
.eclipse
.core
.resources
.IResourceVisitor
;
43 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
44 import org
.eclipse
.core
.runtime
.CoreException
;
45 import org
.eclipse
.core
.runtime
.IPath
;
46 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
47 import org
.eclipse
.core
.runtime
.IStatus
;
48 import org
.eclipse
.core
.runtime
.ListenerList
;
49 import org
.eclipse
.core
.runtime
.Path
;
50 import org
.eclipse
.core
.runtime
.Status
;
51 import org
.eclipse
.core
.runtime
.jobs
.Job
;
52 import org
.eclipse
.emf
.common
.util
.URI
;
53 import org
.eclipse
.emf
.ecore
.EValidator
;
54 import org
.eclipse
.jdt
.annotation
.NonNull
;
55 import org
.eclipse
.jface
.action
.Action
;
56 import org
.eclipse
.jface
.action
.IAction
;
57 import org
.eclipse
.jface
.action
.IMenuListener
;
58 import org
.eclipse
.jface
.action
.IMenuManager
;
59 import org
.eclipse
.jface
.action
.IStatusLineManager
;
60 import org
.eclipse
.jface
.action
.MenuManager
;
61 import org
.eclipse
.jface
.action
.Separator
;
62 import org
.eclipse
.jface
.dialogs
.InputDialog
;
63 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
64 import org
.eclipse
.jface
.resource
.FontDescriptor
;
65 import org
.eclipse
.jface
.resource
.JFaceResources
;
66 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
67 import org
.eclipse
.jface
.util
.OpenStrategy
;
68 import org
.eclipse
.jface
.util
.SafeRunnable
;
69 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
70 import org
.eclipse
.jface
.viewers
.ISelection
;
71 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
72 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
73 import org
.eclipse
.jface
.viewers
.LabelProvider
;
74 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
75 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
76 import org
.eclipse
.jface
.window
.Window
;
77 import org
.eclipse
.swt
.SWT
;
78 import org
.eclipse
.swt
.custom
.SashForm
;
79 import org
.eclipse
.swt
.custom
.TableEditor
;
80 import org
.eclipse
.swt
.events
.ControlAdapter
;
81 import org
.eclipse
.swt
.events
.ControlEvent
;
82 import org
.eclipse
.swt
.events
.FocusAdapter
;
83 import org
.eclipse
.swt
.events
.FocusEvent
;
84 import org
.eclipse
.swt
.events
.KeyAdapter
;
85 import org
.eclipse
.swt
.events
.KeyEvent
;
86 import org
.eclipse
.swt
.events
.MouseAdapter
;
87 import org
.eclipse
.swt
.events
.MouseEvent
;
88 import org
.eclipse
.swt
.events
.SelectionAdapter
;
89 import org
.eclipse
.swt
.events
.SelectionEvent
;
90 import org
.eclipse
.swt
.graphics
.Color
;
91 import org
.eclipse
.swt
.graphics
.Font
;
92 import org
.eclipse
.swt
.graphics
.Image
;
93 import org
.eclipse
.swt
.graphics
.Point
;
94 import org
.eclipse
.swt
.graphics
.Rectangle
;
95 import org
.eclipse
.swt
.layout
.FillLayout
;
96 import org
.eclipse
.swt
.layout
.GridData
;
97 import org
.eclipse
.swt
.layout
.GridLayout
;
98 import org
.eclipse
.swt
.widgets
.Composite
;
99 import org
.eclipse
.swt
.widgets
.Display
;
100 import org
.eclipse
.swt
.widgets
.Event
;
101 import org
.eclipse
.swt
.widgets
.Label
;
102 import org
.eclipse
.swt
.widgets
.Listener
;
103 import org
.eclipse
.swt
.widgets
.Menu
;
104 import org
.eclipse
.swt
.widgets
.MessageBox
;
105 import org
.eclipse
.swt
.widgets
.Shell
;
106 import org
.eclipse
.swt
.widgets
.TableColumn
;
107 import org
.eclipse
.swt
.widgets
.TableItem
;
108 import org
.eclipse
.swt
.widgets
.Text
;
109 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
110 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
111 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
112 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
113 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
114 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
115 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
116 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
117 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
118 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfEventFieldAspect
;
119 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
120 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
121 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
122 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
123 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
124 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesAspectNode
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
141 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
142 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
143 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
144 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
145 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
146 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
147 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
148 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
149 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
150 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
151 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
152 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
153 import org
.eclipse
.ui
.IWorkbenchPage
;
154 import org
.eclipse
.ui
.PlatformUI
;
155 import org
.eclipse
.ui
.commands
.ICommandService
;
156 import org
.eclipse
.ui
.dialogs
.ListDialog
;
157 import org
.eclipse
.ui
.handlers
.IHandlerService
;
158 import org
.eclipse
.ui
.ide
.IDE
;
159 import org
.eclipse
.ui
.ide
.IGotoMarker
;
160 import org
.eclipse
.ui
.themes
.ColorUtil
;
162 import com
.google
.common
.base
.Joiner
;
163 import com
.google
.common
.collect
.HashMultimap
;
164 import com
.google
.common
.collect
.ImmutableList
;
165 import com
.google
.common
.collect
.Multimap
;
168 * The generic TMF Events table
170 * This is a view that will list events that are read from a trace.
172 * @author Francois Chouinard
173 * @author Patrick Tasse
176 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
179 * Empty string array, used by {@link #getItemStrings}.
182 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
188 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
190 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
192 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
193 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
194 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
195 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
196 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
197 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
198 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
199 private static final Image FILTER_IMAGE
= Activator
.getDefault()
200 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
201 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
202 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
203 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
204 private static final int MAX_CACHE_SIZE
= 1000;
206 private static final int MARGIN_COLUMN_INDEX
= 0;
207 private static final int FILTER_SUMMARY_INDEX
= 1;
208 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
211 * The events table search/filter keys
214 * @author Patrick Tasse
216 public interface Key
{
218 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
221 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
224 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
227 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
230 String TIMESTAMP
= "$time"; //$NON-NLS-1$
233 String RANK
= "$rank"; //$NON-NLS-1$
235 /** Bookmark indicator */
236 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
238 /** Event aspect represented by this column */
239 String ASPECT
= "$aspect"; //$NON-NLS-1$
243 * The events table search/filter state
246 * @author Patrick Tasse
248 public static enum HeaderState
{
249 /** A search is being run */
252 /** A filter is applied */
256 interface Direction
{
261 // ------------------------------------------------------------------------
263 // ------------------------------------------------------------------------
265 /** The virtual event table */
266 protected TmfVirtualTable fTable
;
268 private Composite fComposite
;
269 private SashForm fSashForm
;
270 private TmfRawEventViewer fRawViewer
;
271 private ITmfTrace fTrace
;
272 volatile private boolean fPackDone
= false;
273 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
274 private long fSelectedRank
= 0;
275 private ITmfTimestamp fSelectedBeginTimestamp
= null;
276 private IStatusLineManager fStatusLineManager
= null;
279 private long fFilterMatchCount
;
280 private long fFilterCheckCount
;
281 private FilterThread fFilterThread
;
282 private boolean fFilterThreadResume
= false;
283 private final Object fFilterSyncObj
= new Object();
284 private SearchThread fSearchThread
;
285 private final Object fSearchSyncObj
= new Object();
288 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
290 * @see #fireSelectionChanged
292 private ListenerList selectionChangedListeners
= new ListenerList();
294 // Bookmark map <Rank, MarkerId>
295 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
296 private IFile fBookmarksFile
;
297 private long fPendingGotoRank
= -1;
300 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
301 private Color fGrayColor
;
302 private Color fGreenColor
;
303 private Font fBoldFont
;
305 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
308 private final TmfEventsCache fCache
;
309 private boolean fCacheUpdateBusy
= false;
310 private boolean fCacheUpdatePending
= false;
311 private boolean fCacheUpdateCompleted
= false;
312 private final Object fCacheUpdateSyncObj
= new Object();
314 private boolean fDisposeOnClose
;
316 // ------------------------------------------------------------------------
318 // ------------------------------------------------------------------------
321 * Basic constructor, using the default set of columns
324 * The parent composite UI object
326 * The size of the event table cache
328 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
329 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
333 * Legacy constructor, using ColumnData to define columns
336 * The parent composite UI object
338 * The size of the event table cache
341 * @deprecated Deprecated constructor, use
342 * {@link #TmfEventsTable(Composite, int, Collection)}
345 public TmfEventsTable(final Composite parent
, int cacheSize
,
346 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
348 * We'll do a "best-effort" to keep trace types still using this API to
349 * keep working, by defining a TmfEventTableFieldColumn for each
350 * ColumnData they passed.
352 this(parent
, cacheSize
, convertFromColumnData(columnData
));
356 private static @NonNull Iterable
<ITmfEventAspect
> convertFromColumnData(
357 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
359 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
360 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
361 String fieldName
= col
.header
;
362 if (fieldName
!= null) {
363 builder
.add(new TmfEventFieldAspect(fieldName
, fieldName
));
366 return checkNotNull(builder
.build());
370 * Standard constructor, where we define which columns to use.
373 * The parent composite UI object
375 * The size of the event table cache
377 * The event aspects to display in this table. One column per
378 * aspect will be created.
380 * The iteration order of this collection will correspond to the
381 * initial ordering of the columns in the table.
385 public TmfEventsTable(final Composite parent
, int cacheSize
,
386 @NonNull Iterable
<ITmfEventAspect
> aspects
) {
387 super("TmfEventsTable"); //$NON-NLS-1$
389 fComposite
= new Composite(parent
, SWT
.NONE
);
390 final GridLayout gl
= new GridLayout(1, false);
393 gl
.verticalSpacing
= 0;
394 fComposite
.setLayout(gl
);
396 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
397 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
399 // Create a virtual table
400 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
401 fTable
= new TmfVirtualTable(fSashForm
, style
);
403 // Set the table layout
404 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
405 fTable
.setLayoutData(layoutData
);
407 // Some cosmetic enhancements
408 fTable
.setHeaderVisible(true);
409 fTable
.setLinesVisible(true);
412 for (ITmfEventAspect aspect
: aspects
) {
413 if (aspect
!= null) {
414 fColumns
.add(new TmfEventTableColumn(aspect
));
418 TmfMarginColumn collapseCol
= new TmfMarginColumn();
419 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
421 // Create the UI columns in the table
422 for (TmfEventTableColumn col
: fColumns
) {
423 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
424 column
.setText(col
.getHeaderName());
425 column
.setToolTipText(col
.getHeaderTooltip());
426 column
.setData(Key
.ASPECT
, col
.getEventAspect());
428 if (col
instanceof TmfMarginColumn
) {
429 column
.setResizable(false);
430 column
.addControlListener(new ControlAdapter() {
432 * Make sure that the margin column is always first
435 public void controlMoved(ControlEvent e
) {
436 int[] order
= fTable
.getColumnOrder();
437 if (order
[0] == MARGIN_COLUMN_INDEX
) {
440 for (int i
= order
.length
- 1; i
> 0; i
--) {
441 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
442 order
[i
] = order
[i
- 1];
443 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
446 fTable
.setColumnOrder(order
);
450 column
.setMoveable(true);
454 // Set the frozen row for header row
455 fTable
.setFrozenRowCount(1);
457 // Create the header row cell editor
458 createHeaderEditor();
460 // Handle the table item selection
461 fTable
.addSelectionListener(new SelectionAdapter() {
463 public void widgetSelected(final SelectionEvent e
) {
464 if (e
.item
== null) {
467 updateStatusLine(null);
468 if (fTable
.getSelectionIndices().length
> 0) {
469 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
470 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
471 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
473 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
474 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
475 if (fTable
.getSelectionIndices().length
== 1) {
476 fSelectedBeginTimestamp
= ts
;
478 if (fSelectedBeginTimestamp
!= null) {
479 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
480 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
481 if (fTable
.getSelectionIndices().length
== 2) {
482 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
485 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
486 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
490 if (fTable
.getSelectionIndices().length
== 1) {
491 fSelectedBeginTimestamp
= null;
495 if (e
.item
.getData() instanceof ITmfEvent
) {
496 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
497 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
499 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
504 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
505 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
506 fCache
= new TmfEventsCache(realCacheSize
, this);
508 // Handle the table item requests
509 fTable
.addListener(SWT
.SetData
, new Listener() {
512 public void handleEvent(final Event event
) {
514 final TableItem item
= (TableItem
) event
.item
;
515 int index
= event
.index
- 1; // -1 for the header row
517 if (event
.index
== 0) {
518 setHeaderRowItemData(item
);
522 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
523 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
524 setFilterStatusRowItemData(item
);
527 index
= index
- 1; // -1 for top filter status row
530 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
531 if (cachedEvent
!= null) {
532 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
536 // Else, fill the cache asynchronously (and off the UI thread)
541 fTable
.addMouseListener(new MouseAdapter() {
543 public void mouseDoubleClick(final MouseEvent event
) {
544 if (event
.button
!= 1) {
547 // Identify the selected row
548 final Point point
= new Point(event
.x
, event
.y
);
549 final TableItem item
= fTable
.getItem(point
);
551 final Rectangle imageBounds
= item
.getImageBounds(0);
552 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
553 if (imageBounds
.contains(point
)) {
554 final Long rank
= (Long
) item
.getData(Key
.RANK
);
556 toggleBookmark(rank
);
563 final Listener tooltipListener
= new Listener () {
564 Shell tooltipShell
= null;
566 public void handleEvent(final Event event
) {
567 switch (event
.type
) {
569 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
573 final Long rank
= (Long
) item
.getData(Key
.RANK
);
577 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
578 final Rectangle bounds
= item
.getImageBounds(0);
579 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
580 if (!bounds
.contains(event
.x
,event
.y
)) {
583 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
584 tooltipShell
.dispose();
586 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
587 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
588 final FillLayout layout
= new FillLayout();
589 layout
.marginWidth
= 2;
590 tooltipShell
.setLayout(layout
);
591 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
592 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
593 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
594 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
596 label
.addListener(SWT
.MouseExit
, this);
597 label
.addListener(SWT
.MouseDown
, this);
598 label
.addListener(SWT
.MouseWheel
, this);
599 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
601 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
602 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
606 y
+= fTable
.getHeaderHeight();
608 Point pt
= fTable
.toDisplay(event
.x
, y
);
609 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
610 pt
.y
+= item
.getBounds().height
;
611 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
612 tooltipShell
.setVisible(true);
620 if (tooltipShell
!= null) {
621 tooltipShell
.dispose();
631 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
632 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
633 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
634 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
635 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
636 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
637 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
642 ColorSettingsManager
.addColorSettingsListener(this);
644 fTable
.setItemCount(1); // +1 for header row
646 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
648 fRawViewer
.addSelectionListener(new Listener() {
650 public void handleEvent(final Event e
) {
651 if (e
.data
instanceof Long
) {
652 final long rank
= (Long
) e
.data
;
653 int index
= (int) rank
;
654 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
655 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
657 fTable
.setSelection(index
+ 1); // +1 for header row
658 fSelectedRank
= rank
;
659 updateStatusLine(null);
660 } else if (e
.data
instanceof ITmfLocation
) {
661 // DOES NOT WORK: rank undefined in context from seekLocation()
662 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
663 // TmfContext context = fTrace.seekLocation(location);
664 // fTable.setSelection((int) context.getRank());
669 final TableItem
[] selection
= fTable
.getSelection();
670 if ((selection
!= null) && (selection
.length
> 0)) {
671 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
673 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
679 fSashForm
.setWeights(new int[] { 1, 1 });
680 fRawViewer
.setVisible(false);
685 // ------------------------------------------------------------------------
687 // ------------------------------------------------------------------------
690 * Create a pop-up menu.
692 protected void createPopupMenu() {
693 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
696 fTable
.setVisible(true);
701 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
704 fTable
.setVisible(false);
709 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
712 fRawViewer
.setVisible(true);
714 final int index
= fTable
.getSelectionIndex();
716 fRawViewer
.selectAndReveal(index
- 1);
721 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
724 fRawViewer
.setVisible(false);
729 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
732 final TableItem items
[] = fTable
.getSelection();
733 if (items
.length
!= 1) {
736 final TableItem item
= items
[0];
738 final Object data
= item
.getData();
739 if (data
instanceof ITmfSourceLookup
) {
740 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
741 ITmfCallsite cs
= event
.getCallsite();
742 if (cs
== null || cs
.getFileName() == null) {
745 IMarker marker
= null;
747 String fileName
= cs
.getFileName();
748 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
749 final ArrayList
<IFile
> files
= new ArrayList
<>();
750 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
752 public boolean visit(IResource resource
) throws CoreException
{
753 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
754 files
.add((IFile
) resource
);
760 if (files
.size() > 1) {
761 ListDialog dialog
= new ListDialog(getTable().getShell());
762 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
763 dialog
.setLabelProvider(new LabelProvider() {
765 public String
getText(Object element
) {
766 return ((IFile
) element
).getFullPath().toString();
769 dialog
.setInput(files
);
770 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
771 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
773 Object
[] result
= dialog
.getResult();
774 if (result
!= null && result
.length
> 0) {
775 file
= (IFile
) result
[0];
777 } else if (files
.size() == 1) {
781 marker
= file
.createMarker(IMarker
.MARKER
);
782 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
783 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
785 } else if (files
.size() == 0){
786 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
788 } catch (CoreException e
) {
795 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
799 final TableItem items
[] = fTable
.getSelection();
800 if (items
.length
!= 1) {
803 final TableItem item
= items
[0];
805 final Object eventData
= item
.getData();
806 if (eventData
instanceof ITmfModelLookup
) {
807 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
809 if (modelURI
!= null) {
810 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
813 final URI uri
= URI
.createURI(modelURI
);
814 if (uri
.isPlatformResource()) {
815 IPath path
= new Path(uri
.toPlatformString(true));
816 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
817 } else if (uri
.isFile() && !uri
.isRelative()) {
818 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
819 new Path(uri
.toFileString()));
825 * create a temporary validation marker on the
826 * model file, remove it afterwards thus,
827 * navigation works with all model editors
828 * supporting the navigation to a marker
830 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
831 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
832 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
834 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
837 catch (CoreException e
) {
841 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
848 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
851 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
852 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
853 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
854 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
855 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
857 HashMap
<String
, Object
> parameters
= new HashMap
<>();
858 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
859 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
861 IEvaluationContext context
= handlerService
.getCurrentState();
862 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
863 for (int i
: fTable
.getColumnOrder()) {
864 // Omit the margin column
865 if (i
>= EVENT_COLUMNS_START_INDEX
) {
866 exportColumns
.add(fColumns
.get(i
));
869 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
871 handlerService
.executeCommandInContext(cmd
, null, context
);
872 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
878 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
881 fHeaderState
= HeaderState
.SEARCH
;
886 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
889 fHeaderState
= HeaderState
.FILTER
;
894 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
901 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
904 applyFilter(new TmfCollapseFilter());
908 class ToggleBookmarkAction
extends Action
{
911 public ToggleBookmarkAction(final String text
, final Long rank
) {
918 toggleBookmark(fRank
);
922 final MenuManager tablePopupMenu
= new MenuManager();
923 tablePopupMenu
.setRemoveAllWhenShown(true);
924 tablePopupMenu
.addMenuListener(new IMenuListener() {
926 public void menuAboutToShow(final IMenuManager manager
) {
927 if (fTable
.getSelectionIndex() == 0) {
928 // Right-click on header row
929 if (fHeaderState
== HeaderState
.FILTER
) {
930 tablePopupMenu
.add(showSearchBarAction
);
932 tablePopupMenu
.add(showFilterBarAction
);
936 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
937 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
939 final Rectangle imageBounds
= item
.getImageBounds(0);
940 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
941 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
942 // Right-click on left margin
943 final Long rank
= (Long
) item
.getData(Key
.RANK
);
944 if ((rank
!= null) && (fBookmarksFile
!= null)) {
945 if (fBookmarksMap
.containsKey(rank
)) {
946 tablePopupMenu
.add(new ToggleBookmarkAction(
947 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
949 tablePopupMenu
.add(new ToggleBookmarkAction(
950 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
957 // Right-click on table
958 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
959 tablePopupMenu
.add(hideTableAction
);
960 tablePopupMenu
.add(hideRawAction
);
961 } else if (!fTable
.isVisible()) {
962 tablePopupMenu
.add(showTableAction
);
963 } else if (!fRawViewer
.isVisible()) {
964 tablePopupMenu
.add(showRawAction
);
966 tablePopupMenu
.add(exportToTextAction
);
967 tablePopupMenu
.add(new Separator());
970 final Object data
= item
.getData();
971 Separator separator
= null;
972 if (data
instanceof ITmfSourceLookup
) {
973 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
974 if (event
.getCallsite() != null) {
975 tablePopupMenu
.add(openCallsiteAction
);
976 separator
= new Separator();
980 if (data
instanceof ITmfModelLookup
) {
981 ITmfModelLookup event
= (ITmfModelLookup
) data
;
982 if (event
.getModelUri() != null) {
983 tablePopupMenu
.add(openModelAction
);
984 separator
= new Separator();
987 if (separator
!= null) {
988 tablePopupMenu
.add(separator
);
993 // only show collapse filter if at least one trace can be collapsed
994 boolean isCollapsible
= false;
995 if (fTrace
!= null) {
996 ITmfTrace traces
[] = TmfTraceManager
.getTraceSet(fTrace
);
997 for (ITmfTrace trace
: traces
) {
998 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
999 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1000 if (isCollapsible
) {
1006 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1007 tablePopupMenu
.add(collapseAction
);
1008 tablePopupMenu
.add(new Separator());
1011 tablePopupMenu
.add(clearFiltersAction
);
1012 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1013 if (savedFilters
.length
> 0) {
1014 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1015 for (final ITmfFilterTreeNode node
: savedFilters
) {
1016 if (node
instanceof TmfFilterNode
) {
1017 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1018 subMenu
.add(new Action(filter
.getFilterName()) {
1021 applyFilter(filter
);
1026 tablePopupMenu
.add(subMenu
);
1028 appendToTablePopupMenu(tablePopupMenu
, item
);
1032 final MenuManager rawViewerPopupMenu
= new MenuManager();
1033 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1034 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1036 public void menuAboutToShow(final IMenuManager manager
) {
1037 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1038 rawViewerPopupMenu
.add(hideTableAction
);
1039 rawViewerPopupMenu
.add(hideRawAction
);
1040 } else if (!fTable
.isVisible()) {
1041 rawViewerPopupMenu
.add(showTableAction
);
1042 } else if (!fRawViewer
.isVisible()) {
1043 rawViewerPopupMenu
.add(showRawAction
);
1045 appendToRawPopupMenu(tablePopupMenu
);
1049 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1050 fTable
.setMenu(menu
);
1052 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1053 fRawViewer
.setMenu(menu
);
1058 * Append an item to the event table's pop-up menu.
1060 * @param tablePopupMenu
1062 * @param selectedItem
1063 * The item to append
1065 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1066 // override to append more actions
1070 * Append an item to the raw viewer's pop-up menu.
1072 * @param rawViewerPopupMenu
1075 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1076 // override to append more actions
1080 public void dispose() {
1083 ColorSettingsManager
.removeColorSettingsListener(this);
1084 fComposite
.dispose();
1085 if ((fTrace
!= null) && fDisposeOnClose
) {
1088 fResourceManager
.dispose();
1089 fRawViewer
.dispose();
1094 * Assign a layout data object to this view.
1097 * The layout data to assign
1099 public void setLayoutData(final Object layoutData
) {
1100 fComposite
.setLayoutData(layoutData
);
1104 * Get the virtual table contained in this event table.
1106 * @return The TMF virtual table
1108 public TmfVirtualTable
getTable() {
1115 * @deprecated The column headers are now set at the constructor, this
1116 * shouldn't be called anymore.
1119 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1124 * Set a table item's data.
1129 * Which trace event to link with this entry
1131 * Which rank this event has in the trace/experiment
1133 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1134 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1136 // Get the actual ITmfEvent from the CachedEvent
1137 ITmfEvent tmfEvent
= event
;
1138 if (event
instanceof CachedEvent
) {
1139 tmfEvent
= ((CachedEvent
) event
).event
;
1141 item
.setText(itemStrings
);
1142 item
.setData(tmfEvent
);
1143 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1144 item
.setData(Key
.RANK
, rank
);
1146 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1147 if (!markerIds
.isEmpty()) {
1148 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1149 List
<Object
> parts
= new ArrayList
<>();
1150 if (markerIds
.size() > 1) {
1151 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1154 for (long markerId
: markerIds
) {
1155 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1156 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1158 } catch (CoreException e
) {
1159 displayException(e
);
1161 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1163 item
.setData(Key
.BOOKMARK
, null);
1166 boolean searchMatch
= false;
1167 boolean searchNoMatch
= false;
1168 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1169 if (searchFilter
!= null) {
1170 if (searchFilter
.matches(tmfEvent
)) {
1173 searchNoMatch
= true;
1177 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1178 if (searchNoMatch
) {
1179 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1180 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1182 item
.setForeground(colorSetting
.getForegroundColor());
1183 item
.setBackground(colorSetting
.getBackgroundColor());
1187 if (!markerIds
.isEmpty()) {
1188 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1190 item
.setImage(SEARCH_MATCH_IMAGE
);
1192 } else if (!markerIds
.isEmpty()) {
1193 item
.setImage(BOOKMARK_IMAGE
);
1195 item
.setImage((Image
) null);
1198 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1204 * Set the item data of the header row.
1207 * The item to use as table header
1209 protected void setHeaderRowItemData(final TableItem item
) {
1210 String txtKey
= null;
1211 if (fHeaderState
== HeaderState
.SEARCH
) {
1212 item
.setImage(SEARCH_IMAGE
);
1213 txtKey
= Key
.SEARCH_TXT
;
1214 } else if (fHeaderState
== HeaderState
.FILTER
) {
1215 item
.setImage(FILTER_IMAGE
);
1216 txtKey
= Key
.FILTER_TXT
;
1218 item
.setForeground(fGrayColor
);
1219 // Ignore collapse and image column
1220 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1221 final TableColumn column
= fTable
.getColumns()[i
];
1222 final String filter
= (String
) column
.getData(txtKey
);
1223 if (filter
== null) {
1224 if (fHeaderState
== HeaderState
.SEARCH
) {
1225 item
.setText(i
, SEARCH_HINT
);
1226 } else if (fHeaderState
== HeaderState
.FILTER
) {
1227 item
.setText(i
, FILTER_HINT
);
1229 item
.setForeground(i
, fGrayColor
);
1230 item
.setFont(i
, fTable
.getFont());
1232 item
.setText(i
, filter
);
1233 item
.setForeground(i
, fGreenColor
);
1234 item
.setFont(i
, fBoldFont
);
1240 * Set the item data of the "filter status" row.
1243 * The item to use as filter status row
1245 protected void setFilterStatusRowItemData(final TableItem item
) {
1246 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1247 if (i
== MARGIN_COLUMN_INDEX
) {
1248 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1249 item
.setImage(FILTER_IMAGE
);
1251 item
.setImage(STOP_IMAGE
);
1255 if (i
== FILTER_SUMMARY_INDEX
) {
1256 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1258 item
.setText(i
, EMPTY_STRING
);
1262 item
.setData(Key
.TIMESTAMP
, null);
1263 item
.setData(Key
.RANK
, null);
1264 item
.setForeground(null);
1265 item
.setBackground(null);
1269 * Create an editor for the header.
1271 protected void createHeaderEditor() {
1272 final TableEditor tableEditor
= fTable
.createTableEditor();
1273 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1274 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1275 tableEditor
.grabHorizontal
= true;
1276 tableEditor
.minimumWidth
= 50;
1278 // Handle the header row selection
1279 fTable
.addMouseListener(new MouseAdapter() {
1285 public void mouseDown(final MouseEvent event
) {
1286 if (event
.button
!= 1) {
1289 // Identify the selected row
1290 final Point point
= new Point(event
.x
, event
.y
);
1291 item
= fTable
.getItem(point
);
1293 // Header row selected
1294 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1297 if (item
.getImageBounds(0).contains(point
)) {
1298 if (fHeaderState
== HeaderState
.SEARCH
) {
1299 fHeaderState
= HeaderState
.FILTER
;
1300 } else if (fHeaderState
== HeaderState
.FILTER
) {
1301 fHeaderState
= HeaderState
.SEARCH
;
1303 fTable
.setSelection(0);
1308 // Identify the selected column
1310 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1311 final Rectangle rect
= item
.getBounds(i
);
1312 if (rect
.contains(point
)) {
1318 if (columnIndex
== -1) {
1322 column
= fTable
.getColumns()[columnIndex
];
1324 String txtKey
= null;
1325 if (fHeaderState
== HeaderState
.SEARCH
) {
1326 txtKey
= Key
.SEARCH_TXT
;
1327 } else if (fHeaderState
== HeaderState
.FILTER
) {
1328 txtKey
= Key
.FILTER_TXT
;
1331 // The control that will be the editor must be a child of the Table
1332 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1333 final String headerString
= (String
) column
.getData(txtKey
);
1334 if (headerString
!= null) {
1335 newEditor
.setText(headerString
);
1337 newEditor
.addFocusListener(new FocusAdapter() {
1339 public void focusLost(final FocusEvent e
) {
1340 final boolean changed
= updateHeader(newEditor
.getText());
1346 newEditor
.addKeyListener(new KeyAdapter() {
1348 public void keyPressed(final KeyEvent e
) {
1349 if (e
.character
== SWT
.CR
) {
1350 updateHeader(newEditor
.getText());
1353 // Set focus on the table so that the next carriage return goes to the next result
1354 TmfEventsTable
.this.getTable().setFocus();
1355 } else if (e
.character
== SWT
.ESC
) {
1356 tableEditor
.getEditor().dispose();
1360 newEditor
.selectAll();
1361 newEditor
.setFocus();
1362 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1367 * returns true is value was changed
1369 private boolean updateHeader(final String text
) {
1370 String objKey
= null;
1371 String txtKey
= null;
1372 if (fHeaderState
== HeaderState
.SEARCH
) {
1373 objKey
= Key
.SEARCH_OBJ
;
1374 txtKey
= Key
.SEARCH_TXT
;
1375 } else if (fHeaderState
== HeaderState
.FILTER
) {
1376 objKey
= Key
.FILTER_OBJ
;
1377 txtKey
= Key
.FILTER_TXT
;
1379 if (text
.trim().length() > 0) {
1381 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1382 Pattern
.compile(regex
);
1383 if (regex
.equals(column
.getData(txtKey
))) {
1384 tableEditor
.getEditor().dispose();
1387 final TmfFilterMatchesAspectNode filter
= new TmfFilterMatchesAspectNode(null);
1388 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1389 filter
.setEventAspect(aspect
);
1390 filter
.setRegex(regex
);
1391 column
.setData(objKey
, filter
);
1392 column
.setData(txtKey
, regex
);
1393 } catch (final PatternSyntaxException ex
) {
1394 tableEditor
.getEditor().dispose();
1395 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1396 ex
.getDescription(), ex
.getMessage());
1400 if (column
.getData(txtKey
) == null) {
1401 tableEditor
.getEditor().dispose();
1404 column
.setData(objKey
, null);
1405 column
.setData(txtKey
, null);
1410 private void applyHeader() {
1411 if (fHeaderState
== HeaderState
.SEARCH
) {
1413 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1414 for (final TableColumn col
: fTable
.getColumns()) {
1415 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1416 if (filterObj
instanceof ITmfFilterTreeNode
) {
1417 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1420 if (filter
.getChildrenCount() > 0) {
1421 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1424 fireSearchApplied(filter
);
1426 fTable
.setData(Key
.SEARCH_OBJ
, null);
1428 fireSearchApplied(null);
1430 } else if (fHeaderState
== HeaderState
.FILTER
) {
1431 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1432 for (final TableColumn col
: fTable
.getColumns()) {
1433 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1434 if (filterObj
instanceof ITmfFilterTreeNode
) {
1435 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1438 if (filter
.getChildrenCount() > 0) {
1439 applyFilter(filter
);
1445 tableEditor
.getEditor().dispose();
1449 fTable
.addKeyListener(new KeyAdapter() {
1451 public void keyPressed(final KeyEvent e
) {
1453 if (e
.character
== SWT
.ESC
) {
1457 } else if (e
.character
== SWT
.DEL
) {
1458 if (fHeaderState
== HeaderState
.SEARCH
) {
1460 for (final TableColumn column
: fTable
.getColumns()) {
1461 column
.setData(Key
.SEARCH_OBJ
, null);
1462 column
.setData(Key
.SEARCH_TXT
, null);
1464 fTable
.setData(Key
.SEARCH_OBJ
, null);
1466 fireSearchApplied(null);
1467 } else if (fHeaderState
== HeaderState
.FILTER
) {
1470 } else if (e
.character
== SWT
.CR
) {
1471 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1482 * Send an event indicating a filter has been applied.
1485 * The filter that was just applied
1487 protected void fireFilterApplied(final ITmfFilter filter
) {
1488 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1492 * Send an event indicating that a search has been applied.
1495 * The search filter that was just applied
1497 protected void fireSearchApplied(final ITmfFilter filter
) {
1498 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1502 * Start the filtering thread.
1504 protected void startFilterThread() {
1505 synchronized (fFilterSyncObj
) {
1506 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1507 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1508 if (fFilterThread
!= null) {
1509 fFilterThread
.cancel();
1510 fFilterThreadResume
= false;
1512 fFilterThread
= new FilterThread(filter
);
1513 fFilterThread
.start();
1515 fFilterThreadResume
= true;
1521 * Stop the filtering thread.
1523 protected void stopFilterThread() {
1524 synchronized (fFilterSyncObj
) {
1525 if (fFilterThread
!= null) {
1526 fFilterThread
.cancel();
1527 fFilterThread
= null;
1528 fFilterThreadResume
= false;
1537 * 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
2062 public String
[] getItemStrings(ITmfEvent event
) {
2063 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2064 for (int i
: fTable
.getColumnOrder()) {
2065 columns
.add(fColumns
.get(i
));
2067 return getItemStrings(columns
, event
);
2071 * Notify this table that is got the UI focus.
2073 public void setFocus() {
2078 * Assign a new trace to this event table.
2081 * The trace to assign to this event table
2082 * @param disposeOnClose
2083 * true if the trace should be disposed when the table is
2086 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2087 if ((fTrace
!= null) && fDisposeOnClose
) {
2093 fDisposeOnClose
= disposeOnClose
;
2095 // Perform the updates on the UI thread
2096 fTable
.getDisplay().syncExec(new Runnable() {
2100 fCache
.setTrace(fTrace
); // Clear the cache
2101 if (fTrace
!= null) {
2102 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2103 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2104 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2107 fFilterMatchCount
= 0;
2108 fFilterCheckCount
= 0;
2109 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2110 startFilterThread();
2114 fRawViewer
.setTrace(fTrace
);
2120 * Assign the status line manager
2122 * @param statusLineManager
2123 * The status line manager, or null to disable status line messages
2126 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2127 if (fStatusLineManager
!= null && statusLineManager
== null) {
2128 fStatusLineManager
.setMessage(EMPTY_STRING
);
2130 fStatusLineManager
= statusLineManager
;
2133 private void updateStatusLine(ITmfTimestamp delta
) {
2134 if (fStatusLineManager
!= null) {
2135 if (delta
!= null) {
2136 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2138 fStatusLineManager
.setMessage(null);
2143 // ------------------------------------------------------------------------
2145 // ------------------------------------------------------------------------
2148 * Notify that the event cache has been updated
2151 * Also notify if the populating of the cache is complete, or
2154 public void cacheUpdated(final boolean completed
) {
2155 synchronized (fCacheUpdateSyncObj
) {
2156 if (fCacheUpdateBusy
) {
2157 fCacheUpdatePending
= true;
2158 fCacheUpdateCompleted
= completed
;
2161 fCacheUpdateBusy
= true;
2163 // Event cache is now updated. Perform update on the UI thread
2164 if (!fTable
.isDisposed()) {
2165 fTable
.getDisplay().asyncExec(new Runnable() {
2168 if (!fTable
.isDisposed()) {
2173 populateCompleted();
2175 synchronized (fCacheUpdateSyncObj
) {
2176 fCacheUpdateBusy
= false;
2177 if (fCacheUpdatePending
) {
2178 fCacheUpdatePending
= false;
2179 cacheUpdated(fCacheUpdateCompleted
);
2188 * Callback for when populating the table is complete.
2190 protected void populateCompleted() {
2191 // Nothing by default;
2194 // ------------------------------------------------------------------------
2195 // ISelectionProvider
2196 // ------------------------------------------------------------------------
2202 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2203 selectionChangedListeners
.add(listener
);
2210 public ISelection
getSelection() {
2211 if (fTable
== null || fTable
.isDisposed()) {
2212 return StructuredSelection
.EMPTY
;
2214 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2215 for (TableItem item
: fTable
.getSelection()) {
2216 if (item
.getData() != null) {
2217 list
.add(item
.getData());
2220 return new StructuredSelection(list
);
2227 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2228 selectionChangedListeners
.remove(listener
);
2235 public void setSelection(ISelection selection
) {
2240 * Notifies any selection changed listeners that the viewer's selection has changed.
2241 * Only listeners registered at the time this method is called are notified.
2243 * @param event a selection changed event
2245 * @see ISelectionChangedListener#selectionChanged
2248 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2249 Object
[] listeners
= selectionChangedListeners
.getListeners();
2250 for (int i
= 0; i
< listeners
.length
; ++i
) {
2251 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2252 SafeRunnable
.run(new SafeRunnable() {
2255 l
.selectionChanged(event
);
2261 // ------------------------------------------------------------------------
2262 // Bookmark handling
2263 // ------------------------------------------------------------------------
2266 * Add a bookmark to this event table.
2268 * @param bookmarksFile
2269 * The file to use for the bookmarks
2271 public void addBookmark(final IFile bookmarksFile
) {
2272 fBookmarksFile
= bookmarksFile
;
2273 final TableItem
[] selection
= fTable
.getSelection();
2274 if (selection
.length
> 0) {
2275 final TableItem tableItem
= selection
[0];
2276 if (tableItem
.getData(Key
.RANK
) != null) {
2277 final StringBuffer defaultMessage
= new StringBuffer();
2278 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2280 defaultMessage
.append(", "); //$NON-NLS-1$
2282 defaultMessage
.append(tableItem
.getText(i
));
2284 final InputDialog dialog
= new MultiLineInputDialog(
2285 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2286 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2287 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2288 defaultMessage
.toString());
2289 if (dialog
.open() == Window
.OK
) {
2290 final String message
= dialog
.getValue();
2292 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2293 if (bookmark
.exists()) {
2294 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2295 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2296 final int location
= rank
.intValue();
2297 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2298 fBookmarksMap
.put(rank
, bookmark
.getId());
2301 } catch (final CoreException e
) {
2302 displayException(e
);
2311 * Remove a bookmark from this event table.
2314 * The bookmark to remove
2316 public void removeBookmark(final IMarker bookmark
) {
2317 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2318 if (entry
.getValue().equals(bookmark
.getId())) {
2319 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2326 private void toggleBookmark(final Long rank
) {
2327 if (fBookmarksFile
== null) {
2330 if (fBookmarksMap
.containsKey(rank
)) {
2331 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2334 for (long markerId
: markerIds
) {
2335 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2336 if (bookmark
!= null) {
2340 } catch (final CoreException e
) {
2341 displayException(e
);
2344 addBookmark(fBookmarksFile
);
2349 * Refresh the bookmarks assigned to this trace, from the contents of a
2352 * @param bookmarksFile
2353 * The bookmark file to use
2355 public void refreshBookmarks(final IFile bookmarksFile
) {
2356 fBookmarksFile
= bookmarksFile
;
2357 if (bookmarksFile
== null) {
2358 fBookmarksMap
.clear();
2363 fBookmarksMap
.clear();
2364 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2365 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2366 if (location
!= -1) {
2367 final long rank
= location
;
2368 fBookmarksMap
.put(rank
, bookmark
.getId());
2372 } catch (final CoreException e
) {
2373 displayException(e
);
2378 public void gotoMarker(final IMarker marker
) {
2379 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2382 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2383 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2384 } else if (rank
>= fTable
.getItemCount()) {
2385 fPendingGotoRank
= rank
;
2387 fSelectedRank
= rank
;
2388 fTable
.setSelection(index
+ 1); // +1 for header row
2389 updateStatusLine(null);
2393 // ------------------------------------------------------------------------
2395 // ------------------------------------------------------------------------
2398 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2402 // ------------------------------------------------------------------------
2404 // ------------------------------------------------------------------------
2407 * Handler for the trace updated signal
2410 * The incoming signal
2413 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2414 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2417 // Perform the refresh on the UI thread
2418 Display
.getDefault().asyncExec(new Runnable() {
2421 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2422 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2423 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2424 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2425 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2426 fPendingGotoRank
= -1;
2427 updateStatusLine(null);
2430 startFilterThread();
2433 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2434 fRawViewer
.refreshEventCount();
2441 * Handler for the time synch signal.
2444 * The incoming signal
2447 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2448 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2450 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2451 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2452 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2453 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2454 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2456 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2459 public void handleData(final ITmfEvent event
) {
2460 super.handleData(event
);
2464 public void handleSuccess() {
2465 super.handleSuccess();
2466 if (fTrace
== null) {
2470 // Verify if the event is within the trace range and adjust if necessary
2471 ITmfTimestamp timestamp
= ts
;
2472 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2473 timestamp
= fTrace
.getStartTime();
2475 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2476 timestamp
= fTrace
.getEndTime();
2479 // Get the rank of the selected event in the table
2480 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2481 final long rank
= context
.getRank();
2483 fSelectedRank
= rank
;
2485 fTable
.getDisplay().asyncExec(new Runnable() {
2488 // Return if table is disposed
2489 if (fTable
.isDisposed()) {
2493 int index
= (int) rank
;
2494 if (fTable
.isDisposed()) {
2497 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2498 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2500 fTable
.setSelection(index
+ 1); // +1 for header row
2501 fRawViewer
.selectAndReveal(rank
);
2502 updateStatusLine(null);
2508 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2512 // ------------------------------------------------------------------------
2514 // ------------------------------------------------------------------------
2517 * Display an exception in a message box
2519 * @param e the exception
2521 private static void displayException(final Exception e
) {
2522 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2523 mb
.setText(e
.getClass().getSimpleName());
2524 mb
.setMessage(e
.getMessage());
2531 public void refresh() {
2538 * Margin column for images and special text (e.g. collapse count)
2540 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2542 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2545 public String
getName() {
2546 return EMPTY_STRING
;
2550 public String
resolve(ITmfEvent event
) {
2551 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2552 return EMPTY_STRING
;
2554 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2558 public String
getHelpText() {
2559 return EMPTY_STRING
;
2566 public TmfMarginColumn() {
2567 super(MARGIN_ASPECT
);