1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation, replaced Table by TmfVirtualTable
11 * Patrick Tasse - Factored out from events view,
12 * Filter implementation (inspired by www.eclipse.org/mat)
13 * Ansgar Radermacher - Support navigation to model URIs (Bug 396956)
14 * Bernd Hufmann - Updated call site and model URI implementation
15 * Alexandre Montplaisir - Update to new column API
16 *******************************************************************************/
18 package org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
;
20 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
22 import java
.io
.FileNotFoundException
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Collection
;
25 import java
.util
.HashMap
;
26 import java
.util
.LinkedList
;
27 import java
.util
.List
;
28 import java
.util
.Map
.Entry
;
29 import java
.util
.regex
.Matcher
;
30 import java
.util
.regex
.Pattern
;
31 import java
.util
.regex
.PatternSyntaxException
;
33 import org
.eclipse
.core
.commands
.Command
;
34 import org
.eclipse
.core
.commands
.ExecutionException
;
35 import org
.eclipse
.core
.commands
.NotEnabledException
;
36 import org
.eclipse
.core
.commands
.NotHandledException
;
37 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
38 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
39 import org
.eclipse
.core
.expressions
.IEvaluationContext
;
40 import org
.eclipse
.core
.resources
.IFile
;
41 import org
.eclipse
.core
.resources
.IMarker
;
42 import org
.eclipse
.core
.resources
.IResource
;
43 import org
.eclipse
.core
.resources
.IResourceVisitor
;
44 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
45 import org
.eclipse
.core
.runtime
.CoreException
;
46 import org
.eclipse
.core
.runtime
.IPath
;
47 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
48 import org
.eclipse
.core
.runtime
.IStatus
;
49 import org
.eclipse
.core
.runtime
.ListenerList
;
50 import org
.eclipse
.core
.runtime
.Path
;
51 import org
.eclipse
.core
.runtime
.Status
;
52 import org
.eclipse
.core
.runtime
.jobs
.Job
;
53 import org
.eclipse
.emf
.common
.util
.URI
;
54 import org
.eclipse
.emf
.ecore
.EValidator
;
55 import org
.eclipse
.jdt
.annotation
.NonNull
;
56 import org
.eclipse
.jface
.action
.Action
;
57 import org
.eclipse
.jface
.action
.IAction
;
58 import org
.eclipse
.jface
.action
.IMenuListener
;
59 import org
.eclipse
.jface
.action
.IMenuManager
;
60 import org
.eclipse
.jface
.action
.IStatusLineManager
;
61 import org
.eclipse
.jface
.action
.MenuManager
;
62 import org
.eclipse
.jface
.action
.Separator
;
63 import org
.eclipse
.jface
.dialogs
.InputDialog
;
64 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
65 import org
.eclipse
.jface
.resource
.FontRegistry
;
66 import org
.eclipse
.jface
.resource
.JFaceResources
;
67 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
68 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
69 import org
.eclipse
.jface
.util
.OpenStrategy
;
70 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
71 import org
.eclipse
.jface
.util
.SafeRunnable
;
72 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
73 import org
.eclipse
.jface
.viewers
.ISelection
;
74 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
75 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
76 import org
.eclipse
.jface
.viewers
.LabelProvider
;
77 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
78 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
79 import org
.eclipse
.jface
.window
.Window
;
80 import org
.eclipse
.swt
.SWT
;
81 import org
.eclipse
.swt
.custom
.SashForm
;
82 import org
.eclipse
.swt
.custom
.StyleRange
;
83 import org
.eclipse
.swt
.custom
.TableEditor
;
84 import org
.eclipse
.swt
.events
.ControlAdapter
;
85 import org
.eclipse
.swt
.events
.ControlEvent
;
86 import org
.eclipse
.swt
.events
.FocusAdapter
;
87 import org
.eclipse
.swt
.events
.FocusEvent
;
88 import org
.eclipse
.swt
.events
.KeyAdapter
;
89 import org
.eclipse
.swt
.events
.KeyEvent
;
90 import org
.eclipse
.swt
.events
.MouseAdapter
;
91 import org
.eclipse
.swt
.events
.MouseEvent
;
92 import org
.eclipse
.swt
.events
.SelectionAdapter
;
93 import org
.eclipse
.swt
.events
.SelectionEvent
;
94 import org
.eclipse
.swt
.graphics
.Color
;
95 import org
.eclipse
.swt
.graphics
.Font
;
96 import org
.eclipse
.swt
.graphics
.GC
;
97 import org
.eclipse
.swt
.graphics
.Image
;
98 import org
.eclipse
.swt
.graphics
.Point
;
99 import org
.eclipse
.swt
.graphics
.Rectangle
;
100 import org
.eclipse
.swt
.layout
.FillLayout
;
101 import org
.eclipse
.swt
.layout
.GridData
;
102 import org
.eclipse
.swt
.layout
.GridLayout
;
103 import org
.eclipse
.swt
.widgets
.Composite
;
104 import org
.eclipse
.swt
.widgets
.Display
;
105 import org
.eclipse
.swt
.widgets
.Event
;
106 import org
.eclipse
.swt
.widgets
.Label
;
107 import org
.eclipse
.swt
.widgets
.Listener
;
108 import org
.eclipse
.swt
.widgets
.Menu
;
109 import org
.eclipse
.swt
.widgets
.MessageBox
;
110 import org
.eclipse
.swt
.widgets
.Shell
;
111 import org
.eclipse
.swt
.widgets
.TableColumn
;
112 import org
.eclipse
.swt
.widgets
.TableItem
;
113 import org
.eclipse
.swt
.widgets
.Text
;
114 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
115 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
116 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
117 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
118 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
119 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
120 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
121 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
122 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
123 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
124 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfContentFieldAspect
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
141 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
142 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
143 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
144 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
145 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
146 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
147 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
148 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
149 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
150 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
151 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
152 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
153 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
154 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
155 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
156 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
157 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
158 import org
.eclipse
.ui
.IWorkbenchPage
;
159 import org
.eclipse
.ui
.PlatformUI
;
160 import org
.eclipse
.ui
.commands
.ICommandService
;
161 import org
.eclipse
.ui
.dialogs
.ListDialog
;
162 import org
.eclipse
.ui
.handlers
.IHandlerService
;
163 import org
.eclipse
.ui
.ide
.IDE
;
164 import org
.eclipse
.ui
.ide
.IGotoMarker
;
165 import org
.eclipse
.ui
.themes
.ColorUtil
;
166 import org
.eclipse
.ui
.themes
.IThemeManager
;
168 import com
.google
.common
.base
.Joiner
;
169 import com
.google
.common
.collect
.HashMultimap
;
170 import com
.google
.common
.collect
.ImmutableList
;
171 import com
.google
.common
.collect
.Multimap
;
174 * The generic TMF Events table
176 * This is a view that will list events that are read from a trace.
178 * @author Francois Chouinard
179 * @author Patrick Tasse
181 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
, IPropertyChangeListener
{
184 * Empty string array, used by {@link #getItemStrings}.
186 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
191 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
193 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
195 private static final String FONT_DEFINITION_ID
= "org.eclipse.tracecompass.tmf.ui.font.eventtable"; //$NON-NLS-1$
197 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
198 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
199 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
200 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
201 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
202 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
203 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
204 private static final Image FILTER_IMAGE
= Activator
.getDefault()
205 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
206 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
207 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
208 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
209 private static final int MAX_CACHE_SIZE
= 1000;
211 private static final int MARGIN_COLUMN_INDEX
= 0;
212 private static final int FILTER_SUMMARY_INDEX
= 1;
213 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
216 * The events table search/filter keys
219 * @author Patrick Tasse
221 public interface Key
{
223 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
226 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
229 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
232 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
235 String TIMESTAMP
= "$time"; //$NON-NLS-1$
238 String RANK
= "$rank"; //$NON-NLS-1$
240 /** Bookmark indicator */
241 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
243 /** Event aspect represented by this column */
244 String ASPECT
= "$aspect"; //$NON-NLS-1$
246 /** Table item list of style ranges
248 String STYLE_RANGES
= "$style_ranges"; //$NON-NLS-1$
252 * The events table search/filter state
255 * @author Patrick Tasse
257 public static enum HeaderState
{
258 /** A search is being run */
261 /** A filter is applied */
265 interface Direction
{
270 // ------------------------------------------------------------------------
272 // ------------------------------------------------------------------------
274 /** The virtual event table */
275 protected TmfVirtualTable fTable
;
277 private Composite fComposite
;
278 private SashForm fSashForm
;
279 private TmfRawEventViewer fRawViewer
;
280 private ITmfTrace fTrace
;
281 volatile private boolean fPackDone
= false;
282 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
283 private long fSelectedRank
= 0;
284 private ITmfTimestamp fSelectedBeginTimestamp
= null;
285 private IStatusLineManager fStatusLineManager
= null;
288 private long fFilterMatchCount
;
289 private long fFilterCheckCount
;
290 private FilterThread fFilterThread
;
291 private boolean fFilterThreadResume
= false;
292 private final Object fFilterSyncObj
= new Object();
293 private SearchThread fSearchThread
;
294 private final Object fSearchSyncObj
= new Object();
297 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
299 * @see #fireSelectionChanged
301 private ListenerList selectionChangedListeners
= new ListenerList();
303 // Bookmark map <Rank, MarkerId>
304 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
305 private IFile fBookmarksFile
;
306 private long fPendingGotoRank
= -1;
309 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
310 private Color fGrayColor
;
311 private Color fGreenColor
;
313 private Font fBoldFont
;
315 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
318 private final TmfEventsCache fCache
;
319 private boolean fCacheUpdateBusy
= false;
320 private boolean fCacheUpdatePending
= false;
321 private boolean fCacheUpdateCompleted
= false;
322 private final Object fCacheUpdateSyncObj
= new Object();
324 // Keep track of column order, it is needed after table is disposed
325 private int[] fColumnOrder
;
327 private boolean fDisposeOnClose
;
329 // ------------------------------------------------------------------------
331 // ------------------------------------------------------------------------
334 * Basic constructor, using the default set of columns
337 * The parent composite UI object
339 * The size of the event table cache
341 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
342 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
346 * Legacy constructor, using ColumnData to define columns
349 * The parent composite UI object
351 * The size of the event table cache
353 * The column data array
354 * @deprecated Deprecated constructor, use
355 * {@link #TmfEventsTable(Composite, int, Collection)}
358 public TmfEventsTable(final Composite parent
, int cacheSize
,
359 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
361 * We'll do a "best-effort" to keep trace types still using this API to
362 * keep working, by defining a TmfEventTableColumn for each
363 * ColumnData they passed.
365 this(parent
, cacheSize
, convertFromColumnData(columnData
));
369 private static @NonNull Iterable
<ITmfEventAspect
> convertFromColumnData(
370 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
372 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
373 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
374 String fieldName
= col
.header
;
375 if (fieldName
!= null) {
376 builder
.add(new TmfContentFieldAspect(fieldName
, fieldName
));
379 return checkNotNull(builder
.build());
383 * Standard constructor, where we define which columns to use.
386 * The parent composite UI object
388 * The size of the event table cache
390 * The event aspects to display in this table. One column per
391 * aspect will be created.
393 * The iteration order of this collection will correspond to the
394 * initial ordering of the columns in the table.
397 public TmfEventsTable(final Composite parent
, int cacheSize
,
398 @NonNull Iterable
<ITmfEventAspect
> aspects
) {
399 super("TmfEventsTable"); //$NON-NLS-1$
401 fComposite
= new Composite(parent
, SWT
.NONE
);
402 final GridLayout gl
= new GridLayout(1, false);
405 gl
.verticalSpacing
= 0;
406 fComposite
.setLayout(gl
);
408 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
409 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
411 // Create a virtual table
412 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
413 fTable
= new TmfVirtualTable(fSashForm
, style
);
415 // Set the table layout
416 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
417 fTable
.setLayoutData(layoutData
);
419 // Some cosmetic enhancements
420 fTable
.setHeaderVisible(true);
421 fTable
.setLinesVisible(true);
424 for (ITmfEventAspect aspect
: aspects
) {
425 if (aspect
!= null) {
426 fColumns
.add(new TmfEventTableColumn(aspect
));
430 TmfMarginColumn collapseCol
= new TmfMarginColumn();
431 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
433 // Create the UI columns in the table
434 for (TmfEventTableColumn col
: fColumns
) {
435 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
436 column
.setText(col
.getHeaderName());
437 column
.setToolTipText(col
.getHeaderTooltip());
438 column
.setData(Key
.ASPECT
, col
.getEventAspect());
440 if (col
instanceof TmfMarginColumn
) {
441 column
.setResizable(false);
443 column
.setMoveable(true);
445 column
.addControlListener(new ControlAdapter() {
447 * Make sure that the margin column is always first
448 * and keep the column order variable up to date.
451 public void controlMoved(ControlEvent e
) {
452 int[] order
= fTable
.getColumnOrder();
453 if (order
[0] == MARGIN_COLUMN_INDEX
) {
454 fColumnOrder
= order
;
457 for (int i
= order
.length
- 1; i
> 0; i
--) {
458 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
459 order
[i
] = order
[i
- 1];
460 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
463 fTable
.setColumnOrder(order
);
464 fColumnOrder
= fTable
.getColumnOrder();
468 fColumnOrder
= fTable
.getColumnOrder();
470 // Set the frozen row for header row
471 fTable
.setFrozenRowCount(1);
473 // Create the header row cell editor
474 createHeaderEditor();
476 // Handle the table item selection
477 fTable
.addSelectionListener(new SelectionAdapter() {
479 public void widgetSelected(final SelectionEvent e
) {
480 if (e
.item
== null) {
483 updateStatusLine(null);
484 if (fTable
.getSelectionIndices().length
> 0) {
485 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
486 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
487 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
489 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
490 final ITmfTimestamp ts
= NonNullUtils
.checkNotNull((ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
));
491 if (fTable
.getSelectionIndices().length
== 1) {
492 fSelectedBeginTimestamp
= ts
;
494 ITmfTimestamp selectedBeginTimestamp
= fSelectedBeginTimestamp
;
495 if (selectedBeginTimestamp
!= null) {
496 if (selectedBeginTimestamp
.compareTo(ts
) <= 0) {
497 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, selectedBeginTimestamp
, ts
));
498 if (fTable
.getSelectionIndices().length
== 2) {
499 updateStatusLine(ts
.getDelta(selectedBeginTimestamp
));
502 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, checkNotNull(ts
), checkNotNull(fSelectedBeginTimestamp
)));
503 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
507 if (fTable
.getSelectionIndices().length
== 1) {
508 fSelectedBeginTimestamp
= null;
512 if (e
.item
.getData() instanceof ITmfEvent
) {
513 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
514 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
516 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
521 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
522 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
523 fCache
= new TmfEventsCache(realCacheSize
, this);
525 // Handle the table item requests
526 fTable
.addListener(SWT
.SetData
, new Listener() {
529 public void handleEvent(final Event event
) {
531 final TableItem item
= (TableItem
) event
.item
;
532 int index
= event
.index
- 1; // -1 for the header row
534 if (event
.index
== 0) {
535 setHeaderRowItemData(item
);
539 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
540 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
541 setFilterStatusRowItemData(item
);
544 index
= index
- 1; // -1 for top filter status row
547 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
548 if (cachedEvent
!= null) {
549 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
553 // Else, fill the cache asynchronously (and off the UI thread)
558 fTable
.addMouseListener(new MouseAdapter() {
560 public void mouseDoubleClick(final MouseEvent event
) {
561 if (event
.button
!= 1) {
564 // Identify the selected row
565 final Point point
= new Point(event
.x
, event
.y
);
566 final TableItem item
= fTable
.getItem(point
);
568 final Rectangle imageBounds
= item
.getImageBounds(0);
569 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
570 if (imageBounds
.contains(point
)) {
571 final Long rank
= (Long
) item
.getData(Key
.RANK
);
573 toggleBookmark(rank
);
580 final Listener tooltipListener
= new Listener () {
581 Shell tooltipShell
= null;
583 public void handleEvent(final Event event
) {
584 switch (event
.type
) {
586 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
590 final Long rank
= (Long
) item
.getData(Key
.RANK
);
594 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
595 final Rectangle bounds
= item
.getImageBounds(0);
596 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
597 if (!bounds
.contains(event
.x
,event
.y
)) {
600 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
601 tooltipShell
.dispose();
603 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
604 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
605 final FillLayout layout
= new FillLayout();
606 layout
.marginWidth
= 2;
607 tooltipShell
.setLayout(layout
);
608 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
609 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
610 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
611 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
613 label
.addListener(SWT
.MouseExit
, this);
614 label
.addListener(SWT
.MouseDown
, this);
615 label
.addListener(SWT
.MouseWheel
, this);
616 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
618 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
619 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
623 y
+= fTable
.getHeaderHeight();
625 Point pt
= fTable
.toDisplay(event
.x
, y
);
626 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
627 pt
.y
+= item
.getBounds().height
;
628 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
629 tooltipShell
.setVisible(true);
637 if (tooltipShell
!= null) {
638 tooltipShell
.dispose();
648 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
649 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
650 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
651 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
652 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
653 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
654 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
656 fTable
.addListener(SWT
.EraseItem
, new Listener() {
658 public void handleEvent(Event event
) {
659 TableItem item
= (TableItem
) event
.item
;
660 List
<?
> styleRanges
= (List
<?
>) item
.getData(Key
.STYLE_RANGES
);
663 Color background
= item
.getBackground(event
.index
);
665 * Paint the background if it is not the default system color.
666 * In Windows, if you let the widget draw the background, it
667 * will not show the item's background color if the item is
668 * selected or hot. If there are no style ranges and the item
669 * background is the default system color, we do not want to
670 * paint it or otherwise we would override the platform theme
671 * (e.g. alternating colors).
673 if (styleRanges
!= null || !background
.equals(item
.getParent().getBackground())) {
674 // we will paint the table item's background
675 event
.detail
&= ~SWT
.BACKGROUND
;
677 // paint the item's default background
678 gc
.setBackground(background
);
679 gc
.fillRectangle(event
.x
, event
.y
, event
.width
, event
.height
);
683 * We will paint the table item's foreground. In Windows, if you paint
684 * the background but let the widget draw the foreground, it will
685 * override your background, unless the item is selected or hot.
687 event
.detail
&= ~SWT
.FOREGROUND
;
689 // paint the highlighted background for all style ranges
690 if (styleRanges
!= null) {
691 Rectangle textBounds
= item
.getTextBounds(event
.index
);
692 String text
= item
.getText(event
.index
);
693 for (Object o
: styleRanges
) {
694 if (o
instanceof StyleRange
) {
695 StyleRange styleRange
= (StyleRange
) o
;
696 if (styleRange
.data
.equals(event
.index
)) {
697 int startIndex
= styleRange
.start
;
698 int endIndex
= startIndex
+ styleRange
.length
;
699 int startX
= gc
.stringExtent(text
.substring(0, startIndex
)).x
;
700 int endX
= gc
.stringExtent(text
.substring(0, endIndex
)).x
;
701 gc
.setBackground(styleRange
.background
);
702 gc
.fillRectangle(textBounds
.x
+ startX
, textBounds
.y
, (endX
- startX
), textBounds
.height
);
710 fTable
.addListener(SWT
.PaintItem
, new Listener() {
712 public void handleEvent(Event event
) {
713 TableItem item
= (TableItem
) event
.item
;
715 // we promised to paint the table item's foreground
717 Image image
= item
.getImage(event
.index
);
719 Rectangle imageBounds
= item
.getImageBounds(event
.index
);
721 * The image bounds don't match the default image position.
724 gc
.drawImage(image
, imageBounds
.x
+ 1, imageBounds
.y
+ 3);
726 gc
.drawImage(image
, imageBounds
.x
, imageBounds
.y
+ 1);
729 gc
.setForeground(item
.getForeground(event
.index
));
730 gc
.setFont(item
.getFont(event
.index
));
731 String text
= item
.getText(event
.index
);
732 Rectangle textBounds
= item
.getTextBounds(event
.index
);
734 * The text bounds don't match the default text position.
737 gc
.drawText(text
, textBounds
.x
+ 1, textBounds
.y
+ 3, true);
739 gc
.drawText(text
, textBounds
.x
- 1, textBounds
.y
+ 2, true);
748 PlatformUI
.getWorkbench().getThemeManager().addPropertyChangeListener(this);
750 ColorSettingsManager
.addColorSettingsListener(this);
752 fTable
.setItemCount(1); // +1 for header row
754 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
756 fRawViewer
.addSelectionListener(new Listener() {
758 public void handleEvent(final Event e
) {
759 if (e
.data
instanceof Long
) {
760 final long rank
= (Long
) e
.data
;
761 int index
= (int) rank
;
762 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
763 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
765 fTable
.setSelection(index
+ 1); // +1 for header row
766 fSelectedRank
= rank
;
767 updateStatusLine(null);
768 } else if (e
.data
instanceof ITmfLocation
) {
769 // DOES NOT WORK: rank undefined in context from seekLocation()
770 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
771 // TmfContext context = fTrace.seekLocation(location);
772 // fTable.setSelection((int) context.getRank());
777 final TableItem
[] selection
= fTable
.getSelection();
778 if ((selection
!= null) && (selection
.length
> 0)) {
779 TableItem item
= fTable
.getSelection()[0];
780 final TmfTimestamp ts
= (TmfTimestamp
) item
.getData(Key
.TIMESTAMP
);
782 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
784 if (item
.getData() instanceof ITmfEvent
) {
785 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) item
.getData()));
786 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(item
.getData())));
788 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
794 fSashForm
.setWeights(new int[] { 1, 1 });
795 fRawViewer
.setVisible(false);
800 // ------------------------------------------------------------------------
802 // ------------------------------------------------------------------------
805 * Create a pop-up menu.
807 protected void createPopupMenu() {
808 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
811 fTable
.setVisible(true);
816 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
819 fTable
.setVisible(false);
824 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
827 fRawViewer
.setVisible(true);
829 final int index
= fTable
.getSelectionIndex();
831 fRawViewer
.selectAndReveal(index
- 1);
836 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
839 fRawViewer
.setVisible(false);
844 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
847 final TableItem items
[] = fTable
.getSelection();
848 if (items
.length
!= 1) {
851 final TableItem item
= items
[0];
853 final Object data
= item
.getData();
854 if (data
instanceof ITmfSourceLookup
) {
855 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
856 ITmfCallsite cs
= event
.getCallsite();
857 if (cs
== null || cs
.getFileName() == null) {
860 IMarker marker
= null;
862 String fileName
= cs
.getFileName();
863 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
864 final ArrayList
<IFile
> files
= new ArrayList
<>();
865 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
867 public boolean visit(IResource resource
) throws CoreException
{
868 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
869 files
.add((IFile
) resource
);
875 if (files
.size() > 1) {
876 ListDialog dialog
= new ListDialog(getTable().getShell());
877 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
878 dialog
.setLabelProvider(new LabelProvider() {
880 public String
getText(Object element
) {
881 return ((IFile
) element
).getFullPath().toString();
884 dialog
.setInput(files
);
885 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
886 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
888 Object
[] result
= dialog
.getResult();
889 if (result
!= null && result
.length
> 0) {
890 file
= (IFile
) result
[0];
892 } else if (files
.size() == 1) {
896 marker
= file
.createMarker(IMarker
.MARKER
);
897 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
898 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
900 } else if (files
.size() == 0){
901 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
903 } catch (CoreException e
) {
910 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
914 final TableItem items
[] = fTable
.getSelection();
915 if (items
.length
!= 1) {
918 final TableItem item
= items
[0];
920 final Object eventData
= item
.getData();
921 if (eventData
instanceof ITmfModelLookup
) {
922 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
924 if (modelURI
!= null) {
925 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
928 final URI uri
= URI
.createURI(modelURI
);
929 if (uri
.isPlatformResource()) {
930 IPath path
= new Path(uri
.toPlatformString(true));
931 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
932 } else if (uri
.isFile() && !uri
.isRelative()) {
933 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
934 new Path(uri
.toFileString()));
940 * create a temporary validation marker on the
941 * model file, remove it afterwards thus,
942 * navigation works with all model editors
943 * supporting the navigation to a marker
945 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
946 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
947 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
949 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
952 catch (CoreException e
) {
956 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
963 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
966 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
967 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
968 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
969 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
970 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
972 HashMap
<String
, Object
> parameters
= new HashMap
<>();
973 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
974 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
976 IEvaluationContext context
= handlerService
.getCurrentState();
977 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
978 for (int i
: fTable
.getColumnOrder()) {
979 // Omit the margin column
980 if (i
>= EVENT_COLUMNS_START_INDEX
) {
981 exportColumns
.add(fColumns
.get(i
));
984 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
986 handlerService
.executeCommandInContext(cmd
, null, context
);
987 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
993 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
996 fHeaderState
= HeaderState
.SEARCH
;
1002 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
1005 fHeaderState
= HeaderState
.FILTER
;
1011 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
1018 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
1021 applyFilter(new TmfCollapseFilter());
1025 class ToggleBookmarkAction
extends Action
{
1028 public ToggleBookmarkAction(final String text
, final Long rank
) {
1035 toggleBookmark(fRank
);
1039 final MenuManager tablePopupMenu
= new MenuManager();
1040 tablePopupMenu
.setRemoveAllWhenShown(true);
1041 tablePopupMenu
.addMenuListener(new IMenuListener() {
1043 public void menuAboutToShow(final IMenuManager manager
) {
1044 if (fTable
.getSelectionIndex() == 0) {
1045 // Right-click on header row
1046 if (fHeaderState
== HeaderState
.FILTER
) {
1047 tablePopupMenu
.add(showSearchBarAction
);
1049 tablePopupMenu
.add(showFilterBarAction
);
1053 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
1054 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
1056 final Rectangle imageBounds
= item
.getImageBounds(0);
1057 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
1058 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
1059 // Right-click on left margin
1060 final Long rank
= (Long
) item
.getData(Key
.RANK
);
1061 if ((rank
!= null) && (fBookmarksFile
!= null)) {
1062 if (fBookmarksMap
.containsKey(rank
)) {
1063 tablePopupMenu
.add(new ToggleBookmarkAction(
1064 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
1066 tablePopupMenu
.add(new ToggleBookmarkAction(
1067 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
1074 // Right-click on table
1075 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1076 tablePopupMenu
.add(hideTableAction
);
1077 tablePopupMenu
.add(hideRawAction
);
1078 } else if (!fTable
.isVisible()) {
1079 tablePopupMenu
.add(showTableAction
);
1080 } else if (!fRawViewer
.isVisible()) {
1081 tablePopupMenu
.add(showRawAction
);
1083 tablePopupMenu
.add(exportToTextAction
);
1084 tablePopupMenu
.add(new Separator());
1087 final Object data
= item
.getData();
1088 Separator separator
= null;
1089 if (data
instanceof ITmfSourceLookup
) {
1090 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
1091 if (event
.getCallsite() != null) {
1092 tablePopupMenu
.add(openCallsiteAction
);
1093 separator
= new Separator();
1097 if (data
instanceof ITmfModelLookup
) {
1098 ITmfModelLookup event
= (ITmfModelLookup
) data
;
1099 if (event
.getModelUri() != null) {
1100 tablePopupMenu
.add(openModelAction
);
1101 separator
= new Separator();
1104 if (separator
!= null) {
1105 tablePopupMenu
.add(separator
);
1110 // only show collapse filter if at least one trace can be collapsed
1111 boolean isCollapsible
= false;
1112 if (fTrace
!= null) {
1113 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
1114 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1115 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1116 if (isCollapsible
) {
1122 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1123 tablePopupMenu
.add(collapseAction
);
1124 tablePopupMenu
.add(new Separator());
1127 tablePopupMenu
.add(clearFiltersAction
);
1128 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1129 if (savedFilters
.length
> 0) {
1130 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1131 for (final ITmfFilterTreeNode node
: savedFilters
) {
1132 if (node
instanceof TmfFilterNode
) {
1133 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1134 subMenu
.add(new Action(filter
.getFilterName()) {
1137 applyFilter(filter
);
1142 tablePopupMenu
.add(subMenu
);
1144 appendToTablePopupMenu(tablePopupMenu
, item
);
1148 final MenuManager rawViewerPopupMenu
= new MenuManager();
1149 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1150 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1152 public void menuAboutToShow(final IMenuManager manager
) {
1153 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1154 rawViewerPopupMenu
.add(hideTableAction
);
1155 rawViewerPopupMenu
.add(hideRawAction
);
1156 } else if (!fTable
.isVisible()) {
1157 rawViewerPopupMenu
.add(showTableAction
);
1158 } else if (!fRawViewer
.isVisible()) {
1159 rawViewerPopupMenu
.add(showRawAction
);
1161 appendToRawPopupMenu(tablePopupMenu
);
1165 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1166 fTable
.setMenu(menu
);
1168 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1169 fRawViewer
.setMenu(menu
);
1174 * Append an item to the event table's pop-up menu.
1176 * @param tablePopupMenu
1178 * @param selectedItem
1179 * The item to append
1181 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1182 // override to append more actions
1186 * Append an item to the raw viewer's pop-up menu.
1188 * @param rawViewerPopupMenu
1191 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1192 // override to append more actions
1196 public void dispose() {
1199 PlatformUI
.getWorkbench().getThemeManager().removePropertyChangeListener(this);
1200 ColorSettingsManager
.removeColorSettingsListener(this);
1201 fComposite
.dispose();
1202 if ((fTrace
!= null) && fDisposeOnClose
) {
1205 fResourceManager
.dispose();
1206 fRawViewer
.dispose();
1211 * Assign a layout data object to this view.
1214 * The layout data to assign
1216 public void setLayoutData(final Object layoutData
) {
1217 fComposite
.setLayoutData(layoutData
);
1221 * Get the virtual table contained in this event table.
1223 * @return The TMF virtual table
1225 public TmfVirtualTable
getTable() {
1232 * @deprecated The column headers are now set at the constructor, this
1233 * shouldn't be called anymore.
1236 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1241 * Set a table item's data.
1246 * Which trace event to link with this entry
1248 * Which rank this event has in the trace/experiment
1250 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1251 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1253 // Get the actual ITmfEvent from the CachedEvent
1254 ITmfEvent tmfEvent
= event
;
1255 if (event
instanceof CachedEvent
) {
1256 tmfEvent
= ((CachedEvent
) event
).event
;
1258 item
.setText(itemStrings
);
1259 item
.setData(tmfEvent
);
1260 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1261 item
.setData(Key
.RANK
, rank
);
1263 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1264 if (!markerIds
.isEmpty()) {
1265 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1266 List
<Object
> parts
= new ArrayList
<>();
1267 if (markerIds
.size() > 1) {
1268 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1271 for (long markerId
: markerIds
) {
1272 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1273 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1275 } catch (CoreException e
) {
1276 displayException(e
);
1278 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1280 item
.setData(Key
.BOOKMARK
, null);
1283 boolean searchMatch
= false;
1284 boolean searchNoMatch
= false;
1285 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1286 if (searchFilter
!= null) {
1287 if (searchFilter
.matches(tmfEvent
)) {
1290 searchNoMatch
= true;
1294 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1295 if (searchNoMatch
) {
1296 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1297 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1299 item
.setForeground(colorSetting
.getForegroundColor());
1300 item
.setBackground(colorSetting
.getBackgroundColor());
1302 item
.setFont(fFont
);
1305 if (!markerIds
.isEmpty()) {
1306 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1308 item
.setImage(SEARCH_MATCH_IMAGE
);
1310 } else if (!markerIds
.isEmpty()) {
1311 item
.setImage(BOOKMARK_IMAGE
);
1313 item
.setImage((Image
) null);
1316 List
<StyleRange
> styleRanges
= new ArrayList
<>();
1317 for (int index
= 0; index
< fTable
.getColumns().length
; index
++) {
1318 TableColumn column
= fTable
.getColumns()[index
];
1319 String regex
= null;
1320 if (fHeaderState
== HeaderState
.FILTER
) {
1321 regex
= (String
) column
.getData(Key
.FILTER_TXT
);
1322 } else if (searchMatch
) {
1323 regex
= (String
) column
.getData(Key
.SEARCH_TXT
);
1325 if (regex
!= null) {
1326 String text
= item
.getText(index
);
1328 Pattern pattern
= Pattern
.compile(regex
);
1329 Matcher matcher
= pattern
.matcher(text
);
1330 while (matcher
.find()) {
1331 int start
= matcher
.start();
1332 int length
= matcher
.end() - start
;
1333 Color foreground
= colorSetting
.getForegroundColor();
1334 Color background
= item
.getDisplay().getSystemColor(SWT
.COLOR_YELLOW
);
1335 StyleRange styleRange
= new StyleRange(start
, length
, foreground
, background
);
1336 styleRange
.data
= index
;
1337 styleRanges
.add(styleRange
);
1339 } catch (PatternSyntaxException e
) {
1344 if (styleRanges
.isEmpty()) {
1345 item
.setData(Key
.STYLE_RANGES
, null);
1347 item
.setData(Key
.STYLE_RANGES
, styleRanges
);
1349 item
.getParent().redraw();
1351 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1357 * Set the item data of the header row.
1360 * The item to use as table header
1362 protected void setHeaderRowItemData(final TableItem item
) {
1363 String txtKey
= null;
1364 if (fHeaderState
== HeaderState
.SEARCH
) {
1365 item
.setImage(SEARCH_IMAGE
);
1366 txtKey
= Key
.SEARCH_TXT
;
1367 } else if (fHeaderState
== HeaderState
.FILTER
) {
1368 item
.setImage(FILTER_IMAGE
);
1369 txtKey
= Key
.FILTER_TXT
;
1371 item
.setForeground(fGrayColor
);
1372 // Ignore collapse and image column
1373 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1374 final TableColumn column
= fTable
.getColumns()[i
];
1375 final String filter
= (String
) column
.getData(txtKey
);
1376 if (filter
== null) {
1377 if (fHeaderState
== HeaderState
.SEARCH
) {
1378 item
.setText(i
, SEARCH_HINT
);
1379 } else if (fHeaderState
== HeaderState
.FILTER
) {
1380 item
.setText(i
, FILTER_HINT
);
1382 item
.setForeground(i
, fGrayColor
);
1383 item
.setFont(i
, fFont
);
1385 item
.setText(i
, filter
);
1386 item
.setForeground(i
, fGreenColor
);
1387 item
.setFont(i
, fBoldFont
);
1393 * Set the item data of the "filter status" row.
1396 * The item to use as filter status row
1398 protected void setFilterStatusRowItemData(final TableItem item
) {
1399 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1400 if (i
== MARGIN_COLUMN_INDEX
) {
1401 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1402 item
.setImage(FILTER_IMAGE
);
1404 item
.setImage(STOP_IMAGE
);
1408 if (i
== FILTER_SUMMARY_INDEX
) {
1409 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1411 item
.setText(i
, EMPTY_STRING
);
1415 item
.setData(Key
.TIMESTAMP
, null);
1416 item
.setData(Key
.RANK
, null);
1417 item
.setData(Key
.STYLE_RANGES
, null);
1418 item
.setForeground(null);
1419 item
.setBackground(null);
1420 item
.setFont(fFont
);
1424 * Create an editor for the header.
1426 protected void createHeaderEditor() {
1427 final TableEditor tableEditor
= fTable
.createTableEditor();
1428 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1429 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1430 tableEditor
.grabHorizontal
= true;
1431 tableEditor
.minimumWidth
= 50;
1433 // Handle the header row selection
1434 fTable
.addMouseListener(new MouseAdapter() {
1440 public void mouseDown(final MouseEvent event
) {
1441 if (event
.button
!= 1) {
1444 // Identify the selected row
1445 final Point point
= new Point(event
.x
, event
.y
);
1446 item
= fTable
.getItem(point
);
1448 // Header row selected
1449 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1452 if (item
.getImageBounds(0).contains(point
)) {
1453 if (fHeaderState
== HeaderState
.SEARCH
) {
1454 fHeaderState
= HeaderState
.FILTER
;
1455 } else if (fHeaderState
== HeaderState
.FILTER
) {
1456 fHeaderState
= HeaderState
.SEARCH
;
1458 fTable
.setSelection(0);
1464 // Identify the selected column
1466 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1467 final Rectangle rect
= item
.getBounds(i
);
1468 if (rect
.contains(point
)) {
1474 if (columnIndex
== -1) {
1478 column
= fTable
.getColumns()[columnIndex
];
1480 String txtKey
= null;
1481 if (fHeaderState
== HeaderState
.SEARCH
) {
1482 txtKey
= Key
.SEARCH_TXT
;
1483 } else if (fHeaderState
== HeaderState
.FILTER
) {
1484 txtKey
= Key
.FILTER_TXT
;
1487 // The control that will be the editor must be a child of the Table
1488 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1489 final String headerString
= (String
) column
.getData(txtKey
);
1490 if (headerString
!= null) {
1491 newEditor
.setText(headerString
);
1493 newEditor
.addFocusListener(new FocusAdapter() {
1495 public void focusLost(final FocusEvent e
) {
1496 final boolean changed
= updateHeader(newEditor
.getText());
1502 newEditor
.addKeyListener(new KeyAdapter() {
1504 public void keyPressed(final KeyEvent e
) {
1505 if (e
.character
== SWT
.CR
) {
1506 updateHeader(newEditor
.getText());
1509 // Set focus on the table so that the next carriage return goes to the next result
1510 TmfEventsTable
.this.getTable().setFocus();
1511 } else if (e
.character
== SWT
.ESC
) {
1512 tableEditor
.getEditor().dispose();
1516 newEditor
.selectAll();
1517 newEditor
.setFocus();
1518 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1523 * returns true is value was changed
1525 private boolean updateHeader(final String regex
) {
1526 String objKey
= null;
1527 String txtKey
= null;
1528 if (fHeaderState
== HeaderState
.SEARCH
) {
1529 objKey
= Key
.SEARCH_OBJ
;
1530 txtKey
= Key
.SEARCH_TXT
;
1531 } else if (fHeaderState
== HeaderState
.FILTER
) {
1532 objKey
= Key
.FILTER_OBJ
;
1533 txtKey
= Key
.FILTER_TXT
;
1535 if (regex
.length() > 0) {
1537 Pattern
.compile(regex
);
1538 if (regex
.equals(column
.getData(txtKey
))) {
1539 tableEditor
.getEditor().dispose();
1542 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1543 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1544 filter
.setEventAspect(aspect
);
1545 filter
.setRegex(regex
);
1546 column
.setData(objKey
, filter
);
1547 column
.setData(txtKey
, regex
);
1548 } catch (final PatternSyntaxException ex
) {
1549 tableEditor
.getEditor().dispose();
1550 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1551 ex
.getDescription(), ex
.getMessage());
1555 if (column
.getData(txtKey
) == null) {
1556 tableEditor
.getEditor().dispose();
1559 column
.setData(objKey
, null);
1560 column
.setData(txtKey
, null);
1565 private void applyHeader() {
1566 if (fHeaderState
== HeaderState
.SEARCH
) {
1568 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1569 for (final TableColumn col
: fTable
.getColumns()) {
1570 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1571 if (filterObj
instanceof ITmfFilterTreeNode
) {
1572 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1575 if (filter
.getChildrenCount() > 0) {
1576 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1579 fireSearchApplied(filter
);
1581 fTable
.setData(Key
.SEARCH_OBJ
, null);
1583 fireSearchApplied(null);
1585 } else if (fHeaderState
== HeaderState
.FILTER
) {
1586 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1587 for (final TableColumn col
: fTable
.getColumns()) {
1588 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1589 if (filterObj
instanceof ITmfFilterTreeNode
) {
1590 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1593 if (filter
.getChildrenCount() > 0) {
1594 applyFilter(filter
);
1600 tableEditor
.getEditor().dispose();
1604 fTable
.addKeyListener(new KeyAdapter() {
1606 public void keyPressed(final KeyEvent e
) {
1608 if (e
.character
== SWT
.ESC
) {
1612 } else if (e
.character
== SWT
.DEL
) {
1613 if (fHeaderState
== HeaderState
.SEARCH
) {
1615 for (final TableColumn column
: fTable
.getColumns()) {
1616 column
.setData(Key
.SEARCH_OBJ
, null);
1617 column
.setData(Key
.SEARCH_TXT
, null);
1619 fTable
.setData(Key
.SEARCH_OBJ
, null);
1621 fireSearchApplied(null);
1622 } else if (fHeaderState
== HeaderState
.FILTER
) {
1625 } else if (e
.character
== SWT
.CR
) {
1626 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1637 * Send an event indicating a filter has been applied.
1640 * The filter that was just applied
1642 protected void fireFilterApplied(final ITmfFilter filter
) {
1643 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1647 * Send an event indicating that a search has been applied.
1650 * The search filter that was just applied
1652 protected void fireSearchApplied(final ITmfFilter filter
) {
1653 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1657 * Start the filtering thread.
1659 protected void startFilterThread() {
1660 synchronized (fFilterSyncObj
) {
1661 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1662 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1663 if (fFilterThread
!= null) {
1664 fFilterThread
.cancel();
1665 fFilterThreadResume
= false;
1667 fFilterThread
= new FilterThread(filter
);
1668 fFilterThread
.start();
1670 fFilterThreadResume
= true;
1676 * Stop the filtering thread.
1678 protected void stopFilterThread() {
1679 synchronized (fFilterSyncObj
) {
1680 if (fFilterThread
!= null) {
1681 fFilterThread
.cancel();
1682 fFilterThread
= null;
1683 fFilterThreadResume
= false;
1692 * The filter to apply
1694 protected void applyFilter(ITmfFilter filter
) {
1697 fFilterMatchCount
= 0;
1698 fFilterCheckCount
= 0;
1699 fCache
.applyFilter(filter
);
1701 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1702 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1703 startFilterThread();
1704 fireFilterApplied(filter
);
1708 * Clear all currently active filters.
1710 protected void clearFilters() {
1711 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1716 fCache
.clearFilter();
1718 for (final TableColumn column
: fTable
.getColumns()) {
1719 column
.setData(Key
.FILTER_OBJ
, null);
1720 column
.setData(Key
.FILTER_TXT
, null);
1722 fTable
.setData(Key
.FILTER_OBJ
, null);
1723 if (fTrace
!= null) {
1724 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1726 fTable
.setItemCount(1); // +1 for header row
1728 fFilterMatchCount
= 0;
1729 fFilterCheckCount
= 0;
1730 if (fSelectedRank
>= 0) {
1731 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1733 fTable
.setSelection(0);
1735 fireFilterApplied(null);
1736 updateStatusLine(null);
1738 // Set original width
1739 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1744 * Wrapper Thread object for the filtering thread.
1746 protected class FilterThread
extends Thread
{
1747 private final ITmfFilterTreeNode filter
;
1748 private TmfEventRequest request
;
1749 private boolean refreshBusy
= false;
1750 private boolean refreshPending
= false;
1751 private final Object syncObj
= new Object();
1757 * The filter this thread will be processing
1759 public FilterThread(final ITmfFilterTreeNode filter
) {
1760 super("Filter Thread"); //$NON-NLS-1$
1761 this.filter
= filter
;
1766 if (fTrace
== null) {
1769 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1770 if (nbRequested
<= 0) {
1773 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1774 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1776 public void handleData(final ITmfEvent event
) {
1777 super.handleData(event
);
1778 if (request
.isCancelled()) {
1781 boolean refresh
= false;
1782 if (filter
.matches(event
)) {
1783 final long rank
= fFilterCheckCount
;
1784 final int index
= (int) fFilterMatchCount
;
1785 fFilterMatchCount
++;
1786 fCache
.storeEvent(event
, rank
, index
);
1789 if (filter
instanceof TmfCollapseFilter
) {
1790 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1794 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1797 fFilterCheckCount
++;
1800 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1802 request
.waitForCompletion();
1803 } catch (final InterruptedException e
) {
1806 synchronized (fFilterSyncObj
) {
1807 fFilterThread
= null;
1808 if (fFilterThreadResume
) {
1809 fFilterThreadResume
= false;
1810 fFilterThread
= new FilterThread(filter
);
1811 fFilterThread
.start();
1817 * Refresh the filter.
1819 public void refreshTable() {
1820 synchronized (syncObj
) {
1822 refreshPending
= true;
1827 Display
.getDefault().asyncExec(new Runnable() {
1830 if (request
.isCancelled()) {
1833 if (fTable
.isDisposed()) {
1836 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1838 synchronized (syncObj
) {
1839 refreshBusy
= false;
1840 if (refreshPending
) {
1841 refreshPending
= false;
1850 * Cancel this filtering thread.
1852 public void cancel() {
1853 if (request
!= null) {
1860 * Go to the next item of a search.
1862 protected void searchNext() {
1863 synchronized (fSearchSyncObj
) {
1864 if (fSearchThread
!= null) {
1867 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1868 if (searchFilter
== null) {
1871 final int selectionIndex
= fTable
.getSelectionIndex();
1873 if (selectionIndex
> 0) {
1874 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1876 // header row is selected, start at top event
1877 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1879 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1880 if (eventFilter
!= null) {
1881 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1883 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1884 fSearchThread
.schedule();
1889 * Go to the previous item of a search.
1891 protected void searchPrevious() {
1892 synchronized (fSearchSyncObj
) {
1893 if (fSearchThread
!= null) {
1896 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1897 if (searchFilter
== null) {
1900 final int selectionIndex
= fTable
.getSelectionIndex();
1902 if (selectionIndex
> 0) {
1903 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1905 // header row is selected, start at precedent of top event
1906 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1908 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1909 if (eventFilter
!= null) {
1910 startIndex
= startIndex
- 1; // -1 for top filter status row
1912 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1913 fSearchThread
.schedule();
1918 * Stop the search thread.
1920 protected void stopSearchThread() {
1921 fPendingGotoRank
= -1;
1922 synchronized (fSearchSyncObj
) {
1923 if (fSearchThread
!= null) {
1924 fSearchThread
.cancel();
1925 fSearchThread
= null;
1931 * Wrapper for the search thread.
1933 protected class SearchThread
extends Job
{
1935 private ITmfFilterTreeNode searchFilter
;
1936 private ITmfFilterTreeNode eventFilter
;
1937 private int startIndex
;
1938 private int direction
;
1940 private long foundRank
= -1;
1941 private TmfEventRequest request
;
1942 private ITmfTimestamp foundTimestamp
= null;
1947 * @param searchFilter
1949 * @param eventFilter
1952 * The index at which we should start searching
1953 * @param currentRank
1956 * In which direction should we search, forward or backwards
1958 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1959 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1960 final long currentRank
, final int direction
) {
1961 super(Messages
.TmfEventsTable_SearchingJobName
);
1962 this.searchFilter
= searchFilter
;
1963 this.eventFilter
= eventFilter
;
1964 this.startIndex
= startIndex
;
1965 this.rank
= currentRank
;
1966 this.direction
= direction
;
1970 protected IStatus
run(final IProgressMonitor monitor
) {
1971 if (fTrace
== null) {
1972 return Status
.OK_STATUS
;
1974 final Display display
= Display
.getDefault();
1975 if (startIndex
< 0) {
1976 rank
= (int) fTrace
.getNbEvents() - 1;
1977 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1980 int idx
= startIndex
;
1981 while (foundRank
== -1) {
1982 final CachedEvent event
= fCache
.peekEvent(idx
);
1983 if (event
== null) {
1987 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1988 foundRank
= event
.rank
;
1989 foundTimestamp
= event
.event
.getTimestamp();
1992 if (direction
== Direction
.FORWARD
) {
1998 if (foundRank
== -1) {
1999 if (direction
== Direction
.FORWARD
) {
2001 if (rank
> (fTrace
.getNbEvents() - 1)) {
2007 rank
= (int) fTrace
.getNbEvents() - 1;
2012 final int startRank
= (int) rank
;
2013 boolean wrapped
= false;
2014 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
2015 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
2016 if (direction
== Direction
.BACKWARD
) {
2017 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
2019 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
2020 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
2021 long currentRank
= rank
;
2024 public void handleData(final ITmfEvent event
) {
2025 super.handleData(event
);
2026 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
2027 foundRank
= currentRank
;
2028 foundTimestamp
= event
.getTimestamp();
2029 if (direction
== Direction
.FORWARD
) {
2037 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
2039 request
.waitForCompletion();
2040 if (request
.isCancelled()) {
2041 return Status
.OK_STATUS
;
2043 } catch (final InterruptedException e
) {
2044 synchronized (fSearchSyncObj
) {
2045 fSearchThread
= null;
2047 return Status
.OK_STATUS
;
2049 if (foundRank
== -1) {
2050 if (direction
== Direction
.FORWARD
) {
2052 synchronized (fSearchSyncObj
) {
2053 fSearchThread
= null;
2055 return Status
.OK_STATUS
;
2057 nbRequested
= (int) rank
;
2063 rank
= (int) fTrace
.getNbEvents() - 1;
2066 if ((rank
<= startRank
) && wrapped
) {
2067 synchronized (fSearchSyncObj
) {
2068 fSearchThread
= null;
2070 return Status
.OK_STATUS
;
2075 int index
= (int) foundRank
;
2076 if (eventFilter
!= null) {
2077 index
= fCache
.getFilteredEventIndex(foundRank
);
2079 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
2081 display
.asyncExec(new Runnable() {
2084 if (monitor
.isCanceled()) {
2087 if (fTable
.isDisposed()) {
2090 fTable
.setSelection(selection
);
2091 fSelectedRank
= foundRank
;
2092 fRawViewer
.selectAndReveal(fSelectedRank
);
2093 if (foundTimestamp
!= null) {
2094 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
2096 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
2097 synchronized (fSearchSyncObj
) {
2098 fSearchThread
= null;
2100 updateStatusLine(null);
2103 return Status
.OK_STATUS
;
2107 protected void canceling() {
2109 synchronized (fSearchSyncObj
) {
2110 fSearchThread
= null;
2116 * Create the resources.
2118 protected void createResources() {
2119 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
2120 .getForeground().getRGB()));
2121 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
2125 * Initialize the fonts.
2128 protected void initializeFonts() {
2129 FontRegistry fontRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
2130 fFont
= fontRegistry
.get(FONT_DEFINITION_ID
);
2131 fBoldFont
= fontRegistry
.getBold(FONT_DEFINITION_ID
);
2132 fTable
.setFont(fFont
);
2133 /* Column header font cannot be set. See Bug 63038 */
2140 public void propertyChange(PropertyChangeEvent event
) {
2141 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2142 (FONT_DEFINITION_ID
.equals(event
.getProperty()))) {
2151 protected void packColumns() {
2155 fTable
.setRedraw(false);
2157 TableColumn tableColumns
[] = fTable
.getColumns();
2158 for (int i
= 0; i
< tableColumns
.length
; i
++) {
2159 final TableColumn column
= tableColumns
[i
];
2160 packSingleColumn(i
, column
);
2163 // Make sure that redraw is always enabled.
2164 fTable
.setRedraw(true);
2170 private void packMarginColumn() {
2171 TableColumn
[] columns
= fTable
.getColumns();
2172 if (columns
.length
> 0) {
2173 packSingleColumn(0, columns
[0]);
2177 private void packSingleColumn(int i
, final TableColumn column
) {
2178 final int headerWidth
= column
.getWidth();
2180 // Workaround for Linux which doesn't consider the image width of
2181 // search/filter row in TableColumn.pack() after having executed
2182 // TableItem.setImage((Image)null) for other rows than search/filter row.
2183 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2184 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2185 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2188 if (column
.getWidth() < headerWidth
) {
2189 column
.setWidth(headerWidth
);
2194 * Get the array of item strings (e.g., what to display in each cell of the
2195 * table row) corresponding to the columns and trace event passed in
2196 * parameter. The order of the Strings in the returned array will correspond
2197 * to the iteration order of 'columns'.
2200 * To ensure consistent results, make sure only call this within a scope
2201 * synchronized on 'columns'! If the order of 'columns' changes right after
2202 * this method is called, the returned value won't be ordered correctly
2205 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2206 if (event
== null) {
2207 return EMPTY_STRING_ARRAY
;
2209 synchronized (columns
) {
2210 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2211 for (TmfEventTableColumn column
: columns
) {
2212 ITmfEvent passedEvent
= event
;
2213 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2214 // Make sure that the event object from the trace is passed
2215 // to all columns but the TmfMarginColumn
2216 passedEvent
= ((CachedEvent
) event
).event
;
2218 if (passedEvent
== null) {
2219 itemStrings
.add(EMPTY_STRING
);
2221 itemStrings
.add(column
.getItemString(passedEvent
));
2225 return itemStrings
.toArray(new String
[0]);
2230 * Get the contents of the row in the events table corresponding to an
2231 * event. The order of the elements corresponds to the current order of the
2235 * The event printed in this row
2236 * @return The event row entries
2238 public String
[] getItemStrings(ITmfEvent event
) {
2239 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2240 for (int i
: fTable
.getColumnOrder()) {
2241 columns
.add(fColumns
.get(i
));
2243 return getItemStrings(columns
, event
);
2247 * Returns an array of zero-relative integers that map
2248 * the creation order of the receiver's columns to the
2249 * order in which they are currently being displayed.
2251 * Specifically, the indices of the returned array represent
2252 * the current visual order of the columns, and the contents
2253 * of the array represent the creation order of the columns.
2255 * @return the current visual order of the receiver's columns
2258 public int[] getColumnOrder() {
2259 return fColumnOrder
;
2263 * Sets the order that the columns in the receiver should
2264 * be displayed in to the given argument which is described
2265 * in terms of the zero-relative ordering of when the columns
2268 * Specifically, the contents of the array represent the
2269 * original position of each column at the time its creation.
2271 * @param order the new order to display the columns
2274 public void setColumnOrder(int[] order
) {
2275 if (order
== null || order
.length
!= fTable
.getColumns().length
) {
2278 fTable
.setColumnOrder(order
);
2279 fColumnOrder
= fTable
.getColumnOrder();
2283 * Notify this table that is got the UI focus.
2285 public void setFocus() {
2290 * Assign a new trace to this event table.
2293 * The trace to assign to this event table
2294 * @param disposeOnClose
2295 * true if the trace should be disposed when the table is
2298 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2299 if ((fTrace
!= null) && fDisposeOnClose
) {
2305 fDisposeOnClose
= disposeOnClose
;
2307 // Perform the updates on the UI thread
2308 fTable
.getDisplay().syncExec(new Runnable() {
2312 fCache
.setTrace(fTrace
); // Clear the cache
2313 if (fTrace
!= null) {
2314 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2315 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2316 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2319 fFilterMatchCount
= 0;
2320 fFilterCheckCount
= 0;
2321 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2322 startFilterThread();
2326 fRawViewer
.setTrace(fTrace
);
2332 * Assign the status line manager
2334 * @param statusLineManager
2335 * The status line manager, or null to disable status line messages
2337 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2338 if (fStatusLineManager
!= null && statusLineManager
== null) {
2339 fStatusLineManager
.setMessage(EMPTY_STRING
);
2341 fStatusLineManager
= statusLineManager
;
2344 private void updateStatusLine(ITmfTimestamp delta
) {
2345 if (fStatusLineManager
!= null) {
2346 if (delta
!= null) {
2347 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2349 fStatusLineManager
.setMessage(null);
2354 // ------------------------------------------------------------------------
2356 // ------------------------------------------------------------------------
2359 * Notify that the event cache has been updated
2362 * Also notify if the populating of the cache is complete, or
2365 public void cacheUpdated(final boolean completed
) {
2366 synchronized (fCacheUpdateSyncObj
) {
2367 if (fCacheUpdateBusy
) {
2368 fCacheUpdatePending
= true;
2369 fCacheUpdateCompleted
= completed
;
2372 fCacheUpdateBusy
= true;
2374 // Event cache is now updated. Perform update on the UI thread
2375 if (!fTable
.isDisposed()) {
2376 fTable
.getDisplay().asyncExec(new Runnable() {
2379 if (!fTable
.isDisposed()) {
2384 populateCompleted();
2386 synchronized (fCacheUpdateSyncObj
) {
2387 fCacheUpdateBusy
= false;
2388 if (fCacheUpdatePending
) {
2389 fCacheUpdatePending
= false;
2390 cacheUpdated(fCacheUpdateCompleted
);
2399 * Callback for when populating the table is complete.
2401 protected void populateCompleted() {
2402 // Nothing by default;
2405 // ------------------------------------------------------------------------
2406 // ISelectionProvider
2407 // ------------------------------------------------------------------------
2410 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2411 selectionChangedListeners
.add(listener
);
2415 public ISelection
getSelection() {
2416 if (fTable
== null || fTable
.isDisposed()) {
2417 return StructuredSelection
.EMPTY
;
2419 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2420 for (TableItem item
: fTable
.getSelection()) {
2421 if (item
.getData() != null) {
2422 list
.add(item
.getData());
2425 return new StructuredSelection(list
);
2429 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2430 selectionChangedListeners
.remove(listener
);
2434 public void setSelection(ISelection selection
) {
2439 * Notifies any selection changed listeners that the viewer's selection has changed.
2440 * Only listeners registered at the time this method is called are notified.
2442 * @param event a selection changed event
2444 * @see ISelectionChangedListener#selectionChanged
2446 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2447 Object
[] listeners
= selectionChangedListeners
.getListeners();
2448 for (int i
= 0; i
< listeners
.length
; ++i
) {
2449 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2450 SafeRunnable
.run(new SafeRunnable() {
2453 l
.selectionChanged(event
);
2459 // ------------------------------------------------------------------------
2460 // Bookmark handling
2461 // ------------------------------------------------------------------------
2464 * Add a bookmark to this event table.
2466 * @param bookmarksFile
2467 * The file to use for the bookmarks
2469 public void addBookmark(final IFile bookmarksFile
) {
2470 fBookmarksFile
= bookmarksFile
;
2471 final TableItem
[] selection
= fTable
.getSelection();
2472 if (selection
.length
> 0) {
2473 final TableItem tableItem
= selection
[0];
2474 if (tableItem
.getData(Key
.RANK
) != null) {
2475 final StringBuffer defaultMessage
= new StringBuffer();
2476 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2478 defaultMessage
.append(", "); //$NON-NLS-1$
2480 defaultMessage
.append(tableItem
.getText(i
));
2482 final InputDialog dialog
= new MultiLineInputDialog(
2483 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2484 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2485 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2486 defaultMessage
.toString());
2487 if (dialog
.open() == Window
.OK
) {
2488 final String message
= dialog
.getValue();
2490 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2491 if (bookmark
.exists()) {
2492 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2493 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2494 final int location
= rank
.intValue();
2495 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2496 fBookmarksMap
.put(rank
, bookmark
.getId());
2499 } catch (final CoreException e
) {
2500 displayException(e
);
2509 * Remove a bookmark from this event table.
2512 * The bookmark to remove
2514 public void removeBookmark(final IMarker bookmark
) {
2515 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2516 if (entry
.getValue().equals(bookmark
.getId())) {
2517 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2524 private void toggleBookmark(final Long rank
) {
2525 if (fBookmarksFile
== null) {
2528 if (fBookmarksMap
.containsKey(rank
)) {
2529 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2532 for (long markerId
: markerIds
) {
2533 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2534 if (bookmark
!= null) {
2538 } catch (final CoreException e
) {
2539 displayException(e
);
2542 addBookmark(fBookmarksFile
);
2547 * Refresh the bookmarks assigned to this trace, from the contents of a
2550 * @param bookmarksFile
2551 * The bookmark file to use
2553 public void refreshBookmarks(final IFile bookmarksFile
) {
2554 fBookmarksFile
= bookmarksFile
;
2555 if (bookmarksFile
== null) {
2556 fBookmarksMap
.clear();
2561 fBookmarksMap
.clear();
2562 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2563 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2564 if (location
!= -1) {
2565 final long rank
= location
;
2566 fBookmarksMap
.put(rank
, bookmark
.getId());
2570 } catch (final CoreException e
) {
2571 displayException(e
);
2576 public void gotoMarker(final IMarker marker
) {
2577 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2580 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2581 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2582 } else if (rank
>= fTable
.getItemCount()) {
2583 fPendingGotoRank
= rank
;
2585 fSelectedRank
= rank
;
2586 fTable
.setSelection(index
+ 1); // +1 for header row
2587 updateStatusLine(null);
2591 // ------------------------------------------------------------------------
2593 // ------------------------------------------------------------------------
2596 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2600 // ------------------------------------------------------------------------
2602 // ------------------------------------------------------------------------
2605 * Handler for the trace updated signal
2608 * The incoming signal
2611 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2612 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2615 // Perform the refresh on the UI thread
2616 Display
.getDefault().asyncExec(new Runnable() {
2619 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2620 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2621 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2622 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2623 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2624 fPendingGotoRank
= -1;
2625 updateStatusLine(null);
2628 startFilterThread();
2631 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2632 fRawViewer
.refreshEventCount();
2639 * Handler for the time synch signal.
2642 * The incoming signal
2645 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2646 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2648 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2649 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2650 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2651 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2652 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2654 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2657 public void handleData(final ITmfEvent event
) {
2658 super.handleData(event
);
2662 public void handleSuccess() {
2663 super.handleSuccess();
2664 if (fTrace
== null) {
2668 // Verify if the event is within the trace range and adjust if necessary
2669 ITmfTimestamp timestamp
= ts
;
2670 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2671 timestamp
= fTrace
.getStartTime();
2673 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2674 timestamp
= fTrace
.getEndTime();
2677 // Get the rank of the selected event in the table
2678 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2679 final long rank
= context
.getRank();
2681 fSelectedRank
= rank
;
2683 fTable
.getDisplay().asyncExec(new Runnable() {
2686 // Return if table is disposed
2687 if (fTable
.isDisposed()) {
2691 int index
= (int) rank
;
2692 if (fTable
.isDisposed()) {
2695 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2696 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2698 fTable
.setSelection(index
+ 1); // +1 for header row
2699 fRawViewer
.selectAndReveal(rank
);
2700 updateStatusLine(null);
2706 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2710 // ------------------------------------------------------------------------
2712 // ------------------------------------------------------------------------
2715 * Display an exception in a message box
2717 * @param e the exception
2719 private static void displayException(final Exception e
) {
2720 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2721 mb
.setText(e
.getClass().getSimpleName());
2722 mb
.setMessage(e
.getMessage());
2729 public void refresh() {
2736 * Margin column for images and special text (e.g. collapse count)
2738 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2740 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2743 public String
getName() {
2744 return EMPTY_STRING
;
2748 public String
resolve(ITmfEvent event
) {
2749 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2750 return EMPTY_STRING
;
2752 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2756 public String
getHelpText() {
2757 return EMPTY_STRING
;
2764 public TmfMarginColumn() {
2765 super(MARGIN_ASPECT
);