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
.ColorRegistry
;
66 import org
.eclipse
.jface
.resource
.FontRegistry
;
67 import org
.eclipse
.jface
.resource
.JFaceResources
;
68 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
69 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
70 import org
.eclipse
.jface
.util
.OpenStrategy
;
71 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
72 import org
.eclipse
.jface
.util
.SafeRunnable
;
73 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
74 import org
.eclipse
.jface
.viewers
.ISelection
;
75 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
76 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
77 import org
.eclipse
.jface
.viewers
.LabelProvider
;
78 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
79 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
80 import org
.eclipse
.jface
.window
.Window
;
81 import org
.eclipse
.swt
.SWT
;
82 import org
.eclipse
.swt
.custom
.SashForm
;
83 import org
.eclipse
.swt
.custom
.StyleRange
;
84 import org
.eclipse
.swt
.custom
.TableEditor
;
85 import org
.eclipse
.swt
.events
.ControlAdapter
;
86 import org
.eclipse
.swt
.events
.ControlEvent
;
87 import org
.eclipse
.swt
.events
.FocusAdapter
;
88 import org
.eclipse
.swt
.events
.FocusEvent
;
89 import org
.eclipse
.swt
.events
.KeyAdapter
;
90 import org
.eclipse
.swt
.events
.KeyEvent
;
91 import org
.eclipse
.swt
.events
.MouseAdapter
;
92 import org
.eclipse
.swt
.events
.MouseEvent
;
93 import org
.eclipse
.swt
.events
.SelectionAdapter
;
94 import org
.eclipse
.swt
.events
.SelectionEvent
;
95 import org
.eclipse
.swt
.graphics
.Color
;
96 import org
.eclipse
.swt
.graphics
.Font
;
97 import org
.eclipse
.swt
.graphics
.GC
;
98 import org
.eclipse
.swt
.graphics
.Image
;
99 import org
.eclipse
.swt
.graphics
.Point
;
100 import org
.eclipse
.swt
.graphics
.Rectangle
;
101 import org
.eclipse
.swt
.layout
.FillLayout
;
102 import org
.eclipse
.swt
.layout
.GridData
;
103 import org
.eclipse
.swt
.layout
.GridLayout
;
104 import org
.eclipse
.swt
.widgets
.Composite
;
105 import org
.eclipse
.swt
.widgets
.Display
;
106 import org
.eclipse
.swt
.widgets
.Event
;
107 import org
.eclipse
.swt
.widgets
.Label
;
108 import org
.eclipse
.swt
.widgets
.Listener
;
109 import org
.eclipse
.swt
.widgets
.Menu
;
110 import org
.eclipse
.swt
.widgets
.MessageBox
;
111 import org
.eclipse
.swt
.widgets
.Shell
;
112 import org
.eclipse
.swt
.widgets
.TableColumn
;
113 import org
.eclipse
.swt
.widgets
.TableItem
;
114 import org
.eclipse
.swt
.widgets
.Text
;
115 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
116 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
117 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
118 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
119 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
120 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
121 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
122 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
123 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
124 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfContentFieldAspect
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
141 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
142 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
143 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
144 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
145 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
146 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
147 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
148 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
149 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
150 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
151 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
152 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
153 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
154 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
155 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
156 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
157 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
158 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
159 import org
.eclipse
.ui
.IWorkbenchPage
;
160 import org
.eclipse
.ui
.PlatformUI
;
161 import org
.eclipse
.ui
.commands
.ICommandService
;
162 import org
.eclipse
.ui
.dialogs
.ListDialog
;
163 import org
.eclipse
.ui
.handlers
.IHandlerService
;
164 import org
.eclipse
.ui
.ide
.IDE
;
165 import org
.eclipse
.ui
.ide
.IGotoMarker
;
166 import org
.eclipse
.ui
.themes
.ColorUtil
;
167 import org
.eclipse
.ui
.themes
.IThemeManager
;
169 import com
.google
.common
.base
.Joiner
;
170 import com
.google
.common
.collect
.HashMultimap
;
171 import com
.google
.common
.collect
.ImmutableList
;
172 import com
.google
.common
.collect
.Multimap
;
175 * The generic TMF Events table
177 * This is a view that will list events that are read from a trace.
179 * @author Francois Chouinard
180 * @author Patrick Tasse
182 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
, IPropertyChangeListener
{
185 * Empty string array, used by {@link #getItemStrings}.
187 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
192 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
194 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
196 private static final String FONT_DEFINITION_ID
= "org.eclipse.tracecompass.tmf.ui.font.eventtable"; //$NON-NLS-1$
197 private static final String HIGHLIGHT_COLOR_DEFINITION_ID
= "org.eclipse.tracecompass.tmf.ui.color.eventtable.highlight"; //$NON-NLS-1$
199 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
200 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
201 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
202 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
203 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
204 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
205 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
206 private static final Image FILTER_IMAGE
= Activator
.getDefault()
207 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
208 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
209 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
210 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
211 private static final int MAX_CACHE_SIZE
= 1000;
213 private static final int MARGIN_COLUMN_INDEX
= 0;
214 private static final int FILTER_SUMMARY_INDEX
= 1;
215 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
218 * The events table search/filter keys
221 * @author Patrick Tasse
223 public interface Key
{
225 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
228 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
231 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
234 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
237 String TIMESTAMP
= "$time"; //$NON-NLS-1$
240 String RANK
= "$rank"; //$NON-NLS-1$
242 /** Bookmark indicator */
243 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
245 /** Event aspect represented by this column */
246 String ASPECT
= "$aspect"; //$NON-NLS-1$
248 /** Table item list of style ranges
250 String STYLE_RANGES
= "$style_ranges"; //$NON-NLS-1$
254 * The events table search/filter state
257 * @author Patrick Tasse
259 public static enum HeaderState
{
260 /** A search is being run */
263 /** A filter is applied */
267 interface Direction
{
272 // ------------------------------------------------------------------------
274 // ------------------------------------------------------------------------
276 /** The virtual event table */
277 protected TmfVirtualTable fTable
;
279 private Composite fComposite
;
280 private SashForm fSashForm
;
281 private TmfRawEventViewer fRawViewer
;
282 private ITmfTrace fTrace
;
283 private volatile boolean fPackDone
= false;
284 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
285 private long fSelectedRank
= 0;
286 private ITmfTimestamp fSelectedBeginTimestamp
= null;
287 private IStatusLineManager fStatusLineManager
= null;
290 private long fFilterMatchCount
;
291 private long fFilterCheckCount
;
292 private FilterThread fFilterThread
;
293 private boolean fFilterThreadResume
= false;
294 private final Object fFilterSyncObj
= new Object();
295 private SearchThread fSearchThread
;
296 private final Object fSearchSyncObj
= new Object();
299 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
301 * @see #fireSelectionChanged
303 private ListenerList selectionChangedListeners
= new ListenerList();
305 // Bookmark map <Rank, MarkerId>
306 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
307 private IFile fBookmarksFile
;
308 private long fPendingGotoRank
= -1;
311 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
312 private Color fGrayColor
;
313 private Color fGreenColor
;
314 private Color fHighlightColor
;
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 TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, selectedBeginTimestamp
, ts
));
501 if (fTable
.getSelectionIndices().length
== 2) {
502 updateStatusLine(ts
.getDelta(selectedBeginTimestamp
));
505 broadcast(new TmfSelectionRangeUpdatedSignal(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);
752 PlatformUI
.getWorkbench().getThemeManager().addPropertyChangeListener(this);
754 ColorSettingsManager
.addColorSettingsListener(this);
756 fTable
.setItemCount(1); // +1 for header row
758 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
760 fRawViewer
.addSelectionListener(new Listener() {
762 public void handleEvent(final Event e
) {
763 if (e
.data
instanceof Long
) {
764 final long rank
= (Long
) e
.data
;
765 int index
= (int) rank
;
766 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
767 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
769 fTable
.setSelection(index
+ 1); // +1 for header row
770 fSelectedRank
= rank
;
771 updateStatusLine(null);
772 } else if (e
.data
instanceof ITmfLocation
) {
773 // DOES NOT WORK: rank undefined in context from seekLocation()
774 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
775 // TmfContext context = fTrace.seekLocation(location);
776 // fTable.setSelection((int) context.getRank());
781 final TableItem
[] selection
= fTable
.getSelection();
782 if ((selection
!= null) && (selection
.length
> 0)) {
783 TableItem item
= fTable
.getSelection()[0];
784 final TmfTimestamp ts
= (TmfTimestamp
) item
.getData(Key
.TIMESTAMP
);
786 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, ts
));
788 if (item
.getData() instanceof ITmfEvent
) {
789 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) item
.getData()));
790 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(item
.getData())));
792 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
798 fSashForm
.setWeights(new int[] { 1, 1 });
799 fRawViewer
.setVisible(false);
804 // ------------------------------------------------------------------------
806 // ------------------------------------------------------------------------
809 * Create a pop-up menu.
811 protected void createPopupMenu() {
812 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
815 fTable
.setVisible(true);
820 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
823 fTable
.setVisible(false);
828 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
831 fRawViewer
.setVisible(true);
833 final int index
= fTable
.getSelectionIndex();
835 fRawViewer
.selectAndReveal(index
- 1);
840 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
843 fRawViewer
.setVisible(false);
848 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
851 final TableItem items
[] = fTable
.getSelection();
852 if (items
.length
!= 1) {
855 final TableItem item
= items
[0];
857 final Object data
= item
.getData();
858 if (data
instanceof ITmfSourceLookup
) {
859 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
860 ITmfCallsite cs
= event
.getCallsite();
861 if (cs
== null || cs
.getFileName() == null) {
864 IMarker marker
= null;
866 String fileName
= cs
.getFileName();
867 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
868 final ArrayList
<IFile
> files
= new ArrayList
<>();
869 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
871 public boolean visit(IResource resource
) throws CoreException
{
872 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
873 files
.add((IFile
) resource
);
879 if (files
.size() > 1) {
880 ListDialog dialog
= new ListDialog(getTable().getShell());
881 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
882 dialog
.setLabelProvider(new LabelProvider() {
884 public String
getText(Object element
) {
885 return ((IFile
) element
).getFullPath().toString();
888 dialog
.setInput(files
);
889 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
890 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
892 Object
[] result
= dialog
.getResult();
893 if (result
!= null && result
.length
> 0) {
894 file
= (IFile
) result
[0];
896 } else if (files
.size() == 1) {
900 marker
= file
.createMarker(IMarker
.MARKER
);
901 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
902 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
904 } else if (files
.size() == 0){
905 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
907 } catch (CoreException e
) {
914 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
918 final TableItem items
[] = fTable
.getSelection();
919 if (items
.length
!= 1) {
922 final TableItem item
= items
[0];
924 final Object eventData
= item
.getData();
925 if (eventData
instanceof ITmfModelLookup
) {
926 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
928 if (modelURI
!= null) {
929 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
932 final URI uri
= URI
.createURI(modelURI
);
933 if (uri
.isPlatformResource()) {
934 IPath path
= new Path(uri
.toPlatformString(true));
935 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
936 } else if (uri
.isFile() && !uri
.isRelative()) {
937 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
938 new Path(uri
.toFileString()));
944 * create a temporary validation marker on the
945 * model file, remove it afterwards thus,
946 * navigation works with all model editors
947 * supporting the navigation to a marker
949 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
950 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
951 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
953 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
956 catch (CoreException e
) {
960 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
967 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
970 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
971 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
972 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
973 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
974 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
976 HashMap
<String
, Object
> parameters
= new HashMap
<>();
977 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
978 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
980 IEvaluationContext context
= handlerService
.getCurrentState();
981 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
982 for (int i
: fTable
.getColumnOrder()) {
983 // Omit the margin column
984 if (i
>= EVENT_COLUMNS_START_INDEX
) {
985 exportColumns
.add(fColumns
.get(i
));
988 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
990 handlerService
.executeCommandInContext(cmd
, null, context
);
991 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
997 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
1000 fHeaderState
= HeaderState
.SEARCH
;
1006 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
1009 fHeaderState
= HeaderState
.FILTER
;
1015 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
1022 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
1025 applyFilter(new TmfCollapseFilter());
1029 class ToggleBookmarkAction
extends Action
{
1032 public ToggleBookmarkAction(final String text
, final Long rank
) {
1039 toggleBookmark(fRank
);
1043 final MenuManager tablePopupMenu
= new MenuManager();
1044 tablePopupMenu
.setRemoveAllWhenShown(true);
1045 tablePopupMenu
.addMenuListener(new IMenuListener() {
1047 public void menuAboutToShow(final IMenuManager manager
) {
1048 if (fTable
.getSelectionIndex() == 0) {
1049 // Right-click on header row
1050 if (fHeaderState
== HeaderState
.FILTER
) {
1051 tablePopupMenu
.add(showSearchBarAction
);
1053 tablePopupMenu
.add(showFilterBarAction
);
1057 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
1058 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
1060 final Rectangle imageBounds
= item
.getImageBounds(0);
1061 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
1062 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
1063 // Right-click on left margin
1064 final Long rank
= (Long
) item
.getData(Key
.RANK
);
1065 if ((rank
!= null) && (fBookmarksFile
!= null)) {
1066 if (fBookmarksMap
.containsKey(rank
)) {
1067 tablePopupMenu
.add(new ToggleBookmarkAction(
1068 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
1070 tablePopupMenu
.add(new ToggleBookmarkAction(
1071 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
1078 // Right-click on table
1079 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1080 tablePopupMenu
.add(hideTableAction
);
1081 tablePopupMenu
.add(hideRawAction
);
1082 } else if (!fTable
.isVisible()) {
1083 tablePopupMenu
.add(showTableAction
);
1084 } else if (!fRawViewer
.isVisible()) {
1085 tablePopupMenu
.add(showRawAction
);
1087 tablePopupMenu
.add(exportToTextAction
);
1088 tablePopupMenu
.add(new Separator());
1091 final Object data
= item
.getData();
1092 Separator separator
= null;
1093 if (data
instanceof ITmfSourceLookup
) {
1094 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
1095 if (event
.getCallsite() != null) {
1096 tablePopupMenu
.add(openCallsiteAction
);
1097 separator
= new Separator();
1101 if (data
instanceof ITmfModelLookup
) {
1102 ITmfModelLookup event
= (ITmfModelLookup
) data
;
1103 if (event
.getModelUri() != null) {
1104 tablePopupMenu
.add(openModelAction
);
1105 separator
= new Separator();
1108 if (separator
!= null) {
1109 tablePopupMenu
.add(separator
);
1114 // only show collapse filter if at least one trace can be collapsed
1115 boolean isCollapsible
= false;
1116 if (fTrace
!= null) {
1117 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
1118 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1119 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1120 if (isCollapsible
) {
1126 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1127 tablePopupMenu
.add(collapseAction
);
1128 tablePopupMenu
.add(new Separator());
1131 tablePopupMenu
.add(clearFiltersAction
);
1132 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1133 if (savedFilters
.length
> 0) {
1134 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1135 for (final ITmfFilterTreeNode node
: savedFilters
) {
1136 if (node
instanceof TmfFilterNode
) {
1137 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1138 subMenu
.add(new Action(filter
.getFilterName()) {
1141 applyFilter(filter
);
1146 tablePopupMenu
.add(subMenu
);
1148 appendToTablePopupMenu(tablePopupMenu
, item
);
1152 final MenuManager rawViewerPopupMenu
= new MenuManager();
1153 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1154 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1156 public void menuAboutToShow(final IMenuManager manager
) {
1157 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1158 rawViewerPopupMenu
.add(hideTableAction
);
1159 rawViewerPopupMenu
.add(hideRawAction
);
1160 } else if (!fTable
.isVisible()) {
1161 rawViewerPopupMenu
.add(showTableAction
);
1162 } else if (!fRawViewer
.isVisible()) {
1163 rawViewerPopupMenu
.add(showRawAction
);
1165 appendToRawPopupMenu(tablePopupMenu
);
1169 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1170 fTable
.setMenu(menu
);
1172 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1173 fRawViewer
.setMenu(menu
);
1178 * Append an item to the event table's pop-up menu.
1180 * @param tablePopupMenu
1182 * @param selectedItem
1183 * The item to append
1185 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1186 // override to append more actions
1190 * Append an item to the raw viewer's pop-up menu.
1192 * @param rawViewerPopupMenu
1195 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1196 // override to append more actions
1200 public void dispose() {
1203 PlatformUI
.getWorkbench().getThemeManager().removePropertyChangeListener(this);
1204 ColorSettingsManager
.removeColorSettingsListener(this);
1205 fComposite
.dispose();
1206 if ((fTrace
!= null) && fDisposeOnClose
) {
1209 fResourceManager
.dispose();
1210 fRawViewer
.dispose();
1215 * Assign a layout data object to this view.
1218 * The layout data to assign
1220 public void setLayoutData(final Object layoutData
) {
1221 fComposite
.setLayoutData(layoutData
);
1225 * Get the virtual table contained in this event table.
1227 * @return The TMF virtual table
1229 public TmfVirtualTable
getTable() {
1236 * @deprecated The column headers are now set at the constructor, this
1237 * shouldn't be called anymore.
1240 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1245 * Set a table item's data.
1250 * Which trace event to link with this entry
1252 * Which rank this event has in the trace/experiment
1254 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1255 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1257 // Get the actual ITmfEvent from the CachedEvent
1258 ITmfEvent tmfEvent
= event
;
1259 if (event
instanceof CachedEvent
) {
1260 tmfEvent
= ((CachedEvent
) event
).event
;
1262 item
.setText(itemStrings
);
1263 item
.setData(tmfEvent
);
1264 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1265 item
.setData(Key
.RANK
, rank
);
1267 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1268 if (!markerIds
.isEmpty()) {
1269 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1270 List
<Object
> parts
= new ArrayList
<>();
1271 if (markerIds
.size() > 1) {
1272 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1275 for (long markerId
: markerIds
) {
1276 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1277 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1279 } catch (CoreException e
) {
1280 displayException(e
);
1282 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1284 item
.setData(Key
.BOOKMARK
, null);
1287 boolean searchMatch
= false;
1288 boolean searchNoMatch
= false;
1289 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1290 if (searchFilter
!= null) {
1291 if (searchFilter
.matches(tmfEvent
)) {
1294 searchNoMatch
= true;
1298 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1299 if (searchNoMatch
) {
1300 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1301 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1303 item
.setForeground(colorSetting
.getForegroundColor());
1304 item
.setBackground(colorSetting
.getBackgroundColor());
1306 item
.setFont(fFont
);
1309 if (!markerIds
.isEmpty()) {
1310 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1312 item
.setImage(SEARCH_MATCH_IMAGE
);
1314 } else if (!markerIds
.isEmpty()) {
1315 item
.setImage(BOOKMARK_IMAGE
);
1317 item
.setImage((Image
) null);
1320 List
<StyleRange
> styleRanges
= new ArrayList
<>();
1321 for (int index
= 0; index
< fTable
.getColumns().length
; index
++) {
1322 TableColumn column
= fTable
.getColumns()[index
];
1323 String regex
= null;
1324 if (fHeaderState
== HeaderState
.FILTER
) {
1325 regex
= (String
) column
.getData(Key
.FILTER_TXT
);
1326 } else if (searchMatch
) {
1327 regex
= (String
) column
.getData(Key
.SEARCH_TXT
);
1329 if (regex
!= null) {
1330 String text
= item
.getText(index
);
1332 Pattern pattern
= Pattern
.compile(regex
);
1333 Matcher matcher
= pattern
.matcher(text
);
1334 while (matcher
.find()) {
1335 int start
= matcher
.start();
1336 int length
= matcher
.end() - start
;
1337 Color foreground
= colorSetting
.getForegroundColor();
1338 Color background
= fHighlightColor
;
1339 StyleRange styleRange
= new StyleRange(start
, length
, foreground
, background
);
1340 styleRange
.data
= index
;
1341 styleRanges
.add(styleRange
);
1343 } catch (PatternSyntaxException e
) {
1348 if (styleRanges
.isEmpty()) {
1349 item
.setData(Key
.STYLE_RANGES
, null);
1351 item
.setData(Key
.STYLE_RANGES
, styleRanges
);
1353 item
.getParent().redraw();
1355 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1361 * Set the item data of the header row.
1364 * The item to use as table header
1366 protected void setHeaderRowItemData(final TableItem item
) {
1367 String txtKey
= null;
1368 if (fHeaderState
== HeaderState
.SEARCH
) {
1369 item
.setImage(SEARCH_IMAGE
);
1370 txtKey
= Key
.SEARCH_TXT
;
1371 } else if (fHeaderState
== HeaderState
.FILTER
) {
1372 item
.setImage(FILTER_IMAGE
);
1373 txtKey
= Key
.FILTER_TXT
;
1375 item
.setForeground(fGrayColor
);
1376 // Ignore collapse and image column
1377 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1378 final TableColumn column
= fTable
.getColumns()[i
];
1379 final String filter
= (String
) column
.getData(txtKey
);
1380 if (filter
== null) {
1381 if (fHeaderState
== HeaderState
.SEARCH
) {
1382 item
.setText(i
, SEARCH_HINT
);
1383 } else if (fHeaderState
== HeaderState
.FILTER
) {
1384 item
.setText(i
, FILTER_HINT
);
1386 item
.setForeground(i
, fGrayColor
);
1387 item
.setFont(i
, fFont
);
1389 item
.setText(i
, filter
);
1390 item
.setForeground(i
, fGreenColor
);
1391 item
.setFont(i
, fBoldFont
);
1397 * Set the item data of the "filter status" row.
1400 * The item to use as filter status row
1402 protected void setFilterStatusRowItemData(final TableItem item
) {
1403 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1404 if (i
== MARGIN_COLUMN_INDEX
) {
1405 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1406 item
.setImage(FILTER_IMAGE
);
1408 item
.setImage(STOP_IMAGE
);
1412 if (i
== FILTER_SUMMARY_INDEX
) {
1413 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1415 item
.setText(i
, EMPTY_STRING
);
1419 item
.setData(Key
.TIMESTAMP
, null);
1420 item
.setData(Key
.RANK
, null);
1421 item
.setData(Key
.STYLE_RANGES
, null);
1422 item
.setForeground(null);
1423 item
.setBackground(null);
1424 item
.setFont(fFont
);
1428 * Create an editor for the header.
1430 protected void createHeaderEditor() {
1431 final TableEditor tableEditor
= fTable
.createTableEditor();
1432 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1433 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1434 tableEditor
.grabHorizontal
= true;
1435 tableEditor
.minimumWidth
= 50;
1437 // Handle the header row selection
1438 fTable
.addMouseListener(new MouseAdapter() {
1444 public void mouseDown(final MouseEvent event
) {
1445 if (event
.button
!= 1) {
1448 // Identify the selected row
1449 final Point point
= new Point(event
.x
, event
.y
);
1450 item
= fTable
.getItem(point
);
1452 // Header row selected
1453 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1456 if (item
.getImageBounds(0).contains(point
)) {
1457 if (fHeaderState
== HeaderState
.SEARCH
) {
1458 fHeaderState
= HeaderState
.FILTER
;
1459 } else if (fHeaderState
== HeaderState
.FILTER
) {
1460 fHeaderState
= HeaderState
.SEARCH
;
1462 fTable
.setSelection(0);
1468 // Identify the selected column
1470 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1471 final Rectangle rect
= item
.getBounds(i
);
1472 if (rect
.contains(point
)) {
1478 if (columnIndex
== -1) {
1482 column
= fTable
.getColumns()[columnIndex
];
1484 String txtKey
= null;
1485 if (fHeaderState
== HeaderState
.SEARCH
) {
1486 txtKey
= Key
.SEARCH_TXT
;
1487 } else if (fHeaderState
== HeaderState
.FILTER
) {
1488 txtKey
= Key
.FILTER_TXT
;
1491 // The control that will be the editor must be a child of the Table
1492 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1493 final String headerString
= (String
) column
.getData(txtKey
);
1494 if (headerString
!= null) {
1495 newEditor
.setText(headerString
);
1497 newEditor
.addFocusListener(new FocusAdapter() {
1499 public void focusLost(final FocusEvent e
) {
1500 final boolean changed
= updateHeader(newEditor
.getText());
1506 newEditor
.addKeyListener(new KeyAdapter() {
1508 public void keyPressed(final KeyEvent e
) {
1509 if (e
.character
== SWT
.CR
) {
1510 updateHeader(newEditor
.getText());
1513 // Set focus on the table so that the next carriage return goes to the next result
1514 TmfEventsTable
.this.getTable().setFocus();
1515 } else if (e
.character
== SWT
.ESC
) {
1516 tableEditor
.getEditor().dispose();
1520 newEditor
.selectAll();
1521 newEditor
.setFocus();
1522 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1527 * returns true is value was changed
1529 private boolean updateHeader(final String regex
) {
1530 String objKey
= null;
1531 String txtKey
= null;
1532 if (fHeaderState
== HeaderState
.SEARCH
) {
1533 objKey
= Key
.SEARCH_OBJ
;
1534 txtKey
= Key
.SEARCH_TXT
;
1535 } else if (fHeaderState
== HeaderState
.FILTER
) {
1536 objKey
= Key
.FILTER_OBJ
;
1537 txtKey
= Key
.FILTER_TXT
;
1539 if (regex
.length() > 0) {
1541 Pattern
.compile(regex
);
1542 if (regex
.equals(column
.getData(txtKey
))) {
1543 tableEditor
.getEditor().dispose();
1546 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1547 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1548 filter
.setEventAspect(aspect
);
1549 filter
.setRegex(regex
);
1550 column
.setData(objKey
, filter
);
1551 column
.setData(txtKey
, regex
);
1552 } catch (final PatternSyntaxException ex
) {
1553 tableEditor
.getEditor().dispose();
1554 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1555 ex
.getDescription(), ex
.getMessage());
1559 if (column
.getData(txtKey
) == null) {
1560 tableEditor
.getEditor().dispose();
1563 column
.setData(objKey
, null);
1564 column
.setData(txtKey
, null);
1569 private void applyHeader() {
1570 if (fHeaderState
== HeaderState
.SEARCH
) {
1572 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1573 for (final TableColumn col
: fTable
.getColumns()) {
1574 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1575 if (filterObj
instanceof ITmfFilterTreeNode
) {
1576 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1579 if (filter
.getChildrenCount() > 0) {
1580 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1583 fireSearchApplied(filter
);
1585 fTable
.setData(Key
.SEARCH_OBJ
, null);
1587 fireSearchApplied(null);
1589 } else if (fHeaderState
== HeaderState
.FILTER
) {
1590 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1591 for (final TableColumn col
: fTable
.getColumns()) {
1592 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1593 if (filterObj
instanceof ITmfFilterTreeNode
) {
1594 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1597 if (filter
.getChildrenCount() > 0) {
1598 applyFilter(filter
);
1604 tableEditor
.getEditor().dispose();
1608 fTable
.addKeyListener(new KeyAdapter() {
1610 public void keyPressed(final KeyEvent e
) {
1612 if (e
.character
== SWT
.ESC
) {
1616 } else if (e
.character
== SWT
.DEL
) {
1617 if (fHeaderState
== HeaderState
.SEARCH
) {
1619 for (final TableColumn column
: fTable
.getColumns()) {
1620 column
.setData(Key
.SEARCH_OBJ
, null);
1621 column
.setData(Key
.SEARCH_TXT
, null);
1623 fTable
.setData(Key
.SEARCH_OBJ
, null);
1625 fireSearchApplied(null);
1626 } else if (fHeaderState
== HeaderState
.FILTER
) {
1629 } else if (e
.character
== SWT
.CR
) {
1630 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1641 * Send an event indicating a filter has been applied.
1644 * The filter that was just applied
1646 protected void fireFilterApplied(final ITmfFilter filter
) {
1647 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1651 * Send an event indicating that a search has been applied.
1654 * The search filter that was just applied
1656 protected void fireSearchApplied(final ITmfFilter filter
) {
1657 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1661 * Start the filtering thread.
1663 protected void startFilterThread() {
1664 synchronized (fFilterSyncObj
) {
1665 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1666 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1667 if (fFilterThread
!= null) {
1668 fFilterThread
.cancel();
1669 fFilterThreadResume
= false;
1671 fFilterThread
= new FilterThread(filter
);
1672 fFilterThread
.start();
1674 fFilterThreadResume
= true;
1680 * Stop the filtering thread.
1682 protected void stopFilterThread() {
1683 synchronized (fFilterSyncObj
) {
1684 if (fFilterThread
!= null) {
1685 fFilterThread
.cancel();
1686 fFilterThread
= null;
1687 fFilterThreadResume
= false;
1696 * The filter to apply
1698 protected void applyFilter(ITmfFilter filter
) {
1701 fFilterMatchCount
= 0;
1702 fFilterCheckCount
= 0;
1703 fCache
.applyFilter(filter
);
1705 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1706 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1707 startFilterThread();
1708 fireFilterApplied(filter
);
1712 * Clear all currently active filters.
1714 protected void clearFilters() {
1715 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1720 fCache
.clearFilter();
1722 for (final TableColumn column
: fTable
.getColumns()) {
1723 column
.setData(Key
.FILTER_OBJ
, null);
1724 column
.setData(Key
.FILTER_TXT
, null);
1726 fTable
.setData(Key
.FILTER_OBJ
, null);
1727 if (fTrace
!= null) {
1728 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1730 fTable
.setItemCount(1); // +1 for header row
1732 fFilterMatchCount
= 0;
1733 fFilterCheckCount
= 0;
1734 if (fSelectedRank
>= 0) {
1735 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1737 fTable
.setSelection(0);
1739 fireFilterApplied(null);
1740 updateStatusLine(null);
1742 // Set original width
1743 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1748 * Wrapper Thread object for the filtering thread.
1750 protected class FilterThread
extends Thread
{
1751 private final ITmfFilterTreeNode filter
;
1752 private TmfEventRequest request
;
1753 private boolean refreshBusy
= false;
1754 private boolean refreshPending
= false;
1755 private final Object syncObj
= new Object();
1761 * The filter this thread will be processing
1763 public FilterThread(final ITmfFilterTreeNode filter
) {
1764 super("Filter Thread"); //$NON-NLS-1$
1765 this.filter
= filter
;
1770 if (fTrace
== null) {
1773 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1774 if (nbRequested
<= 0) {
1777 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1778 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1780 public void handleData(final ITmfEvent event
) {
1781 super.handleData(event
);
1782 if (request
.isCancelled()) {
1785 boolean refresh
= false;
1786 if (filter
.matches(event
)) {
1787 final long rank
= fFilterCheckCount
;
1788 final int index
= (int) fFilterMatchCount
;
1789 fFilterMatchCount
++;
1790 fCache
.storeEvent(event
, rank
, index
);
1793 if (filter
instanceof TmfCollapseFilter
) {
1794 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1798 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1801 fFilterCheckCount
++;
1804 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1806 request
.waitForCompletion();
1807 } catch (final InterruptedException e
) {
1810 synchronized (fFilterSyncObj
) {
1811 fFilterThread
= null;
1812 if (fFilterThreadResume
) {
1813 fFilterThreadResume
= false;
1814 fFilterThread
= new FilterThread(filter
);
1815 fFilterThread
.start();
1821 * Refresh the filter.
1823 public void refreshTable() {
1824 synchronized (syncObj
) {
1826 refreshPending
= true;
1831 Display
.getDefault().asyncExec(new Runnable() {
1834 if (request
.isCancelled()) {
1837 if (fTable
.isDisposed()) {
1840 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1842 synchronized (syncObj
) {
1843 refreshBusy
= false;
1844 if (refreshPending
) {
1845 refreshPending
= false;
1854 * Cancel this filtering thread.
1856 public void cancel() {
1857 if (request
!= null) {
1864 * Go to the next item of a search.
1866 protected void searchNext() {
1867 synchronized (fSearchSyncObj
) {
1868 if (fSearchThread
!= null) {
1871 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1872 if (searchFilter
== null) {
1875 final int selectionIndex
= fTable
.getSelectionIndex();
1877 if (selectionIndex
> 0) {
1878 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1880 // header row is selected, start at top event
1881 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1883 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1884 if (eventFilter
!= null) {
1885 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1887 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1888 fSearchThread
.schedule();
1893 * Go to the previous item of a search.
1895 protected void searchPrevious() {
1896 synchronized (fSearchSyncObj
) {
1897 if (fSearchThread
!= null) {
1900 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1901 if (searchFilter
== null) {
1904 final int selectionIndex
= fTable
.getSelectionIndex();
1906 if (selectionIndex
> 0) {
1907 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1909 // header row is selected, start at precedent of top event
1910 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1912 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1913 if (eventFilter
!= null) {
1914 startIndex
= startIndex
- 1; // -1 for top filter status row
1916 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1917 fSearchThread
.schedule();
1922 * Stop the search thread.
1924 protected void stopSearchThread() {
1925 fPendingGotoRank
= -1;
1926 synchronized (fSearchSyncObj
) {
1927 if (fSearchThread
!= null) {
1928 fSearchThread
.cancel();
1929 fSearchThread
= null;
1935 * Wrapper for the search thread.
1937 protected class SearchThread
extends Job
{
1939 private ITmfFilterTreeNode searchFilter
;
1940 private ITmfFilterTreeNode eventFilter
;
1941 private int startIndex
;
1942 private int direction
;
1944 private long foundRank
= -1;
1945 private TmfEventRequest request
;
1946 private ITmfTimestamp foundTimestamp
= null;
1951 * @param searchFilter
1953 * @param eventFilter
1956 * The index at which we should start searching
1957 * @param currentRank
1960 * In which direction should we search, forward or backwards
1962 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1963 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1964 final long currentRank
, final int direction
) {
1965 super(Messages
.TmfEventsTable_SearchingJobName
);
1966 this.searchFilter
= searchFilter
;
1967 this.eventFilter
= eventFilter
;
1968 this.startIndex
= startIndex
;
1969 this.rank
= currentRank
;
1970 this.direction
= direction
;
1974 protected IStatus
run(final IProgressMonitor monitor
) {
1975 if (fTrace
== null) {
1976 return Status
.OK_STATUS
;
1978 final Display display
= Display
.getDefault();
1979 if (startIndex
< 0) {
1980 rank
= (int) fTrace
.getNbEvents() - 1;
1981 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1984 int idx
= startIndex
;
1985 while (foundRank
== -1) {
1986 final CachedEvent event
= fCache
.peekEvent(idx
);
1987 if (event
== null) {
1991 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1992 foundRank
= event
.rank
;
1993 foundTimestamp
= event
.event
.getTimestamp();
1996 if (direction
== Direction
.FORWARD
) {
2002 if (foundRank
== -1) {
2003 if (direction
== Direction
.FORWARD
) {
2005 if (rank
> (fTrace
.getNbEvents() - 1)) {
2011 rank
= (int) fTrace
.getNbEvents() - 1;
2016 final int startRank
= (int) rank
;
2017 boolean wrapped
= false;
2018 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
2019 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
2020 if (direction
== Direction
.BACKWARD
) {
2021 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
2023 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
2024 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
2025 long currentRank
= rank
;
2028 public void handleData(final ITmfEvent event
) {
2029 super.handleData(event
);
2030 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
2031 foundRank
= currentRank
;
2032 foundTimestamp
= event
.getTimestamp();
2033 if (direction
== Direction
.FORWARD
) {
2041 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
2043 request
.waitForCompletion();
2044 if (request
.isCancelled()) {
2045 return Status
.OK_STATUS
;
2047 } catch (final InterruptedException e
) {
2048 synchronized (fSearchSyncObj
) {
2049 fSearchThread
= null;
2051 return Status
.OK_STATUS
;
2053 if (foundRank
== -1) {
2054 if (direction
== Direction
.FORWARD
) {
2056 synchronized (fSearchSyncObj
) {
2057 fSearchThread
= null;
2059 return Status
.OK_STATUS
;
2061 nbRequested
= (int) rank
;
2067 rank
= (int) fTrace
.getNbEvents() - 1;
2070 if ((rank
<= startRank
) && wrapped
) {
2071 synchronized (fSearchSyncObj
) {
2072 fSearchThread
= null;
2074 return Status
.OK_STATUS
;
2079 int index
= (int) foundRank
;
2080 if (eventFilter
!= null) {
2081 index
= fCache
.getFilteredEventIndex(foundRank
);
2083 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
2085 display
.asyncExec(new Runnable() {
2088 if (monitor
.isCanceled()) {
2091 if (fTable
.isDisposed()) {
2094 fTable
.setSelection(selection
);
2095 fSelectedRank
= foundRank
;
2096 fRawViewer
.selectAndReveal(fSelectedRank
);
2097 if (foundTimestamp
!= null) {
2098 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, foundTimestamp
));
2100 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
2101 synchronized (fSearchSyncObj
) {
2102 fSearchThread
= null;
2104 updateStatusLine(null);
2107 return Status
.OK_STATUS
;
2111 protected void canceling() {
2113 synchronized (fSearchSyncObj
) {
2114 fSearchThread
= null;
2120 * Create the resources.
2122 protected void createResources() {
2123 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
2124 .getForeground().getRGB()));
2125 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
2129 * Initialize the fonts.
2132 protected void initializeFonts() {
2133 FontRegistry fontRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
2134 fFont
= fontRegistry
.get(FONT_DEFINITION_ID
);
2135 fBoldFont
= fontRegistry
.getBold(FONT_DEFINITION_ID
);
2136 fTable
.setFont(fFont
);
2137 /* Column header font cannot be set. See Bug 63038 */
2141 * Initialize the colors.
2144 protected void initializeColors() {
2145 ColorRegistry colorRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
2146 fHighlightColor
= colorRegistry
.get(HIGHLIGHT_COLOR_DEFINITION_ID
);
2153 public void propertyChange(PropertyChangeEvent event
) {
2154 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2155 (FONT_DEFINITION_ID
.equals(event
.getProperty()))) {
2159 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2160 (HIGHLIGHT_COLOR_DEFINITION_ID
.equals(event
.getProperty()))) {
2169 protected void packColumns() {
2173 fTable
.setRedraw(false);
2175 TableColumn tableColumns
[] = fTable
.getColumns();
2176 for (int i
= 0; i
< tableColumns
.length
; i
++) {
2177 final TableColumn column
= tableColumns
[i
];
2178 packSingleColumn(i
, column
);
2181 // Make sure that redraw is always enabled.
2182 fTable
.setRedraw(true);
2188 private void packMarginColumn() {
2189 TableColumn
[] columns
= fTable
.getColumns();
2190 if (columns
.length
> 0) {
2191 packSingleColumn(0, columns
[0]);
2195 private void packSingleColumn(int i
, final TableColumn column
) {
2196 final int headerWidth
= column
.getWidth();
2198 // Workaround for Linux which doesn't consider the image width of
2199 // search/filter row in TableColumn.pack() after having executed
2200 // TableItem.setImage((Image)null) for other rows than search/filter row.
2201 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2202 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2203 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2206 if (column
.getWidth() < headerWidth
) {
2207 column
.setWidth(headerWidth
);
2212 * Get the array of item strings (e.g., what to display in each cell of the
2213 * table row) corresponding to the columns and trace event passed in
2214 * parameter. The order of the Strings in the returned array will correspond
2215 * to the iteration order of 'columns'.
2218 * To ensure consistent results, make sure only call this within a scope
2219 * synchronized on 'columns'! If the order of 'columns' changes right after
2220 * this method is called, the returned value won't be ordered correctly
2223 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2224 if (event
== null) {
2225 return EMPTY_STRING_ARRAY
;
2227 synchronized (columns
) {
2228 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2229 for (TmfEventTableColumn column
: columns
) {
2230 ITmfEvent passedEvent
= event
;
2231 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2232 // Make sure that the event object from the trace is passed
2233 // to all columns but the TmfMarginColumn
2234 passedEvent
= ((CachedEvent
) event
).event
;
2236 if (passedEvent
== null) {
2237 itemStrings
.add(EMPTY_STRING
);
2239 itemStrings
.add(column
.getItemString(passedEvent
));
2243 return itemStrings
.toArray(new String
[0]);
2248 * Get the contents of the row in the events table corresponding to an
2249 * event. The order of the elements corresponds to the current order of the
2253 * The event printed in this row
2254 * @return The event row entries
2256 public String
[] getItemStrings(ITmfEvent event
) {
2257 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2258 for (int i
: fTable
.getColumnOrder()) {
2259 columns
.add(fColumns
.get(i
));
2261 return getItemStrings(columns
, event
);
2265 * Returns an array of zero-relative integers that map
2266 * the creation order of the receiver's columns to the
2267 * order in which they are currently being displayed.
2269 * Specifically, the indices of the returned array represent
2270 * the current visual order of the columns, and the contents
2271 * of the array represent the creation order of the columns.
2273 * @return the current visual order of the receiver's columns
2276 public int[] getColumnOrder() {
2277 return fColumnOrder
;
2281 * Sets the order that the columns in the receiver should
2282 * be displayed in to the given argument which is described
2283 * in terms of the zero-relative ordering of when the columns
2286 * Specifically, the contents of the array represent the
2287 * original position of each column at the time its creation.
2289 * @param order the new order to display the columns
2292 public void setColumnOrder(int[] order
) {
2293 if (order
== null || order
.length
!= fTable
.getColumns().length
) {
2296 fTable
.setColumnOrder(order
);
2297 fColumnOrder
= fTable
.getColumnOrder();
2301 * Notify this table that is got the UI focus.
2303 public void setFocus() {
2308 * Assign a new trace to this event table.
2311 * The trace to assign to this event table
2312 * @param disposeOnClose
2313 * true if the trace should be disposed when the table is
2316 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2317 if ((fTrace
!= null) && fDisposeOnClose
) {
2323 fDisposeOnClose
= disposeOnClose
;
2325 // Perform the updates on the UI thread
2326 fTable
.getDisplay().syncExec(new Runnable() {
2330 fCache
.setTrace(fTrace
); // Clear the cache
2331 if (fTrace
!= null) {
2332 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2333 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2334 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2337 fFilterMatchCount
= 0;
2338 fFilterCheckCount
= 0;
2339 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2340 startFilterThread();
2344 fRawViewer
.setTrace(fTrace
);
2350 * Assign the status line manager
2352 * @param statusLineManager
2353 * The status line manager, or null to disable status line messages
2355 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2356 if (fStatusLineManager
!= null && statusLineManager
== null) {
2357 fStatusLineManager
.setMessage(EMPTY_STRING
);
2359 fStatusLineManager
= statusLineManager
;
2362 private void updateStatusLine(ITmfTimestamp delta
) {
2363 if (fStatusLineManager
!= null) {
2364 if (delta
!= null) {
2365 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2367 fStatusLineManager
.setMessage(null);
2372 // ------------------------------------------------------------------------
2374 // ------------------------------------------------------------------------
2377 * Notify that the event cache has been updated
2380 * Also notify if the populating of the cache is complete, or
2383 public void cacheUpdated(final boolean completed
) {
2384 synchronized (fCacheUpdateSyncObj
) {
2385 if (fCacheUpdateBusy
) {
2386 fCacheUpdatePending
= true;
2387 fCacheUpdateCompleted
= completed
;
2390 fCacheUpdateBusy
= true;
2392 // Event cache is now updated. Perform update on the UI thread
2393 if (!fTable
.isDisposed()) {
2394 fTable
.getDisplay().asyncExec(new Runnable() {
2397 if (!fTable
.isDisposed()) {
2402 populateCompleted();
2404 synchronized (fCacheUpdateSyncObj
) {
2405 fCacheUpdateBusy
= false;
2406 if (fCacheUpdatePending
) {
2407 fCacheUpdatePending
= false;
2408 cacheUpdated(fCacheUpdateCompleted
);
2417 * Callback for when populating the table is complete.
2419 protected void populateCompleted() {
2420 // Nothing by default;
2423 // ------------------------------------------------------------------------
2424 // ISelectionProvider
2425 // ------------------------------------------------------------------------
2428 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2429 selectionChangedListeners
.add(listener
);
2433 public ISelection
getSelection() {
2434 if (fTable
== null || fTable
.isDisposed()) {
2435 return StructuredSelection
.EMPTY
;
2437 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2438 for (TableItem item
: fTable
.getSelection()) {
2439 if (item
.getData() != null) {
2440 list
.add(item
.getData());
2443 return new StructuredSelection(list
);
2447 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2448 selectionChangedListeners
.remove(listener
);
2452 public void setSelection(ISelection selection
) {
2457 * Notifies any selection changed listeners that the viewer's selection has changed.
2458 * Only listeners registered at the time this method is called are notified.
2460 * @param event a selection changed event
2462 * @see ISelectionChangedListener#selectionChanged
2464 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2465 Object
[] listeners
= selectionChangedListeners
.getListeners();
2466 for (int i
= 0; i
< listeners
.length
; ++i
) {
2467 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2468 SafeRunnable
.run(new SafeRunnable() {
2471 l
.selectionChanged(event
);
2477 // ------------------------------------------------------------------------
2478 // Bookmark handling
2479 // ------------------------------------------------------------------------
2482 * Add a bookmark to this event table.
2484 * @param bookmarksFile
2485 * The file to use for the bookmarks
2487 public void addBookmark(final IFile bookmarksFile
) {
2488 fBookmarksFile
= bookmarksFile
;
2489 final TableItem
[] selection
= fTable
.getSelection();
2490 if (selection
.length
> 0) {
2491 final TableItem tableItem
= selection
[0];
2492 if (tableItem
.getData(Key
.RANK
) != null) {
2493 final StringBuffer defaultMessage
= new StringBuffer();
2494 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2496 defaultMessage
.append(", "); //$NON-NLS-1$
2498 defaultMessage
.append(tableItem
.getText(i
));
2500 final InputDialog dialog
= new MultiLineInputDialog(
2501 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2502 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2503 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2504 defaultMessage
.toString());
2505 if (dialog
.open() == Window
.OK
) {
2506 final String message
= dialog
.getValue();
2508 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2509 if (bookmark
.exists()) {
2510 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2511 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2512 final int location
= rank
.intValue();
2513 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2514 fBookmarksMap
.put(rank
, bookmark
.getId());
2517 } catch (final CoreException e
) {
2518 displayException(e
);
2527 * Remove a bookmark from this event table.
2530 * The bookmark to remove
2532 public void removeBookmark(final IMarker bookmark
) {
2533 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2534 if (entry
.getValue().equals(bookmark
.getId())) {
2535 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2542 private void toggleBookmark(final Long rank
) {
2543 if (fBookmarksFile
== null) {
2546 if (fBookmarksMap
.containsKey(rank
)) {
2547 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2550 for (long markerId
: markerIds
) {
2551 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2552 if (bookmark
!= null) {
2556 } catch (final CoreException e
) {
2557 displayException(e
);
2560 addBookmark(fBookmarksFile
);
2565 * Refresh the bookmarks assigned to this trace, from the contents of a
2568 * @param bookmarksFile
2569 * The bookmark file to use
2571 public void refreshBookmarks(final IFile bookmarksFile
) {
2572 fBookmarksFile
= bookmarksFile
;
2573 if (bookmarksFile
== null) {
2574 fBookmarksMap
.clear();
2579 fBookmarksMap
.clear();
2580 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2581 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2582 if (location
!= -1) {
2583 final long rank
= location
;
2584 fBookmarksMap
.put(rank
, bookmark
.getId());
2588 } catch (final CoreException e
) {
2589 displayException(e
);
2594 public void gotoMarker(final IMarker marker
) {
2595 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2598 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2599 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2600 } else if (rank
>= fTable
.getItemCount()) {
2601 fPendingGotoRank
= rank
;
2603 fSelectedRank
= rank
;
2604 fTable
.setSelection(index
+ 1); // +1 for header row
2605 updateStatusLine(null);
2609 // ------------------------------------------------------------------------
2611 // ------------------------------------------------------------------------
2614 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2618 // ------------------------------------------------------------------------
2620 // ------------------------------------------------------------------------
2623 * Handler for the trace updated signal
2626 * The incoming signal
2629 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2630 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2633 // Perform the refresh on the UI thread
2634 Display
.getDefault().asyncExec(new Runnable() {
2637 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2638 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2639 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2640 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2641 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2642 fPendingGotoRank
= -1;
2643 updateStatusLine(null);
2646 startFilterThread();
2649 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2650 fRawViewer
.refreshEventCount();
2657 * Handler for the selection range signal.
2660 * The incoming signal
2664 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
2665 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2667 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2668 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2669 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2670 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2671 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2673 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2676 public void handleData(final ITmfEvent event
) {
2677 super.handleData(event
);
2681 public void handleSuccess() {
2682 super.handleSuccess();
2683 if (fTrace
== null) {
2687 // Verify if the event is within the trace range and adjust if necessary
2688 ITmfTimestamp timestamp
= ts
;
2689 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2690 timestamp
= fTrace
.getStartTime();
2692 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2693 timestamp
= fTrace
.getEndTime();
2696 // Get the rank of the selected event in the table
2697 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2698 final long rank
= context
.getRank();
2700 fSelectedRank
= rank
;
2702 fTable
.getDisplay().asyncExec(new Runnable() {
2705 // Return if table is disposed
2706 if (fTable
.isDisposed()) {
2710 int index
= (int) rank
;
2711 if (fTable
.isDisposed()) {
2714 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2715 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2717 fTable
.setSelection(index
+ 1); // +1 for header row
2718 fRawViewer
.selectAndReveal(rank
);
2719 updateStatusLine(null);
2725 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2729 // ------------------------------------------------------------------------
2731 // ------------------------------------------------------------------------
2734 * Display an exception in a message box
2736 * @param e the exception
2738 private static void displayException(final Exception e
) {
2739 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2740 mb
.setText(e
.getClass().getSimpleName());
2741 mb
.setMessage(e
.getMessage());
2748 public void refresh() {
2755 * Margin column for images and special text (e.g. collapse count)
2757 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2759 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2762 public String
getName() {
2763 return EMPTY_STRING
;
2767 public String
resolve(ITmfEvent event
) {
2768 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2769 return EMPTY_STRING
;
2771 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2775 public String
getHelpText() {
2776 return EMPTY_STRING
;
2783 public TmfMarginColumn() {
2784 super(MARGIN_ASPECT
);