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
.Matcher
;
30 import java
.util
.regex
.Pattern
;
31 import java
.util
.regex
.PatternSyntaxException
;
33 import org
.eclipse
.core
.commands
.Command
;
34 import org
.eclipse
.core
.commands
.ExecutionException
;
35 import org
.eclipse
.core
.commands
.NotEnabledException
;
36 import org
.eclipse
.core
.commands
.NotHandledException
;
37 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
38 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
39 import org
.eclipse
.core
.expressions
.IEvaluationContext
;
40 import org
.eclipse
.core
.resources
.IFile
;
41 import org
.eclipse
.core
.resources
.IMarker
;
42 import org
.eclipse
.core
.resources
.IResource
;
43 import org
.eclipse
.core
.resources
.IResourceVisitor
;
44 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
45 import org
.eclipse
.core
.runtime
.CoreException
;
46 import org
.eclipse
.core
.runtime
.IPath
;
47 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
48 import org
.eclipse
.core
.runtime
.IStatus
;
49 import org
.eclipse
.core
.runtime
.ListenerList
;
50 import org
.eclipse
.core
.runtime
.Path
;
51 import org
.eclipse
.core
.runtime
.Status
;
52 import org
.eclipse
.core
.runtime
.jobs
.Job
;
53 import org
.eclipse
.emf
.common
.util
.URI
;
54 import org
.eclipse
.emf
.ecore
.EValidator
;
55 import org
.eclipse
.jdt
.annotation
.NonNull
;
56 import org
.eclipse
.jface
.action
.Action
;
57 import org
.eclipse
.jface
.action
.IAction
;
58 import org
.eclipse
.jface
.action
.IMenuListener
;
59 import org
.eclipse
.jface
.action
.IMenuManager
;
60 import org
.eclipse
.jface
.action
.IStatusLineManager
;
61 import org
.eclipse
.jface
.action
.MenuManager
;
62 import org
.eclipse
.jface
.action
.Separator
;
63 import org
.eclipse
.jface
.dialogs
.InputDialog
;
64 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
65 import org
.eclipse
.jface
.resource
.FontRegistry
;
66 import org
.eclipse
.jface
.resource
.JFaceResources
;
67 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
68 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
69 import org
.eclipse
.jface
.util
.OpenStrategy
;
70 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
71 import org
.eclipse
.jface
.util
.SafeRunnable
;
72 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
73 import org
.eclipse
.jface
.viewers
.ISelection
;
74 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
75 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
76 import org
.eclipse
.jface
.viewers
.LabelProvider
;
77 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
78 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
79 import org
.eclipse
.jface
.window
.Window
;
80 import org
.eclipse
.swt
.SWT
;
81 import org
.eclipse
.swt
.custom
.SashForm
;
82 import org
.eclipse
.swt
.custom
.StyleRange
;
83 import org
.eclipse
.swt
.custom
.TableEditor
;
84 import org
.eclipse
.swt
.events
.ControlAdapter
;
85 import org
.eclipse
.swt
.events
.ControlEvent
;
86 import org
.eclipse
.swt
.events
.FocusAdapter
;
87 import org
.eclipse
.swt
.events
.FocusEvent
;
88 import org
.eclipse
.swt
.events
.KeyAdapter
;
89 import org
.eclipse
.swt
.events
.KeyEvent
;
90 import org
.eclipse
.swt
.events
.MouseAdapter
;
91 import org
.eclipse
.swt
.events
.MouseEvent
;
92 import org
.eclipse
.swt
.events
.SelectionAdapter
;
93 import org
.eclipse
.swt
.events
.SelectionEvent
;
94 import org
.eclipse
.swt
.graphics
.Color
;
95 import org
.eclipse
.swt
.graphics
.Font
;
96 import org
.eclipse
.swt
.graphics
.GC
;
97 import org
.eclipse
.swt
.graphics
.Image
;
98 import org
.eclipse
.swt
.graphics
.Point
;
99 import org
.eclipse
.swt
.graphics
.Rectangle
;
100 import org
.eclipse
.swt
.layout
.FillLayout
;
101 import org
.eclipse
.swt
.layout
.GridData
;
102 import org
.eclipse
.swt
.layout
.GridLayout
;
103 import org
.eclipse
.swt
.widgets
.Composite
;
104 import org
.eclipse
.swt
.widgets
.Display
;
105 import org
.eclipse
.swt
.widgets
.Event
;
106 import org
.eclipse
.swt
.widgets
.Label
;
107 import org
.eclipse
.swt
.widgets
.Listener
;
108 import org
.eclipse
.swt
.widgets
.Menu
;
109 import org
.eclipse
.swt
.widgets
.MessageBox
;
110 import org
.eclipse
.swt
.widgets
.Shell
;
111 import org
.eclipse
.swt
.widgets
.TableColumn
;
112 import org
.eclipse
.swt
.widgets
.TableItem
;
113 import org
.eclipse
.swt
.widgets
.Text
;
114 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
115 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
116 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
117 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
118 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
119 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
120 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
121 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
122 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
123 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
124 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfContentFieldAspect
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
141 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
142 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
143 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
144 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
145 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
146 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
147 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
148 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
149 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
150 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
151 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
152 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
153 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
154 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
155 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
156 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
157 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
158 import org
.eclipse
.ui
.IWorkbenchPage
;
159 import org
.eclipse
.ui
.PlatformUI
;
160 import org
.eclipse
.ui
.commands
.ICommandService
;
161 import org
.eclipse
.ui
.dialogs
.ListDialog
;
162 import org
.eclipse
.ui
.handlers
.IHandlerService
;
163 import org
.eclipse
.ui
.ide
.IDE
;
164 import org
.eclipse
.ui
.ide
.IGotoMarker
;
165 import org
.eclipse
.ui
.themes
.ColorUtil
;
166 import org
.eclipse
.ui
.themes
.IThemeManager
;
168 import com
.google
.common
.base
.Joiner
;
169 import com
.google
.common
.collect
.HashMultimap
;
170 import com
.google
.common
.collect
.ImmutableList
;
171 import com
.google
.common
.collect
.Multimap
;
174 * The generic TMF Events table
176 * This is a view that will list events that are read from a trace.
178 * @author Francois Chouinard
179 * @author Patrick Tasse
181 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
, IPropertyChangeListener
{
184 * Empty string array, used by {@link #getItemStrings}.
186 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
191 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
193 private static final @NonNull String DOT_STAR_PREFIX
= "^\\.\\*"; //$NON-NLS-1$
194 private static final @NonNull String DOT_STAR_SUFFIX
= "\\.\\*$"; //$NON-NLS-1$
196 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
198 private static final String FONT_DEFINITION_ID
= "org.eclipse.tracecompass.tmf.ui.font.eventtable"; //$NON-NLS-1$
200 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
201 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
202 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
203 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
204 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
205 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
206 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
207 private static final Image FILTER_IMAGE
= Activator
.getDefault()
208 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
209 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
210 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
211 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
212 private static final int MAX_CACHE_SIZE
= 1000;
214 private static final int MARGIN_COLUMN_INDEX
= 0;
215 private static final int FILTER_SUMMARY_INDEX
= 1;
216 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
219 * The events table search/filter keys
222 * @author Patrick Tasse
224 public interface Key
{
226 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
229 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
232 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
235 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
238 String TIMESTAMP
= "$time"; //$NON-NLS-1$
241 String RANK
= "$rank"; //$NON-NLS-1$
243 /** Bookmark indicator */
244 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
246 /** Event aspect represented by this column */
247 String ASPECT
= "$aspect"; //$NON-NLS-1$
249 /** Table item list of style ranges
251 String STYLE_RANGES
= "$style_ranges"; //$NON-NLS-1$
255 * The events table search/filter state
258 * @author Patrick Tasse
260 public static enum HeaderState
{
261 /** A search is being run */
264 /** A filter is applied */
268 interface Direction
{
273 // ------------------------------------------------------------------------
275 // ------------------------------------------------------------------------
277 /** The virtual event table */
278 protected TmfVirtualTable fTable
;
280 private Composite fComposite
;
281 private SashForm fSashForm
;
282 private TmfRawEventViewer fRawViewer
;
283 private ITmfTrace fTrace
;
284 volatile private boolean fPackDone
= false;
285 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
286 private long fSelectedRank
= 0;
287 private ITmfTimestamp fSelectedBeginTimestamp
= null;
288 private IStatusLineManager fStatusLineManager
= null;
291 private long fFilterMatchCount
;
292 private long fFilterCheckCount
;
293 private FilterThread fFilterThread
;
294 private boolean fFilterThreadResume
= false;
295 private final Object fFilterSyncObj
= new Object();
296 private SearchThread fSearchThread
;
297 private final Object fSearchSyncObj
= new Object();
300 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
302 * @see #fireSelectionChanged
304 private ListenerList selectionChangedListeners
= new ListenerList();
306 // Bookmark map <Rank, MarkerId>
307 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
308 private IFile fBookmarksFile
;
309 private long fPendingGotoRank
= -1;
312 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
313 private Color fGrayColor
;
314 private Color fGreenColor
;
316 private Font fBoldFont
;
318 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
321 private final TmfEventsCache fCache
;
322 private boolean fCacheUpdateBusy
= false;
323 private boolean fCacheUpdatePending
= false;
324 private boolean fCacheUpdateCompleted
= false;
325 private final Object fCacheUpdateSyncObj
= new Object();
327 // Keep track of column order, it is needed after table is disposed
328 private int[] fColumnOrder
;
330 private boolean fDisposeOnClose
;
332 // ------------------------------------------------------------------------
334 // ------------------------------------------------------------------------
337 * Basic constructor, using the default set of columns
340 * The parent composite UI object
342 * The size of the event table cache
344 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
345 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
349 * Legacy constructor, using ColumnData to define columns
352 * The parent composite UI object
354 * The size of the event table cache
356 * The column data array
357 * @deprecated Deprecated constructor, use
358 * {@link #TmfEventsTable(Composite, int, Collection)}
361 public TmfEventsTable(final Composite parent
, int cacheSize
,
362 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
364 * We'll do a "best-effort" to keep trace types still using this API to
365 * keep working, by defining a TmfEventTableColumn for each
366 * ColumnData they passed.
368 this(parent
, cacheSize
, convertFromColumnData(columnData
));
372 private static @NonNull Iterable
<ITmfEventAspect
> convertFromColumnData(
373 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
375 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
376 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
377 String fieldName
= col
.header
;
378 if (fieldName
!= null) {
379 builder
.add(new TmfContentFieldAspect(fieldName
, fieldName
));
382 return checkNotNull(builder
.build());
386 * Standard constructor, where we define which columns to use.
389 * The parent composite UI object
391 * The size of the event table cache
393 * The event aspects to display in this table. One column per
394 * aspect will be created.
396 * The iteration order of this collection will correspond to the
397 * initial ordering of the columns in the table.
400 public TmfEventsTable(final Composite parent
, int cacheSize
,
401 @NonNull Iterable
<ITmfEventAspect
> aspects
) {
402 super("TmfEventsTable"); //$NON-NLS-1$
404 fComposite
= new Composite(parent
, SWT
.NONE
);
405 final GridLayout gl
= new GridLayout(1, false);
408 gl
.verticalSpacing
= 0;
409 fComposite
.setLayout(gl
);
411 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
412 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
414 // Create a virtual table
415 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
416 fTable
= new TmfVirtualTable(fSashForm
, style
);
418 // Set the table layout
419 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
420 fTable
.setLayoutData(layoutData
);
422 // Some cosmetic enhancements
423 fTable
.setHeaderVisible(true);
424 fTable
.setLinesVisible(true);
427 for (ITmfEventAspect aspect
: aspects
) {
428 if (aspect
!= null) {
429 fColumns
.add(new TmfEventTableColumn(aspect
));
433 TmfMarginColumn collapseCol
= new TmfMarginColumn();
434 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
436 // Create the UI columns in the table
437 for (TmfEventTableColumn col
: fColumns
) {
438 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
439 column
.setText(col
.getHeaderName());
440 column
.setToolTipText(col
.getHeaderTooltip());
441 column
.setData(Key
.ASPECT
, col
.getEventAspect());
443 if (col
instanceof TmfMarginColumn
) {
444 column
.setResizable(false);
446 column
.setMoveable(true);
448 column
.addControlListener(new ControlAdapter() {
450 * Make sure that the margin column is always first
451 * and keep the column order variable up to date.
454 public void controlMoved(ControlEvent e
) {
455 int[] order
= fTable
.getColumnOrder();
456 if (order
[0] == MARGIN_COLUMN_INDEX
) {
457 fColumnOrder
= order
;
460 for (int i
= order
.length
- 1; i
> 0; i
--) {
461 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
462 order
[i
] = order
[i
- 1];
463 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
466 fTable
.setColumnOrder(order
);
467 fColumnOrder
= fTable
.getColumnOrder();
471 fColumnOrder
= fTable
.getColumnOrder();
473 // Set the frozen row for header row
474 fTable
.setFrozenRowCount(1);
476 // Create the header row cell editor
477 createHeaderEditor();
479 // Handle the table item selection
480 fTable
.addSelectionListener(new SelectionAdapter() {
482 public void widgetSelected(final SelectionEvent e
) {
483 if (e
.item
== null) {
486 updateStatusLine(null);
487 if (fTable
.getSelectionIndices().length
> 0) {
488 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
489 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
490 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
492 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
493 final ITmfTimestamp ts
= NonNullUtils
.checkNotNull((ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
));
494 if (fTable
.getSelectionIndices().length
== 1) {
495 fSelectedBeginTimestamp
= ts
;
497 ITmfTimestamp selectedBeginTimestamp
= fSelectedBeginTimestamp
;
498 if (selectedBeginTimestamp
!= null) {
499 if (selectedBeginTimestamp
.compareTo(ts
) <= 0) {
500 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, selectedBeginTimestamp
, ts
));
501 if (fTable
.getSelectionIndices().length
== 2) {
502 updateStatusLine(ts
.getDelta(selectedBeginTimestamp
));
505 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, checkNotNull(ts
), checkNotNull(fSelectedBeginTimestamp
)));
506 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
510 if (fTable
.getSelectionIndices().length
== 1) {
511 fSelectedBeginTimestamp
= null;
515 if (e
.item
.getData() instanceof ITmfEvent
) {
516 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
517 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
519 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
524 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
525 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
526 fCache
= new TmfEventsCache(realCacheSize
, this);
528 // Handle the table item requests
529 fTable
.addListener(SWT
.SetData
, new Listener() {
532 public void handleEvent(final Event event
) {
534 final TableItem item
= (TableItem
) event
.item
;
535 int index
= event
.index
- 1; // -1 for the header row
537 if (event
.index
== 0) {
538 setHeaderRowItemData(item
);
542 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
543 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
544 setFilterStatusRowItemData(item
);
547 index
= index
- 1; // -1 for top filter status row
550 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
551 if (cachedEvent
!= null) {
552 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
556 // Else, fill the cache asynchronously (and off the UI thread)
561 fTable
.addMouseListener(new MouseAdapter() {
563 public void mouseDoubleClick(final MouseEvent event
) {
564 if (event
.button
!= 1) {
567 // Identify the selected row
568 final Point point
= new Point(event
.x
, event
.y
);
569 final TableItem item
= fTable
.getItem(point
);
571 final Rectangle imageBounds
= item
.getImageBounds(0);
572 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
573 if (imageBounds
.contains(point
)) {
574 final Long rank
= (Long
) item
.getData(Key
.RANK
);
576 toggleBookmark(rank
);
583 final Listener tooltipListener
= new Listener () {
584 Shell tooltipShell
= null;
586 public void handleEvent(final Event event
) {
587 switch (event
.type
) {
589 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
593 final Long rank
= (Long
) item
.getData(Key
.RANK
);
597 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
598 final Rectangle bounds
= item
.getImageBounds(0);
599 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
600 if (!bounds
.contains(event
.x
,event
.y
)) {
603 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
604 tooltipShell
.dispose();
606 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
607 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
608 final FillLayout layout
= new FillLayout();
609 layout
.marginWidth
= 2;
610 tooltipShell
.setLayout(layout
);
611 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
612 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
613 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
614 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
616 label
.addListener(SWT
.MouseExit
, this);
617 label
.addListener(SWT
.MouseDown
, this);
618 label
.addListener(SWT
.MouseWheel
, this);
619 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
621 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
622 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
626 y
+= fTable
.getHeaderHeight();
628 Point pt
= fTable
.toDisplay(event
.x
, y
);
629 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
630 pt
.y
+= item
.getBounds().height
;
631 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
632 tooltipShell
.setVisible(true);
640 if (tooltipShell
!= null) {
641 tooltipShell
.dispose();
651 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
652 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
653 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
654 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
655 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
656 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
657 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
659 fTable
.addListener(SWT
.EraseItem
, new Listener() {
661 public void handleEvent(Event event
) {
662 TableItem item
= (TableItem
) event
.item
;
663 List
<?
> styleRanges
= (List
<?
>) item
.getData(Key
.STYLE_RANGES
);
666 Color background
= item
.getBackground(event
.index
);
668 * Paint the background if it is not the default system color.
669 * In Windows, if you let the widget draw the background, it
670 * will not show the item's background color if the item is
671 * selected or hot. If there are no style ranges and the item
672 * background is the default system color, we do not want to
673 * paint it or otherwise we would override the platform theme
674 * (e.g. alternating colors).
676 if (styleRanges
!= null || !background
.equals(item
.getParent().getBackground())) {
677 // we will paint the table item's background
678 event
.detail
&= ~SWT
.BACKGROUND
;
680 // paint the item's default background
681 gc
.setBackground(background
);
682 gc
.fillRectangle(event
.x
, event
.y
, event
.width
, event
.height
);
686 * We will paint the table item's foreground. In Windows, if you paint
687 * the background but let the widget draw the foreground, it will
688 * override your background, unless the item is selected or hot.
690 event
.detail
&= ~SWT
.FOREGROUND
;
692 // paint the highlighted background for all style ranges
693 if (styleRanges
!= null) {
694 Rectangle textBounds
= item
.getTextBounds(event
.index
);
695 String text
= item
.getText(event
.index
);
696 for (Object o
: styleRanges
) {
697 if (o
instanceof StyleRange
) {
698 StyleRange styleRange
= (StyleRange
) o
;
699 if (styleRange
.data
.equals(event
.index
)) {
700 int startIndex
= styleRange
.start
;
701 int endIndex
= startIndex
+ styleRange
.length
;
702 int startX
= gc
.stringExtent(text
.substring(0, startIndex
)).x
;
703 int endX
= gc
.stringExtent(text
.substring(0, endIndex
)).x
;
704 gc
.setBackground(styleRange
.background
);
705 gc
.fillRectangle(textBounds
.x
+ startX
, textBounds
.y
, (endX
- startX
), textBounds
.height
);
713 fTable
.addListener(SWT
.PaintItem
, new Listener() {
715 public void handleEvent(Event event
) {
716 TableItem item
= (TableItem
) event
.item
;
718 // we promised to paint the table item's foreground
720 Image image
= item
.getImage(event
.index
);
722 Rectangle imageBounds
= item
.getImageBounds(event
.index
);
724 * The image bounds don't match the default image position.
727 gc
.drawImage(image
, imageBounds
.x
+ 1, imageBounds
.y
+ 3);
729 gc
.drawImage(image
, imageBounds
.x
, imageBounds
.y
+ 1);
732 gc
.setForeground(item
.getForeground(event
.index
));
733 gc
.setFont(item
.getFont(event
.index
));
734 String text
= item
.getText(event
.index
);
735 Rectangle textBounds
= item
.getTextBounds(event
.index
);
737 * The text bounds don't match the default text position.
740 gc
.drawText(text
, textBounds
.x
+ 1, textBounds
.y
+ 3, true);
742 gc
.drawText(text
, textBounds
.x
- 1, textBounds
.y
+ 2, true);
751 PlatformUI
.getWorkbench().getThemeManager().addPropertyChangeListener(this);
753 ColorSettingsManager
.addColorSettingsListener(this);
755 fTable
.setItemCount(1); // +1 for header row
757 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
759 fRawViewer
.addSelectionListener(new Listener() {
761 public void handleEvent(final Event e
) {
762 if (e
.data
instanceof Long
) {
763 final long rank
= (Long
) e
.data
;
764 int index
= (int) rank
;
765 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
766 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
768 fTable
.setSelection(index
+ 1); // +1 for header row
769 fSelectedRank
= rank
;
770 updateStatusLine(null);
771 } else if (e
.data
instanceof ITmfLocation
) {
772 // DOES NOT WORK: rank undefined in context from seekLocation()
773 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
774 // TmfContext context = fTrace.seekLocation(location);
775 // fTable.setSelection((int) context.getRank());
780 final TableItem
[] selection
= fTable
.getSelection();
781 if ((selection
!= null) && (selection
.length
> 0)) {
782 TableItem item
= fTable
.getSelection()[0];
783 final TmfTimestamp ts
= (TmfTimestamp
) item
.getData(Key
.TIMESTAMP
);
785 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
787 if (item
.getData() instanceof ITmfEvent
) {
788 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) item
.getData()));
789 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(item
.getData())));
791 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
797 fSashForm
.setWeights(new int[] { 1, 1 });
798 fRawViewer
.setVisible(false);
803 // ------------------------------------------------------------------------
805 // ------------------------------------------------------------------------
808 * Create a pop-up menu.
810 protected void createPopupMenu() {
811 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
814 fTable
.setVisible(true);
819 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
822 fTable
.setVisible(false);
827 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
830 fRawViewer
.setVisible(true);
832 final int index
= fTable
.getSelectionIndex();
834 fRawViewer
.selectAndReveal(index
- 1);
839 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
842 fRawViewer
.setVisible(false);
847 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
850 final TableItem items
[] = fTable
.getSelection();
851 if (items
.length
!= 1) {
854 final TableItem item
= items
[0];
856 final Object data
= item
.getData();
857 if (data
instanceof ITmfSourceLookup
) {
858 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
859 ITmfCallsite cs
= event
.getCallsite();
860 if (cs
== null || cs
.getFileName() == null) {
863 IMarker marker
= null;
865 String fileName
= cs
.getFileName();
866 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
867 final ArrayList
<IFile
> files
= new ArrayList
<>();
868 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
870 public boolean visit(IResource resource
) throws CoreException
{
871 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
872 files
.add((IFile
) resource
);
878 if (files
.size() > 1) {
879 ListDialog dialog
= new ListDialog(getTable().getShell());
880 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
881 dialog
.setLabelProvider(new LabelProvider() {
883 public String
getText(Object element
) {
884 return ((IFile
) element
).getFullPath().toString();
887 dialog
.setInput(files
);
888 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
889 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
891 Object
[] result
= dialog
.getResult();
892 if (result
!= null && result
.length
> 0) {
893 file
= (IFile
) result
[0];
895 } else if (files
.size() == 1) {
899 marker
= file
.createMarker(IMarker
.MARKER
);
900 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
901 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
903 } else if (files
.size() == 0){
904 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
906 } catch (CoreException e
) {
913 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
917 final TableItem items
[] = fTable
.getSelection();
918 if (items
.length
!= 1) {
921 final TableItem item
= items
[0];
923 final Object eventData
= item
.getData();
924 if (eventData
instanceof ITmfModelLookup
) {
925 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
927 if (modelURI
!= null) {
928 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
931 final URI uri
= URI
.createURI(modelURI
);
932 if (uri
.isPlatformResource()) {
933 IPath path
= new Path(uri
.toPlatformString(true));
934 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
935 } else if (uri
.isFile() && !uri
.isRelative()) {
936 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
937 new Path(uri
.toFileString()));
943 * create a temporary validation marker on the
944 * model file, remove it afterwards thus,
945 * navigation works with all model editors
946 * supporting the navigation to a marker
948 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
949 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
950 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
952 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
955 catch (CoreException e
) {
959 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
966 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
969 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
970 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
971 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
972 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
973 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
975 HashMap
<String
, Object
> parameters
= new HashMap
<>();
976 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
977 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
979 IEvaluationContext context
= handlerService
.getCurrentState();
980 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
981 for (int i
: fTable
.getColumnOrder()) {
982 // Omit the margin column
983 if (i
>= EVENT_COLUMNS_START_INDEX
) {
984 exportColumns
.add(fColumns
.get(i
));
987 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
989 handlerService
.executeCommandInContext(cmd
, null, context
);
990 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
996 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
999 fHeaderState
= HeaderState
.SEARCH
;
1005 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
1008 fHeaderState
= HeaderState
.FILTER
;
1014 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
1021 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
1024 applyFilter(new TmfCollapseFilter());
1028 class ToggleBookmarkAction
extends Action
{
1031 public ToggleBookmarkAction(final String text
, final Long rank
) {
1038 toggleBookmark(fRank
);
1042 final MenuManager tablePopupMenu
= new MenuManager();
1043 tablePopupMenu
.setRemoveAllWhenShown(true);
1044 tablePopupMenu
.addMenuListener(new IMenuListener() {
1046 public void menuAboutToShow(final IMenuManager manager
) {
1047 if (fTable
.getSelectionIndex() == 0) {
1048 // Right-click on header row
1049 if (fHeaderState
== HeaderState
.FILTER
) {
1050 tablePopupMenu
.add(showSearchBarAction
);
1052 tablePopupMenu
.add(showFilterBarAction
);
1056 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
1057 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
1059 final Rectangle imageBounds
= item
.getImageBounds(0);
1060 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
1061 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
1062 // Right-click on left margin
1063 final Long rank
= (Long
) item
.getData(Key
.RANK
);
1064 if ((rank
!= null) && (fBookmarksFile
!= null)) {
1065 if (fBookmarksMap
.containsKey(rank
)) {
1066 tablePopupMenu
.add(new ToggleBookmarkAction(
1067 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
1069 tablePopupMenu
.add(new ToggleBookmarkAction(
1070 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
1077 // Right-click on table
1078 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1079 tablePopupMenu
.add(hideTableAction
);
1080 tablePopupMenu
.add(hideRawAction
);
1081 } else if (!fTable
.isVisible()) {
1082 tablePopupMenu
.add(showTableAction
);
1083 } else if (!fRawViewer
.isVisible()) {
1084 tablePopupMenu
.add(showRawAction
);
1086 tablePopupMenu
.add(exportToTextAction
);
1087 tablePopupMenu
.add(new Separator());
1090 final Object data
= item
.getData();
1091 Separator separator
= null;
1092 if (data
instanceof ITmfSourceLookup
) {
1093 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
1094 if (event
.getCallsite() != null) {
1095 tablePopupMenu
.add(openCallsiteAction
);
1096 separator
= new Separator();
1100 if (data
instanceof ITmfModelLookup
) {
1101 ITmfModelLookup event
= (ITmfModelLookup
) data
;
1102 if (event
.getModelUri() != null) {
1103 tablePopupMenu
.add(openModelAction
);
1104 separator
= new Separator();
1107 if (separator
!= null) {
1108 tablePopupMenu
.add(separator
);
1113 // only show collapse filter if at least one trace can be collapsed
1114 boolean isCollapsible
= false;
1115 if (fTrace
!= null) {
1116 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
1117 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1118 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1119 if (isCollapsible
) {
1125 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1126 tablePopupMenu
.add(collapseAction
);
1127 tablePopupMenu
.add(new Separator());
1130 tablePopupMenu
.add(clearFiltersAction
);
1131 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1132 if (savedFilters
.length
> 0) {
1133 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1134 for (final ITmfFilterTreeNode node
: savedFilters
) {
1135 if (node
instanceof TmfFilterNode
) {
1136 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1137 subMenu
.add(new Action(filter
.getFilterName()) {
1140 applyFilter(filter
);
1145 tablePopupMenu
.add(subMenu
);
1147 appendToTablePopupMenu(tablePopupMenu
, item
);
1151 final MenuManager rawViewerPopupMenu
= new MenuManager();
1152 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1153 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1155 public void menuAboutToShow(final IMenuManager manager
) {
1156 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1157 rawViewerPopupMenu
.add(hideTableAction
);
1158 rawViewerPopupMenu
.add(hideRawAction
);
1159 } else if (!fTable
.isVisible()) {
1160 rawViewerPopupMenu
.add(showTableAction
);
1161 } else if (!fRawViewer
.isVisible()) {
1162 rawViewerPopupMenu
.add(showRawAction
);
1164 appendToRawPopupMenu(tablePopupMenu
);
1168 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1169 fTable
.setMenu(menu
);
1171 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1172 fRawViewer
.setMenu(menu
);
1177 * Append an item to the event table's pop-up menu.
1179 * @param tablePopupMenu
1181 * @param selectedItem
1182 * The item to append
1184 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1185 // override to append more actions
1189 * Append an item to the raw viewer's pop-up menu.
1191 * @param rawViewerPopupMenu
1194 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1195 // override to append more actions
1199 public void dispose() {
1202 PlatformUI
.getWorkbench().getThemeManager().removePropertyChangeListener(this);
1203 ColorSettingsManager
.removeColorSettingsListener(this);
1204 fComposite
.dispose();
1205 if ((fTrace
!= null) && fDisposeOnClose
) {
1208 fResourceManager
.dispose();
1209 fRawViewer
.dispose();
1214 * Assign a layout data object to this view.
1217 * The layout data to assign
1219 public void setLayoutData(final Object layoutData
) {
1220 fComposite
.setLayoutData(layoutData
);
1224 * Get the virtual table contained in this event table.
1226 * @return The TMF virtual table
1228 public TmfVirtualTable
getTable() {
1235 * @deprecated The column headers are now set at the constructor, this
1236 * shouldn't be called anymore.
1239 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1244 * Set a table item's data.
1249 * Which trace event to link with this entry
1251 * Which rank this event has in the trace/experiment
1253 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1254 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1256 // Get the actual ITmfEvent from the CachedEvent
1257 ITmfEvent tmfEvent
= event
;
1258 if (event
instanceof CachedEvent
) {
1259 tmfEvent
= ((CachedEvent
) event
).event
;
1261 item
.setText(itemStrings
);
1262 item
.setData(tmfEvent
);
1263 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1264 item
.setData(Key
.RANK
, rank
);
1266 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1267 if (!markerIds
.isEmpty()) {
1268 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1269 List
<Object
> parts
= new ArrayList
<>();
1270 if (markerIds
.size() > 1) {
1271 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1274 for (long markerId
: markerIds
) {
1275 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1276 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1278 } catch (CoreException e
) {
1279 displayException(e
);
1281 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1283 item
.setData(Key
.BOOKMARK
, null);
1286 boolean searchMatch
= false;
1287 boolean searchNoMatch
= false;
1288 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1289 if (searchFilter
!= null) {
1290 if (searchFilter
.matches(tmfEvent
)) {
1293 searchNoMatch
= true;
1297 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1298 if (searchNoMatch
) {
1299 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1300 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1302 item
.setForeground(colorSetting
.getForegroundColor());
1303 item
.setBackground(colorSetting
.getBackgroundColor());
1305 item
.setFont(fFont
);
1308 if (!markerIds
.isEmpty()) {
1309 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1311 item
.setImage(SEARCH_MATCH_IMAGE
);
1313 } else if (!markerIds
.isEmpty()) {
1314 item
.setImage(BOOKMARK_IMAGE
);
1316 item
.setImage((Image
) null);
1319 List
<StyleRange
> styleRanges
= new ArrayList
<>();
1320 for (int index
= 0; index
< fTable
.getColumns().length
; index
++) {
1321 TableColumn column
= fTable
.getColumns()[index
];
1322 String regex
= null;
1323 if (fHeaderState
== HeaderState
.FILTER
) {
1324 regex
= (String
) column
.getData(Key
.FILTER_TXT
);
1325 } else if (searchMatch
) {
1326 regex
= (String
) column
.getData(Key
.SEARCH_TXT
);
1328 if (regex
!= null) {
1329 // remove '.*' at beginning and end of regex
1330 regex
= regex
.replaceAll(DOT_STAR_PREFIX
, EMPTY_STRING
).replaceAll(DOT_STAR_SUFFIX
, EMPTY_STRING
);
1331 String text
= item
.getText(index
);
1333 Pattern pattern
= Pattern
.compile(regex
);
1334 Matcher matcher
= pattern
.matcher(text
);
1335 while (matcher
.find()) {
1336 int start
= matcher
.start();
1337 int length
= matcher
.end() - start
;
1338 Color foreground
= colorSetting
.getForegroundColor();
1339 Color background
= item
.getDisplay().getSystemColor(SWT
.COLOR_YELLOW
);
1340 StyleRange styleRange
= new StyleRange(start
, length
, foreground
, background
);
1341 styleRange
.data
= index
;
1342 styleRanges
.add(styleRange
);
1344 } catch (PatternSyntaxException e
) {
1349 if (styleRanges
.isEmpty()) {
1350 item
.setData(Key
.STYLE_RANGES
, null);
1352 item
.setData(Key
.STYLE_RANGES
, styleRanges
);
1354 item
.getParent().redraw();
1356 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1362 * Set the item data of the header row.
1365 * The item to use as table header
1367 protected void setHeaderRowItemData(final TableItem item
) {
1368 String txtKey
= null;
1369 if (fHeaderState
== HeaderState
.SEARCH
) {
1370 item
.setImage(SEARCH_IMAGE
);
1371 txtKey
= Key
.SEARCH_TXT
;
1372 } else if (fHeaderState
== HeaderState
.FILTER
) {
1373 item
.setImage(FILTER_IMAGE
);
1374 txtKey
= Key
.FILTER_TXT
;
1376 item
.setForeground(fGrayColor
);
1377 // Ignore collapse and image column
1378 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1379 final TableColumn column
= fTable
.getColumns()[i
];
1380 final String filter
= (String
) column
.getData(txtKey
);
1381 if (filter
== null) {
1382 if (fHeaderState
== HeaderState
.SEARCH
) {
1383 item
.setText(i
, SEARCH_HINT
);
1384 } else if (fHeaderState
== HeaderState
.FILTER
) {
1385 item
.setText(i
, FILTER_HINT
);
1387 item
.setForeground(i
, fGrayColor
);
1388 item
.setFont(i
, fFont
);
1390 item
.setText(i
, filter
);
1391 item
.setForeground(i
, fGreenColor
);
1392 item
.setFont(i
, fBoldFont
);
1398 * Set the item data of the "filter status" row.
1401 * The item to use as filter status row
1403 protected void setFilterStatusRowItemData(final TableItem item
) {
1404 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1405 if (i
== MARGIN_COLUMN_INDEX
) {
1406 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1407 item
.setImage(FILTER_IMAGE
);
1409 item
.setImage(STOP_IMAGE
);
1413 if (i
== FILTER_SUMMARY_INDEX
) {
1414 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1416 item
.setText(i
, EMPTY_STRING
);
1420 item
.setData(Key
.TIMESTAMP
, null);
1421 item
.setData(Key
.RANK
, null);
1422 item
.setData(Key
.STYLE_RANGES
, null);
1423 item
.setForeground(null);
1424 item
.setBackground(null);
1425 item
.setFont(fFont
);
1429 * Create an editor for the header.
1431 protected void createHeaderEditor() {
1432 final TableEditor tableEditor
= fTable
.createTableEditor();
1433 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1434 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1435 tableEditor
.grabHorizontal
= true;
1436 tableEditor
.minimumWidth
= 50;
1438 // Handle the header row selection
1439 fTable
.addMouseListener(new MouseAdapter() {
1445 public void mouseDown(final MouseEvent event
) {
1446 if (event
.button
!= 1) {
1449 // Identify the selected row
1450 final Point point
= new Point(event
.x
, event
.y
);
1451 item
= fTable
.getItem(point
);
1453 // Header row selected
1454 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1457 if (item
.getImageBounds(0).contains(point
)) {
1458 if (fHeaderState
== HeaderState
.SEARCH
) {
1459 fHeaderState
= HeaderState
.FILTER
;
1460 } else if (fHeaderState
== HeaderState
.FILTER
) {
1461 fHeaderState
= HeaderState
.SEARCH
;
1463 fTable
.setSelection(0);
1469 // Identify the selected column
1471 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1472 final Rectangle rect
= item
.getBounds(i
);
1473 if (rect
.contains(point
)) {
1479 if (columnIndex
== -1) {
1483 column
= fTable
.getColumns()[columnIndex
];
1485 String txtKey
= null;
1486 if (fHeaderState
== HeaderState
.SEARCH
) {
1487 txtKey
= Key
.SEARCH_TXT
;
1488 } else if (fHeaderState
== HeaderState
.FILTER
) {
1489 txtKey
= Key
.FILTER_TXT
;
1492 // The control that will be the editor must be a child of the Table
1493 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1494 final String headerString
= (String
) column
.getData(txtKey
);
1495 if (headerString
!= null) {
1496 newEditor
.setText(headerString
);
1498 newEditor
.addFocusListener(new FocusAdapter() {
1500 public void focusLost(final FocusEvent e
) {
1501 final boolean changed
= updateHeader(newEditor
.getText());
1507 newEditor
.addKeyListener(new KeyAdapter() {
1509 public void keyPressed(final KeyEvent e
) {
1510 if (e
.character
== SWT
.CR
) {
1511 updateHeader(newEditor
.getText());
1514 // Set focus on the table so that the next carriage return goes to the next result
1515 TmfEventsTable
.this.getTable().setFocus();
1516 } else if (e
.character
== SWT
.ESC
) {
1517 tableEditor
.getEditor().dispose();
1521 newEditor
.selectAll();
1522 newEditor
.setFocus();
1523 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1528 * returns true is value was changed
1530 private boolean updateHeader(final String text
) {
1531 String objKey
= null;
1532 String txtKey
= null;
1533 if (fHeaderState
== HeaderState
.SEARCH
) {
1534 objKey
= Key
.SEARCH_OBJ
;
1535 txtKey
= Key
.SEARCH_TXT
;
1536 } else if (fHeaderState
== HeaderState
.FILTER
) {
1537 objKey
= Key
.FILTER_OBJ
;
1538 txtKey
= Key
.FILTER_TXT
;
1540 if (text
.trim().length() > 0) {
1542 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1543 Pattern
.compile(regex
);
1544 if (regex
.equals(column
.getData(txtKey
))) {
1545 tableEditor
.getEditor().dispose();
1548 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1549 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1550 filter
.setEventAspect(aspect
);
1551 filter
.setRegex(regex
);
1552 column
.setData(objKey
, filter
);
1553 column
.setData(txtKey
, regex
);
1554 } catch (final PatternSyntaxException ex
) {
1555 tableEditor
.getEditor().dispose();
1556 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1557 ex
.getDescription(), ex
.getMessage());
1561 if (column
.getData(txtKey
) == null) {
1562 tableEditor
.getEditor().dispose();
1565 column
.setData(objKey
, null);
1566 column
.setData(txtKey
, null);
1571 private void applyHeader() {
1572 if (fHeaderState
== HeaderState
.SEARCH
) {
1574 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1575 for (final TableColumn col
: fTable
.getColumns()) {
1576 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1577 if (filterObj
instanceof ITmfFilterTreeNode
) {
1578 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1581 if (filter
.getChildrenCount() > 0) {
1582 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1585 fireSearchApplied(filter
);
1587 fTable
.setData(Key
.SEARCH_OBJ
, null);
1589 fireSearchApplied(null);
1591 } else if (fHeaderState
== HeaderState
.FILTER
) {
1592 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1593 for (final TableColumn col
: fTable
.getColumns()) {
1594 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1595 if (filterObj
instanceof ITmfFilterTreeNode
) {
1596 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1599 if (filter
.getChildrenCount() > 0) {
1600 applyFilter(filter
);
1606 tableEditor
.getEditor().dispose();
1610 fTable
.addKeyListener(new KeyAdapter() {
1612 public void keyPressed(final KeyEvent e
) {
1614 if (e
.character
== SWT
.ESC
) {
1618 } else if (e
.character
== SWT
.DEL
) {
1619 if (fHeaderState
== HeaderState
.SEARCH
) {
1621 for (final TableColumn column
: fTable
.getColumns()) {
1622 column
.setData(Key
.SEARCH_OBJ
, null);
1623 column
.setData(Key
.SEARCH_TXT
, null);
1625 fTable
.setData(Key
.SEARCH_OBJ
, null);
1627 fireSearchApplied(null);
1628 } else if (fHeaderState
== HeaderState
.FILTER
) {
1631 } else if (e
.character
== SWT
.CR
) {
1632 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1643 * Send an event indicating a filter has been applied.
1646 * The filter that was just applied
1648 protected void fireFilterApplied(final ITmfFilter filter
) {
1649 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1653 * Send an event indicating that a search has been applied.
1656 * The search filter that was just applied
1658 protected void fireSearchApplied(final ITmfFilter filter
) {
1659 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1663 * Start the filtering thread.
1665 protected void startFilterThread() {
1666 synchronized (fFilterSyncObj
) {
1667 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1668 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1669 if (fFilterThread
!= null) {
1670 fFilterThread
.cancel();
1671 fFilterThreadResume
= false;
1673 fFilterThread
= new FilterThread(filter
);
1674 fFilterThread
.start();
1676 fFilterThreadResume
= true;
1682 * Stop the filtering thread.
1684 protected void stopFilterThread() {
1685 synchronized (fFilterSyncObj
) {
1686 if (fFilterThread
!= null) {
1687 fFilterThread
.cancel();
1688 fFilterThread
= null;
1689 fFilterThreadResume
= false;
1698 * The filter to apply
1700 protected void applyFilter(ITmfFilter filter
) {
1703 fFilterMatchCount
= 0;
1704 fFilterCheckCount
= 0;
1705 fCache
.applyFilter(filter
);
1707 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1708 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1709 startFilterThread();
1710 fireFilterApplied(filter
);
1714 * Clear all currently active filters.
1716 protected void clearFilters() {
1717 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1722 fCache
.clearFilter();
1724 for (final TableColumn column
: fTable
.getColumns()) {
1725 column
.setData(Key
.FILTER_OBJ
, null);
1726 column
.setData(Key
.FILTER_TXT
, null);
1728 fTable
.setData(Key
.FILTER_OBJ
, null);
1729 if (fTrace
!= null) {
1730 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1732 fTable
.setItemCount(1); // +1 for header row
1734 fFilterMatchCount
= 0;
1735 fFilterCheckCount
= 0;
1736 if (fSelectedRank
>= 0) {
1737 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1739 fTable
.setSelection(0);
1741 fireFilterApplied(null);
1742 updateStatusLine(null);
1744 // Set original width
1745 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1750 * Wrapper Thread object for the filtering thread.
1752 protected class FilterThread
extends Thread
{
1753 private final ITmfFilterTreeNode filter
;
1754 private TmfEventRequest request
;
1755 private boolean refreshBusy
= false;
1756 private boolean refreshPending
= false;
1757 private final Object syncObj
= new Object();
1763 * The filter this thread will be processing
1765 public FilterThread(final ITmfFilterTreeNode filter
) {
1766 super("Filter Thread"); //$NON-NLS-1$
1767 this.filter
= filter
;
1772 if (fTrace
== null) {
1775 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1776 if (nbRequested
<= 0) {
1779 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1780 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1782 public void handleData(final ITmfEvent event
) {
1783 super.handleData(event
);
1784 if (request
.isCancelled()) {
1787 boolean refresh
= false;
1788 if (filter
.matches(event
)) {
1789 final long rank
= fFilterCheckCount
;
1790 final int index
= (int) fFilterMatchCount
;
1791 fFilterMatchCount
++;
1792 fCache
.storeEvent(event
, rank
, index
);
1795 if (filter
instanceof TmfCollapseFilter
) {
1796 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1800 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1803 fFilterCheckCount
++;
1806 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1808 request
.waitForCompletion();
1809 } catch (final InterruptedException e
) {
1812 synchronized (fFilterSyncObj
) {
1813 fFilterThread
= null;
1814 if (fFilterThreadResume
) {
1815 fFilterThreadResume
= false;
1816 fFilterThread
= new FilterThread(filter
);
1817 fFilterThread
.start();
1823 * Refresh the filter.
1825 public void refreshTable() {
1826 synchronized (syncObj
) {
1828 refreshPending
= true;
1833 Display
.getDefault().asyncExec(new Runnable() {
1836 if (request
.isCancelled()) {
1839 if (fTable
.isDisposed()) {
1842 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1844 synchronized (syncObj
) {
1845 refreshBusy
= false;
1846 if (refreshPending
) {
1847 refreshPending
= false;
1856 * Cancel this filtering thread.
1858 public void cancel() {
1859 if (request
!= null) {
1866 * Go to the next item of a search.
1868 protected void searchNext() {
1869 synchronized (fSearchSyncObj
) {
1870 if (fSearchThread
!= null) {
1873 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1874 if (searchFilter
== null) {
1877 final int selectionIndex
= fTable
.getSelectionIndex();
1879 if (selectionIndex
> 0) {
1880 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1882 // header row is selected, start at top event
1883 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1885 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1886 if (eventFilter
!= null) {
1887 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1889 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1890 fSearchThread
.schedule();
1895 * Go to the previous item of a search.
1897 protected void searchPrevious() {
1898 synchronized (fSearchSyncObj
) {
1899 if (fSearchThread
!= null) {
1902 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1903 if (searchFilter
== null) {
1906 final int selectionIndex
= fTable
.getSelectionIndex();
1908 if (selectionIndex
> 0) {
1909 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1911 // header row is selected, start at precedent of top event
1912 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1914 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1915 if (eventFilter
!= null) {
1916 startIndex
= startIndex
- 1; // -1 for top filter status row
1918 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1919 fSearchThread
.schedule();
1924 * Stop the search thread.
1926 protected void stopSearchThread() {
1927 fPendingGotoRank
= -1;
1928 synchronized (fSearchSyncObj
) {
1929 if (fSearchThread
!= null) {
1930 fSearchThread
.cancel();
1931 fSearchThread
= null;
1937 * Wrapper for the search thread.
1939 protected class SearchThread
extends Job
{
1941 private ITmfFilterTreeNode searchFilter
;
1942 private ITmfFilterTreeNode eventFilter
;
1943 private int startIndex
;
1944 private int direction
;
1946 private long foundRank
= -1;
1947 private TmfEventRequest request
;
1948 private ITmfTimestamp foundTimestamp
= null;
1953 * @param searchFilter
1955 * @param eventFilter
1958 * The index at which we should start searching
1959 * @param currentRank
1962 * In which direction should we search, forward or backwards
1964 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1965 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1966 final long currentRank
, final int direction
) {
1967 super(Messages
.TmfEventsTable_SearchingJobName
);
1968 this.searchFilter
= searchFilter
;
1969 this.eventFilter
= eventFilter
;
1970 this.startIndex
= startIndex
;
1971 this.rank
= currentRank
;
1972 this.direction
= direction
;
1976 protected IStatus
run(final IProgressMonitor monitor
) {
1977 if (fTrace
== null) {
1978 return Status
.OK_STATUS
;
1980 final Display display
= Display
.getDefault();
1981 if (startIndex
< 0) {
1982 rank
= (int) fTrace
.getNbEvents() - 1;
1983 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1986 int idx
= startIndex
;
1987 while (foundRank
== -1) {
1988 final CachedEvent event
= fCache
.peekEvent(idx
);
1989 if (event
== null) {
1993 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1994 foundRank
= event
.rank
;
1995 foundTimestamp
= event
.event
.getTimestamp();
1998 if (direction
== Direction
.FORWARD
) {
2004 if (foundRank
== -1) {
2005 if (direction
== Direction
.FORWARD
) {
2007 if (rank
> (fTrace
.getNbEvents() - 1)) {
2013 rank
= (int) fTrace
.getNbEvents() - 1;
2018 final int startRank
= (int) rank
;
2019 boolean wrapped
= false;
2020 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
2021 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
2022 if (direction
== Direction
.BACKWARD
) {
2023 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
2025 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
2026 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
2027 long currentRank
= rank
;
2030 public void handleData(final ITmfEvent event
) {
2031 super.handleData(event
);
2032 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
2033 foundRank
= currentRank
;
2034 foundTimestamp
= event
.getTimestamp();
2035 if (direction
== Direction
.FORWARD
) {
2043 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
2045 request
.waitForCompletion();
2046 if (request
.isCancelled()) {
2047 return Status
.OK_STATUS
;
2049 } catch (final InterruptedException e
) {
2050 synchronized (fSearchSyncObj
) {
2051 fSearchThread
= null;
2053 return Status
.OK_STATUS
;
2055 if (foundRank
== -1) {
2056 if (direction
== Direction
.FORWARD
) {
2058 synchronized (fSearchSyncObj
) {
2059 fSearchThread
= null;
2061 return Status
.OK_STATUS
;
2063 nbRequested
= (int) rank
;
2069 rank
= (int) fTrace
.getNbEvents() - 1;
2072 if ((rank
<= startRank
) && wrapped
) {
2073 synchronized (fSearchSyncObj
) {
2074 fSearchThread
= null;
2076 return Status
.OK_STATUS
;
2081 int index
= (int) foundRank
;
2082 if (eventFilter
!= null) {
2083 index
= fCache
.getFilteredEventIndex(foundRank
);
2085 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
2087 display
.asyncExec(new Runnable() {
2090 if (monitor
.isCanceled()) {
2093 if (fTable
.isDisposed()) {
2096 fTable
.setSelection(selection
);
2097 fSelectedRank
= foundRank
;
2098 fRawViewer
.selectAndReveal(fSelectedRank
);
2099 if (foundTimestamp
!= null) {
2100 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
2102 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
2103 synchronized (fSearchSyncObj
) {
2104 fSearchThread
= null;
2106 updateStatusLine(null);
2109 return Status
.OK_STATUS
;
2113 protected void canceling() {
2115 synchronized (fSearchSyncObj
) {
2116 fSearchThread
= null;
2122 * Create the resources.
2124 protected void createResources() {
2125 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
2126 .getForeground().getRGB()));
2127 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
2131 * Initialize the fonts.
2134 protected void initializeFonts() {
2135 FontRegistry fontRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
2136 fFont
= fontRegistry
.get(FONT_DEFINITION_ID
);
2137 fBoldFont
= fontRegistry
.getBold(FONT_DEFINITION_ID
);
2138 fTable
.setFont(fFont
);
2139 /* Column header font cannot be set. See Bug 63038 */
2146 public void propertyChange(PropertyChangeEvent event
) {
2147 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2148 (FONT_DEFINITION_ID
.equals(event
.getProperty()))) {
2157 protected void packColumns() {
2161 fTable
.setRedraw(false);
2163 TableColumn tableColumns
[] = fTable
.getColumns();
2164 for (int i
= 0; i
< tableColumns
.length
; i
++) {
2165 final TableColumn column
= tableColumns
[i
];
2166 packSingleColumn(i
, column
);
2169 // Make sure that redraw is always enabled.
2170 fTable
.setRedraw(true);
2176 private void packMarginColumn() {
2177 TableColumn
[] columns
= fTable
.getColumns();
2178 if (columns
.length
> 0) {
2179 packSingleColumn(0, columns
[0]);
2183 private void packSingleColumn(int i
, final TableColumn column
) {
2184 final int headerWidth
= column
.getWidth();
2186 // Workaround for Linux which doesn't consider the image width of
2187 // search/filter row in TableColumn.pack() after having executed
2188 // TableItem.setImage((Image)null) for other rows than search/filter row.
2189 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2190 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2191 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2194 if (column
.getWidth() < headerWidth
) {
2195 column
.setWidth(headerWidth
);
2200 * Get the array of item strings (e.g., what to display in each cell of the
2201 * table row) corresponding to the columns and trace event passed in
2202 * parameter. The order of the Strings in the returned array will correspond
2203 * to the iteration order of 'columns'.
2206 * To ensure consistent results, make sure only call this within a scope
2207 * synchronized on 'columns'! If the order of 'columns' changes right after
2208 * this method is called, the returned value won't be ordered correctly
2211 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2212 if (event
== null) {
2213 return EMPTY_STRING_ARRAY
;
2215 synchronized (columns
) {
2216 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2217 for (TmfEventTableColumn column
: columns
) {
2218 ITmfEvent passedEvent
= event
;
2219 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2220 // Make sure that the event object from the trace is passed
2221 // to all columns but the TmfMarginColumn
2222 passedEvent
= ((CachedEvent
) event
).event
;
2224 if (passedEvent
== null) {
2225 itemStrings
.add(EMPTY_STRING
);
2227 itemStrings
.add(column
.getItemString(passedEvent
));
2231 return itemStrings
.toArray(new String
[0]);
2236 * Get the contents of the row in the events table corresponding to an
2237 * event. The order of the elements corresponds to the current order of the
2241 * The event printed in this row
2242 * @return The event row entries
2244 public String
[] getItemStrings(ITmfEvent event
) {
2245 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2246 for (int i
: fTable
.getColumnOrder()) {
2247 columns
.add(fColumns
.get(i
));
2249 return getItemStrings(columns
, event
);
2253 * Returns an array of zero-relative integers that map
2254 * the creation order of the receiver's columns to the
2255 * order in which they are currently being displayed.
2257 * Specifically, the indices of the returned array represent
2258 * the current visual order of the columns, and the contents
2259 * of the array represent the creation order of the columns.
2261 * @return the current visual order of the receiver's columns
2264 public int[] getColumnOrder() {
2265 return fColumnOrder
;
2269 * Sets the order that the columns in the receiver should
2270 * be displayed in to the given argument which is described
2271 * in terms of the zero-relative ordering of when the columns
2274 * Specifically, the contents of the array represent the
2275 * original position of each column at the time its creation.
2277 * @param order the new order to display the columns
2280 public void setColumnOrder(int[] order
) {
2281 if (order
== null || order
.length
!= fTable
.getColumns().length
) {
2284 fTable
.setColumnOrder(order
);
2285 fColumnOrder
= fTable
.getColumnOrder();
2289 * Notify this table that is got the UI focus.
2291 public void setFocus() {
2296 * Assign a new trace to this event table.
2299 * The trace to assign to this event table
2300 * @param disposeOnClose
2301 * true if the trace should be disposed when the table is
2304 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2305 if ((fTrace
!= null) && fDisposeOnClose
) {
2311 fDisposeOnClose
= disposeOnClose
;
2313 // Perform the updates on the UI thread
2314 fTable
.getDisplay().syncExec(new Runnable() {
2318 fCache
.setTrace(fTrace
); // Clear the cache
2319 if (fTrace
!= null) {
2320 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2321 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2322 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2325 fFilterMatchCount
= 0;
2326 fFilterCheckCount
= 0;
2327 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2328 startFilterThread();
2332 fRawViewer
.setTrace(fTrace
);
2338 * Assign the status line manager
2340 * @param statusLineManager
2341 * The status line manager, or null to disable status line messages
2343 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2344 if (fStatusLineManager
!= null && statusLineManager
== null) {
2345 fStatusLineManager
.setMessage(EMPTY_STRING
);
2347 fStatusLineManager
= statusLineManager
;
2350 private void updateStatusLine(ITmfTimestamp delta
) {
2351 if (fStatusLineManager
!= null) {
2352 if (delta
!= null) {
2353 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2355 fStatusLineManager
.setMessage(null);
2360 // ------------------------------------------------------------------------
2362 // ------------------------------------------------------------------------
2365 * Notify that the event cache has been updated
2368 * Also notify if the populating of the cache is complete, or
2371 public void cacheUpdated(final boolean completed
) {
2372 synchronized (fCacheUpdateSyncObj
) {
2373 if (fCacheUpdateBusy
) {
2374 fCacheUpdatePending
= true;
2375 fCacheUpdateCompleted
= completed
;
2378 fCacheUpdateBusy
= true;
2380 // Event cache is now updated. Perform update on the UI thread
2381 if (!fTable
.isDisposed()) {
2382 fTable
.getDisplay().asyncExec(new Runnable() {
2385 if (!fTable
.isDisposed()) {
2390 populateCompleted();
2392 synchronized (fCacheUpdateSyncObj
) {
2393 fCacheUpdateBusy
= false;
2394 if (fCacheUpdatePending
) {
2395 fCacheUpdatePending
= false;
2396 cacheUpdated(fCacheUpdateCompleted
);
2405 * Callback for when populating the table is complete.
2407 protected void populateCompleted() {
2408 // Nothing by default;
2411 // ------------------------------------------------------------------------
2412 // ISelectionProvider
2413 // ------------------------------------------------------------------------
2416 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2417 selectionChangedListeners
.add(listener
);
2421 public ISelection
getSelection() {
2422 if (fTable
== null || fTable
.isDisposed()) {
2423 return StructuredSelection
.EMPTY
;
2425 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2426 for (TableItem item
: fTable
.getSelection()) {
2427 if (item
.getData() != null) {
2428 list
.add(item
.getData());
2431 return new StructuredSelection(list
);
2435 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2436 selectionChangedListeners
.remove(listener
);
2440 public void setSelection(ISelection selection
) {
2445 * Notifies any selection changed listeners that the viewer's selection has changed.
2446 * Only listeners registered at the time this method is called are notified.
2448 * @param event a selection changed event
2450 * @see ISelectionChangedListener#selectionChanged
2452 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2453 Object
[] listeners
= selectionChangedListeners
.getListeners();
2454 for (int i
= 0; i
< listeners
.length
; ++i
) {
2455 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2456 SafeRunnable
.run(new SafeRunnable() {
2459 l
.selectionChanged(event
);
2465 // ------------------------------------------------------------------------
2466 // Bookmark handling
2467 // ------------------------------------------------------------------------
2470 * Add a bookmark to this event table.
2472 * @param bookmarksFile
2473 * The file to use for the bookmarks
2475 public void addBookmark(final IFile bookmarksFile
) {
2476 fBookmarksFile
= bookmarksFile
;
2477 final TableItem
[] selection
= fTable
.getSelection();
2478 if (selection
.length
> 0) {
2479 final TableItem tableItem
= selection
[0];
2480 if (tableItem
.getData(Key
.RANK
) != null) {
2481 final StringBuffer defaultMessage
= new StringBuffer();
2482 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2484 defaultMessage
.append(", "); //$NON-NLS-1$
2486 defaultMessage
.append(tableItem
.getText(i
));
2488 final InputDialog dialog
= new MultiLineInputDialog(
2489 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2490 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2491 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2492 defaultMessage
.toString());
2493 if (dialog
.open() == Window
.OK
) {
2494 final String message
= dialog
.getValue();
2496 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2497 if (bookmark
.exists()) {
2498 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2499 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2500 final int location
= rank
.intValue();
2501 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2502 fBookmarksMap
.put(rank
, bookmark
.getId());
2505 } catch (final CoreException e
) {
2506 displayException(e
);
2515 * Remove a bookmark from this event table.
2518 * The bookmark to remove
2520 public void removeBookmark(final IMarker bookmark
) {
2521 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2522 if (entry
.getValue().equals(bookmark
.getId())) {
2523 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2530 private void toggleBookmark(final Long rank
) {
2531 if (fBookmarksFile
== null) {
2534 if (fBookmarksMap
.containsKey(rank
)) {
2535 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2538 for (long markerId
: markerIds
) {
2539 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2540 if (bookmark
!= null) {
2544 } catch (final CoreException e
) {
2545 displayException(e
);
2548 addBookmark(fBookmarksFile
);
2553 * Refresh the bookmarks assigned to this trace, from the contents of a
2556 * @param bookmarksFile
2557 * The bookmark file to use
2559 public void refreshBookmarks(final IFile bookmarksFile
) {
2560 fBookmarksFile
= bookmarksFile
;
2561 if (bookmarksFile
== null) {
2562 fBookmarksMap
.clear();
2567 fBookmarksMap
.clear();
2568 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2569 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2570 if (location
!= -1) {
2571 final long rank
= location
;
2572 fBookmarksMap
.put(rank
, bookmark
.getId());
2576 } catch (final CoreException e
) {
2577 displayException(e
);
2582 public void gotoMarker(final IMarker marker
) {
2583 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2586 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2587 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2588 } else if (rank
>= fTable
.getItemCount()) {
2589 fPendingGotoRank
= rank
;
2591 fSelectedRank
= rank
;
2592 fTable
.setSelection(index
+ 1); // +1 for header row
2593 updateStatusLine(null);
2597 // ------------------------------------------------------------------------
2599 // ------------------------------------------------------------------------
2602 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2606 // ------------------------------------------------------------------------
2608 // ------------------------------------------------------------------------
2611 * Handler for the trace updated signal
2614 * The incoming signal
2617 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2618 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2621 // Perform the refresh on the UI thread
2622 Display
.getDefault().asyncExec(new Runnable() {
2625 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2626 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2627 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2628 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2629 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2630 fPendingGotoRank
= -1;
2631 updateStatusLine(null);
2634 startFilterThread();
2637 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2638 fRawViewer
.refreshEventCount();
2645 * Handler for the time synch signal.
2648 * The incoming signal
2651 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2652 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2654 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2655 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2656 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2657 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2658 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2660 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2663 public void handleData(final ITmfEvent event
) {
2664 super.handleData(event
);
2668 public void handleSuccess() {
2669 super.handleSuccess();
2670 if (fTrace
== null) {
2674 // Verify if the event is within the trace range and adjust if necessary
2675 ITmfTimestamp timestamp
= ts
;
2676 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2677 timestamp
= fTrace
.getStartTime();
2679 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2680 timestamp
= fTrace
.getEndTime();
2683 // Get the rank of the selected event in the table
2684 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2685 final long rank
= context
.getRank();
2687 fSelectedRank
= rank
;
2689 fTable
.getDisplay().asyncExec(new Runnable() {
2692 // Return if table is disposed
2693 if (fTable
.isDisposed()) {
2697 int index
= (int) rank
;
2698 if (fTable
.isDisposed()) {
2701 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2702 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2704 fTable
.setSelection(index
+ 1); // +1 for header row
2705 fRawViewer
.selectAndReveal(rank
);
2706 updateStatusLine(null);
2712 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2716 // ------------------------------------------------------------------------
2718 // ------------------------------------------------------------------------
2721 * Display an exception in a message box
2723 * @param e the exception
2725 private static void displayException(final Exception e
) {
2726 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2727 mb
.setText(e
.getClass().getSimpleName());
2728 mb
.setMessage(e
.getMessage());
2735 public void refresh() {
2742 * Margin column for images and special text (e.g. collapse count)
2744 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2746 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2749 public String
getName() {
2750 return EMPTY_STRING
;
2754 public String
resolve(ITmfEvent event
) {
2755 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2756 return EMPTY_STRING
;
2758 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2762 public String
getHelpText() {
2763 return EMPTY_STRING
;
2770 public TmfMarginColumn() {
2771 super(MARGIN_ASPECT
);