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 * Matthew Khouzam - Add hide columns
17 *******************************************************************************/
19 package org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
;
21 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
23 import java
.io
.FileNotFoundException
;
24 import java
.lang
.reflect
.InvocationTargetException
;
25 import java
.util
.ArrayList
;
26 import java
.util
.Collection
;
27 import java
.util
.HashMap
;
28 import java
.util
.LinkedList
;
29 import java
.util
.List
;
30 import java
.util
.Map
.Entry
;
31 import java
.util
.regex
.Matcher
;
32 import java
.util
.regex
.Pattern
;
33 import java
.util
.regex
.PatternSyntaxException
;
35 import org
.eclipse
.core
.commands
.Command
;
36 import org
.eclipse
.core
.commands
.ExecutionException
;
37 import org
.eclipse
.core
.commands
.NotEnabledException
;
38 import org
.eclipse
.core
.commands
.NotHandledException
;
39 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
40 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
41 import org
.eclipse
.core
.expressions
.IEvaluationContext
;
42 import org
.eclipse
.core
.resources
.IFile
;
43 import org
.eclipse
.core
.resources
.IMarker
;
44 import org
.eclipse
.core
.resources
.IResource
;
45 import org
.eclipse
.core
.resources
.IResourceVisitor
;
46 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
47 import org
.eclipse
.core
.runtime
.CoreException
;
48 import org
.eclipse
.core
.runtime
.IPath
;
49 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
50 import org
.eclipse
.core
.runtime
.IStatus
;
51 import org
.eclipse
.core
.runtime
.ListenerList
;
52 import org
.eclipse
.core
.runtime
.Path
;
53 import org
.eclipse
.core
.runtime
.Status
;
54 import org
.eclipse
.core
.runtime
.jobs
.Job
;
55 import org
.eclipse
.emf
.common
.util
.URI
;
56 import org
.eclipse
.emf
.ecore
.EValidator
;
57 import org
.eclipse
.jdt
.annotation
.NonNull
;
58 import org
.eclipse
.jface
.action
.Action
;
59 import org
.eclipse
.jface
.action
.IAction
;
60 import org
.eclipse
.jface
.action
.IMenuListener
;
61 import org
.eclipse
.jface
.action
.IMenuManager
;
62 import org
.eclipse
.jface
.action
.IStatusLineManager
;
63 import org
.eclipse
.jface
.action
.MenuManager
;
64 import org
.eclipse
.jface
.action
.Separator
;
65 import org
.eclipse
.jface
.dialogs
.InputDialog
;
66 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
67 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
68 import org
.eclipse
.jface
.resource
.ColorRegistry
;
69 import org
.eclipse
.jface
.resource
.FontRegistry
;
70 import org
.eclipse
.jface
.resource
.JFaceResources
;
71 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
72 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
73 import org
.eclipse
.jface
.util
.OpenStrategy
;
74 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
75 import org
.eclipse
.jface
.util
.SafeRunnable
;
76 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
77 import org
.eclipse
.jface
.viewers
.ISelection
;
78 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
79 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
80 import org
.eclipse
.jface
.viewers
.LabelProvider
;
81 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
82 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
83 import org
.eclipse
.jface
.window
.Window
;
84 import org
.eclipse
.swt
.SWT
;
85 import org
.eclipse
.swt
.custom
.SashForm
;
86 import org
.eclipse
.swt
.custom
.StyleRange
;
87 import org
.eclipse
.swt
.custom
.TableEditor
;
88 import org
.eclipse
.swt
.events
.ControlAdapter
;
89 import org
.eclipse
.swt
.events
.ControlEvent
;
90 import org
.eclipse
.swt
.events
.FocusAdapter
;
91 import org
.eclipse
.swt
.events
.FocusEvent
;
92 import org
.eclipse
.swt
.events
.KeyAdapter
;
93 import org
.eclipse
.swt
.events
.KeyEvent
;
94 import org
.eclipse
.swt
.events
.MouseAdapter
;
95 import org
.eclipse
.swt
.events
.MouseEvent
;
96 import org
.eclipse
.swt
.events
.SelectionAdapter
;
97 import org
.eclipse
.swt
.events
.SelectionEvent
;
98 import org
.eclipse
.swt
.graphics
.Color
;
99 import org
.eclipse
.swt
.graphics
.Font
;
100 import org
.eclipse
.swt
.graphics
.GC
;
101 import org
.eclipse
.swt
.graphics
.Image
;
102 import org
.eclipse
.swt
.graphics
.Point
;
103 import org
.eclipse
.swt
.graphics
.Rectangle
;
104 import org
.eclipse
.swt
.layout
.FillLayout
;
105 import org
.eclipse
.swt
.layout
.GridData
;
106 import org
.eclipse
.swt
.layout
.GridLayout
;
107 import org
.eclipse
.swt
.widgets
.Composite
;
108 import org
.eclipse
.swt
.widgets
.Display
;
109 import org
.eclipse
.swt
.widgets
.Event
;
110 import org
.eclipse
.swt
.widgets
.Label
;
111 import org
.eclipse
.swt
.widgets
.Listener
;
112 import org
.eclipse
.swt
.widgets
.Menu
;
113 import org
.eclipse
.swt
.widgets
.MessageBox
;
114 import org
.eclipse
.swt
.widgets
.Shell
;
115 import org
.eclipse
.swt
.widgets
.TableColumn
;
116 import org
.eclipse
.swt
.widgets
.TableItem
;
117 import org
.eclipse
.swt
.widgets
.Text
;
118 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
119 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
120 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
121 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
122 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.CopyToClipboardOperation
;
123 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
124 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfContentFieldAspect
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
141 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
142 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
143 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
144 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
145 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
146 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
147 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
148 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
149 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
150 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
151 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
152 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
153 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
154 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
155 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
156 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
157 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
158 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
159 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
160 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
161 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
162 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
163 import org
.eclipse
.ui
.IEditorSite
;
164 import org
.eclipse
.ui
.IWorkbenchPage
;
165 import org
.eclipse
.ui
.IWorkbenchPartSite
;
166 import org
.eclipse
.ui
.PlatformUI
;
167 import org
.eclipse
.ui
.commands
.ICommandService
;
168 import org
.eclipse
.ui
.dialogs
.ListDialog
;
169 import org
.eclipse
.ui
.handlers
.IHandlerService
;
170 import org
.eclipse
.ui
.ide
.IDE
;
171 import org
.eclipse
.ui
.ide
.IGotoMarker
;
172 import org
.eclipse
.ui
.themes
.ColorUtil
;
173 import org
.eclipse
.ui
.themes
.IThemeManager
;
175 import com
.google
.common
.base
.Joiner
;
176 import com
.google
.common
.collect
.HashMultimap
;
177 import com
.google
.common
.collect
.ImmutableList
;
178 import com
.google
.common
.collect
.Multimap
;
181 * The generic TMF Events table
183 * This is a view that will list events that are read from a trace.
185 * @author Francois Chouinard
186 * @author Patrick Tasse
188 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
, IPropertyChangeListener
{
191 * Empty string array, used by {@link #getItemStrings}.
193 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
198 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
200 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
202 private static final String FONT_DEFINITION_ID
= "org.eclipse.tracecompass.tmf.ui.font.eventtable"; //$NON-NLS-1$
203 private static final String HIGHLIGHT_COLOR_DEFINITION_ID
= "org.eclipse.tracecompass.tmf.ui.color.eventtable.highlight"; //$NON-NLS-1$
205 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
206 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
207 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
208 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
209 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
210 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
211 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
212 private static final Image FILTER_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
213 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
214 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
215 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
216 private static final int MAX_CACHE_SIZE
= 1000;
218 private static final int MARGIN_COLUMN_INDEX
= 0;
219 private static final int FILTER_SUMMARY_INDEX
= 1;
220 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
223 * The events table search/filter/data keys
225 * @author Patrick Tasse
226 * @noimplement This interface only contains Event Table specific
227 * static definitions.
229 public interface Key
{
232 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
235 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
238 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
241 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
244 String TIMESTAMP
= "$time"; //$NON-NLS-1$
247 String RANK
= "$rank"; //$NON-NLS-1$
249 /** Bookmark indicator */
250 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
252 /** Event aspect represented by this column */
253 String ASPECT
= "$aspect"; //$NON-NLS-1$
256 * Table item list of style ranges
260 String STYLE_RANGES
= "$style_ranges"; //$NON-NLS-1$
263 * The width of a table item
267 String WIDTH
= "$width"; //$NON-NLS-1$
271 * The events table search/filter state
274 * @author Patrick Tasse
276 public static enum HeaderState
{
277 /** A search is being run */
280 /** A filter is applied */
284 interface Direction
{
289 // ------------------------------------------------------------------------
291 // ------------------------------------------------------------------------
293 /** The virtual event table */
294 protected TmfVirtualTable fTable
;
296 private Composite fComposite
;
297 private SashForm fSashForm
;
298 private TmfRawEventViewer fRawViewer
;
299 private ITmfTrace fTrace
;
300 private volatile boolean fPackDone
= false;
301 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
302 private long fSelectedRank
= -1;
303 private long fSelectedBeginRank
= -1;
304 private ITmfTimestamp fSelectedBeginTimestamp
= null;
305 private IStatusLineManager fStatusLineManager
= null;
308 private long fFilterMatchCount
;
309 private long fFilterCheckCount
;
310 private FilterThread fFilterThread
;
311 private boolean fFilterThreadResume
= false;
312 private final Object fFilterSyncObj
= new Object();
313 private SearchThread fSearchThread
;
314 private final Object fSearchSyncObj
= new Object();
317 * List of selection change listeners (element type:
318 * <code>ISelectionChangedListener</code>).
320 * @see #fireSelectionChanged
322 private ListenerList selectionChangedListeners
= new ListenerList();
324 // Bookmark map <Rank, MarkerId>
325 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
326 private IFile fBookmarksFile
;
327 private long fPendingGotoRank
= -1;
330 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
331 private Color fGrayColor
;
332 private Color fGreenColor
;
333 private Color fHighlightColor
;
335 private Font fBoldFont
;
337 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
340 private final TmfEventsCache fCache
;
341 private boolean fCacheUpdateBusy
= false;
342 private boolean fCacheUpdatePending
= false;
343 private boolean fCacheUpdateCompleted
= false;
344 private final Object fCacheUpdateSyncObj
= new Object();
346 // Keep track of column order, it is needed after table is disposed
347 private int[] fColumnOrder
;
349 private boolean fDisposeOnClose
;
351 private Menu fHeaderMenu
;
353 private Menu fTablePopup
;
355 private Menu fRawTablePopup
;
357 private Point fLastMenuCursorLocation
;
358 private MenuManager fRawViewerPopupMenuManager
;
359 private MenuManager fTablePopupMenuManager
;
360 private MenuManager fHeaderPopupMenuManager
;
362 // ------------------------------------------------------------------------
364 // ------------------------------------------------------------------------
367 * Basic constructor, using the default set of columns
370 * The parent composite UI object
372 * The size of the event table cache
374 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
375 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
379 * Legacy constructor, using ColumnData to define columns
382 * The parent composite UI object
384 * The size of the event table cache
386 * The column data array
387 * @deprecated Deprecated constructor, use
388 * {@link #TmfEventsTable(Composite, int, Collection)}
391 public TmfEventsTable(final Composite parent
, int cacheSize
,
392 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
394 * We'll do a "best-effort" to keep trace types still using this API to
395 * keep working, by defining a TmfEventTableColumn for each ColumnData
398 this(parent
, cacheSize
, convertFromColumnData(columnData
));
402 private static @NonNull Iterable
<ITmfEventAspect
> convertFromColumnData(
403 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
405 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
406 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
407 String fieldName
= col
.header
;
408 if (fieldName
!= null) {
409 builder
.add(new TmfContentFieldAspect(fieldName
, fieldName
));
412 return checkNotNull(builder
.build());
416 * Standard constructor, where we define which columns to use.
419 * The parent composite UI object
421 * The size of the event table cache
423 * The event aspects to display in this table. One column per
424 * aspect will be created.
426 * The iteration order of this collection will correspond to the
427 * initial ordering of the columns in the table.
430 public TmfEventsTable(final Composite parent
, int cacheSize
,
431 @NonNull Iterable
<ITmfEventAspect
> aspects
) {
432 super("TmfEventsTable"); //$NON-NLS-1$
434 fComposite
= new Composite(parent
, SWT
.NONE
);
435 final GridLayout gl
= new GridLayout(1, false);
438 gl
.verticalSpacing
= 0;
439 fComposite
.setLayout(gl
);
441 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
442 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
444 // Create a virtual table
445 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
446 fTable
= new TmfVirtualTable(fSashForm
, style
);
448 // Set the table layout
449 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
450 fTable
.setLayoutData(layoutData
);
452 // Some cosmetic enhancements
453 fTable
.setHeaderVisible(true);
454 fTable
.setLinesVisible(true);
457 for (ITmfEventAspect aspect
: aspects
) {
458 if (aspect
!= null) {
459 fColumns
.add(new TmfEventTableColumn(aspect
));
463 TmfMarginColumn collapseCol
= new TmfMarginColumn();
464 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
466 fHeaderMenu
= new Menu(fTable
);
467 // Create the UI columns in the table
468 for (TmfEventTableColumn col
: fColumns
) {
469 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
470 column
.setText(col
.getHeaderName());
471 column
.setToolTipText(col
.getHeaderTooltip());
472 column
.setData(Key
.ASPECT
, col
.getEventAspect());
474 if (col
instanceof TmfMarginColumn
) {
475 column
.setResizable(false);
477 column
.setMoveable(true);
478 column
.setData(Key
.WIDTH
, -1);
480 column
.addControlListener(new ControlAdapter() {
482 * Make sure that the margin column is always first and keep the
483 * column order variable up to date.
486 public void controlMoved(ControlEvent e
) {
487 int[] order
= fTable
.getColumnOrder();
488 if (order
[0] == MARGIN_COLUMN_INDEX
) {
489 fColumnOrder
= order
;
492 for (int i
= order
.length
- 1; i
> 0; i
--) {
493 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
494 order
[i
] = order
[i
- 1];
495 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
498 fTable
.setColumnOrder(order
);
499 fColumnOrder
= fTable
.getColumnOrder();
503 fColumnOrder
= fTable
.getColumnOrder();
505 // Set the frozen row for header row
506 fTable
.setFrozenRowCount(1);
508 // Create the header row cell editor
509 createHeaderEditor();
511 // Handle the table item selection
512 fTable
.addSelectionListener(new SelectionAdapter() {
514 public void widgetSelected(final SelectionEvent e
) {
515 if (e
.item
== null) {
518 updateStatusLine(null);
519 if (fTable
.getSelectionIndices().length
> 0) {
520 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
521 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
522 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
526 if (fTable
.getSelectionIndices().length
== 1) {
527 fSelectedBeginRank
= fSelectedRank
;
529 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
530 final ITmfTimestamp ts
= NonNullUtils
.checkNotNull((ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
));
531 if (fTable
.getSelectionIndices().length
== 1) {
532 fSelectedBeginTimestamp
= ts
;
534 ITmfTimestamp selectedBeginTimestamp
= fSelectedBeginTimestamp
;
535 if (selectedBeginTimestamp
!= null) {
536 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, selectedBeginTimestamp
, ts
));
537 if (fTable
.getSelectionIndices().length
== 2) {
538 updateStatusLine(ts
.getDelta(selectedBeginTimestamp
));
542 if (fTable
.getSelectionIndices().length
== 1) {
543 fSelectedBeginTimestamp
= null;
547 if (e
.item
.getData() instanceof ITmfEvent
) {
548 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
549 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
551 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
556 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
557 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
558 fCache
= new TmfEventsCache(realCacheSize
, this);
560 // Handle the table item requests
561 fTable
.addListener(SWT
.SetData
, new Listener() {
564 public void handleEvent(final Event event
) {
566 final TableItem item
= (TableItem
) event
.item
;
567 int index
= event
.index
- 1; // -1 for the header row
569 if (event
.index
== 0) {
570 setHeaderRowItemData(item
);
574 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
575 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
576 setFilterStatusRowItemData(item
);
579 /* -1 for top filter status row */
583 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
584 if (cachedEvent
!= null) {
585 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
589 // Else, fill the cache asynchronously (and off the UI thread)
594 fTable
.addListener(SWT
.MenuDetect
, new Listener() {
596 public void handleEvent(Event event
) {
597 fLastMenuCursorLocation
= new Point(event
.x
, event
.y
);
598 Point pt
= fTable
.getDisplay().map(null, fTable
, fLastMenuCursorLocation
);
599 Rectangle clientArea
= fTable
.getClientArea();
600 boolean header
= clientArea
.y
<= pt
.y
&& pt
.y
< (clientArea
.y
+ fTable
.getHeaderHeight());
601 fTable
.setMenu(header ? fHeaderMenu
: fTablePopup
);
605 fTable
.addMouseListener(new MouseAdapter() {
607 public void mouseDoubleClick(final MouseEvent event
) {
608 if (event
.button
!= 1) {
611 // Identify the selected row
612 final Point point
= new Point(event
.x
, event
.y
);
613 final TableItem item
= fTable
.getItem(point
);
615 final Rectangle imageBounds
= item
.getImageBounds(0);
616 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
617 if (imageBounds
.contains(point
)) {
618 final Long rank
= (Long
) item
.getData(Key
.RANK
);
620 toggleBookmark(rank
);
627 final Listener tooltipListener
= new Listener() {
628 Shell tooltipShell
= null;
631 public void handleEvent(final Event event
) {
632 switch (event
.type
) {
634 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
638 final Long rank
= (Long
) item
.getData(Key
.RANK
);
642 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
643 final Rectangle bounds
= item
.getImageBounds(0);
644 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
645 if (!bounds
.contains(event
.x
, event
.y
)) {
648 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
649 tooltipShell
.dispose();
651 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
652 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
653 final FillLayout layout
= new FillLayout();
654 layout
.marginWidth
= 2;
655 tooltipShell
.setLayout(layout
);
656 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
657 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
658 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
659 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
661 label
.addListener(SWT
.MouseExit
, this);
662 label
.addListener(SWT
.MouseDown
, this);
663 label
.addListener(SWT
.MouseWheel
, this);
664 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
666 * Bug in Linux. The coordinates of the event have an origin
667 * that excludes the table header but the method toDisplay()
668 * expects coordinates relative to an origin that includes
673 y
+= fTable
.getHeaderHeight();
675 Point pt
= fTable
.toDisplay(event
.x
, y
);
676 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
677 pt
.y
+= item
.getBounds().height
;
678 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
679 tooltipShell
.setVisible(true);
687 if (tooltipShell
!= null) {
688 tooltipShell
.dispose();
698 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
699 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
700 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
701 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
702 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
703 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
704 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
706 fTable
.addListener(SWT
.EraseItem
, new Listener() {
708 public void handleEvent(Event event
) {
709 TableItem item
= (TableItem
) event
.item
;
710 List
<?
> styleRanges
= (List
<?
>) item
.getData(Key
.STYLE_RANGES
);
713 Color background
= item
.getBackground(event
.index
);
715 * Paint the background if it is not the default system color.
716 * In Windows, if you let the widget draw the background, it
717 * will not show the item's background color if the item is
718 * selected or hot. If there are no style ranges and the item
719 * background is the default system color, we do not want to
720 * paint it or otherwise we would override the platform theme
721 * (e.g. alternating colors).
723 if (styleRanges
!= null || !background
.equals(item
.getParent().getBackground())) {
724 // we will paint the table item's background
725 event
.detail
&= ~SWT
.BACKGROUND
;
727 // paint the item's default background
728 gc
.setBackground(background
);
729 gc
.fillRectangle(event
.x
, event
.y
, event
.width
, event
.height
);
733 * We will paint the table item's foreground. In Windows, if you
734 * paint the background but let the widget draw the foreground,
735 * it will override your background, unless the item is selected
738 event
.detail
&= ~SWT
.FOREGROUND
;
740 // paint the highlighted background for all style ranges
741 if (styleRanges
!= null) {
742 Rectangle textBounds
= item
.getTextBounds(event
.index
);
743 String text
= item
.getText(event
.index
);
744 for (Object o
: styleRanges
) {
745 if (o
instanceof StyleRange
) {
746 StyleRange styleRange
= (StyleRange
) o
;
747 if (styleRange
.data
.equals(event
.index
)) {
748 int startIndex
= styleRange
.start
;
749 int endIndex
= startIndex
+ styleRange
.length
;
750 int startX
= gc
.textExtent(text
.substring(0, startIndex
)).x
;
751 int endX
= gc
.textExtent(text
.substring(0, endIndex
)).x
;
752 gc
.setBackground(styleRange
.background
);
753 gc
.fillRectangle(textBounds
.x
+ startX
, textBounds
.y
, (endX
- startX
), textBounds
.height
);
761 fTable
.addListener(SWT
.PaintItem
, new Listener() {
763 public void handleEvent(Event event
) {
764 TableItem item
= (TableItem
) event
.item
;
766 // we promised to paint the table item's foreground
768 Image image
= item
.getImage(event
.index
);
770 Rectangle imageBounds
= item
.getImageBounds(event
.index
);
772 * The image bounds don't match the default image position.
775 gc
.drawImage(image
, imageBounds
.x
+ 1, imageBounds
.y
+ 3);
777 gc
.drawImage(image
, imageBounds
.x
, imageBounds
.y
+ 1);
780 gc
.setForeground(item
.getForeground(event
.index
));
781 gc
.setFont(item
.getFont(event
.index
));
782 String text
= item
.getText(event
.index
);
783 Rectangle textBounds
= item
.getTextBounds(event
.index
);
785 * The text bounds don't match the default text position.
788 gc
.drawText(text
, textBounds
.x
+ 1, textBounds
.y
+ 3, true);
790 gc
.drawText(text
, textBounds
.x
- 1, textBounds
.y
+ 2, true);
800 PlatformUI
.getWorkbench().getThemeManager().addPropertyChangeListener(this);
802 ColorSettingsManager
.addColorSettingsListener(this);
804 fTable
.setItemCount(1); // +1 for header row
806 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
808 fRawViewer
.addSelectionListener(new Listener() {
810 public void handleEvent(final Event e
) {
811 if (fTrace
== null) {
815 if (e
.data
instanceof Long
) {
816 rank
= (Long
) e
.data
;
817 } else if (e
.data
instanceof ITmfLocation
) {
818 rank
= findRank((ITmfLocation
) e
.data
);
822 int index
= (int) rank
;
823 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
824 // +1 for top filter status row
825 index
= fCache
.getFilteredEventIndex(rank
) + 1;
828 fTable
.setSelection(index
+ 1);
829 fSelectedRank
= rank
;
830 fSelectedBeginRank
= fSelectedRank
;
831 updateStatusLine(null);
832 final TableItem
[] selection
= fTable
.getSelection();
833 if ((selection
!= null) && (selection
.length
> 0)) {
834 TableItem item
= fTable
.getSelection()[0];
835 final TmfTimestamp ts
= (TmfTimestamp
) item
.getData(Key
.TIMESTAMP
);
837 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, ts
));
839 if (item
.getData() instanceof ITmfEvent
) {
840 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) item
.getData()));
841 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(item
.getData())));
843 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
848 private long findRank(final ITmfLocation selectedLocation
) {
849 final double selectedRatio
= fTrace
.getLocationRatio(selectedLocation
);
851 long high
= fTrace
.getNbEvents();
852 long rank
= high
/ 2;
854 while (ratio
!= selectedRatio
) {
855 ITmfContext context
= fTrace
.seekEvent(rank
);
856 ratio
= fTrace
.getLocationRatio(context
.getLocation());
858 if (ratio
< selectedRatio
) {
860 rank
= (rank
+ high
) / 2;
861 } else if (ratio
> selectedRatio
) {
863 rank
= (rank
+ low
) / 2;
865 if ((high
- low
) < 2) {
873 fSashForm
.setWeights(new int[] { 1, 1 });
874 fRawViewer
.setVisible(false);
880 * Checked menu creator to make columns visible or not.
887 private static IAction
createHeaderAction(final TableColumn column
) {
888 final IAction columnMenuAction
= new Action(column
.getText(), IAction
.AS_CHECK_BOX
) {
892 column
.setWidth((int) column
.getData(Key
.WIDTH
));
893 column
.setResizable(true);
895 column
.setData(Key
.WIDTH
, column
.getWidth());
897 column
.setResizable(false);
901 columnMenuAction
.setChecked(column
.getResizable());
902 return columnMenuAction
;
905 private IAction
createResetHeaderAction() {
906 return new Action(Messages
.TmfEventsTable_ShowAll
) {
909 for (TableColumn column
: fTable
.getColumns()) {
910 final Object widthVal
= column
.getData(Key
.WIDTH
);
911 if (widthVal
instanceof Integer
) {
912 Integer width
= (Integer
) widthVal
;
913 if (!column
.getResizable()) {
914 column
.setWidth(width
);
915 column
.setResizable(true);
917 * This is because Linux always resizes the last
918 * column to fill in the void, this means that
919 * hiding a column resizes others and we can have 10
920 * columns that are 1000 pixels wide by hiding the
921 * last one progressively.
933 // ------------------------------------------------------------------------
935 // ------------------------------------------------------------------------
938 * Create a pop-up menu.
940 private void createPopupMenu() {
941 final IAction copyAction
= new Action(Messages
.TmfEventsTable_CopyToClipboardActionText
) {
944 ITmfTrace trace
= fTrace
;
945 if (trace
== null || (fSelectedRank
== -1 && fSelectedBeginRank
== -1)) {
949 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
950 for (int i
: fTable
.getColumnOrder()) {
951 TableColumn column
= fTable
.getColumns()[i
];
952 // Omit the margin column and hidden columns
953 if (i
>= EVENT_COLUMNS_START_INDEX
&& (column
.getResizable() || column
.getWidth() > 0)) {
954 columns
.add(fColumns
.get(i
));
958 long start
= Math
.min(fSelectedBeginRank
, fSelectedRank
);
959 long end
= Math
.max(fSelectedBeginRank
, fSelectedRank
);
960 final ITmfFilter filter
= (ITmfFilter
) fTable
.getData(Key
.FILTER_OBJ
);
961 IRunnableWithProgress operation
= new CopyToClipboardOperation(trace
, filter
, columns
, start
, end
);
963 PlatformUI
.getWorkbench().getProgressService().busyCursorWhile(operation
);
964 } catch (InvocationTargetException e
) {
965 Activator
.getDefault().logError("Invocation target exception copying to clipboard ", e
); //$NON-NLS-1$
966 } catch (InterruptedException e
) {
972 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
975 fTable
.setVisible(true);
980 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
983 fTable
.setVisible(false);
988 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
991 fRawViewer
.setVisible(true);
993 final int index
= fTable
.getSelectionIndex();
995 fRawViewer
.selectAndReveal(index
- 1);
1000 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
1003 fRawViewer
.setVisible(false);
1008 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
1011 final TableItem items
[] = fTable
.getSelection();
1012 if (items
.length
!= 1) {
1015 final TableItem item
= items
[0];
1017 final Object data
= item
.getData();
1018 if (data
instanceof ITmfSourceLookup
) {
1019 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
1020 ITmfCallsite cs
= event
.getCallsite();
1021 if (cs
== null || cs
.getFileName() == null) {
1024 IMarker marker
= null;
1026 String fileName
= cs
.getFileName();
1027 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
1028 final ArrayList
<IFile
> files
= new ArrayList
<>();
1029 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
1031 public boolean visit(IResource resource
) throws CoreException
{
1032 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
1033 files
.add((IFile
) resource
);
1039 if (files
.size() > 1) {
1040 ListDialog dialog
= new ListDialog(getTable().getShell());
1041 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
1042 dialog
.setLabelProvider(new LabelProvider() {
1044 public String
getText(Object element
) {
1045 return ((IFile
) element
).getFullPath().toString();
1048 dialog
.setInput(files
);
1049 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
1050 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
1052 Object
[] result
= dialog
.getResult();
1053 if (result
!= null && result
.length
> 0) {
1054 file
= (IFile
) result
[0];
1056 } else if (files
.size() == 1) {
1057 file
= files
.get(0);
1060 marker
= file
.createMarker(IMarker
.MARKER
);
1061 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
1062 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
1064 } else if (files
.size() == 0) {
1065 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
1067 } catch (CoreException e
) {
1068 displayException(e
);
1074 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
1078 final TableItem items
[] = fTable
.getSelection();
1079 if (items
.length
!= 1) {
1082 final TableItem item
= items
[0];
1084 final Object eventData
= item
.getData();
1085 if (eventData
instanceof ITmfModelLookup
) {
1086 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
1088 if (modelURI
!= null) {
1089 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1092 final URI uri
= URI
.createURI(modelURI
);
1093 if (uri
.isPlatformResource()) {
1094 IPath path
= new Path(uri
.toPlatformString(true));
1095 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
1096 } else if (uri
.isFile() && !uri
.isRelative()) {
1097 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
1098 new Path(uri
.toFileString()));
1104 * create a temporary validation marker on the
1105 * model file, remove it afterwards thus,
1106 * navigation works with all model editors
1107 * supporting the navigation to a marker
1109 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
1110 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
1111 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
1113 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
1115 } catch (CoreException e
) {
1116 displayException(e
);
1119 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
1126 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
1129 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1130 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
1131 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
1132 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
1133 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
1135 HashMap
<String
, Object
> parameters
= new HashMap
<>();
1136 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
1137 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
1139 IEvaluationContext context
= handlerService
.getCurrentState();
1140 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
1141 for (int i
: fTable
.getColumnOrder()) {
1142 TableColumn column
= fTable
.getColumns()[i
];
1143 // Omit the margin column and hidden columns
1144 if (i
>= EVENT_COLUMNS_START_INDEX
&& (column
.getResizable() || column
.getWidth() > 0)) {
1145 exportColumns
.add(fColumns
.get(i
));
1148 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
1150 handlerService
.executeCommandInContext(cmd
, null, context
);
1151 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
1152 displayException(e
);
1157 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
1160 fHeaderState
= HeaderState
.SEARCH
;
1166 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
1169 fHeaderState
= HeaderState
.FILTER
;
1175 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
1182 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
1185 applyFilter(new TmfCollapseFilter());
1189 class ToggleBookmarkAction
extends Action
{
1192 public ToggleBookmarkAction(final String text
, final Long rank
) {
1199 toggleBookmark(fRank
);
1203 fHeaderPopupMenuManager
= new MenuManager();
1204 fHeaderPopupMenuManager
.setRemoveAllWhenShown(true);
1205 fHeaderPopupMenuManager
.addMenuListener(new IMenuListener() {
1207 public void menuAboutToShow(IMenuManager manager
) {
1208 for (int index
: fTable
.getColumnOrder()) {
1209 if (fTable
.getColumns()[index
].getData(Key
.WIDTH
) != null) {
1210 fHeaderPopupMenuManager
.add(createHeaderAction(fTable
.getColumns()[index
]));
1213 fHeaderPopupMenuManager
.add(new Separator());
1214 fHeaderPopupMenuManager
.add(createResetHeaderAction());
1218 fTablePopupMenuManager
= new MenuManager();
1219 fTablePopupMenuManager
.setRemoveAllWhenShown(true);
1220 fTablePopupMenuManager
.addMenuListener(new IMenuListener() {
1222 public void menuAboutToShow(final IMenuManager manager
) {
1223 if (fTable
.getSelectionIndices().length
== 1 && fTable
.getSelectionIndices()[0] == 0) {
1224 // Right-click on header row
1225 if (fHeaderState
== HeaderState
.FILTER
) {
1226 fTablePopupMenuManager
.add(showSearchBarAction
);
1228 fTablePopupMenuManager
.add(showFilterBarAction
);
1232 final Point point
= fTable
.toControl(fLastMenuCursorLocation
);
1233 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
1235 final Rectangle imageBounds
= item
.getImageBounds(0);
1236 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
1237 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
1238 // Right-click on left margin
1239 final Long rank
= (Long
) item
.getData(Key
.RANK
);
1240 if ((rank
!= null) && (fBookmarksFile
!= null)) {
1241 if (fBookmarksMap
.containsKey(rank
)) {
1242 fTablePopupMenuManager
.add(new ToggleBookmarkAction(
1243 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
1245 fTablePopupMenuManager
.add(new ToggleBookmarkAction(
1246 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
1253 // Right-click on table
1254 if (fSelectedRank
!= -1 && fSelectedBeginRank
!= -1) {
1255 fTablePopupMenuManager
.add(copyAction
);
1256 fTablePopupMenuManager
.add(new Separator());
1258 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1259 fTablePopupMenuManager
.add(hideTableAction
);
1260 fTablePopupMenuManager
.add(hideRawAction
);
1261 } else if (!fTable
.isVisible()) {
1262 fTablePopupMenuManager
.add(showTableAction
);
1263 } else if (!fRawViewer
.isVisible()) {
1264 fTablePopupMenuManager
.add(showRawAction
);
1266 fTablePopupMenuManager
.add(exportToTextAction
);
1267 fTablePopupMenuManager
.add(new Separator());
1270 final Object data
= item
.getData();
1271 Separator separator
= null;
1272 if (data
instanceof ITmfSourceLookup
) {
1273 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
1274 if (event
.getCallsite() != null) {
1275 fTablePopupMenuManager
.add(openCallsiteAction
);
1276 separator
= new Separator();
1280 if (data
instanceof ITmfModelLookup
) {
1281 ITmfModelLookup event
= (ITmfModelLookup
) data
;
1282 if (event
.getModelUri() != null) {
1283 fTablePopupMenuManager
.add(openModelAction
);
1284 separator
= new Separator();
1287 if (separator
!= null) {
1288 fTablePopupMenuManager
.add(separator
);
1294 * Only show collapse filter if at least one trace can be
1297 boolean isCollapsible
= false;
1298 if (fTrace
!= null) {
1299 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
1300 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1301 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1302 if (isCollapsible
) {
1308 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1309 fTablePopupMenuManager
.add(collapseAction
);
1310 fTablePopupMenuManager
.add(new Separator());
1313 fTablePopupMenuManager
.add(clearFiltersAction
);
1314 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1315 if (savedFilters
.length
> 0) {
1316 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1317 for (final ITmfFilterTreeNode node
: savedFilters
) {
1318 if (node
instanceof TmfFilterNode
) {
1319 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1320 subMenu
.add(new Action(filter
.getFilterName()) {
1323 applyFilter(filter
);
1328 fTablePopupMenuManager
.add(subMenu
);
1330 appendToTablePopupMenu(fTablePopupMenuManager
, item
);
1334 fRawViewerPopupMenuManager
= new MenuManager();
1335 fRawViewerPopupMenuManager
.setRemoveAllWhenShown(true);
1336 fRawViewerPopupMenuManager
.addMenuListener(new IMenuListener() {
1338 public void menuAboutToShow(final IMenuManager manager
) {
1339 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1340 fRawViewerPopupMenuManager
.add(hideTableAction
);
1341 fRawViewerPopupMenuManager
.add(hideRawAction
);
1342 } else if (!fTable
.isVisible()) {
1343 fRawViewerPopupMenuManager
.add(showTableAction
);
1344 } else if (!fRawViewer
.isVisible()) {
1345 fRawViewerPopupMenuManager
.add(showRawAction
);
1347 appendToRawPopupMenu(fRawViewerPopupMenuManager
);
1351 fHeaderMenu
= fHeaderPopupMenuManager
.createContextMenu(fTable
);
1353 fTablePopup
= fTablePopupMenuManager
.createContextMenu(fTable
);
1354 fTable
.setMenu(fTablePopup
);
1356 fRawTablePopup
= fRawViewerPopupMenuManager
.createContextMenu(fRawViewer
);
1357 fRawViewer
.setMenu(fRawTablePopup
);
1361 * Append an item to the event table's pop-up menu.
1363 * @param tablePopupMenu
1365 * @param selectedItem
1366 * The item to append
1368 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1369 // override to append more actions
1373 * Append an item to the raw viewer's pop-up menu.
1375 * @param rawViewerPopupMenu
1378 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1379 // override to append more actions
1383 public void dispose() {
1386 PlatformUI
.getWorkbench().getThemeManager().removePropertyChangeListener(this);
1387 ColorSettingsManager
.removeColorSettingsListener(this);
1388 fComposite
.dispose();
1389 if ((fTrace
!= null) && fDisposeOnClose
) {
1392 fResourceManager
.dispose();
1393 fRawViewer
.dispose();
1394 if (fRawViewerPopupMenuManager
!= null) {
1395 fRawViewerPopupMenuManager
.dispose();
1397 if (fHeaderPopupMenuManager
!= null) {
1398 fHeaderPopupMenuManager
.dispose();
1400 if (fTablePopupMenuManager
!= null) {
1401 fTablePopupMenuManager
.dispose();
1408 * Assign a layout data object to this view.
1411 * The layout data to assign
1413 public void setLayoutData(final Object layoutData
) {
1414 fComposite
.setLayoutData(layoutData
);
1418 * Get the virtual table contained in this event table.
1420 * @return The TMF virtual table
1422 public TmfVirtualTable
getTable() {
1429 * @deprecated The column headers are now set at the constructor, this
1430 * shouldn't be called anymore.
1433 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1438 * Set a table item's data.
1443 * Which trace event to link with this entry
1445 * Which rank this event has in the trace/experiment
1447 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1448 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1450 // Get the actual ITmfEvent from the CachedEvent
1451 ITmfEvent tmfEvent
= event
;
1452 if (event
instanceof CachedEvent
) {
1453 tmfEvent
= ((CachedEvent
) event
).event
;
1455 item
.setText(itemStrings
);
1456 item
.setData(tmfEvent
);
1457 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1458 item
.setData(Key
.RANK
, rank
);
1460 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1461 if (!markerIds
.isEmpty()) {
1462 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1463 List
<Object
> parts
= new ArrayList
<>();
1464 if (markerIds
.size() > 1) {
1465 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1468 for (long markerId
: markerIds
) {
1469 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1470 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1472 } catch (CoreException e
) {
1473 displayException(e
);
1475 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1477 item
.setData(Key
.BOOKMARK
, null);
1480 boolean searchMatch
= false;
1481 boolean searchNoMatch
= false;
1482 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1483 if (searchFilter
!= null) {
1484 if (searchFilter
.matches(tmfEvent
)) {
1487 searchNoMatch
= true;
1491 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1492 if (searchNoMatch
) {
1493 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1494 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1496 item
.setForeground(colorSetting
.getForegroundColor());
1497 item
.setBackground(colorSetting
.getBackgroundColor());
1499 item
.setFont(fFont
);
1502 if (!markerIds
.isEmpty()) {
1503 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1505 item
.setImage(SEARCH_MATCH_IMAGE
);
1507 } else if (!markerIds
.isEmpty()) {
1508 item
.setImage(BOOKMARK_IMAGE
);
1510 item
.setImage((Image
) null);
1513 List
<StyleRange
> styleRanges
= new ArrayList
<>();
1514 for (int index
= 0; index
< fTable
.getColumns().length
; index
++) {
1515 TableColumn column
= fTable
.getColumns()[index
];
1516 String regex
= null;
1517 if (fHeaderState
== HeaderState
.FILTER
) {
1518 regex
= (String
) column
.getData(Key
.FILTER_TXT
);
1519 } else if (searchMatch
) {
1520 regex
= (String
) column
.getData(Key
.SEARCH_TXT
);
1522 if (regex
!= null) {
1523 String text
= item
.getText(index
);
1525 Pattern pattern
= Pattern
.compile(regex
);
1526 Matcher matcher
= pattern
.matcher(text
);
1527 while (matcher
.find()) {
1528 int start
= matcher
.start();
1529 int length
= matcher
.end() - start
;
1530 Color foreground
= colorSetting
.getForegroundColor();
1531 Color background
= fHighlightColor
;
1532 StyleRange styleRange
= new StyleRange(start
, length
, foreground
, background
);
1533 styleRange
.data
= index
;
1534 styleRanges
.add(styleRange
);
1536 } catch (PatternSyntaxException e
) {
1541 if (styleRanges
.isEmpty()) {
1542 item
.setData(Key
.STYLE_RANGES
, null);
1544 item
.setData(Key
.STYLE_RANGES
, styleRanges
);
1546 item
.getParent().redraw();
1548 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1554 * Set the item data of the header row.
1557 * The item to use as table header
1559 protected void setHeaderRowItemData(final TableItem item
) {
1560 String txtKey
= null;
1561 if (fHeaderState
== HeaderState
.SEARCH
) {
1562 item
.setImage(SEARCH_IMAGE
);
1563 txtKey
= Key
.SEARCH_TXT
;
1564 } else if (fHeaderState
== HeaderState
.FILTER
) {
1565 item
.setImage(FILTER_IMAGE
);
1566 txtKey
= Key
.FILTER_TXT
;
1568 item
.setForeground(fGrayColor
);
1569 // Ignore collapse and image column
1570 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1571 final TableColumn column
= fTable
.getColumns()[i
];
1572 final String filter
= (String
) column
.getData(txtKey
);
1573 if (filter
== null) {
1574 if (fHeaderState
== HeaderState
.SEARCH
) {
1575 item
.setText(i
, SEARCH_HINT
);
1576 } else if (fHeaderState
== HeaderState
.FILTER
) {
1577 item
.setText(i
, FILTER_HINT
);
1579 item
.setForeground(i
, fGrayColor
);
1580 item
.setFont(i
, fFont
);
1582 item
.setText(i
, filter
);
1583 item
.setForeground(i
, fGreenColor
);
1584 item
.setFont(i
, fBoldFont
);
1590 * Set the item data of the "filter status" row.
1593 * The item to use as filter status row
1595 protected void setFilterStatusRowItemData(final TableItem item
) {
1596 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1597 if (i
== MARGIN_COLUMN_INDEX
) {
1598 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1599 item
.setImage(FILTER_IMAGE
);
1601 item
.setImage(STOP_IMAGE
);
1605 if (i
== FILTER_SUMMARY_INDEX
) {
1606 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1608 item
.setText(i
, EMPTY_STRING
);
1612 item
.setData(Key
.TIMESTAMP
, null);
1613 item
.setData(Key
.RANK
, null);
1614 item
.setData(Key
.STYLE_RANGES
, null);
1615 item
.setForeground(null);
1616 item
.setBackground(null);
1617 item
.setFont(fFont
);
1621 * Create an editor for the header.
1623 private void createHeaderEditor() {
1624 final TableEditor tableEditor
= fTable
.createTableEditor();
1625 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1626 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1627 tableEditor
.grabHorizontal
= true;
1628 tableEditor
.minimumWidth
= 50;
1630 // Handle the header row selection
1631 fTable
.addMouseListener(new MouseAdapter() {
1637 public void mouseDown(final MouseEvent event
) {
1638 if (event
.button
!= 1) {
1641 // Identify the selected row
1642 final Point point
= new Point(event
.x
, event
.y
);
1643 item
= fTable
.getItem(point
);
1645 // Header row selected
1646 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1648 // Margin column selected
1649 if (item
.getBounds(0).contains(point
)) {
1650 if (fHeaderState
== HeaderState
.SEARCH
) {
1651 fHeaderState
= HeaderState
.FILTER
;
1652 } else if (fHeaderState
== HeaderState
.FILTER
) {
1653 fHeaderState
= HeaderState
.SEARCH
;
1655 fTable
.setSelection(0);
1661 // Identify the selected column
1663 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1664 final Rectangle rect
= item
.getBounds(i
);
1665 if (rect
.contains(point
)) {
1671 if (columnIndex
== -1) {
1675 column
= fTable
.getColumns()[columnIndex
];
1677 String txtKey
= null;
1678 if (fHeaderState
== HeaderState
.SEARCH
) {
1679 txtKey
= Key
.SEARCH_TXT
;
1680 } else if (fHeaderState
== HeaderState
.FILTER
) {
1681 txtKey
= Key
.FILTER_TXT
;
1685 * The control that will be the editor must be a child of
1688 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1689 final String headerString
= (String
) column
.getData(txtKey
);
1690 if (headerString
!= null) {
1691 newEditor
.setText(headerString
);
1693 newEditor
.addFocusListener(new FocusAdapter() {
1695 public void focusLost(final FocusEvent e
) {
1696 final boolean changed
= updateHeader(newEditor
.getText());
1702 newEditor
.addKeyListener(new KeyAdapter() {
1704 public void keyPressed(final KeyEvent e
) {
1705 if (e
.character
== SWT
.CR
) {
1706 updateHeader(newEditor
.getText());
1710 * Set focus on the table so that the next
1711 * carriage return goes to the next result
1713 TmfEventsTable
.this.getTable().setFocus();
1714 } else if (e
.character
== SWT
.ESC
) {
1715 tableEditor
.getEditor().dispose();
1719 newEditor
.selectAll();
1720 newEditor
.setFocus();
1721 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1726 * returns true is value was changed
1728 private boolean updateHeader(final String regex
) {
1729 String objKey
= null;
1730 String txtKey
= null;
1731 if (fHeaderState
== HeaderState
.SEARCH
) {
1732 objKey
= Key
.SEARCH_OBJ
;
1733 txtKey
= Key
.SEARCH_TXT
;
1734 } else if (fHeaderState
== HeaderState
.FILTER
) {
1735 objKey
= Key
.FILTER_OBJ
;
1736 txtKey
= Key
.FILTER_TXT
;
1738 if (regex
.length() > 0) {
1740 Pattern
.compile(regex
);
1741 if (regex
.equals(column
.getData(txtKey
))) {
1742 tableEditor
.getEditor().dispose();
1745 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1746 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1747 filter
.setEventAspect(aspect
);
1748 filter
.setRegex(regex
);
1749 column
.setData(objKey
, filter
);
1750 column
.setData(txtKey
, regex
);
1751 } catch (final PatternSyntaxException ex
) {
1752 tableEditor
.getEditor().dispose();
1753 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1754 ex
.getDescription(), ex
.getMessage());
1758 if (column
.getData(txtKey
) == null) {
1759 tableEditor
.getEditor().dispose();
1762 column
.setData(objKey
, null);
1763 column
.setData(txtKey
, null);
1768 private void applyHeader() {
1769 if (fHeaderState
== HeaderState
.SEARCH
) {
1771 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1772 for (final TableColumn col
: fTable
.getColumns()) {
1773 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1774 if (filterObj
instanceof ITmfFilterTreeNode
) {
1775 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1778 if (filter
.getChildrenCount() > 0) {
1779 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1782 fireSearchApplied(filter
);
1784 fTable
.setData(Key
.SEARCH_OBJ
, null);
1786 fireSearchApplied(null);
1788 } else if (fHeaderState
== HeaderState
.FILTER
) {
1789 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1790 for (final TableColumn col
: fTable
.getColumns()) {
1791 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1792 if (filterObj
instanceof ITmfFilterTreeNode
) {
1793 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1796 if (filter
.getChildrenCount() > 0) {
1797 applyFilter(filter
);
1803 tableEditor
.getEditor().dispose();
1807 fTable
.addKeyListener(new KeyAdapter() {
1809 public void keyPressed(final KeyEvent e
) {
1811 if (e
.character
== SWT
.ESC
) {
1815 } else if (e
.character
== SWT
.DEL
) {
1816 if (fHeaderState
== HeaderState
.SEARCH
) {
1818 for (final TableColumn column
: fTable
.getColumns()) {
1819 column
.setData(Key
.SEARCH_OBJ
, null);
1820 column
.setData(Key
.SEARCH_TXT
, null);
1822 fTable
.setData(Key
.SEARCH_OBJ
, null);
1824 fireSearchApplied(null);
1825 } else if (fHeaderState
== HeaderState
.FILTER
) {
1828 } else if (e
.character
== SWT
.CR
) {
1829 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1840 * Send an event indicating a filter has been applied.
1843 * The filter that was just applied
1845 protected void fireFilterApplied(final ITmfFilter filter
) {
1846 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1850 * Send an event indicating that a search has been applied.
1853 * The search filter that was just applied
1855 protected void fireSearchApplied(final ITmfFilter filter
) {
1856 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1860 * Start the filtering thread.
1862 protected void startFilterThread() {
1863 synchronized (fFilterSyncObj
) {
1864 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1865 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1866 if (fFilterThread
!= null) {
1867 fFilterThread
.cancel();
1868 fFilterThreadResume
= false;
1870 fFilterThread
= new FilterThread(filter
);
1871 fFilterThread
.start();
1873 fFilterThreadResume
= true;
1879 * Stop the filtering thread.
1881 protected void stopFilterThread() {
1882 synchronized (fFilterSyncObj
) {
1883 if (fFilterThread
!= null) {
1884 fFilterThread
.cancel();
1885 fFilterThread
= null;
1886 fFilterThreadResume
= false;
1895 * The filter to apply
1897 protected void applyFilter(ITmfFilter filter
) {
1900 fFilterMatchCount
= 0;
1901 fFilterCheckCount
= 0;
1902 fCache
.applyFilter(filter
);
1904 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1905 /* +1 for header row, +2 for top and bottom filter status rows */
1906 fTable
.setItemCount(3);
1907 startFilterThread();
1908 fireFilterApplied(filter
);
1912 * Clear all currently active filters.
1914 protected void clearFilters() {
1915 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1920 fCache
.clearFilter();
1922 for (final TableColumn column
: fTable
.getColumns()) {
1923 column
.setData(Key
.FILTER_OBJ
, null);
1924 column
.setData(Key
.FILTER_TXT
, null);
1926 fTable
.setData(Key
.FILTER_OBJ
, null);
1927 if (fTrace
!= null) {
1928 /* +1 for header row */
1929 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1);
1931 /* +1 for header row */
1932 fTable
.setItemCount(1);
1934 fFilterMatchCount
= 0;
1935 fFilterCheckCount
= 0;
1936 if (fSelectedRank
>= 0) {
1937 /* +1 for header row */
1938 fTable
.setSelection((int) fSelectedRank
+ 1);
1940 fTable
.setSelection(0);
1942 fireFilterApplied(null);
1943 updateStatusLine(null);
1945 // Set original width
1946 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1951 * Wrapper Thread object for the filtering thread.
1953 protected class FilterThread
extends Thread
{
1954 private final ITmfFilterTreeNode filter
;
1955 private TmfEventRequest request
;
1956 private boolean refreshBusy
= false;
1957 private boolean refreshPending
= false;
1958 private final Object syncObj
= new Object();
1964 * The filter this thread will be processing
1966 public FilterThread(final ITmfFilterTreeNode filter
) {
1967 super("Filter Thread"); //$NON-NLS-1$
1968 this.filter
= filter
;
1973 if (fTrace
== null) {
1976 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1977 if (nbRequested
<= 0) {
1980 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1981 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1983 public void handleData(final ITmfEvent event
) {
1984 super.handleData(event
);
1985 if (request
.isCancelled()) {
1988 boolean refresh
= false;
1989 if (filter
.matches(event
)) {
1990 final long rank
= fFilterCheckCount
;
1991 final int index
= (int) fFilterMatchCount
;
1992 fFilterMatchCount
++;
1993 fCache
.storeEvent(event
, rank
, index
);
1996 if (filter
instanceof TmfCollapseFilter
) {
1997 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
2001 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
2004 fFilterCheckCount
++;
2007 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
2009 request
.waitForCompletion();
2010 } catch (final InterruptedException e
) {
2013 synchronized (fFilterSyncObj
) {
2014 fFilterThread
= null;
2015 if (fFilterThreadResume
) {
2016 fFilterThreadResume
= false;
2017 fFilterThread
= new FilterThread(filter
);
2018 fFilterThread
.start();
2024 * Refresh the filter.
2026 public void refreshTable() {
2027 synchronized (syncObj
) {
2029 refreshPending
= true;
2034 Display
.getDefault().asyncExec(new Runnable() {
2037 if (request
.isCancelled()) {
2040 if (fTable
.isDisposed()) {
2044 * +1 for header row, +2 for top and bottom filter status
2047 fTable
.setItemCount((int) fFilterMatchCount
+ 3);
2049 synchronized (syncObj
) {
2050 refreshBusy
= false;
2051 if (refreshPending
) {
2052 refreshPending
= false;
2061 * Cancel this filtering thread.
2063 public void cancel() {
2064 if (request
!= null) {
2071 * Go to the next item of a search.
2073 protected void searchNext() {
2074 synchronized (fSearchSyncObj
) {
2075 if (fSearchThread
!= null) {
2078 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
2079 if (searchFilter
== null) {
2082 final int selectionIndex
= fTable
.getSelectionIndex();
2084 if (selectionIndex
> 0) {
2085 /* -1 for header row, +1 for next event */
2086 startIndex
= selectionIndex
;
2089 * header row is selected, start at top event
2091 /* -1 for header row */
2092 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1);
2094 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
2095 if (eventFilter
!= null) {
2096 // -1 for top filter status row
2097 startIndex
= Math
.max(0, startIndex
- 1);
2099 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
2100 fSearchThread
.schedule();
2105 * Go to the previous item of a search.
2107 protected void searchPrevious() {
2108 synchronized (fSearchSyncObj
) {
2109 if (fSearchThread
!= null) {
2112 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
2113 if (searchFilter
== null) {
2116 final int selectionIndex
= fTable
.getSelectionIndex();
2118 if (selectionIndex
> 0) {
2119 /* -1 for header row, -1 for previous event */
2120 startIndex
= selectionIndex
- 2;
2123 * Header row is selected, start at precedent of top event
2125 /* -1 for header row, -1 for previous event */
2126 startIndex
= fTable
.getTopIndex() - 2;
2128 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
2129 if (eventFilter
!= null) {
2130 /* -1 for top filter status row */
2131 startIndex
= startIndex
- 1;
2133 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
2134 fSearchThread
.schedule();
2139 * Stop the search thread.
2141 protected void stopSearchThread() {
2142 fPendingGotoRank
= -1;
2143 synchronized (fSearchSyncObj
) {
2144 if (fSearchThread
!= null) {
2145 fSearchThread
.cancel();
2146 fSearchThread
= null;
2152 * Wrapper for the search thread.
2154 protected class SearchThread
extends Job
{
2156 private ITmfFilterTreeNode searchFilter
;
2157 private ITmfFilterTreeNode eventFilter
;
2158 private int startIndex
;
2159 private int direction
;
2161 private long foundRank
= -1;
2162 private TmfEventRequest request
;
2163 private ITmfTimestamp foundTimestamp
= null;
2168 * @param searchFilter
2170 * @param eventFilter
2173 * The index at which we should start searching
2174 * @param currentRank
2177 * In which direction should we search, forward or backwards
2179 public SearchThread(final ITmfFilterTreeNode searchFilter
,
2180 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
2181 final long currentRank
, final int direction
) {
2182 super(Messages
.TmfEventsTable_SearchingJobName
);
2183 this.searchFilter
= searchFilter
;
2184 this.eventFilter
= eventFilter
;
2185 this.startIndex
= startIndex
;
2186 this.rank
= currentRank
;
2187 this.direction
= direction
;
2191 protected IStatus
run(final IProgressMonitor monitor
) {
2192 final ITmfTrace trace
= fTrace
;
2193 if (trace
== null) {
2194 return Status
.OK_STATUS
;
2196 final Display display
= Display
.getDefault();
2197 if (startIndex
< 0) {
2198 rank
= (int) trace
.getNbEvents() - 1;
2200 * -1 for header row, -3 for header and top and bottom filter
2203 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) {
2206 int idx
= startIndex
;
2207 while (foundRank
== -1) {
2208 final CachedEvent event
= fCache
.peekEvent(idx
);
2209 if (event
== null) {
2213 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
2214 foundRank
= event
.rank
;
2215 foundTimestamp
= event
.event
.getTimestamp();
2218 if (direction
== Direction
.FORWARD
) {
2224 if (foundRank
== -1) {
2225 if (direction
== Direction
.FORWARD
) {
2227 if (rank
> (trace
.getNbEvents() - 1)) {
2233 rank
= (int) trace
.getNbEvents() - 1;
2238 final int startRank
= (int) rank
;
2239 boolean wrapped
= false;
2240 while (!monitor
.isCanceled() && (foundRank
== -1)) {
2241 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, trace
.getCacheSize()));
2242 if (direction
== Direction
.BACKWARD
) {
2243 rank
= Math
.max(0, rank
- trace
.getCacheSize() + 1);
2245 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
2246 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
2247 long currentRank
= rank
;
2250 public void handleData(final ITmfEvent event
) {
2251 super.handleData(event
);
2252 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
2253 foundRank
= currentRank
;
2254 foundTimestamp
= event
.getTimestamp();
2255 if (direction
== Direction
.FORWARD
) {
2263 ((ITmfEventProvider
) trace
).sendRequest(request
);
2265 request
.waitForCompletion();
2266 if (request
.isCancelled()) {
2267 return Status
.OK_STATUS
;
2269 } catch (final InterruptedException e
) {
2270 synchronized (fSearchSyncObj
) {
2271 fSearchThread
= null;
2273 return Status
.OK_STATUS
;
2275 if (foundRank
== -1) {
2276 if (direction
== Direction
.FORWARD
) {
2278 synchronized (fSearchSyncObj
) {
2279 fSearchThread
= null;
2281 return Status
.OK_STATUS
;
2283 nbRequested
= (int) rank
;
2289 rank
= (int) trace
.getNbEvents() - 1;
2292 if ((rank
<= startRank
) && wrapped
) {
2293 synchronized (fSearchSyncObj
) {
2294 fSearchThread
= null;
2296 return Status
.OK_STATUS
;
2301 int index
= (int) foundRank
;
2302 if (eventFilter
!= null) {
2303 index
= fCache
.getFilteredEventIndex(foundRank
);
2305 /* +1 for header row, +1 for top filter status row */
2306 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0);
2308 display
.asyncExec(new Runnable() {
2311 if (monitor
.isCanceled()) {
2314 if (fTable
.isDisposed()) {
2317 fTable
.setSelection(selection
);
2318 fSelectedRank
= foundRank
;
2319 fSelectedBeginRank
= fSelectedRank
;
2320 fRawViewer
.selectAndReveal(fSelectedRank
);
2321 if (foundTimestamp
!= null) {
2322 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, foundTimestamp
));
2324 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
2325 synchronized (fSearchSyncObj
) {
2326 fSearchThread
= null;
2328 updateStatusLine(null);
2331 return Status
.OK_STATUS
;
2335 protected void canceling() {
2337 synchronized (fSearchSyncObj
) {
2338 fSearchThread
= null;
2344 * Create the resources.
2346 private void createResources() {
2347 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
.getForeground().getRGB()));
2348 fGreenColor
= PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
2352 * Initialize the fonts.
2354 private void initializeFonts() {
2355 FontRegistry fontRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
2356 fFont
= fontRegistry
.get(FONT_DEFINITION_ID
);
2357 fBoldFont
= fontRegistry
.getBold(FONT_DEFINITION_ID
);
2358 fTable
.setFont(fFont
);
2359 /* Column header font cannot be set. See Bug 63038 */
2363 * Initialize the colors.
2365 private void initializeColors() {
2366 ColorRegistry colorRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
2367 fHighlightColor
= colorRegistry
.get(HIGHLIGHT_COLOR_DEFINITION_ID
);
2374 public void propertyChange(PropertyChangeEvent event
) {
2375 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2376 (FONT_DEFINITION_ID
.equals(event
.getProperty()))) {
2380 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2381 (HIGHLIGHT_COLOR_DEFINITION_ID
.equals(event
.getProperty()))) {
2390 protected void packColumns() {
2394 fTable
.setRedraw(false);
2396 TableColumn tableColumns
[] = fTable
.getColumns();
2397 for (int i
= 0; i
< tableColumns
.length
; i
++) {
2398 final TableColumn column
= tableColumns
[i
];
2399 packSingleColumn(i
, column
);
2403 // Make sure that redraw is always enabled.
2404 fTable
.setRedraw(true);
2409 private void packMarginColumn() {
2410 TableColumn
[] columns
= fTable
.getColumns();
2411 if (columns
.length
> 0) {
2412 packSingleColumn(0, columns
[0]);
2416 private void packSingleColumn(int i
, final TableColumn column
) {
2417 final int headerWidth
= column
.getWidth();
2420 * Workaround for Linux which doesn't consider the image width of
2421 * search/filter row in TableColumn.pack() after having executed
2422 * TableItem.setImage(null) for other rows than search/filter row.
2424 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2425 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2426 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2429 if (column
.getWidth() < headerWidth
) {
2430 column
.setWidth(headerWidth
);
2435 * Get the array of item strings (e.g., what to display in each cell of the
2436 * table row) corresponding to the columns and trace event passed in
2437 * parameter. The order of the Strings in the returned array will correspond
2438 * to the iteration order of 'columns'.
2441 * To ensure consistent results, make sure only call this within a scope
2442 * synchronized on 'columns'! If the order of 'columns' changes right after
2443 * this method is called, the returned value won't be ordered correctly
2446 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2447 if (event
== null) {
2448 return EMPTY_STRING_ARRAY
;
2450 synchronized (columns
) {
2451 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2452 for (TmfEventTableColumn column
: columns
) {
2453 ITmfEvent passedEvent
= event
;
2454 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2456 * Make sure that the event object from the trace is passed
2457 * to all columns but the TmfMarginColumn
2459 passedEvent
= ((CachedEvent
) event
).event
;
2461 if (passedEvent
== null) {
2462 itemStrings
.add(EMPTY_STRING
);
2464 itemStrings
.add(column
.getItemString(passedEvent
));
2468 return itemStrings
.toArray(new String
[0]);
2473 * Get the contents of the row in the events table corresponding to an
2474 * event. The order of the elements corresponds to the current order of the
2478 * The event printed in this row
2479 * @return The event row entries
2481 public String
[] getItemStrings(ITmfEvent event
) {
2482 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2483 for (int i
: fTable
.getColumnOrder()) {
2484 columns
.add(fColumns
.get(i
));
2486 return getItemStrings(columns
, event
);
2490 * Returns an array of zero-relative integers that map the creation order of
2491 * the receiver's columns to the order in which they are currently being
2494 * Specifically, the indices of the returned array represent the current
2495 * visual order of the columns, and the contents of the array represent the
2496 * creation order of the columns.
2498 * @return the current visual order of the receiver's columns
2501 public int[] getColumnOrder() {
2502 return fColumnOrder
;
2506 * Sets the order that the columns in the receiver should be displayed in to
2507 * the given argument which is described in terms of the zero-relative
2508 * ordering of when the columns were added.
2510 * Specifically, the contents of the array represent the original position
2511 * of each column at the time its creation.
2514 * the new order to display the columns
2517 public void setColumnOrder(int[] order
) {
2518 if (order
== null || order
.length
!= fTable
.getColumns().length
) {
2521 fTable
.setColumnOrder(order
);
2522 fColumnOrder
= fTable
.getColumnOrder();
2526 * Notify this table that is got the UI focus.
2528 public void setFocus() {
2533 * Registers context menus with a site for extension. This method can be
2534 * called for part sites so that context menu contributions can be added.
2537 * the site that the context menus will be registered for
2541 public void registerContextMenus(IWorkbenchPartSite site
) {
2542 if (site
instanceof IEditorSite
) {
2543 IEditorSite editorSite
= (IEditorSite
) site
;
2544 // Don't use the editor input when adding contributions, otherwise
2545 // we get too many unwanted things.
2546 editorSite
.registerContextMenu(fTablePopupMenuManager
, this, false);
2551 * Assign a new trace to this event table.
2554 * The trace to assign to this event table
2555 * @param disposeOnClose
2556 * true if the trace should be disposed when the table is
2559 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2560 if ((fTrace
!= null) && fDisposeOnClose
) {
2565 fDisposeOnClose
= disposeOnClose
;
2567 // Perform the updates on the UI thread
2568 PlatformUI
.getWorkbench().getDisplay().syncExec(new Runnable() {
2572 fSelectedBeginRank
= -1;
2574 fCache
.setTrace(trace
); // Clear the cache
2575 if (trace
!= null) {
2576 if (!fTable
.isDisposed()) {
2577 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2578 // +1 for header row
2579 fTable
.setItemCount((int) trace
.getNbEvents() + 1);
2582 fFilterMatchCount
= 0;
2583 fFilterCheckCount
= 0;
2585 * +1 for header row, +2 for top and bottom filter
2588 fTable
.setItemCount(3);
2589 startFilterThread();
2593 fRawViewer
.setTrace(trace
);
2599 * Assign the status line manager
2601 * @param statusLineManager
2602 * The status line manager, or null to disable status line
2605 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2606 if (fStatusLineManager
!= null && statusLineManager
== null) {
2607 fStatusLineManager
.setMessage(EMPTY_STRING
);
2609 fStatusLineManager
= statusLineManager
;
2612 private void updateStatusLine(ITmfTimestamp delta
) {
2613 if (fStatusLineManager
!= null) {
2614 if (delta
!= null) {
2615 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2617 fStatusLineManager
.setMessage(null);
2622 // ------------------------------------------------------------------------
2624 // ------------------------------------------------------------------------
2627 * Notify that the event cache has been updated
2630 * Also notify if the populating of the cache is complete, or
2633 public void cacheUpdated(final boolean completed
) {
2634 synchronized (fCacheUpdateSyncObj
) {
2635 if (fCacheUpdateBusy
) {
2636 fCacheUpdatePending
= true;
2637 fCacheUpdateCompleted
= completed
;
2640 fCacheUpdateBusy
= true;
2642 // Event cache is now updated. Perform update on the UI thread
2643 PlatformUI
.getWorkbench().getDisplay().asyncExec(new Runnable() {
2646 if (!fTable
.isDisposed()) {
2651 populateCompleted();
2653 synchronized (fCacheUpdateSyncObj
) {
2654 fCacheUpdateBusy
= false;
2655 if (fCacheUpdatePending
) {
2656 fCacheUpdatePending
= false;
2657 cacheUpdated(fCacheUpdateCompleted
);
2665 * Callback for when populating the table is complete.
2667 protected void populateCompleted() {
2668 // Nothing by default;
2671 // ------------------------------------------------------------------------
2672 // ISelectionProvider
2673 // ------------------------------------------------------------------------
2676 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2677 selectionChangedListeners
.add(listener
);
2681 public ISelection
getSelection() {
2682 if (fTable
== null || fTable
.isDisposed()) {
2683 return StructuredSelection
.EMPTY
;
2685 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2686 for (TableItem item
: fTable
.getSelection()) {
2687 if (item
.getData() != null) {
2688 list
.add(item
.getData());
2691 return new StructuredSelection(list
);
2695 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2696 selectionChangedListeners
.remove(listener
);
2700 public void setSelection(ISelection selection
) {
2705 * Notifies any selection changed listeners that the viewer's selection has
2706 * changed. Only listeners registered at the time this method is called are
2710 * a selection changed event
2712 * @see ISelectionChangedListener#selectionChanged
2714 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2715 Object
[] listeners
= selectionChangedListeners
.getListeners();
2716 for (int i
= 0; i
< listeners
.length
; ++i
) {
2717 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2718 SafeRunnable
.run(new SafeRunnable() {
2721 l
.selectionChanged(event
);
2727 // ------------------------------------------------------------------------
2728 // Bookmark handling
2729 // ------------------------------------------------------------------------
2732 * Add a bookmark to this event table.
2734 * @param bookmarksFile
2735 * The file to use for the bookmarks
2737 public void addBookmark(final IFile bookmarksFile
) {
2738 fBookmarksFile
= bookmarksFile
;
2739 final TableItem
[] selection
= fTable
.getSelection();
2740 if (selection
.length
> 0) {
2741 final TableItem tableItem
= selection
[0];
2742 if (tableItem
.getData(Key
.RANK
) != null) {
2743 final StringBuffer defaultMessage
= new StringBuffer();
2744 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2746 defaultMessage
.append(", "); //$NON-NLS-1$
2748 defaultMessage
.append(tableItem
.getText(i
));
2750 final InputDialog dialog
= new MultiLineInputDialog(
2751 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2752 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2753 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2754 defaultMessage
.toString());
2755 if (dialog
.open() == Window
.OK
) {
2756 final String message
= dialog
.getValue();
2758 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2759 if (bookmark
.exists()) {
2760 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2761 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2762 final int location
= rank
.intValue();
2763 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2764 fBookmarksMap
.put(rank
, bookmark
.getId());
2767 } catch (final CoreException e
) {
2768 displayException(e
);
2777 * Remove a bookmark from this event table.
2780 * The bookmark to remove
2782 public void removeBookmark(final IMarker bookmark
) {
2783 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2784 if (entry
.getValue().equals(bookmark
.getId())) {
2785 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2792 private void toggleBookmark(final Long rank
) {
2793 if (fBookmarksFile
== null) {
2796 if (fBookmarksMap
.containsKey(rank
)) {
2797 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2800 for (long markerId
: markerIds
) {
2801 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2802 if (bookmark
!= null) {
2806 } catch (final CoreException e
) {
2807 displayException(e
);
2810 addBookmark(fBookmarksFile
);
2815 * Refresh the bookmarks assigned to this trace, from the contents of a
2818 * @param bookmarksFile
2819 * The bookmark file to use
2821 public void refreshBookmarks(final IFile bookmarksFile
) {
2822 fBookmarksFile
= bookmarksFile
;
2823 if (bookmarksFile
== null) {
2824 fBookmarksMap
.clear();
2829 fBookmarksMap
.clear();
2830 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2831 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2832 if (location
!= -1) {
2833 final long rank
= location
;
2834 fBookmarksMap
.put(rank
, bookmark
.getId());
2838 } catch (final CoreException e
) {
2839 displayException(e
);
2844 public void gotoMarker(final IMarker marker
) {
2845 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2848 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2849 // +1 for top filter status row
2850 index
= fCache
.getFilteredEventIndex(rank
) + 1;
2851 } else if (rank
>= fTable
.getItemCount()) {
2852 fPendingGotoRank
= rank
;
2854 fSelectedRank
= rank
;
2855 fSelectedBeginRank
= fSelectedRank
;
2856 fTable
.setSelection(index
+ 1); // +1 for header row
2857 updateStatusLine(null);
2861 // ------------------------------------------------------------------------
2863 // ------------------------------------------------------------------------
2866 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2870 // ------------------------------------------------------------------------
2872 // ------------------------------------------------------------------------
2875 * Handler for the trace updated signal
2878 * The incoming signal
2881 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2882 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2885 // Perform the refresh on the UI thread
2886 Display
.getDefault().asyncExec(new Runnable() {
2889 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2890 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2891 /* +1 for header row */
2892 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1);
2893 /* +1 for header row */
2894 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) {
2895 /* +1 for header row */
2896 fTable
.setSelection((int) fPendingGotoRank
+ 1);
2897 fPendingGotoRank
= -1;
2898 updateStatusLine(null);
2901 startFilterThread();
2904 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2905 fRawViewer
.refreshEventCount();
2912 * Handler for the selection range signal.
2915 * The incoming signal
2919 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
2920 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2923 * Create a request for one event that will be queued after other
2924 * ongoing requests. When this request is completed do the work to
2925 * select the actual event with the timestamp specified in the
2926 * signal. This procedure prevents the method fTrace.getRank() from
2927 * interfering and delaying ongoing requests.
2929 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2930 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2932 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2935 public void handleData(final ITmfEvent event
) {
2936 super.handleData(event
);
2940 public void handleSuccess() {
2941 super.handleSuccess();
2942 if (fTrace
== null) {
2947 * Verify if the event is within the trace range and adjust
2950 ITmfTimestamp timestamp
= ts
;
2951 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2952 timestamp
= fTrace
.getStartTime();
2954 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2955 timestamp
= fTrace
.getEndTime();
2958 // Get the rank of the selected event in the table
2959 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2960 final long rank
= context
.getRank();
2963 PlatformUI
.getWorkbench().getDisplay().asyncExec(new Runnable() {
2966 // Return if table is disposed
2967 if (fTable
.isDisposed()) {
2971 fSelectedRank
= rank
;
2972 fSelectedBeginRank
= fSelectedRank
;
2973 int index
= (int) rank
;
2974 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2975 /* +1 for top filter status row */
2976 index
= fCache
.getFilteredEventIndex(rank
) + 1;
2978 /* +1 for header row */
2979 fTable
.setSelection(index
+ 1);
2980 fRawViewer
.selectAndReveal(rank
);
2981 updateStatusLine(null);
2987 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2991 // ------------------------------------------------------------------------
2993 // ------------------------------------------------------------------------
2996 * Display an exception in a message box
3001 private static void displayException(final Exception e
) {
3002 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
3003 mb
.setText(e
.getClass().getSimpleName());
3004 mb
.setMessage(e
.getMessage());
3011 public void refresh() {
3018 * Margin column for images and special text (e.g. collapse count)
3020 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
3022 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
3025 public String
getName() {
3026 return EMPTY_STRING
;
3030 public String
resolve(ITmfEvent event
) {
3031 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
3032 return EMPTY_STRING
;
3034 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
3038 public String
getHelpText() {
3039 return EMPTY_STRING
;
3046 public TmfMarginColumn() {
3047 super(MARGIN_ASPECT
);