1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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 java
.io
.FileNotFoundException
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collection
;
23 import java
.util
.HashMap
;
24 import java
.util
.LinkedList
;
25 import java
.util
.List
;
26 import java
.util
.Map
.Entry
;
27 import java
.util
.regex
.Pattern
;
28 import java
.util
.regex
.PatternSyntaxException
;
30 import org
.eclipse
.core
.commands
.Command
;
31 import org
.eclipse
.core
.commands
.ExecutionException
;
32 import org
.eclipse
.core
.commands
.NotEnabledException
;
33 import org
.eclipse
.core
.commands
.NotHandledException
;
34 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
35 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
36 import org
.eclipse
.core
.expressions
.IEvaluationContext
;
37 import org
.eclipse
.core
.resources
.IFile
;
38 import org
.eclipse
.core
.resources
.IMarker
;
39 import org
.eclipse
.core
.resources
.IResource
;
40 import org
.eclipse
.core
.resources
.IResourceVisitor
;
41 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
42 import org
.eclipse
.core
.runtime
.CoreException
;
43 import org
.eclipse
.core
.runtime
.IPath
;
44 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
45 import org
.eclipse
.core
.runtime
.IStatus
;
46 import org
.eclipse
.core
.runtime
.ListenerList
;
47 import org
.eclipse
.core
.runtime
.Path
;
48 import org
.eclipse
.core
.runtime
.Status
;
49 import org
.eclipse
.core
.runtime
.jobs
.Job
;
50 import org
.eclipse
.emf
.common
.util
.URI
;
51 import org
.eclipse
.emf
.ecore
.EValidator
;
52 import org
.eclipse
.jdt
.annotation
.NonNull
;
53 import org
.eclipse
.jface
.action
.Action
;
54 import org
.eclipse
.jface
.action
.IAction
;
55 import org
.eclipse
.jface
.action
.IMenuListener
;
56 import org
.eclipse
.jface
.action
.IMenuManager
;
57 import org
.eclipse
.jface
.action
.IStatusLineManager
;
58 import org
.eclipse
.jface
.action
.MenuManager
;
59 import org
.eclipse
.jface
.action
.Separator
;
60 import org
.eclipse
.jface
.dialogs
.InputDialog
;
61 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
62 import org
.eclipse
.jface
.resource
.FontDescriptor
;
63 import org
.eclipse
.jface
.resource
.JFaceResources
;
64 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
65 import org
.eclipse
.jface
.util
.OpenStrategy
;
66 import org
.eclipse
.jface
.util
.SafeRunnable
;
67 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
68 import org
.eclipse
.jface
.viewers
.ISelection
;
69 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
70 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
71 import org
.eclipse
.jface
.viewers
.LabelProvider
;
72 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
73 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
74 import org
.eclipse
.jface
.window
.Window
;
75 import org
.eclipse
.swt
.SWT
;
76 import org
.eclipse
.swt
.custom
.SashForm
;
77 import org
.eclipse
.swt
.custom
.TableEditor
;
78 import org
.eclipse
.swt
.events
.ControlAdapter
;
79 import org
.eclipse
.swt
.events
.ControlEvent
;
80 import org
.eclipse
.swt
.events
.FocusAdapter
;
81 import org
.eclipse
.swt
.events
.FocusEvent
;
82 import org
.eclipse
.swt
.events
.KeyAdapter
;
83 import org
.eclipse
.swt
.events
.KeyEvent
;
84 import org
.eclipse
.swt
.events
.MouseAdapter
;
85 import org
.eclipse
.swt
.events
.MouseEvent
;
86 import org
.eclipse
.swt
.events
.SelectionAdapter
;
87 import org
.eclipse
.swt
.events
.SelectionEvent
;
88 import org
.eclipse
.swt
.graphics
.Color
;
89 import org
.eclipse
.swt
.graphics
.Font
;
90 import org
.eclipse
.swt
.graphics
.Image
;
91 import org
.eclipse
.swt
.graphics
.Point
;
92 import org
.eclipse
.swt
.graphics
.Rectangle
;
93 import org
.eclipse
.swt
.layout
.FillLayout
;
94 import org
.eclipse
.swt
.layout
.GridData
;
95 import org
.eclipse
.swt
.layout
.GridLayout
;
96 import org
.eclipse
.swt
.widgets
.Composite
;
97 import org
.eclipse
.swt
.widgets
.Display
;
98 import org
.eclipse
.swt
.widgets
.Event
;
99 import org
.eclipse
.swt
.widgets
.Label
;
100 import org
.eclipse
.swt
.widgets
.Listener
;
101 import org
.eclipse
.swt
.widgets
.Menu
;
102 import org
.eclipse
.swt
.widgets
.MessageBox
;
103 import org
.eclipse
.swt
.widgets
.Shell
;
104 import org
.eclipse
.swt
.widgets
.TableColumn
;
105 import org
.eclipse
.swt
.widgets
.TableItem
;
106 import org
.eclipse
.swt
.widgets
.Text
;
107 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
108 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
109 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
110 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
111 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
112 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
113 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
114 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
115 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
116 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfEventFieldAspect
;
117 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
118 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
119 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
120 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
121 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
122 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
123 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
124 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
141 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
142 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
143 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
144 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
145 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
146 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
147 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
148 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
149 import org
.eclipse
.ui
.IWorkbenchPage
;
150 import org
.eclipse
.ui
.PlatformUI
;
151 import org
.eclipse
.ui
.commands
.ICommandService
;
152 import org
.eclipse
.ui
.dialogs
.ListDialog
;
153 import org
.eclipse
.ui
.handlers
.IHandlerService
;
154 import org
.eclipse
.ui
.ide
.IDE
;
155 import org
.eclipse
.ui
.ide
.IGotoMarker
;
156 import org
.eclipse
.ui
.themes
.ColorUtil
;
158 import com
.google
.common
.base
.Joiner
;
159 import com
.google
.common
.collect
.HashMultimap
;
160 import com
.google
.common
.collect
.ImmutableList
;
161 import com
.google
.common
.collect
.Multimap
;
164 * The generic TMF Events table
166 * This is a view that will list events that are read from a trace.
168 * @author Francois Chouinard
169 * @author Patrick Tasse
172 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
175 * Empty string array, used by {@link #getItemStrings}.
178 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
184 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
186 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
188 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
189 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
190 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
191 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
192 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
193 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
194 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
195 private static final Image FILTER_IMAGE
= Activator
.getDefault()
196 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
197 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
198 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
199 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
200 private static final int MAX_CACHE_SIZE
= 1000;
202 private static final int MARGIN_COLUMN_INDEX
= 0;
203 private static final int FILTER_SUMMARY_INDEX
= 1;
204 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
207 * Default set of columns to use for trace types that do not specify
211 public static final Collection
<TmfEventTableColumn
> DEFAULT_COLUMNS
= ImmutableList
.of(
212 new TmfEventTableColumn(ITmfEventAspect
.BaseAspects
.TIMESTAMP
),
213 new TmfEventTableColumn(ITmfEventAspect
.BaseAspects
.EVENT_TYPE
),
214 new TmfEventTableColumn(ITmfEventAspect
.BaseAspects
.CONTENTS
)
218 * The events table search/filter keys
221 * @author Patrick Tasse
223 public interface Key
{
225 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
228 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
231 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
234 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
237 String TIMESTAMP
= "$time"; //$NON-NLS-1$
240 String RANK
= "$rank"; //$NON-NLS-1$
243 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
245 /** Bookmark indicator */
246 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
250 * The events table search/filter state
253 * @author Patrick Tasse
255 public static enum HeaderState
{
256 /** A search is being run */
259 /** A filter is applied */
263 interface Direction
{
268 // ------------------------------------------------------------------------
270 // ------------------------------------------------------------------------
272 /** The virtual event table */
273 protected TmfVirtualTable fTable
;
275 private Composite fComposite
;
276 private SashForm fSashForm
;
277 private TmfRawEventViewer fRawViewer
;
278 private ITmfTrace fTrace
;
279 volatile private boolean fPackDone
= false;
280 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
281 private long fSelectedRank
= 0;
282 private ITmfTimestamp fSelectedBeginTimestamp
= null;
283 private IStatusLineManager fStatusLineManager
= null;
286 private long fFilterMatchCount
;
287 private long fFilterCheckCount
;
288 private FilterThread fFilterThread
;
289 private boolean fFilterThreadResume
= false;
290 private final Object fFilterSyncObj
= new Object();
291 private SearchThread fSearchThread
;
292 private final Object fSearchSyncObj
= new Object();
295 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
297 * @see #fireSelectionChanged
299 private ListenerList selectionChangedListeners
= new ListenerList();
301 // Bookmark map <Rank, MarkerId>
302 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
303 private IFile fBookmarksFile
;
304 private long fPendingGotoRank
= -1;
307 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
308 private Color fGrayColor
;
309 private Color fGreenColor
;
310 private Font fBoldFont
;
312 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
315 private final TmfEventsCache fCache
;
316 private boolean fCacheUpdateBusy
= false;
317 private boolean fCacheUpdatePending
= false;
318 private boolean fCacheUpdateCompleted
= false;
319 private final Object fCacheUpdateSyncObj
= new Object();
321 private boolean fDisposeOnClose
;
323 // ------------------------------------------------------------------------
325 // ------------------------------------------------------------------------
328 * Basic constructor, using the default set of columns
331 * The parent composite UI object
333 * The size of the event table cache
335 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
336 this(parent
, cacheSize
, DEFAULT_COLUMNS
);
340 * Legacy constructor, using ColumnData to define columns
343 * The parent composite UI object
345 * The size of the event table cache
348 * @deprecated Deprecated constructor, use
349 * {@link #TmfEventsTable(Composite, int, Collection)}
352 public TmfEventsTable(final Composite parent
, int cacheSize
,
353 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
355 * We'll do a "best-effort" to keep trace types still using this API to
356 * keep working, by defining a TmfEventTableFieldColumn for each
357 * ColumnData they passed.
359 this(parent
, cacheSize
, convertFromColumnData(columnData
));
363 private static Collection
<TmfEventTableColumn
> convertFromColumnData(
364 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
366 ImmutableList
.Builder
<TmfEventTableColumn
> builder
= new ImmutableList
.Builder
<>();
367 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
368 String fieldName
= col
.header
;
369 if (fieldName
!= null) {
370 builder
.add(new TmfEventTableColumn(new TmfEventFieldAspect(fieldName
, fieldName
)));
373 return builder
.build();
377 * Standard constructor, where we define which columns to use.
380 * The parent composite UI object
382 * The size of the event table cache
384 * The columns to use in this table.
386 * The iteration order of this collection will correspond to the
387 * initial ordering of this series of columns in the table.
391 public TmfEventsTable(final Composite parent
, int cacheSize
,
392 Collection
<?
extends TmfEventTableColumn
> columns
) {
393 super("TmfEventsTable"); //$NON-NLS-1$
395 fComposite
= new Composite(parent
, SWT
.NONE
);
396 final GridLayout gl
= new GridLayout(1, false);
399 gl
.verticalSpacing
= 0;
400 fComposite
.setLayout(gl
);
402 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
403 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
405 // Create a virtual table
406 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
407 fTable
= new TmfVirtualTable(fSashForm
, style
);
409 // Set the table layout
410 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
411 fTable
.setLayoutData(layoutData
);
413 // Some cosmetic enhancements
414 fTable
.setHeaderVisible(true);
415 fTable
.setLinesVisible(true);
418 if (columns
!= null) {
419 fColumns
.addAll(columns
);
422 TmfMarginColumn collapseCol
= new TmfMarginColumn();
423 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
425 // Create the UI columns in the table
426 for (TmfEventTableColumn col
: fColumns
) {
427 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
428 column
.setText(col
.getHeaderName());
429 column
.setToolTipText(col
.getHeaderTooltip());
430 column
.setData(Key
.FIELD_ID
, col
.getFilterFieldId());
432 if (col
instanceof TmfMarginColumn
) {
433 column
.setResizable(false);
434 column
.addControlListener(new ControlAdapter() {
436 * Make sure that the margin column is always first
439 public void controlMoved(ControlEvent e
) {
440 int[] order
= fTable
.getColumnOrder();
441 if (order
[0] == MARGIN_COLUMN_INDEX
) {
444 for (int i
= order
.length
- 1; i
> 0; i
--) {
445 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
446 order
[i
] = order
[i
- 1];
447 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
450 fTable
.setColumnOrder(order
);
454 column
.setMoveable(true);
458 // Set the frozen row for header row
459 fTable
.setFrozenRowCount(1);
461 // Create the header row cell editor
462 createHeaderEditor();
464 // Handle the table item selection
465 fTable
.addSelectionListener(new SelectionAdapter() {
467 public void widgetSelected(final SelectionEvent e
) {
468 if (e
.item
== null) {
471 updateStatusLine(null);
472 if (fTable
.getSelectionIndices().length
> 0) {
473 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
474 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
475 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
477 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
478 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
479 if (fTable
.getSelectionIndices().length
== 1) {
480 fSelectedBeginTimestamp
= ts
;
482 if (fSelectedBeginTimestamp
!= null) {
483 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
484 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
485 if (fTable
.getSelectionIndices().length
== 2) {
486 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
489 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
490 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
494 if (fTable
.getSelectionIndices().length
== 1) {
495 fSelectedBeginTimestamp
= null;
499 if (e
.item
.getData() instanceof ITmfEvent
) {
500 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
501 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
503 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
508 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
509 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
510 fCache
= new TmfEventsCache(realCacheSize
, this);
512 // Handle the table item requests
513 fTable
.addListener(SWT
.SetData
, new Listener() {
516 public void handleEvent(final Event event
) {
518 final TableItem item
= (TableItem
) event
.item
;
519 int index
= event
.index
- 1; // -1 for the header row
521 if (event
.index
== 0) {
522 setHeaderRowItemData(item
);
526 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
527 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
528 setFilterStatusRowItemData(item
);
531 index
= index
- 1; // -1 for top filter status row
534 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
535 if (cachedEvent
!= null) {
536 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
540 // Else, fill the cache asynchronously (and off the UI thread)
545 fTable
.addMouseListener(new MouseAdapter() {
547 public void mouseDoubleClick(final MouseEvent event
) {
548 if (event
.button
!= 1) {
551 // Identify the selected row
552 final Point point
= new Point(event
.x
, event
.y
);
553 final TableItem item
= fTable
.getItem(point
);
555 final Rectangle imageBounds
= item
.getImageBounds(0);
556 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
557 if (imageBounds
.contains(point
)) {
558 final Long rank
= (Long
) item
.getData(Key
.RANK
);
560 toggleBookmark(rank
);
567 final Listener tooltipListener
= new Listener () {
568 Shell tooltipShell
= null;
570 public void handleEvent(final Event event
) {
571 switch (event
.type
) {
573 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
577 final Long rank
= (Long
) item
.getData(Key
.RANK
);
581 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
582 final Rectangle bounds
= item
.getImageBounds(0);
583 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
584 if (!bounds
.contains(event
.x
,event
.y
)) {
587 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
588 tooltipShell
.dispose();
590 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
591 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
592 final FillLayout layout
= new FillLayout();
593 layout
.marginWidth
= 2;
594 tooltipShell
.setLayout(layout
);
595 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
596 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
597 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
598 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
600 label
.addListener(SWT
.MouseExit
, this);
601 label
.addListener(SWT
.MouseDown
, this);
602 label
.addListener(SWT
.MouseWheel
, this);
603 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
605 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
606 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
610 y
+= fTable
.getHeaderHeight();
612 Point pt
= fTable
.toDisplay(event
.x
, y
);
613 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
614 pt
.y
+= item
.getBounds().height
;
615 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
616 tooltipShell
.setVisible(true);
624 if (tooltipShell
!= null) {
625 tooltipShell
.dispose();
635 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
636 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
637 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
638 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
639 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
640 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
641 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
646 ColorSettingsManager
.addColorSettingsListener(this);
648 fTable
.setItemCount(1); // +1 for header row
650 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
652 fRawViewer
.addSelectionListener(new Listener() {
654 public void handleEvent(final Event e
) {
655 if (e
.data
instanceof Long
) {
656 final long rank
= (Long
) e
.data
;
657 int index
= (int) rank
;
658 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
659 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
661 fTable
.setSelection(index
+ 1); // +1 for header row
662 fSelectedRank
= rank
;
663 updateStatusLine(null);
664 } else if (e
.data
instanceof ITmfLocation
) {
665 // DOES NOT WORK: rank undefined in context from seekLocation()
666 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
667 // TmfContext context = fTrace.seekLocation(location);
668 // fTable.setSelection((int) context.getRank());
673 final TableItem
[] selection
= fTable
.getSelection();
674 if ((selection
!= null) && (selection
.length
> 0)) {
675 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
677 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
683 fSashForm
.setWeights(new int[] { 1, 1 });
684 fRawViewer
.setVisible(false);
689 // ------------------------------------------------------------------------
691 // ------------------------------------------------------------------------
694 * Create a pop-up menu.
696 protected void createPopupMenu() {
697 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
700 fTable
.setVisible(true);
705 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
708 fTable
.setVisible(false);
713 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
716 fRawViewer
.setVisible(true);
718 final int index
= fTable
.getSelectionIndex();
720 fRawViewer
.selectAndReveal(index
- 1);
725 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
728 fRawViewer
.setVisible(false);
733 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
736 final TableItem items
[] = fTable
.getSelection();
737 if (items
.length
!= 1) {
740 final TableItem item
= items
[0];
742 final Object data
= item
.getData();
743 if (data
instanceof ITmfSourceLookup
) {
744 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
745 ITmfCallsite cs
= event
.getCallsite();
746 if (cs
== null || cs
.getFileName() == null) {
749 IMarker marker
= null;
751 String fileName
= cs
.getFileName();
752 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
753 final ArrayList
<IFile
> files
= new ArrayList
<>();
754 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
756 public boolean visit(IResource resource
) throws CoreException
{
757 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
758 files
.add((IFile
) resource
);
764 if (files
.size() > 1) {
765 ListDialog dialog
= new ListDialog(getTable().getShell());
766 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
767 dialog
.setLabelProvider(new LabelProvider() {
769 public String
getText(Object element
) {
770 return ((IFile
) element
).getFullPath().toString();
773 dialog
.setInput(files
);
774 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
775 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
777 Object
[] result
= dialog
.getResult();
778 if (result
!= null && result
.length
> 0) {
779 file
= (IFile
) result
[0];
781 } else if (files
.size() == 1) {
785 marker
= file
.createMarker(IMarker
.MARKER
);
786 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
787 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
789 } else if (files
.size() == 0){
790 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
792 } catch (CoreException e
) {
799 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
803 final TableItem items
[] = fTable
.getSelection();
804 if (items
.length
!= 1) {
807 final TableItem item
= items
[0];
809 final Object eventData
= item
.getData();
810 if (eventData
instanceof ITmfModelLookup
) {
811 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
813 if (modelURI
!= null) {
814 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
817 final URI uri
= URI
.createURI(modelURI
);
818 if (uri
.isPlatformResource()) {
819 IPath path
= new Path(uri
.toPlatformString(true));
820 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
821 } else if (uri
.isFile() && !uri
.isRelative()) {
822 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
823 new Path(uri
.toFileString()));
829 * create a temporary validation marker on the
830 * model file, remove it afterwards thus,
831 * navigation works with all model editors
832 * supporting the navigation to a marker
834 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
835 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
836 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
838 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
841 catch (CoreException e
) {
845 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
852 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
855 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
856 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
857 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
858 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
859 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
861 HashMap
<String
, Object
> parameters
= new HashMap
<>();
862 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
863 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
865 IEvaluationContext context
= handlerService
.getCurrentState();
866 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
867 for (int i
: fTable
.getColumnOrder()) {
868 // Omit the margin column
869 if (i
>= EVENT_COLUMNS_START_INDEX
) {
870 exportColumns
.add(fColumns
.get(i
));
873 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
875 handlerService
.executeCommandInContext(cmd
, null, context
);
876 } catch (ExecutionException e
) {
878 } catch (NotDefinedException e
) {
880 } catch (NotEnabledException e
) {
882 } catch (NotHandledException e
) {
888 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
891 fHeaderState
= HeaderState
.SEARCH
;
896 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
899 fHeaderState
= HeaderState
.FILTER
;
904 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
911 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
914 applyFilter(new TmfCollapseFilter());
918 class ToggleBookmarkAction
extends Action
{
921 public ToggleBookmarkAction(final String text
, final Long rank
) {
928 toggleBookmark(fRank
);
932 final MenuManager tablePopupMenu
= new MenuManager();
933 tablePopupMenu
.setRemoveAllWhenShown(true);
934 tablePopupMenu
.addMenuListener(new IMenuListener() {
936 public void menuAboutToShow(final IMenuManager manager
) {
937 if (fTable
.getSelectionIndex() == 0) {
938 // Right-click on header row
939 if (fHeaderState
== HeaderState
.FILTER
) {
940 tablePopupMenu
.add(showSearchBarAction
);
942 tablePopupMenu
.add(showFilterBarAction
);
946 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
947 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
949 final Rectangle imageBounds
= item
.getImageBounds(0);
950 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
951 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
952 // Right-click on left margin
953 final Long rank
= (Long
) item
.getData(Key
.RANK
);
954 if ((rank
!= null) && (fBookmarksFile
!= null)) {
955 if (fBookmarksMap
.containsKey(rank
)) {
956 tablePopupMenu
.add(new ToggleBookmarkAction(
957 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
959 tablePopupMenu
.add(new ToggleBookmarkAction(
960 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
967 // Right-click on table
968 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
969 tablePopupMenu
.add(hideTableAction
);
970 tablePopupMenu
.add(hideRawAction
);
971 } else if (!fTable
.isVisible()) {
972 tablePopupMenu
.add(showTableAction
);
973 } else if (!fRawViewer
.isVisible()) {
974 tablePopupMenu
.add(showRawAction
);
976 tablePopupMenu
.add(exportToTextAction
);
977 tablePopupMenu
.add(new Separator());
980 final Object data
= item
.getData();
981 Separator separator
= null;
982 if (data
instanceof ITmfSourceLookup
) {
983 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
984 if (event
.getCallsite() != null) {
985 tablePopupMenu
.add(openCallsiteAction
);
986 separator
= new Separator();
990 if (data
instanceof ITmfModelLookup
) {
991 ITmfModelLookup event
= (ITmfModelLookup
) data
;
992 if (event
.getModelUri() != null) {
993 tablePopupMenu
.add(openModelAction
);
994 separator
= new Separator();
997 if (separator
!= null) {
998 tablePopupMenu
.add(separator
);
1003 // only show collapse filter if at least one trace can be collapsed
1004 boolean isCollapsible
= false;
1005 if (fTrace
!= null) {
1006 ITmfTrace traces
[] = TmfTraceManager
.getTraceSet(fTrace
);
1007 for (ITmfTrace trace
: traces
) {
1008 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1009 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1010 if (isCollapsible
) {
1016 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1017 tablePopupMenu
.add(collapseAction
);
1018 tablePopupMenu
.add(new Separator());
1021 tablePopupMenu
.add(clearFiltersAction
);
1022 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1023 if (savedFilters
.length
> 0) {
1024 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1025 for (final ITmfFilterTreeNode node
: savedFilters
) {
1026 if (node
instanceof TmfFilterNode
) {
1027 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1028 subMenu
.add(new Action(filter
.getFilterName()) {
1031 applyFilter(filter
);
1036 tablePopupMenu
.add(subMenu
);
1038 appendToTablePopupMenu(tablePopupMenu
, item
);
1042 final MenuManager rawViewerPopupMenu
= new MenuManager();
1043 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1044 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1046 public void menuAboutToShow(final IMenuManager manager
) {
1047 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1048 rawViewerPopupMenu
.add(hideTableAction
);
1049 rawViewerPopupMenu
.add(hideRawAction
);
1050 } else if (!fTable
.isVisible()) {
1051 rawViewerPopupMenu
.add(showTableAction
);
1052 } else if (!fRawViewer
.isVisible()) {
1053 rawViewerPopupMenu
.add(showRawAction
);
1055 appendToRawPopupMenu(tablePopupMenu
);
1059 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1060 fTable
.setMenu(menu
);
1062 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1063 fRawViewer
.setMenu(menu
);
1068 * Append an item to the event table's pop-up menu.
1070 * @param tablePopupMenu
1072 * @param selectedItem
1073 * The item to append
1075 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1076 // override to append more actions
1080 * Append an item to the raw viewer's pop-up menu.
1082 * @param rawViewerPopupMenu
1085 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1086 // override to append more actions
1090 public void dispose() {
1093 ColorSettingsManager
.removeColorSettingsListener(this);
1094 fComposite
.dispose();
1095 if ((fTrace
!= null) && fDisposeOnClose
) {
1098 fResourceManager
.dispose();
1099 fRawViewer
.dispose();
1104 * Assign a layout data object to this view.
1107 * The layout data to assign
1109 public void setLayoutData(final Object layoutData
) {
1110 fComposite
.setLayoutData(layoutData
);
1114 * Get the virtual table contained in this event table.
1116 * @return The TMF virtual table
1118 public TmfVirtualTable
getTable() {
1125 * @deprecated The column headers are now set at the constructor, this
1126 * shouldn't be called anymore.
1129 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1134 * Set a table item's data.
1139 * Which trace event to link with this entry
1141 * Which rank this event has in the trace/experiment
1143 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1144 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1145 item
.setText(itemStrings
);
1146 item
.setData(event
);
1147 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1148 item
.setData(Key
.RANK
, rank
);
1150 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1151 if (!markerIds
.isEmpty()) {
1152 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1153 List
<Object
> parts
= new ArrayList
<>();
1154 if (markerIds
.size() > 1) {
1155 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1158 for (long markerId
: markerIds
) {
1159 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1160 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1162 } catch (CoreException e
) {
1163 displayException(e
);
1165 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1167 item
.setData(Key
.BOOKMARK
, null);
1170 boolean searchMatch
= false;
1171 boolean searchNoMatch
= false;
1172 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1173 if (searchFilter
!= null) {
1174 if (searchFilter
.matches(event
)) {
1177 searchNoMatch
= true;
1181 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1182 if (searchNoMatch
) {
1183 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1184 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1186 item
.setForeground(colorSetting
.getForegroundColor());
1187 item
.setBackground(colorSetting
.getBackgroundColor());
1191 if (!markerIds
.isEmpty()) {
1192 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1194 item
.setImage(SEARCH_MATCH_IMAGE
);
1196 } else if (!markerIds
.isEmpty()) {
1197 item
.setImage(BOOKMARK_IMAGE
);
1199 item
.setImage((Image
) null);
1202 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1208 * Set the item data of the header row.
1211 * The item to use as table header
1213 protected void setHeaderRowItemData(final TableItem item
) {
1214 String txtKey
= null;
1215 if (fHeaderState
== HeaderState
.SEARCH
) {
1216 item
.setImage(SEARCH_IMAGE
);
1217 txtKey
= Key
.SEARCH_TXT
;
1218 } else if (fHeaderState
== HeaderState
.FILTER
) {
1219 item
.setImage(FILTER_IMAGE
);
1220 txtKey
= Key
.FILTER_TXT
;
1222 item
.setForeground(fGrayColor
);
1223 // Ignore collapse and image column
1224 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1225 final TableColumn column
= fTable
.getColumns()[i
];
1226 final String filter
= (String
) column
.getData(txtKey
);
1227 if (filter
== null) {
1228 if (fHeaderState
== HeaderState
.SEARCH
) {
1229 item
.setText(i
, SEARCH_HINT
);
1230 } else if (fHeaderState
== HeaderState
.FILTER
) {
1231 item
.setText(i
, FILTER_HINT
);
1233 item
.setForeground(i
, fGrayColor
);
1234 item
.setFont(i
, fTable
.getFont());
1236 item
.setText(i
, filter
);
1237 item
.setForeground(i
, fGreenColor
);
1238 item
.setFont(i
, fBoldFont
);
1244 * Set the item data of the "filter status" row.
1247 * The item to use as filter status row
1249 protected void setFilterStatusRowItemData(final TableItem item
) {
1250 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1251 if (i
== MARGIN_COLUMN_INDEX
) {
1252 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1253 item
.setImage(FILTER_IMAGE
);
1255 item
.setImage(STOP_IMAGE
);
1259 if (i
== FILTER_SUMMARY_INDEX
) {
1260 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1262 item
.setText(i
, EMPTY_STRING
);
1266 item
.setData(Key
.TIMESTAMP
, null);
1267 item
.setData(Key
.RANK
, null);
1268 item
.setForeground(null);
1269 item
.setBackground(null);
1273 * Create an editor for the header.
1275 protected void createHeaderEditor() {
1276 final TableEditor tableEditor
= fTable
.createTableEditor();
1277 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1278 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1279 tableEditor
.grabHorizontal
= true;
1280 tableEditor
.minimumWidth
= 50;
1282 // Handle the header row selection
1283 fTable
.addMouseListener(new MouseAdapter() {
1289 public void mouseDown(final MouseEvent event
) {
1290 if (event
.button
!= 1) {
1293 // Identify the selected row
1294 final Point point
= new Point(event
.x
, event
.y
);
1295 item
= fTable
.getItem(point
);
1297 // Header row selected
1298 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1301 if (item
.getImageBounds(0).contains(point
)) {
1302 if (fHeaderState
== HeaderState
.SEARCH
) {
1303 fHeaderState
= HeaderState
.FILTER
;
1304 } else if (fHeaderState
== HeaderState
.FILTER
) {
1305 fHeaderState
= HeaderState
.SEARCH
;
1307 fTable
.setSelection(0);
1312 // Identify the selected column
1314 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1315 final Rectangle rect
= item
.getBounds(i
);
1316 if (rect
.contains(point
)) {
1322 if (columnIndex
== -1) {
1326 column
= fTable
.getColumns()[columnIndex
];
1328 String txtKey
= null;
1329 if (fHeaderState
== HeaderState
.SEARCH
) {
1330 txtKey
= Key
.SEARCH_TXT
;
1331 } else if (fHeaderState
== HeaderState
.FILTER
) {
1332 txtKey
= Key
.FILTER_TXT
;
1335 // The control that will be the editor must be a child of the Table
1336 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1337 final String headerString
= (String
) column
.getData(txtKey
);
1338 if (headerString
!= null) {
1339 newEditor
.setText(headerString
);
1341 newEditor
.addFocusListener(new FocusAdapter() {
1343 public void focusLost(final FocusEvent e
) {
1344 final boolean changed
= updateHeader(newEditor
.getText());
1350 newEditor
.addKeyListener(new KeyAdapter() {
1352 public void keyPressed(final KeyEvent e
) {
1353 if (e
.character
== SWT
.CR
) {
1354 updateHeader(newEditor
.getText());
1357 // Set focus on the table so that the next carriage return goes to the next result
1358 TmfEventsTable
.this.getTable().setFocus();
1359 } else if (e
.character
== SWT
.ESC
) {
1360 tableEditor
.getEditor().dispose();
1364 newEditor
.selectAll();
1365 newEditor
.setFocus();
1366 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1371 * returns true is value was changed
1373 private boolean updateHeader(final String text
) {
1374 String objKey
= null;
1375 String txtKey
= null;
1376 if (fHeaderState
== HeaderState
.SEARCH
) {
1377 objKey
= Key
.SEARCH_OBJ
;
1378 txtKey
= Key
.SEARCH_TXT
;
1379 } else if (fHeaderState
== HeaderState
.FILTER
) {
1380 objKey
= Key
.FILTER_OBJ
;
1381 txtKey
= Key
.FILTER_TXT
;
1383 if (text
.trim().length() > 0) {
1385 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1386 Pattern
.compile(regex
);
1387 if (regex
.equals(column
.getData(txtKey
))) {
1388 tableEditor
.getEditor().dispose();
1391 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1392 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1393 if (fieldId
== null) {
1394 fieldId
= column
.getText();
1396 filter
.setField(fieldId
);
1397 filter
.setRegex(regex
);
1398 column
.setData(objKey
, filter
);
1399 column
.setData(txtKey
, regex
);
1400 } catch (final PatternSyntaxException ex
) {
1401 tableEditor
.getEditor().dispose();
1402 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1403 ex
.getDescription(), ex
.getMessage());
1407 if (column
.getData(txtKey
) == null) {
1408 tableEditor
.getEditor().dispose();
1411 column
.setData(objKey
, null);
1412 column
.setData(txtKey
, null);
1417 private void applyHeader() {
1418 if (fHeaderState
== HeaderState
.SEARCH
) {
1420 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1421 for (final TableColumn col
: fTable
.getColumns()) {
1422 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1423 if (filterObj
instanceof ITmfFilterTreeNode
) {
1424 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1427 if (filter
.getChildrenCount() > 0) {
1428 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1431 fireSearchApplied(filter
);
1433 fTable
.setData(Key
.SEARCH_OBJ
, null);
1435 fireSearchApplied(null);
1437 } else if (fHeaderState
== HeaderState
.FILTER
) {
1438 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1439 for (final TableColumn col
: fTable
.getColumns()) {
1440 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1441 if (filterObj
instanceof ITmfFilterTreeNode
) {
1442 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1445 if (filter
.getChildrenCount() > 0) {
1446 applyFilter(filter
);
1452 tableEditor
.getEditor().dispose();
1456 fTable
.addKeyListener(new KeyAdapter() {
1458 public void keyPressed(final KeyEvent e
) {
1460 if (e
.character
== SWT
.ESC
) {
1464 } else if (e
.character
== SWT
.DEL
) {
1465 if (fHeaderState
== HeaderState
.SEARCH
) {
1467 for (final TableColumn column
: fTable
.getColumns()) {
1468 column
.setData(Key
.SEARCH_OBJ
, null);
1469 column
.setData(Key
.SEARCH_TXT
, null);
1471 fTable
.setData(Key
.SEARCH_OBJ
, null);
1473 fireSearchApplied(null);
1474 } else if (fHeaderState
== HeaderState
.FILTER
) {
1477 } else if (e
.character
== SWT
.CR
) {
1478 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1489 * Send an event indicating a filter has been applied.
1492 * The filter that was just applied
1494 protected void fireFilterApplied(final ITmfFilter filter
) {
1495 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1499 * Send an event indicating that a search has been applied.
1502 * The search filter that was just applied
1504 protected void fireSearchApplied(final ITmfFilter filter
) {
1505 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1509 * Start the filtering thread.
1511 protected void startFilterThread() {
1512 synchronized (fFilterSyncObj
) {
1513 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1514 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1515 if (fFilterThread
!= null) {
1516 fFilterThread
.cancel();
1517 fFilterThreadResume
= false;
1519 fFilterThread
= new FilterThread(filter
);
1520 fFilterThread
.start();
1522 fFilterThreadResume
= true;
1528 * Stop the filtering thread.
1530 protected void stopFilterThread() {
1531 synchronized (fFilterSyncObj
) {
1532 if (fFilterThread
!= null) {
1533 fFilterThread
.cancel();
1534 fFilterThread
= null;
1535 fFilterThreadResume
= false;
1544 * The filter to apply
1547 protected void applyFilter(ITmfFilter filter
) {
1550 fFilterMatchCount
= 0;
1551 fFilterCheckCount
= 0;
1552 fCache
.applyFilter(filter
);
1554 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1555 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1556 startFilterThread();
1557 fireFilterApplied(filter
);
1561 * Clear all currently active filters.
1563 protected void clearFilters() {
1564 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1569 fCache
.clearFilter();
1571 for (final TableColumn column
: fTable
.getColumns()) {
1572 column
.setData(Key
.FILTER_OBJ
, null);
1573 column
.setData(Key
.FILTER_TXT
, null);
1575 fTable
.setData(Key
.FILTER_OBJ
, null);
1576 if (fTrace
!= null) {
1577 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1579 fTable
.setItemCount(1); // +1 for header row
1581 fFilterMatchCount
= 0;
1582 fFilterCheckCount
= 0;
1583 if (fSelectedRank
>= 0) {
1584 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1586 fTable
.setSelection(0);
1588 fireFilterApplied(null);
1589 updateStatusLine(null);
1591 // Set original width
1592 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1597 * Wrapper Thread object for the filtering thread.
1599 protected class FilterThread
extends Thread
{
1600 private final ITmfFilterTreeNode filter
;
1601 private TmfEventRequest request
;
1602 private boolean refreshBusy
= false;
1603 private boolean refreshPending
= false;
1604 private final Object syncObj
= new Object();
1610 * The filter this thread will be processing
1612 public FilterThread(final ITmfFilterTreeNode filter
) {
1613 super("Filter Thread"); //$NON-NLS-1$
1614 this.filter
= filter
;
1619 if (fTrace
== null) {
1622 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1623 if (nbRequested
<= 0) {
1626 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1627 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1629 public void handleData(final ITmfEvent event
) {
1630 super.handleData(event
);
1631 if (request
.isCancelled()) {
1634 boolean refresh
= false;
1635 if (filter
.matches(event
)) {
1636 final long rank
= fFilterCheckCount
;
1637 final int index
= (int) fFilterMatchCount
;
1638 fFilterMatchCount
++;
1639 fCache
.storeEvent(event
, rank
, index
);
1642 if (filter
instanceof TmfCollapseFilter
) {
1643 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1647 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1650 fFilterCheckCount
++;
1653 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1655 request
.waitForCompletion();
1656 } catch (final InterruptedException e
) {
1659 synchronized (fFilterSyncObj
) {
1660 fFilterThread
= null;
1661 if (fFilterThreadResume
) {
1662 fFilterThreadResume
= false;
1663 fFilterThread
= new FilterThread(filter
);
1664 fFilterThread
.start();
1670 * Refresh the filter.
1672 public void refreshTable() {
1673 synchronized (syncObj
) {
1675 refreshPending
= true;
1680 Display
.getDefault().asyncExec(new Runnable() {
1683 if (request
.isCancelled()) {
1686 if (fTable
.isDisposed()) {
1689 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1691 synchronized (syncObj
) {
1692 refreshBusy
= false;
1693 if (refreshPending
) {
1694 refreshPending
= false;
1703 * Cancel this filtering thread.
1705 public void cancel() {
1706 if (request
!= null) {
1713 * Go to the next item of a search.
1715 protected void searchNext() {
1716 synchronized (fSearchSyncObj
) {
1717 if (fSearchThread
!= null) {
1720 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1721 if (searchFilter
== null) {
1724 final int selectionIndex
= fTable
.getSelectionIndex();
1726 if (selectionIndex
> 0) {
1727 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1729 // header row is selected, start at top event
1730 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1732 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1733 if (eventFilter
!= null) {
1734 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1736 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1737 fSearchThread
.schedule();
1742 * Go to the previous item of a search.
1744 protected void searchPrevious() {
1745 synchronized (fSearchSyncObj
) {
1746 if (fSearchThread
!= null) {
1749 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1750 if (searchFilter
== null) {
1753 final int selectionIndex
= fTable
.getSelectionIndex();
1755 if (selectionIndex
> 0) {
1756 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1758 // header row is selected, start at precedent of top event
1759 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1761 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1762 if (eventFilter
!= null) {
1763 startIndex
= startIndex
- 1; // -1 for top filter status row
1765 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1766 fSearchThread
.schedule();
1771 * Stop the search thread.
1773 protected void stopSearchThread() {
1774 fPendingGotoRank
= -1;
1775 synchronized (fSearchSyncObj
) {
1776 if (fSearchThread
!= null) {
1777 fSearchThread
.cancel();
1778 fSearchThread
= null;
1784 * Wrapper for the search thread.
1786 protected class SearchThread
extends Job
{
1788 private ITmfFilterTreeNode searchFilter
;
1789 private ITmfFilterTreeNode eventFilter
;
1790 private int startIndex
;
1791 private int direction
;
1793 private long foundRank
= -1;
1794 private TmfEventRequest request
;
1795 private ITmfTimestamp foundTimestamp
= null;
1800 * @param searchFilter
1802 * @param eventFilter
1805 * The index at which we should start searching
1806 * @param currentRank
1809 * In which direction should we search, forward or backwards
1811 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1812 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1813 final long currentRank
, final int direction
) {
1814 super(Messages
.TmfEventsTable_SearchingJobName
);
1815 this.searchFilter
= searchFilter
;
1816 this.eventFilter
= eventFilter
;
1817 this.startIndex
= startIndex
;
1818 this.rank
= currentRank
;
1819 this.direction
= direction
;
1823 protected IStatus
run(final IProgressMonitor monitor
) {
1824 if (fTrace
== null) {
1825 return Status
.OK_STATUS
;
1827 final Display display
= Display
.getDefault();
1828 if (startIndex
< 0) {
1829 rank
= (int) fTrace
.getNbEvents() - 1;
1830 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1833 int idx
= startIndex
;
1834 while (foundRank
== -1) {
1835 final CachedEvent event
= fCache
.peekEvent(idx
);
1836 if (event
== null) {
1840 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1841 foundRank
= event
.rank
;
1842 foundTimestamp
= event
.event
.getTimestamp();
1845 if (direction
== Direction
.FORWARD
) {
1851 if (foundRank
== -1) {
1852 if (direction
== Direction
.FORWARD
) {
1854 if (rank
> (fTrace
.getNbEvents() - 1)) {
1860 rank
= (int) fTrace
.getNbEvents() - 1;
1865 final int startRank
= (int) rank
;
1866 boolean wrapped
= false;
1867 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1868 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1869 if (direction
== Direction
.BACKWARD
) {
1870 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1872 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1873 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1874 long currentRank
= rank
;
1877 public void handleData(final ITmfEvent event
) {
1878 super.handleData(event
);
1879 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1880 foundRank
= currentRank
;
1881 foundTimestamp
= event
.getTimestamp();
1882 if (direction
== Direction
.FORWARD
) {
1890 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1892 request
.waitForCompletion();
1893 if (request
.isCancelled()) {
1894 return Status
.OK_STATUS
;
1896 } catch (final InterruptedException e
) {
1897 synchronized (fSearchSyncObj
) {
1898 fSearchThread
= null;
1900 return Status
.OK_STATUS
;
1902 if (foundRank
== -1) {
1903 if (direction
== Direction
.FORWARD
) {
1905 synchronized (fSearchSyncObj
) {
1906 fSearchThread
= null;
1908 return Status
.OK_STATUS
;
1910 nbRequested
= (int) rank
;
1916 rank
= (int) fTrace
.getNbEvents() - 1;
1919 if ((rank
<= startRank
) && wrapped
) {
1920 synchronized (fSearchSyncObj
) {
1921 fSearchThread
= null;
1923 return Status
.OK_STATUS
;
1928 int index
= (int) foundRank
;
1929 if (eventFilter
!= null) {
1930 index
= fCache
.getFilteredEventIndex(foundRank
);
1932 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1934 display
.asyncExec(new Runnable() {
1937 if (monitor
.isCanceled()) {
1940 if (fTable
.isDisposed()) {
1943 fTable
.setSelection(selection
);
1944 fSelectedRank
= foundRank
;
1945 fRawViewer
.selectAndReveal(fSelectedRank
);
1946 if (foundTimestamp
!= null) {
1947 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1949 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1950 synchronized (fSearchSyncObj
) {
1951 fSearchThread
= null;
1953 updateStatusLine(null);
1956 return Status
.OK_STATUS
;
1960 protected void canceling() {
1962 synchronized (fSearchSyncObj
) {
1963 fSearchThread
= null;
1969 * Create the resources.
1971 protected void createResources() {
1972 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1973 .getForeground().getRGB()));
1974 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1975 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1981 protected void packColumns() {
1985 fTable
.setRedraw(false);
1987 TableColumn tableColumns
[] = fTable
.getColumns();
1988 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1989 final TableColumn column
= tableColumns
[i
];
1990 packSingleColumn(i
, column
);
1993 // Make sure that redraw is always enabled.
1994 fTable
.setRedraw(true);
2000 private void packMarginColumn() {
2001 TableColumn
[] columns
= fTable
.getColumns();
2002 if (columns
.length
> 0) {
2003 packSingleColumn(0, columns
[0]);
2007 private void packSingleColumn(int i
, final TableColumn column
) {
2008 final int headerWidth
= column
.getWidth();
2010 // Workaround for Linux which doesn't consider the image width of
2011 // search/filter row in TableColumn.pack() after having executed
2012 // TableItem.setImage((Image)null) for other rows than search/filter row.
2013 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2014 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2015 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2018 if (column
.getWidth() < headerWidth
) {
2019 column
.setWidth(headerWidth
);
2024 * Get the array of item strings (e.g., what to display in each cell of the
2025 * table row) corresponding to the columns and trace event passed in
2026 * parameter. The order of the Strings in the returned array will correspond
2027 * to the iteration order of 'columns'.
2030 * To ensure consistent results, make sure only call this within a scope
2031 * synchronized on 'columns'! If the order of 'columns' changes right after
2032 * this method is called, the returned value won't be ordered correctly
2035 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2036 if (event
== null) {
2037 return EMPTY_STRING_ARRAY
;
2039 synchronized (columns
) {
2040 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2041 for (TmfEventTableColumn column
: columns
) {
2042 ITmfEvent passedEvent
= event
;
2043 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2044 // Make sure that the event object from the trace is passed
2045 // to all columns but the TmfMarginColumn
2046 passedEvent
= ((CachedEvent
) event
).event
;
2048 if (passedEvent
== null) {
2049 itemStrings
.add(EMPTY_STRING
);
2051 itemStrings
.add(column
.getItemString(passedEvent
));
2055 return itemStrings
.toArray(new String
[0]);
2060 * Get the contents of the row in the events table corresponding to an
2061 * event. The order of the elements corresponds to the current order of the
2065 * The event printed in this row
2066 * @return The event row entries
2069 public String
[] getItemStrings(ITmfEvent event
) {
2070 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2071 for (int i
: fTable
.getColumnOrder()) {
2072 columns
.add(fColumns
.get(i
));
2074 return getItemStrings(columns
, event
);
2078 * Notify this table that is got the UI focus.
2080 public void setFocus() {
2085 * Assign a new trace to this event table.
2088 * The trace to assign to this event table
2089 * @param disposeOnClose
2090 * true if the trace should be disposed when the table is
2093 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2094 if ((fTrace
!= null) && fDisposeOnClose
) {
2100 fDisposeOnClose
= disposeOnClose
;
2102 // Perform the updates on the UI thread
2103 fTable
.getDisplay().syncExec(new Runnable() {
2107 fCache
.setTrace(fTrace
); // Clear the cache
2108 if (fTrace
!= null) {
2109 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2110 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2111 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2114 fFilterMatchCount
= 0;
2115 fFilterCheckCount
= 0;
2116 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2117 startFilterThread();
2121 fRawViewer
.setTrace(fTrace
);
2127 * Assign the status line manager
2129 * @param statusLineManager
2130 * The status line manager, or null to disable status line messages
2133 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2134 if (fStatusLineManager
!= null && statusLineManager
== null) {
2135 fStatusLineManager
.setMessage(EMPTY_STRING
);
2137 fStatusLineManager
= statusLineManager
;
2140 private void updateStatusLine(ITmfTimestamp delta
) {
2141 if (fStatusLineManager
!= null) {
2142 if (delta
!= null) {
2143 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2145 fStatusLineManager
.setMessage(null);
2150 // ------------------------------------------------------------------------
2152 // ------------------------------------------------------------------------
2155 * Notify that the event cache has been updated
2158 * Also notify if the populating of the cache is complete, or
2161 public void cacheUpdated(final boolean completed
) {
2162 synchronized (fCacheUpdateSyncObj
) {
2163 if (fCacheUpdateBusy
) {
2164 fCacheUpdatePending
= true;
2165 fCacheUpdateCompleted
= completed
;
2168 fCacheUpdateBusy
= true;
2170 // Event cache is now updated. Perform update on the UI thread
2171 if (!fTable
.isDisposed()) {
2172 fTable
.getDisplay().asyncExec(new Runnable() {
2175 if (!fTable
.isDisposed()) {
2180 populateCompleted();
2182 synchronized (fCacheUpdateSyncObj
) {
2183 fCacheUpdateBusy
= false;
2184 if (fCacheUpdatePending
) {
2185 fCacheUpdatePending
= false;
2186 cacheUpdated(fCacheUpdateCompleted
);
2195 * Callback for when populating the table is complete.
2197 protected void populateCompleted() {
2198 // Nothing by default;
2201 // ------------------------------------------------------------------------
2202 // ISelectionProvider
2203 // ------------------------------------------------------------------------
2209 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2210 selectionChangedListeners
.add(listener
);
2217 public ISelection
getSelection() {
2218 if (fTable
== null || fTable
.isDisposed()) {
2219 return StructuredSelection
.EMPTY
;
2221 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2222 for (TableItem item
: fTable
.getSelection()) {
2223 if (item
.getData() != null) {
2224 list
.add(item
.getData());
2227 return new StructuredSelection(list
);
2234 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2235 selectionChangedListeners
.remove(listener
);
2242 public void setSelection(ISelection selection
) {
2247 * Notifies any selection changed listeners that the viewer's selection has changed.
2248 * Only listeners registered at the time this method is called are notified.
2250 * @param event a selection changed event
2252 * @see ISelectionChangedListener#selectionChanged
2255 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2256 Object
[] listeners
= selectionChangedListeners
.getListeners();
2257 for (int i
= 0; i
< listeners
.length
; ++i
) {
2258 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2259 SafeRunnable
.run(new SafeRunnable() {
2262 l
.selectionChanged(event
);
2268 // ------------------------------------------------------------------------
2269 // Bookmark handling
2270 // ------------------------------------------------------------------------
2273 * Add a bookmark to this event table.
2275 * @param bookmarksFile
2276 * The file to use for the bookmarks
2278 public void addBookmark(final IFile bookmarksFile
) {
2279 fBookmarksFile
= bookmarksFile
;
2280 final TableItem
[] selection
= fTable
.getSelection();
2281 if (selection
.length
> 0) {
2282 final TableItem tableItem
= selection
[0];
2283 if (tableItem
.getData(Key
.RANK
) != null) {
2284 final StringBuffer defaultMessage
= new StringBuffer();
2285 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2287 defaultMessage
.append(", "); //$NON-NLS-1$
2289 defaultMessage
.append(tableItem
.getText(i
));
2291 final InputDialog dialog
= new MultiLineInputDialog(
2292 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2293 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2294 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2295 defaultMessage
.toString());
2296 if (dialog
.open() == Window
.OK
) {
2297 final String message
= dialog
.getValue();
2299 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2300 if (bookmark
.exists()) {
2301 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2302 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2303 final int location
= rank
.intValue();
2304 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2305 fBookmarksMap
.put(rank
, bookmark
.getId());
2308 } catch (final CoreException e
) {
2309 displayException(e
);
2318 * Remove a bookmark from this event table.
2321 * The bookmark to remove
2323 public void removeBookmark(final IMarker bookmark
) {
2324 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2325 if (entry
.getValue().equals(bookmark
.getId())) {
2326 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2333 private void toggleBookmark(final Long rank
) {
2334 if (fBookmarksFile
== null) {
2337 if (fBookmarksMap
.containsKey(rank
)) {
2338 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2341 for (long markerId
: markerIds
) {
2342 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2343 if (bookmark
!= null) {
2347 } catch (final CoreException e
) {
2348 displayException(e
);
2351 addBookmark(fBookmarksFile
);
2356 * Refresh the bookmarks assigned to this trace, from the contents of a
2359 * @param bookmarksFile
2360 * The bookmark file to use
2362 public void refreshBookmarks(final IFile bookmarksFile
) {
2363 fBookmarksFile
= bookmarksFile
;
2364 if (bookmarksFile
== null) {
2365 fBookmarksMap
.clear();
2370 fBookmarksMap
.clear();
2371 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2372 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2373 if (location
!= -1) {
2374 final long rank
= location
;
2375 fBookmarksMap
.put(rank
, bookmark
.getId());
2379 } catch (final CoreException e
) {
2380 displayException(e
);
2385 public void gotoMarker(final IMarker marker
) {
2386 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2389 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2390 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2391 } else if (rank
>= fTable
.getItemCount()) {
2392 fPendingGotoRank
= rank
;
2394 fSelectedRank
= rank
;
2395 fTable
.setSelection(index
+ 1); // +1 for header row
2396 updateStatusLine(null);
2400 // ------------------------------------------------------------------------
2402 // ------------------------------------------------------------------------
2405 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2409 // ------------------------------------------------------------------------
2411 // ------------------------------------------------------------------------
2414 * Handler for the trace updated signal
2417 * The incoming signal
2420 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2421 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2424 // Perform the refresh on the UI thread
2425 Display
.getDefault().asyncExec(new Runnable() {
2428 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2429 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2430 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2431 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2432 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2433 fPendingGotoRank
= -1;
2434 updateStatusLine(null);
2437 startFilterThread();
2440 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2441 fRawViewer
.refreshEventCount();
2448 * Handler for the time synch signal.
2451 * The incoming signal
2454 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2455 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2457 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2458 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2459 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2460 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2461 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2463 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2466 public void handleData(final ITmfEvent event
) {
2467 super.handleData(event
);
2471 public void handleCompleted() {
2472 super.handleCompleted();
2473 if (fTrace
== null) {
2477 // Verify if the event is within the trace range and adjust if necessary
2478 ITmfTimestamp timestamp
= ts
;
2479 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2480 timestamp
= fTrace
.getStartTime();
2482 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2483 timestamp
= fTrace
.getEndTime();
2486 // Get the rank of the selected event in the table
2487 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2488 final long rank
= context
.getRank();
2490 fSelectedRank
= rank
;
2492 fTable
.getDisplay().asyncExec(new Runnable() {
2495 // Return if table is disposed
2496 if (fTable
.isDisposed()) {
2500 int index
= (int) rank
;
2501 if (fTable
.isDisposed()) {
2504 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2505 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2507 fTable
.setSelection(index
+ 1); // +1 for header row
2508 fRawViewer
.selectAndReveal(rank
);
2509 updateStatusLine(null);
2515 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2519 // ------------------------------------------------------------------------
2521 // ------------------------------------------------------------------------
2524 * Display an exception in a message box
2526 * @param e the exception
2528 private static void displayException(final Exception e
) {
2529 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2530 mb
.setText(e
.getClass().getSimpleName());
2531 mb
.setMessage(e
.getMessage());
2538 public void refresh() {
2545 * Margin column for images and special text (e.g. collapse count)
2547 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2549 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
2552 public String
getName() {
2553 return EMPTY_STRING
;
2557 public String
resolve(ITmfEvent event
) {
2558 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2559 return EMPTY_STRING
;
2561 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2565 public String
getHelpText() {
2566 return EMPTY_STRING
;
2570 public String
getFilterId() {
2578 public TmfMarginColumn() {
2579 super(MARGIN_ASPECT
);