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().getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
207 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
208 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
209 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
210 private static final int MAX_CACHE_SIZE
= 1000;
212 private static final int MARGIN_COLUMN_INDEX
= 0;
213 private static final int FILTER_SUMMARY_INDEX
= 1;
214 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
217 * The events table search/filter keys
220 * @author Patrick Tasse
222 public interface Key
{
224 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
227 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
230 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
233 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
236 String TIMESTAMP
= "$time"; //$NON-NLS-1$
239 String RANK
= "$rank"; //$NON-NLS-1$
241 /** Bookmark indicator */
242 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
244 /** Event aspect represented by this column */
245 String ASPECT
= "$aspect"; //$NON-NLS-1$
248 * Table item list of style ranges
252 String STYLE_RANGES
= "$style_ranges"; //$NON-NLS-1$
256 * The events table search/filter state
259 * @author Patrick Tasse
261 public static enum HeaderState
{
262 /** A search is being run */
265 /** A filter is applied */
269 interface Direction
{
274 // ------------------------------------------------------------------------
276 // ------------------------------------------------------------------------
278 /** The virtual event table */
279 protected TmfVirtualTable fTable
;
281 private Composite fComposite
;
282 private SashForm fSashForm
;
283 private TmfRawEventViewer fRawViewer
;
284 private ITmfTrace fTrace
;
285 private volatile boolean fPackDone
= false;
286 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
287 private long fSelectedRank
= 0;
288 private ITmfTimestamp fSelectedBeginTimestamp
= null;
289 private IStatusLineManager fStatusLineManager
= null;
292 private long fFilterMatchCount
;
293 private long fFilterCheckCount
;
294 private FilterThread fFilterThread
;
295 private boolean fFilterThreadResume
= false;
296 private final Object fFilterSyncObj
= new Object();
297 private SearchThread fSearchThread
;
298 private final Object fSearchSyncObj
= new Object();
301 * List of selection change listeners (element type:
302 * <code>ISelectionChangedListener</code>).
304 * @see #fireSelectionChanged
306 private ListenerList selectionChangedListeners
= new ListenerList();
308 // Bookmark map <Rank, MarkerId>
309 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
310 private IFile fBookmarksFile
;
311 private long fPendingGotoRank
= -1;
314 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
315 private Color fGrayColor
;
316 private Color fGreenColor
;
317 private Color fHighlightColor
;
319 private Font fBoldFont
;
321 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
324 private final TmfEventsCache fCache
;
325 private boolean fCacheUpdateBusy
= false;
326 private boolean fCacheUpdatePending
= false;
327 private boolean fCacheUpdateCompleted
= false;
328 private final Object fCacheUpdateSyncObj
= new Object();
330 // Keep track of column order, it is needed after table is disposed
331 private int[] fColumnOrder
;
333 private boolean fDisposeOnClose
;
335 // ------------------------------------------------------------------------
337 // ------------------------------------------------------------------------
340 * Basic constructor, using the default set of columns
343 * The parent composite UI object
345 * The size of the event table cache
347 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
348 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
352 * Legacy constructor, using ColumnData to define columns
355 * The parent composite UI object
357 * The size of the event table cache
359 * The column data array
360 * @deprecated Deprecated constructor, use
361 * {@link #TmfEventsTable(Composite, int, Collection)}
364 public TmfEventsTable(final Composite parent
, int cacheSize
,
365 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
367 * We'll do a "best-effort" to keep trace types still using this API to
368 * keep working, by defining a TmfEventTableColumn for each ColumnData
371 this(parent
, cacheSize
, convertFromColumnData(columnData
));
375 private static @NonNull Iterable
<ITmfEventAspect
> convertFromColumnData(
376 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
378 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
379 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
380 String fieldName
= col
.header
;
381 if (fieldName
!= null) {
382 builder
.add(new TmfContentFieldAspect(fieldName
, fieldName
));
385 return checkNotNull(builder
.build());
389 * Standard constructor, where we define which columns to use.
392 * The parent composite UI object
394 * The size of the event table cache
396 * The event aspects to display in this table. One column per
397 * aspect will be created.
399 * The iteration order of this collection will correspond to the
400 * initial ordering of the columns in the table.
403 public TmfEventsTable(final Composite parent
, int cacheSize
,
404 @NonNull Iterable
<ITmfEventAspect
> aspects
) {
405 super("TmfEventsTable"); //$NON-NLS-1$
407 fComposite
= new Composite(parent
, SWT
.NONE
);
408 final GridLayout gl
= new GridLayout(1, false);
411 gl
.verticalSpacing
= 0;
412 fComposite
.setLayout(gl
);
414 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
415 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
417 // Create a virtual table
418 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
419 fTable
= new TmfVirtualTable(fSashForm
, style
);
421 // Set the table layout
422 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
423 fTable
.setLayoutData(layoutData
);
425 // Some cosmetic enhancements
426 fTable
.setHeaderVisible(true);
427 fTable
.setLinesVisible(true);
430 for (ITmfEventAspect aspect
: aspects
) {
431 if (aspect
!= null) {
432 fColumns
.add(new TmfEventTableColumn(aspect
));
436 TmfMarginColumn collapseCol
= new TmfMarginColumn();
437 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
439 // Create the UI columns in the table
440 for (TmfEventTableColumn col
: fColumns
) {
441 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
442 column
.setText(col
.getHeaderName());
443 column
.setToolTipText(col
.getHeaderTooltip());
444 column
.setData(Key
.ASPECT
, col
.getEventAspect());
446 if (col
instanceof TmfMarginColumn
) {
447 column
.setResizable(false);
449 column
.setMoveable(true);
451 column
.addControlListener(new ControlAdapter() {
453 * Make sure that the margin column is always first and keep the
454 * column order variable up to date.
457 public void controlMoved(ControlEvent e
) {
458 int[] order
= fTable
.getColumnOrder();
459 if (order
[0] == MARGIN_COLUMN_INDEX
) {
460 fColumnOrder
= order
;
463 for (int i
= order
.length
- 1; i
> 0; i
--) {
464 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
465 order
[i
] = order
[i
- 1];
466 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
469 fTable
.setColumnOrder(order
);
470 fColumnOrder
= fTable
.getColumnOrder();
474 fColumnOrder
= fTable
.getColumnOrder();
476 // Set the frozen row for header row
477 fTable
.setFrozenRowCount(1);
479 // Create the header row cell editor
480 createHeaderEditor();
482 // Handle the table item selection
483 fTable
.addSelectionListener(new SelectionAdapter() {
485 public void widgetSelected(final SelectionEvent e
) {
486 if (e
.item
== null) {
489 updateStatusLine(null);
490 if (fTable
.getSelectionIndices().length
> 0) {
491 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
492 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
493 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
495 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
496 final ITmfTimestamp ts
= NonNullUtils
.checkNotNull((ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
));
497 if (fTable
.getSelectionIndices().length
== 1) {
498 fSelectedBeginTimestamp
= ts
;
500 ITmfTimestamp selectedBeginTimestamp
= fSelectedBeginTimestamp
;
501 if (selectedBeginTimestamp
!= null) {
502 if (selectedBeginTimestamp
.compareTo(ts
) <= 0) {
503 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, selectedBeginTimestamp
, ts
));
504 if (fTable
.getSelectionIndices().length
== 2) {
505 updateStatusLine(ts
.getDelta(selectedBeginTimestamp
));
508 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, checkNotNull(ts
), checkNotNull(fSelectedBeginTimestamp
)));
509 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
513 if (fTable
.getSelectionIndices().length
== 1) {
514 fSelectedBeginTimestamp
= null;
518 if (e
.item
.getData() instanceof ITmfEvent
) {
519 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
520 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
522 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
527 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
528 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
529 fCache
= new TmfEventsCache(realCacheSize
, this);
531 // Handle the table item requests
532 fTable
.addListener(SWT
.SetData
, new Listener() {
535 public void handleEvent(final Event event
) {
537 final TableItem item
= (TableItem
) event
.item
;
538 int index
= event
.index
- 1; // -1 for the header row
540 if (event
.index
== 0) {
541 setHeaderRowItemData(item
);
545 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
546 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
547 setFilterStatusRowItemData(item
);
550 /* -1 for top filter status row */
554 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
555 if (cachedEvent
!= null) {
556 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
560 // Else, fill the cache asynchronously (and off the UI thread)
565 fTable
.addMouseListener(new MouseAdapter() {
567 public void mouseDoubleClick(final MouseEvent event
) {
568 if (event
.button
!= 1) {
571 // Identify the selected row
572 final Point point
= new Point(event
.x
, event
.y
);
573 final TableItem item
= fTable
.getItem(point
);
575 final Rectangle imageBounds
= item
.getImageBounds(0);
576 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
577 if (imageBounds
.contains(point
)) {
578 final Long rank
= (Long
) item
.getData(Key
.RANK
);
580 toggleBookmark(rank
);
587 final Listener tooltipListener
= new Listener() {
588 Shell tooltipShell
= null;
591 public void handleEvent(final Event event
) {
592 switch (event
.type
) {
594 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
598 final Long rank
= (Long
) item
.getData(Key
.RANK
);
602 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
603 final Rectangle bounds
= item
.getImageBounds(0);
604 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
605 if (!bounds
.contains(event
.x
, event
.y
)) {
608 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
609 tooltipShell
.dispose();
611 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
612 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
613 final FillLayout layout
= new FillLayout();
614 layout
.marginWidth
= 2;
615 tooltipShell
.setLayout(layout
);
616 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
617 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
618 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
619 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
621 label
.addListener(SWT
.MouseExit
, this);
622 label
.addListener(SWT
.MouseDown
, this);
623 label
.addListener(SWT
.MouseWheel
, this);
624 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
626 * Bug in Linux. The coordinates of the event have an origin
627 * that excludes the table header but the method toDisplay()
628 * expects coordinates relative to an origin that includes
633 y
+= fTable
.getHeaderHeight();
635 Point pt
= fTable
.toDisplay(event
.x
, y
);
636 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
637 pt
.y
+= item
.getBounds().height
;
638 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
639 tooltipShell
.setVisible(true);
647 if (tooltipShell
!= null) {
648 tooltipShell
.dispose();
658 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
659 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
660 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
661 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
662 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
663 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
664 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
666 fTable
.addListener(SWT
.EraseItem
, new Listener() {
668 public void handleEvent(Event event
) {
669 TableItem item
= (TableItem
) event
.item
;
670 List
<?
> styleRanges
= (List
<?
>) item
.getData(Key
.STYLE_RANGES
);
673 Color background
= item
.getBackground(event
.index
);
675 * Paint the background if it is not the default system color.
676 * In Windows, if you let the widget draw the background, it
677 * will not show the item's background color if the item is
678 * selected or hot. If there are no style ranges and the item
679 * background is the default system color, we do not want to
680 * paint it or otherwise we would override the platform theme
681 * (e.g. alternating colors).
683 if (styleRanges
!= null || !background
.equals(item
.getParent().getBackground())) {
684 // we will paint the table item's background
685 event
.detail
&= ~SWT
.BACKGROUND
;
687 // paint the item's default background
688 gc
.setBackground(background
);
689 gc
.fillRectangle(event
.x
, event
.y
, event
.width
, event
.height
);
693 * We will paint the table item's foreground. In Windows, if you
694 * paint the background but let the widget draw the foreground,
695 * it will override your background, unless the item is selected
698 event
.detail
&= ~SWT
.FOREGROUND
;
700 // paint the highlighted background for all style ranges
701 if (styleRanges
!= null) {
702 Rectangle textBounds
= item
.getTextBounds(event
.index
);
703 String text
= item
.getText(event
.index
);
704 for (Object o
: styleRanges
) {
705 if (o
instanceof StyleRange
) {
706 StyleRange styleRange
= (StyleRange
) o
;
707 if (styleRange
.data
.equals(event
.index
)) {
708 int startIndex
= styleRange
.start
;
709 int endIndex
= startIndex
+ styleRange
.length
;
710 int startX
= gc
.stringExtent(text
.substring(0, startIndex
)).x
;
711 int endX
= gc
.stringExtent(text
.substring(0, endIndex
)).x
;
712 gc
.setBackground(styleRange
.background
);
713 gc
.fillRectangle(textBounds
.x
+ startX
, textBounds
.y
, (endX
- startX
), textBounds
.height
);
721 fTable
.addListener(SWT
.PaintItem
, new Listener() {
723 public void handleEvent(Event event
) {
724 TableItem item
= (TableItem
) event
.item
;
726 // we promised to paint the table item's foreground
728 Image image
= item
.getImage(event
.index
);
730 Rectangle imageBounds
= item
.getImageBounds(event
.index
);
732 * The image bounds don't match the default image position.
735 gc
.drawImage(image
, imageBounds
.x
+ 1, imageBounds
.y
+ 3);
737 gc
.drawImage(image
, imageBounds
.x
, imageBounds
.y
+ 1);
740 gc
.setForeground(item
.getForeground(event
.index
));
741 gc
.setFont(item
.getFont(event
.index
));
742 String text
= item
.getText(event
.index
);
743 Rectangle textBounds
= item
.getTextBounds(event
.index
);
745 * The text bounds don't match the default text position.
748 gc
.drawText(text
, textBounds
.x
+ 1, textBounds
.y
+ 3, true);
750 gc
.drawText(text
, textBounds
.x
- 1, textBounds
.y
+ 2, true);
760 PlatformUI
.getWorkbench().getThemeManager().addPropertyChangeListener(this);
762 ColorSettingsManager
.addColorSettingsListener(this);
764 fTable
.setItemCount(1); // +1 for header row
766 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
768 fRawViewer
.addSelectionListener(new Listener() {
770 public void handleEvent(final Event e
) {
771 if (e
.data
instanceof Long
) {
772 final long rank
= (Long
) e
.data
;
773 int index
= (int) rank
;
774 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
775 // +1 for top filter status row
776 index
= fCache
.getFilteredEventIndex(rank
) + 1;
779 fTable
.setSelection(index
+ 1);
780 fSelectedRank
= rank
;
781 updateStatusLine(null);
782 } else if (e
.data
instanceof ITmfLocation
) {
784 * DOES NOT WORK: rank undefined in context from
785 * seekLocation() <code>
786 * ITmfLocation<?> location = (ITmfLocation<?>) e.data;
787 * TmfContext context = fTrace.seekLocation(location);
788 * fTable.setSelection((int) context.getRank());
795 final TableItem
[] selection
= fTable
.getSelection();
796 if ((selection
!= null) && (selection
.length
> 0)) {
797 TableItem item
= fTable
.getSelection()[0];
798 final TmfTimestamp ts
= (TmfTimestamp
) item
.getData(Key
.TIMESTAMP
);
800 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, ts
));
802 if (item
.getData() instanceof ITmfEvent
) {
803 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) item
.getData()));
804 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(item
.getData())));
806 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
812 fSashForm
.setWeights(new int[] { 1, 1 });
813 fRawViewer
.setVisible(false);
818 // ------------------------------------------------------------------------
820 // ------------------------------------------------------------------------
823 * Create a pop-up menu.
825 private void createPopupMenu() {
826 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
829 fTable
.setVisible(true);
834 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
837 fTable
.setVisible(false);
842 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
845 fRawViewer
.setVisible(true);
847 final int index
= fTable
.getSelectionIndex();
849 fRawViewer
.selectAndReveal(index
- 1);
854 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
857 fRawViewer
.setVisible(false);
862 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
865 final TableItem items
[] = fTable
.getSelection();
866 if (items
.length
!= 1) {
869 final TableItem item
= items
[0];
871 final Object data
= item
.getData();
872 if (data
instanceof ITmfSourceLookup
) {
873 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
874 ITmfCallsite cs
= event
.getCallsite();
875 if (cs
== null || cs
.getFileName() == null) {
878 IMarker marker
= null;
880 String fileName
= cs
.getFileName();
881 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
882 final ArrayList
<IFile
> files
= new ArrayList
<>();
883 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
885 public boolean visit(IResource resource
) throws CoreException
{
886 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
887 files
.add((IFile
) resource
);
893 if (files
.size() > 1) {
894 ListDialog dialog
= new ListDialog(getTable().getShell());
895 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
896 dialog
.setLabelProvider(new LabelProvider() {
898 public String
getText(Object element
) {
899 return ((IFile
) element
).getFullPath().toString();
902 dialog
.setInput(files
);
903 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
904 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
906 Object
[] result
= dialog
.getResult();
907 if (result
!= null && result
.length
> 0) {
908 file
= (IFile
) result
[0];
910 } else if (files
.size() == 1) {
914 marker
= file
.createMarker(IMarker
.MARKER
);
915 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
916 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
918 } else if (files
.size() == 0) {
919 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
921 } catch (CoreException e
) {
928 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
932 final TableItem items
[] = fTable
.getSelection();
933 if (items
.length
!= 1) {
936 final TableItem item
= items
[0];
938 final Object eventData
= item
.getData();
939 if (eventData
instanceof ITmfModelLookup
) {
940 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
942 if (modelURI
!= null) {
943 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
946 final URI uri
= URI
.createURI(modelURI
);
947 if (uri
.isPlatformResource()) {
948 IPath path
= new Path(uri
.toPlatformString(true));
949 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
950 } else if (uri
.isFile() && !uri
.isRelative()) {
951 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
952 new Path(uri
.toFileString()));
958 * create a temporary validation marker on the
959 * model file, remove it afterwards thus,
960 * navigation works with all model editors
961 * supporting the navigation to a marker
963 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
964 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
965 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
967 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
969 } catch (CoreException e
) {
973 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
980 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
983 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
984 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
985 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
986 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
987 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
989 HashMap
<String
, Object
> parameters
= new HashMap
<>();
990 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
991 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
993 IEvaluationContext context
= handlerService
.getCurrentState();
994 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
995 for (int i
: fTable
.getColumnOrder()) {
996 // Omit the margin column
997 if (i
>= EVENT_COLUMNS_START_INDEX
) {
998 exportColumns
.add(fColumns
.get(i
));
1001 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
1003 handlerService
.executeCommandInContext(cmd
, null, context
);
1004 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
1005 displayException(e
);
1010 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
1013 fHeaderState
= HeaderState
.SEARCH
;
1019 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
1022 fHeaderState
= HeaderState
.FILTER
;
1028 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
1035 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
1038 applyFilter(new TmfCollapseFilter());
1042 class ToggleBookmarkAction
extends Action
{
1045 public ToggleBookmarkAction(final String text
, final Long rank
) {
1052 toggleBookmark(fRank
);
1056 final MenuManager tablePopupMenu
= new MenuManager();
1057 tablePopupMenu
.setRemoveAllWhenShown(true);
1058 tablePopupMenu
.addMenuListener(new IMenuListener() {
1060 public void menuAboutToShow(final IMenuManager manager
) {
1061 if (fTable
.getSelectionIndex() == 0) {
1062 // Right-click on header row
1063 if (fHeaderState
== HeaderState
.FILTER
) {
1064 tablePopupMenu
.add(showSearchBarAction
);
1066 tablePopupMenu
.add(showFilterBarAction
);
1070 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
1071 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
1073 final Rectangle imageBounds
= item
.getImageBounds(0);
1074 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
1075 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
1076 // Right-click on left margin
1077 final Long rank
= (Long
) item
.getData(Key
.RANK
);
1078 if ((rank
!= null) && (fBookmarksFile
!= null)) {
1079 if (fBookmarksMap
.containsKey(rank
)) {
1080 tablePopupMenu
.add(new ToggleBookmarkAction(
1081 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
1083 tablePopupMenu
.add(new ToggleBookmarkAction(
1084 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
1091 // Right-click on table
1092 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1093 tablePopupMenu
.add(hideTableAction
);
1094 tablePopupMenu
.add(hideRawAction
);
1095 } else if (!fTable
.isVisible()) {
1096 tablePopupMenu
.add(showTableAction
);
1097 } else if (!fRawViewer
.isVisible()) {
1098 tablePopupMenu
.add(showRawAction
);
1100 tablePopupMenu
.add(exportToTextAction
);
1101 tablePopupMenu
.add(new Separator());
1104 final Object data
= item
.getData();
1105 Separator separator
= null;
1106 if (data
instanceof ITmfSourceLookup
) {
1107 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
1108 if (event
.getCallsite() != null) {
1109 tablePopupMenu
.add(openCallsiteAction
);
1110 separator
= new Separator();
1114 if (data
instanceof ITmfModelLookup
) {
1115 ITmfModelLookup event
= (ITmfModelLookup
) data
;
1116 if (event
.getModelUri() != null) {
1117 tablePopupMenu
.add(openModelAction
);
1118 separator
= new Separator();
1121 if (separator
!= null) {
1122 tablePopupMenu
.add(separator
);
1128 * Only show collapse filter if at least one trace can be
1131 boolean isCollapsible
= false;
1132 if (fTrace
!= null) {
1133 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
1134 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1135 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1136 if (isCollapsible
) {
1142 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1143 tablePopupMenu
.add(collapseAction
);
1144 tablePopupMenu
.add(new Separator());
1147 tablePopupMenu
.add(clearFiltersAction
);
1148 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1149 if (savedFilters
.length
> 0) {
1150 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1151 for (final ITmfFilterTreeNode node
: savedFilters
) {
1152 if (node
instanceof TmfFilterNode
) {
1153 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1154 subMenu
.add(new Action(filter
.getFilterName()) {
1157 applyFilter(filter
);
1162 tablePopupMenu
.add(subMenu
);
1164 appendToTablePopupMenu(tablePopupMenu
, item
);
1168 final MenuManager rawViewerPopupMenu
= new MenuManager();
1169 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1170 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1172 public void menuAboutToShow(final IMenuManager manager
) {
1173 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1174 rawViewerPopupMenu
.add(hideTableAction
);
1175 rawViewerPopupMenu
.add(hideRawAction
);
1176 } else if (!fTable
.isVisible()) {
1177 rawViewerPopupMenu
.add(showTableAction
);
1178 } else if (!fRawViewer
.isVisible()) {
1179 rawViewerPopupMenu
.add(showRawAction
);
1181 appendToRawPopupMenu(tablePopupMenu
);
1185 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1186 fTable
.setMenu(menu
);
1188 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1189 fRawViewer
.setMenu(menu
);
1193 * Append an item to the event table's pop-up menu.
1195 * @param tablePopupMenu
1197 * @param selectedItem
1198 * The item to append
1200 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1201 // override to append more actions
1205 * Append an item to the raw viewer's pop-up menu.
1207 * @param rawViewerPopupMenu
1210 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1211 // override to append more actions
1215 public void dispose() {
1218 PlatformUI
.getWorkbench().getThemeManager().removePropertyChangeListener(this);
1219 ColorSettingsManager
.removeColorSettingsListener(this);
1220 fComposite
.dispose();
1221 if ((fTrace
!= null) && fDisposeOnClose
) {
1224 fResourceManager
.dispose();
1225 fRawViewer
.dispose();
1230 * Assign a layout data object to this view.
1233 * The layout data to assign
1235 public void setLayoutData(final Object layoutData
) {
1236 fComposite
.setLayoutData(layoutData
);
1240 * Get the virtual table contained in this event table.
1242 * @return The TMF virtual table
1244 public TmfVirtualTable
getTable() {
1251 * @deprecated The column headers are now set at the constructor, this
1252 * shouldn't be called anymore.
1255 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1260 * Set a table item's data.
1265 * Which trace event to link with this entry
1267 * Which rank this event has in the trace/experiment
1269 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1270 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1272 // Get the actual ITmfEvent from the CachedEvent
1273 ITmfEvent tmfEvent
= event
;
1274 if (event
instanceof CachedEvent
) {
1275 tmfEvent
= ((CachedEvent
) event
).event
;
1277 item
.setText(itemStrings
);
1278 item
.setData(tmfEvent
);
1279 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1280 item
.setData(Key
.RANK
, rank
);
1282 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1283 if (!markerIds
.isEmpty()) {
1284 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1285 List
<Object
> parts
= new ArrayList
<>();
1286 if (markerIds
.size() > 1) {
1287 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1290 for (long markerId
: markerIds
) {
1291 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1292 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1294 } catch (CoreException e
) {
1295 displayException(e
);
1297 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1299 item
.setData(Key
.BOOKMARK
, null);
1302 boolean searchMatch
= false;
1303 boolean searchNoMatch
= false;
1304 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1305 if (searchFilter
!= null) {
1306 if (searchFilter
.matches(tmfEvent
)) {
1309 searchNoMatch
= true;
1313 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1314 if (searchNoMatch
) {
1315 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1316 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1318 item
.setForeground(colorSetting
.getForegroundColor());
1319 item
.setBackground(colorSetting
.getBackgroundColor());
1321 item
.setFont(fFont
);
1324 if (!markerIds
.isEmpty()) {
1325 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1327 item
.setImage(SEARCH_MATCH_IMAGE
);
1329 } else if (!markerIds
.isEmpty()) {
1330 item
.setImage(BOOKMARK_IMAGE
);
1332 item
.setImage((Image
) null);
1335 List
<StyleRange
> styleRanges
= new ArrayList
<>();
1336 for (int index
= 0; index
< fTable
.getColumns().length
; index
++) {
1337 TableColumn column
= fTable
.getColumns()[index
];
1338 String regex
= null;
1339 if (fHeaderState
== HeaderState
.FILTER
) {
1340 regex
= (String
) column
.getData(Key
.FILTER_TXT
);
1341 } else if (searchMatch
) {
1342 regex
= (String
) column
.getData(Key
.SEARCH_TXT
);
1344 if (regex
!= null) {
1345 String text
= item
.getText(index
);
1347 Pattern pattern
= Pattern
.compile(regex
);
1348 Matcher matcher
= pattern
.matcher(text
);
1349 while (matcher
.find()) {
1350 int start
= matcher
.start();
1351 int length
= matcher
.end() - start
;
1352 Color foreground
= colorSetting
.getForegroundColor();
1353 Color background
= fHighlightColor
;
1354 StyleRange styleRange
= new StyleRange(start
, length
, foreground
, background
);
1355 styleRange
.data
= index
;
1356 styleRanges
.add(styleRange
);
1358 } catch (PatternSyntaxException e
) {
1363 if (styleRanges
.isEmpty()) {
1364 item
.setData(Key
.STYLE_RANGES
, null);
1366 item
.setData(Key
.STYLE_RANGES
, styleRanges
);
1368 item
.getParent().redraw();
1370 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1376 * Set the item data of the header row.
1379 * The item to use as table header
1381 protected void setHeaderRowItemData(final TableItem item
) {
1382 String txtKey
= null;
1383 if (fHeaderState
== HeaderState
.SEARCH
) {
1384 item
.setImage(SEARCH_IMAGE
);
1385 txtKey
= Key
.SEARCH_TXT
;
1386 } else if (fHeaderState
== HeaderState
.FILTER
) {
1387 item
.setImage(FILTER_IMAGE
);
1388 txtKey
= Key
.FILTER_TXT
;
1390 item
.setForeground(fGrayColor
);
1391 // Ignore collapse and image column
1392 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1393 final TableColumn column
= fTable
.getColumns()[i
];
1394 final String filter
= (String
) column
.getData(txtKey
);
1395 if (filter
== null) {
1396 if (fHeaderState
== HeaderState
.SEARCH
) {
1397 item
.setText(i
, SEARCH_HINT
);
1398 } else if (fHeaderState
== HeaderState
.FILTER
) {
1399 item
.setText(i
, FILTER_HINT
);
1401 item
.setForeground(i
, fGrayColor
);
1402 item
.setFont(i
, fFont
);
1404 item
.setText(i
, filter
);
1405 item
.setForeground(i
, fGreenColor
);
1406 item
.setFont(i
, fBoldFont
);
1412 * Set the item data of the "filter status" row.
1415 * The item to use as filter status row
1417 protected void setFilterStatusRowItemData(final TableItem item
) {
1418 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1419 if (i
== MARGIN_COLUMN_INDEX
) {
1420 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1421 item
.setImage(FILTER_IMAGE
);
1423 item
.setImage(STOP_IMAGE
);
1427 if (i
== FILTER_SUMMARY_INDEX
) {
1428 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1430 item
.setText(i
, EMPTY_STRING
);
1434 item
.setData(Key
.TIMESTAMP
, null);
1435 item
.setData(Key
.RANK
, null);
1436 item
.setData(Key
.STYLE_RANGES
, null);
1437 item
.setForeground(null);
1438 item
.setBackground(null);
1439 item
.setFont(fFont
);
1443 * Create an editor for the header.
1445 private void createHeaderEditor() {
1446 final TableEditor tableEditor
= fTable
.createTableEditor();
1447 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1448 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1449 tableEditor
.grabHorizontal
= true;
1450 tableEditor
.minimumWidth
= 50;
1452 // Handle the header row selection
1453 fTable
.addMouseListener(new MouseAdapter() {
1459 public void mouseDown(final MouseEvent event
) {
1460 if (event
.button
!= 1) {
1463 // Identify the selected row
1464 final Point point
= new Point(event
.x
, event
.y
);
1465 item
= fTable
.getItem(point
);
1467 // Header row selected
1468 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1471 if (item
.getImageBounds(0).contains(point
)) {
1472 if (fHeaderState
== HeaderState
.SEARCH
) {
1473 fHeaderState
= HeaderState
.FILTER
;
1474 } else if (fHeaderState
== HeaderState
.FILTER
) {
1475 fHeaderState
= HeaderState
.SEARCH
;
1477 fTable
.setSelection(0);
1483 // Identify the selected column
1485 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1486 final Rectangle rect
= item
.getBounds(i
);
1487 if (rect
.contains(point
)) {
1493 if (columnIndex
== -1) {
1497 column
= fTable
.getColumns()[columnIndex
];
1499 String txtKey
= null;
1500 if (fHeaderState
== HeaderState
.SEARCH
) {
1501 txtKey
= Key
.SEARCH_TXT
;
1502 } else if (fHeaderState
== HeaderState
.FILTER
) {
1503 txtKey
= Key
.FILTER_TXT
;
1507 * The control that will be the editor must be a child of
1510 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1511 final String headerString
= (String
) column
.getData(txtKey
);
1512 if (headerString
!= null) {
1513 newEditor
.setText(headerString
);
1515 newEditor
.addFocusListener(new FocusAdapter() {
1517 public void focusLost(final FocusEvent e
) {
1518 final boolean changed
= updateHeader(newEditor
.getText());
1524 newEditor
.addKeyListener(new KeyAdapter() {
1526 public void keyPressed(final KeyEvent e
) {
1527 if (e
.character
== SWT
.CR
) {
1528 updateHeader(newEditor
.getText());
1532 * Set focus on the table so that the next
1533 * carriage return goes to the next result
1535 TmfEventsTable
.this.getTable().setFocus();
1536 } else if (e
.character
== SWT
.ESC
) {
1537 tableEditor
.getEditor().dispose();
1541 newEditor
.selectAll();
1542 newEditor
.setFocus();
1543 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1548 * returns true is value was changed
1550 private boolean updateHeader(final String regex
) {
1551 String objKey
= null;
1552 String txtKey
= null;
1553 if (fHeaderState
== HeaderState
.SEARCH
) {
1554 objKey
= Key
.SEARCH_OBJ
;
1555 txtKey
= Key
.SEARCH_TXT
;
1556 } else if (fHeaderState
== HeaderState
.FILTER
) {
1557 objKey
= Key
.FILTER_OBJ
;
1558 txtKey
= Key
.FILTER_TXT
;
1560 if (regex
.length() > 0) {
1562 Pattern
.compile(regex
);
1563 if (regex
.equals(column
.getData(txtKey
))) {
1564 tableEditor
.getEditor().dispose();
1567 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1568 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1569 filter
.setEventAspect(aspect
);
1570 filter
.setRegex(regex
);
1571 column
.setData(objKey
, filter
);
1572 column
.setData(txtKey
, regex
);
1573 } catch (final PatternSyntaxException ex
) {
1574 tableEditor
.getEditor().dispose();
1575 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1576 ex
.getDescription(), ex
.getMessage());
1580 if (column
.getData(txtKey
) == null) {
1581 tableEditor
.getEditor().dispose();
1584 column
.setData(objKey
, null);
1585 column
.setData(txtKey
, null);
1590 private void applyHeader() {
1591 if (fHeaderState
== HeaderState
.SEARCH
) {
1593 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1594 for (final TableColumn col
: fTable
.getColumns()) {
1595 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1596 if (filterObj
instanceof ITmfFilterTreeNode
) {
1597 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1600 if (filter
.getChildrenCount() > 0) {
1601 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1604 fireSearchApplied(filter
);
1606 fTable
.setData(Key
.SEARCH_OBJ
, null);
1608 fireSearchApplied(null);
1610 } else if (fHeaderState
== HeaderState
.FILTER
) {
1611 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1612 for (final TableColumn col
: fTable
.getColumns()) {
1613 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1614 if (filterObj
instanceof ITmfFilterTreeNode
) {
1615 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1618 if (filter
.getChildrenCount() > 0) {
1619 applyFilter(filter
);
1625 tableEditor
.getEditor().dispose();
1629 fTable
.addKeyListener(new KeyAdapter() {
1631 public void keyPressed(final KeyEvent e
) {
1633 if (e
.character
== SWT
.ESC
) {
1637 } else if (e
.character
== SWT
.DEL
) {
1638 if (fHeaderState
== HeaderState
.SEARCH
) {
1640 for (final TableColumn column
: fTable
.getColumns()) {
1641 column
.setData(Key
.SEARCH_OBJ
, null);
1642 column
.setData(Key
.SEARCH_TXT
, null);
1644 fTable
.setData(Key
.SEARCH_OBJ
, null);
1646 fireSearchApplied(null);
1647 } else if (fHeaderState
== HeaderState
.FILTER
) {
1650 } else if (e
.character
== SWT
.CR
) {
1651 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1662 * Send an event indicating a filter has been applied.
1665 * The filter that was just applied
1667 protected void fireFilterApplied(final ITmfFilter filter
) {
1668 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1672 * Send an event indicating that a search has been applied.
1675 * The search filter that was just applied
1677 protected void fireSearchApplied(final ITmfFilter filter
) {
1678 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1682 * Start the filtering thread.
1684 protected void startFilterThread() {
1685 synchronized (fFilterSyncObj
) {
1686 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1687 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1688 if (fFilterThread
!= null) {
1689 fFilterThread
.cancel();
1690 fFilterThreadResume
= false;
1692 fFilterThread
= new FilterThread(filter
);
1693 fFilterThread
.start();
1695 fFilterThreadResume
= true;
1701 * Stop the filtering thread.
1703 protected void stopFilterThread() {
1704 synchronized (fFilterSyncObj
) {
1705 if (fFilterThread
!= null) {
1706 fFilterThread
.cancel();
1707 fFilterThread
= null;
1708 fFilterThreadResume
= false;
1717 * The filter to apply
1719 protected void applyFilter(ITmfFilter filter
) {
1722 fFilterMatchCount
= 0;
1723 fFilterCheckCount
= 0;
1724 fCache
.applyFilter(filter
);
1726 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1727 /* +1 for header row, +2 for top and bottom filter status rows */
1728 fTable
.setItemCount(3);
1729 startFilterThread();
1730 fireFilterApplied(filter
);
1734 * Clear all currently active filters.
1736 protected void clearFilters() {
1737 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1742 fCache
.clearFilter();
1744 for (final TableColumn column
: fTable
.getColumns()) {
1745 column
.setData(Key
.FILTER_OBJ
, null);
1746 column
.setData(Key
.FILTER_TXT
, null);
1748 fTable
.setData(Key
.FILTER_OBJ
, null);
1749 if (fTrace
!= null) {
1750 /* +1 for header row */
1751 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1);
1753 /* +1 for header row */
1754 fTable
.setItemCount(1);
1756 fFilterMatchCount
= 0;
1757 fFilterCheckCount
= 0;
1758 if (fSelectedRank
>= 0) {
1759 /* +1 for header row */
1760 fTable
.setSelection((int) fSelectedRank
+ 1);
1762 fTable
.setSelection(0);
1764 fireFilterApplied(null);
1765 updateStatusLine(null);
1767 // Set original width
1768 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1773 * Wrapper Thread object for the filtering thread.
1775 protected class FilterThread
extends Thread
{
1776 private final ITmfFilterTreeNode filter
;
1777 private TmfEventRequest request
;
1778 private boolean refreshBusy
= false;
1779 private boolean refreshPending
= false;
1780 private final Object syncObj
= new Object();
1786 * The filter this thread will be processing
1788 public FilterThread(final ITmfFilterTreeNode filter
) {
1789 super("Filter Thread"); //$NON-NLS-1$
1790 this.filter
= filter
;
1795 if (fTrace
== null) {
1798 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1799 if (nbRequested
<= 0) {
1802 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1803 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1805 public void handleData(final ITmfEvent event
) {
1806 super.handleData(event
);
1807 if (request
.isCancelled()) {
1810 boolean refresh
= false;
1811 if (filter
.matches(event
)) {
1812 final long rank
= fFilterCheckCount
;
1813 final int index
= (int) fFilterMatchCount
;
1814 fFilterMatchCount
++;
1815 fCache
.storeEvent(event
, rank
, index
);
1818 if (filter
instanceof TmfCollapseFilter
) {
1819 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1823 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1826 fFilterCheckCount
++;
1829 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1831 request
.waitForCompletion();
1832 } catch (final InterruptedException e
) {
1835 synchronized (fFilterSyncObj
) {
1836 fFilterThread
= null;
1837 if (fFilterThreadResume
) {
1838 fFilterThreadResume
= false;
1839 fFilterThread
= new FilterThread(filter
);
1840 fFilterThread
.start();
1846 * Refresh the filter.
1848 public void refreshTable() {
1849 synchronized (syncObj
) {
1851 refreshPending
= true;
1856 Display
.getDefault().asyncExec(new Runnable() {
1859 if (request
.isCancelled()) {
1862 if (fTable
.isDisposed()) {
1866 * +1 for header row, +2 for top and bottom filter status
1869 fTable
.setItemCount((int) fFilterMatchCount
+ 3);
1871 synchronized (syncObj
) {
1872 refreshBusy
= false;
1873 if (refreshPending
) {
1874 refreshPending
= false;
1883 * Cancel this filtering thread.
1885 public void cancel() {
1886 if (request
!= null) {
1893 * Go to the next item of a search.
1895 protected void searchNext() {
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 /* -1 for header row, +1 for next event */
1908 startIndex
= selectionIndex
;
1911 * header row is selected, start at top event
1913 /* -1 for header row */
1914 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1);
1916 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1917 if (eventFilter
!= null) {
1918 // -1 for top filter status row
1919 startIndex
= Math
.max(0, startIndex
- 1);
1921 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1922 fSearchThread
.schedule();
1927 * Go to the previous item of a search.
1929 protected void searchPrevious() {
1930 synchronized (fSearchSyncObj
) {
1931 if (fSearchThread
!= null) {
1934 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1935 if (searchFilter
== null) {
1938 final int selectionIndex
= fTable
.getSelectionIndex();
1940 if (selectionIndex
> 0) {
1941 /* -1 for header row, -1 for previous event */
1942 startIndex
= selectionIndex
- 2;
1945 * Header row is selected, start at precedent of top event
1947 /* -1 for header row, -1 for previous event */
1948 startIndex
= fTable
.getTopIndex() - 2;
1950 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1951 if (eventFilter
!= null) {
1952 /* -1 for top filter status row */
1953 startIndex
= startIndex
- 1;
1955 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1956 fSearchThread
.schedule();
1961 * Stop the search thread.
1963 protected void stopSearchThread() {
1964 fPendingGotoRank
= -1;
1965 synchronized (fSearchSyncObj
) {
1966 if (fSearchThread
!= null) {
1967 fSearchThread
.cancel();
1968 fSearchThread
= null;
1974 * Wrapper for the search thread.
1976 protected class SearchThread
extends Job
{
1978 private ITmfFilterTreeNode searchFilter
;
1979 private ITmfFilterTreeNode eventFilter
;
1980 private int startIndex
;
1981 private int direction
;
1983 private long foundRank
= -1;
1984 private TmfEventRequest request
;
1985 private ITmfTimestamp foundTimestamp
= null;
1990 * @param searchFilter
1992 * @param eventFilter
1995 * The index at which we should start searching
1996 * @param currentRank
1999 * In which direction should we search, forward or backwards
2001 public SearchThread(final ITmfFilterTreeNode searchFilter
,
2002 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
2003 final long currentRank
, final int direction
) {
2004 super(Messages
.TmfEventsTable_SearchingJobName
);
2005 this.searchFilter
= searchFilter
;
2006 this.eventFilter
= eventFilter
;
2007 this.startIndex
= startIndex
;
2008 this.rank
= currentRank
;
2009 this.direction
= direction
;
2013 protected IStatus
run(final IProgressMonitor monitor
) {
2014 if (fTrace
== null) {
2015 return Status
.OK_STATUS
;
2017 final Display display
= Display
.getDefault();
2018 if (startIndex
< 0) {
2019 rank
= (int) fTrace
.getNbEvents() - 1;
2021 * -1 for header row, -3 for header and top and bottom filter
2024 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) {
2027 int idx
= startIndex
;
2028 while (foundRank
== -1) {
2029 final CachedEvent event
= fCache
.peekEvent(idx
);
2030 if (event
== null) {
2034 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
2035 foundRank
= event
.rank
;
2036 foundTimestamp
= event
.event
.getTimestamp();
2039 if (direction
== Direction
.FORWARD
) {
2045 if (foundRank
== -1) {
2046 if (direction
== Direction
.FORWARD
) {
2048 if (rank
> (fTrace
.getNbEvents() - 1)) {
2054 rank
= (int) fTrace
.getNbEvents() - 1;
2059 final int startRank
= (int) rank
;
2060 boolean wrapped
= false;
2061 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
2062 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
2063 if (direction
== Direction
.BACKWARD
) {
2064 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
2066 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
2067 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
2068 long currentRank
= rank
;
2071 public void handleData(final ITmfEvent event
) {
2072 super.handleData(event
);
2073 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
2074 foundRank
= currentRank
;
2075 foundTimestamp
= event
.getTimestamp();
2076 if (direction
== Direction
.FORWARD
) {
2084 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
2086 request
.waitForCompletion();
2087 if (request
.isCancelled()) {
2088 return Status
.OK_STATUS
;
2090 } catch (final InterruptedException e
) {
2091 synchronized (fSearchSyncObj
) {
2092 fSearchThread
= null;
2094 return Status
.OK_STATUS
;
2096 if (foundRank
== -1) {
2097 if (direction
== Direction
.FORWARD
) {
2099 synchronized (fSearchSyncObj
) {
2100 fSearchThread
= null;
2102 return Status
.OK_STATUS
;
2104 nbRequested
= (int) rank
;
2110 rank
= (int) fTrace
.getNbEvents() - 1;
2113 if ((rank
<= startRank
) && wrapped
) {
2114 synchronized (fSearchSyncObj
) {
2115 fSearchThread
= null;
2117 return Status
.OK_STATUS
;
2122 int index
= (int) foundRank
;
2123 if (eventFilter
!= null) {
2124 index
= fCache
.getFilteredEventIndex(foundRank
);
2126 /* +1 for header row, +1 for top filter status row */
2127 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0);
2129 display
.asyncExec(new Runnable() {
2132 if (monitor
.isCanceled()) {
2135 if (fTable
.isDisposed()) {
2138 fTable
.setSelection(selection
);
2139 fSelectedRank
= foundRank
;
2140 fRawViewer
.selectAndReveal(fSelectedRank
);
2141 if (foundTimestamp
!= null) {
2142 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, foundTimestamp
));
2144 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
2145 synchronized (fSearchSyncObj
) {
2146 fSearchThread
= null;
2148 updateStatusLine(null);
2151 return Status
.OK_STATUS
;
2155 protected void canceling() {
2157 synchronized (fSearchSyncObj
) {
2158 fSearchThread
= null;
2164 * Create the resources.
2166 private void createResources() {
2167 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
.getForeground().getRGB()));
2168 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
2172 * Initialize the fonts.
2174 private void initializeFonts() {
2175 FontRegistry fontRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
2176 fFont
= fontRegistry
.get(FONT_DEFINITION_ID
);
2177 fBoldFont
= fontRegistry
.getBold(FONT_DEFINITION_ID
);
2178 fTable
.setFont(fFont
);
2179 /* Column header font cannot be set. See Bug 63038 */
2183 * Initialize the colors.
2185 private void initializeColors() {
2186 ColorRegistry colorRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
2187 fHighlightColor
= colorRegistry
.get(HIGHLIGHT_COLOR_DEFINITION_ID
);
2194 public void propertyChange(PropertyChangeEvent event
) {
2195 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2196 (FONT_DEFINITION_ID
.equals(event
.getProperty()))) {
2200 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2201 (HIGHLIGHT_COLOR_DEFINITION_ID
.equals(event
.getProperty()))) {
2210 protected void packColumns() {
2214 fTable
.setRedraw(false);
2216 TableColumn tableColumns
[] = fTable
.getColumns();
2217 for (int i
= 0; i
< tableColumns
.length
; i
++) {
2218 final TableColumn column
= tableColumns
[i
];
2219 packSingleColumn(i
, column
);
2222 // Make sure that redraw is always enabled.
2223 fTable
.setRedraw(true);
2228 private void packMarginColumn() {
2229 TableColumn
[] columns
= fTable
.getColumns();
2230 if (columns
.length
> 0) {
2231 packSingleColumn(0, columns
[0]);
2235 private void packSingleColumn(int i
, final TableColumn column
) {
2236 final int headerWidth
= column
.getWidth();
2239 * Workaround for Linux which doesn't consider the image width of
2240 * search/filter row in TableColumn.pack() after having executed
2241 * TableItem.setImage(null) for other rows than search/filter row.
2243 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2244 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2245 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2248 if (column
.getWidth() < headerWidth
) {
2249 column
.setWidth(headerWidth
);
2254 * Get the array of item strings (e.g., what to display in each cell of the
2255 * table row) corresponding to the columns and trace event passed in
2256 * parameter. The order of the Strings in the returned array will correspond
2257 * to the iteration order of 'columns'.
2260 * To ensure consistent results, make sure only call this within a scope
2261 * synchronized on 'columns'! If the order of 'columns' changes right after
2262 * this method is called, the returned value won't be ordered correctly
2265 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2266 if (event
== null) {
2267 return EMPTY_STRING_ARRAY
;
2269 synchronized (columns
) {
2270 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2271 for (TmfEventTableColumn column
: columns
) {
2272 ITmfEvent passedEvent
= event
;
2273 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2275 * Make sure that the event object from the trace is passed
2276 * to all columns but the TmfMarginColumn
2278 passedEvent
= ((CachedEvent
) event
).event
;
2280 if (passedEvent
== null) {
2281 itemStrings
.add(EMPTY_STRING
);
2283 itemStrings
.add(column
.getItemString(passedEvent
));
2287 return itemStrings
.toArray(new String
[0]);
2292 * Get the contents of the row in the events table corresponding to an
2293 * event. The order of the elements corresponds to the current order of the
2297 * The event printed in this row
2298 * @return The event row entries
2300 public String
[] getItemStrings(ITmfEvent event
) {
2301 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2302 for (int i
: fTable
.getColumnOrder()) {
2303 columns
.add(fColumns
.get(i
));
2305 return getItemStrings(columns
, event
);
2309 * Returns an array of zero-relative integers that map the creation order of
2310 * the receiver's columns to the order in which they are currently being
2313 * Specifically, the indices of the returned array represent the current
2314 * visual order of the columns, and the contents of the array represent the
2315 * creation order of the columns.
2317 * @return the current visual order of the receiver's columns
2320 public int[] getColumnOrder() {
2321 return fColumnOrder
;
2325 * Sets the order that the columns in the receiver should be displayed in to
2326 * the given argument which is described in terms of the zero-relative
2327 * ordering of when the columns were added.
2329 * Specifically, the contents of the array represent the original position
2330 * of each column at the time its creation.
2333 * the new order to display the columns
2336 public void setColumnOrder(int[] order
) {
2337 if (order
== null || order
.length
!= fTable
.getColumns().length
) {
2340 fTable
.setColumnOrder(order
);
2341 fColumnOrder
= fTable
.getColumnOrder();
2345 * Notify this table that is got the UI focus.
2347 public void setFocus() {
2352 * Assign a new trace to this event table.
2355 * The trace to assign to this event table
2356 * @param disposeOnClose
2357 * true if the trace should be disposed when the table is
2360 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2361 if ((fTrace
!= null) && fDisposeOnClose
) {
2367 fDisposeOnClose
= disposeOnClose
;
2369 // Perform the updates on the UI thread
2370 fTable
.getDisplay().syncExec(new Runnable() {
2374 fCache
.setTrace(fTrace
); // Clear the cache
2375 if (fTrace
!= null) {
2376 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2377 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2378 // +1 for header row
2379 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1);
2382 fFilterMatchCount
= 0;
2383 fFilterCheckCount
= 0;
2385 * +1 for header row, +2 for top and bottom filter
2388 fTable
.setItemCount(3);
2389 startFilterThread();
2393 fRawViewer
.setTrace(fTrace
);
2399 * Assign the status line manager
2401 * @param statusLineManager
2402 * The status line manager, or null to disable status line
2405 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2406 if (fStatusLineManager
!= null && statusLineManager
== null) {
2407 fStatusLineManager
.setMessage(EMPTY_STRING
);
2409 fStatusLineManager
= statusLineManager
;
2412 private void updateStatusLine(ITmfTimestamp delta
) {
2413 if (fStatusLineManager
!= null) {
2414 if (delta
!= null) {
2415 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2417 fStatusLineManager
.setMessage(null);
2422 // ------------------------------------------------------------------------
2424 // ------------------------------------------------------------------------
2427 * Notify that the event cache has been updated
2430 * Also notify if the populating of the cache is complete, or
2433 public void cacheUpdated(final boolean completed
) {
2434 synchronized (fCacheUpdateSyncObj
) {
2435 if (fCacheUpdateBusy
) {
2436 fCacheUpdatePending
= true;
2437 fCacheUpdateCompleted
= completed
;
2440 fCacheUpdateBusy
= true;
2442 // Event cache is now updated. Perform update on the UI thread
2443 if (!fTable
.isDisposed()) {
2444 fTable
.getDisplay().asyncExec(new Runnable() {
2447 if (!fTable
.isDisposed()) {
2452 populateCompleted();
2454 synchronized (fCacheUpdateSyncObj
) {
2455 fCacheUpdateBusy
= false;
2456 if (fCacheUpdatePending
) {
2457 fCacheUpdatePending
= false;
2458 cacheUpdated(fCacheUpdateCompleted
);
2467 * Callback for when populating the table is complete.
2469 protected void populateCompleted() {
2470 // Nothing by default;
2473 // ------------------------------------------------------------------------
2474 // ISelectionProvider
2475 // ------------------------------------------------------------------------
2478 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2479 selectionChangedListeners
.add(listener
);
2483 public ISelection
getSelection() {
2484 if (fTable
== null || fTable
.isDisposed()) {
2485 return StructuredSelection
.EMPTY
;
2487 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2488 for (TableItem item
: fTable
.getSelection()) {
2489 if (item
.getData() != null) {
2490 list
.add(item
.getData());
2493 return new StructuredSelection(list
);
2497 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2498 selectionChangedListeners
.remove(listener
);
2502 public void setSelection(ISelection selection
) {
2507 * Notifies any selection changed listeners that the viewer's selection has
2508 * changed. Only listeners registered at the time this method is called are
2512 * a selection changed event
2514 * @see ISelectionChangedListener#selectionChanged
2516 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2517 Object
[] listeners
= selectionChangedListeners
.getListeners();
2518 for (int i
= 0; i
< listeners
.length
; ++i
) {
2519 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2520 SafeRunnable
.run(new SafeRunnable() {
2523 l
.selectionChanged(event
);
2529 // ------------------------------------------------------------------------
2530 // Bookmark handling
2531 // ------------------------------------------------------------------------
2534 * Add a bookmark to this event table.
2536 * @param bookmarksFile
2537 * The file to use for the bookmarks
2539 public void addBookmark(final IFile bookmarksFile
) {
2540 fBookmarksFile
= bookmarksFile
;
2541 final TableItem
[] selection
= fTable
.getSelection();
2542 if (selection
.length
> 0) {
2543 final TableItem tableItem
= selection
[0];
2544 if (tableItem
.getData(Key
.RANK
) != null) {
2545 final StringBuffer defaultMessage
= new StringBuffer();
2546 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2548 defaultMessage
.append(", "); //$NON-NLS-1$
2550 defaultMessage
.append(tableItem
.getText(i
));
2552 final InputDialog dialog
= new MultiLineInputDialog(
2553 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2554 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2555 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2556 defaultMessage
.toString());
2557 if (dialog
.open() == Window
.OK
) {
2558 final String message
= dialog
.getValue();
2560 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2561 if (bookmark
.exists()) {
2562 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2563 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2564 final int location
= rank
.intValue();
2565 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2566 fBookmarksMap
.put(rank
, bookmark
.getId());
2569 } catch (final CoreException e
) {
2570 displayException(e
);
2579 * Remove a bookmark from this event table.
2582 * The bookmark to remove
2584 public void removeBookmark(final IMarker bookmark
) {
2585 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2586 if (entry
.getValue().equals(bookmark
.getId())) {
2587 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2594 private void toggleBookmark(final Long rank
) {
2595 if (fBookmarksFile
== null) {
2598 if (fBookmarksMap
.containsKey(rank
)) {
2599 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2602 for (long markerId
: markerIds
) {
2603 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2604 if (bookmark
!= null) {
2608 } catch (final CoreException e
) {
2609 displayException(e
);
2612 addBookmark(fBookmarksFile
);
2617 * Refresh the bookmarks assigned to this trace, from the contents of a
2620 * @param bookmarksFile
2621 * The bookmark file to use
2623 public void refreshBookmarks(final IFile bookmarksFile
) {
2624 fBookmarksFile
= bookmarksFile
;
2625 if (bookmarksFile
== null) {
2626 fBookmarksMap
.clear();
2631 fBookmarksMap
.clear();
2632 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2633 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2634 if (location
!= -1) {
2635 final long rank
= location
;
2636 fBookmarksMap
.put(rank
, bookmark
.getId());
2640 } catch (final CoreException e
) {
2641 displayException(e
);
2646 public void gotoMarker(final IMarker marker
) {
2647 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2650 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2651 // +1 for top filter status row
2652 index
= fCache
.getFilteredEventIndex(rank
) + 1;
2653 } else if (rank
>= fTable
.getItemCount()) {
2654 fPendingGotoRank
= rank
;
2656 fSelectedRank
= rank
;
2657 fTable
.setSelection(index
+ 1); // +1 for header row
2658 updateStatusLine(null);
2662 // ------------------------------------------------------------------------
2664 // ------------------------------------------------------------------------
2667 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2671 // ------------------------------------------------------------------------
2673 // ------------------------------------------------------------------------
2676 * Handler for the trace updated signal
2679 * The incoming signal
2682 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2683 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2686 // Perform the refresh on the UI thread
2687 Display
.getDefault().asyncExec(new Runnable() {
2690 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2691 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2692 /* +1 for header row */
2693 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1);
2694 /* +1 for header row */
2695 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) {
2696 /* +1 for header row */
2697 fTable
.setSelection((int) fPendingGotoRank
+ 1);
2698 fPendingGotoRank
= -1;
2699 updateStatusLine(null);
2702 startFilterThread();
2705 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2706 fRawViewer
.refreshEventCount();
2713 * Handler for the selection range signal.
2716 * The incoming signal
2720 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
2721 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2724 * Create a request for one event that will be queued after other
2725 * ongoing requests. When this request is completed do the work to
2726 * select the actual event with the timestamp specified in the
2727 * signal. This procedure prevents the method fTrace.getRank() from
2728 * interfering and delaying ongoing requests.
2730 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2731 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2733 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2736 public void handleData(final ITmfEvent event
) {
2737 super.handleData(event
);
2741 public void handleSuccess() {
2742 super.handleSuccess();
2743 if (fTrace
== null) {
2748 * Verify if the event is within the trace range and adjust
2751 ITmfTimestamp timestamp
= ts
;
2752 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2753 timestamp
= fTrace
.getStartTime();
2755 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2756 timestamp
= fTrace
.getEndTime();
2759 // Get the rank of the selected event in the table
2760 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2761 final long rank
= context
.getRank();
2763 fSelectedRank
= rank
;
2765 fTable
.getDisplay().asyncExec(new Runnable() {
2768 // Return if table is disposed
2769 if (fTable
.isDisposed()) {
2773 int index
= (int) rank
;
2774 if (fTable
.isDisposed()) {
2777 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2778 /* +1 for top filter status row */
2779 index
= fCache
.getFilteredEventIndex(rank
) + 1;
2781 /* +1 for header row */
2782 fTable
.setSelection(index
+ 1);
2783 fRawViewer
.selectAndReveal(rank
);
2784 updateStatusLine(null);
2790 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2794 // ------------------------------------------------------------------------
2796 // ------------------------------------------------------------------------
2799 * Display an exception in a message box
2804 private static void displayException(final Exception e
) {
2805 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2806 mb
.setText(e
.getClass().getSimpleName());
2807 mb
.setMessage(e
.getMessage());
2814 public void refresh() {
2821 * Margin column for images and special text (e.g. collapse count)
2823 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2825 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2828 public String
getName() {
2829 return EMPTY_STRING
;
2833 public String
resolve(ITmfEvent event
) {
2834 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2835 return EMPTY_STRING
;
2837 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2841 public String
getHelpText() {
2842 return EMPTY_STRING
;
2849 public TmfMarginColumn() {
2850 super(MARGIN_ASPECT
);