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
.FocusAdapter
;
79 import org
.eclipse
.swt
.events
.FocusEvent
;
80 import org
.eclipse
.swt
.events
.KeyAdapter
;
81 import org
.eclipse
.swt
.events
.KeyEvent
;
82 import org
.eclipse
.swt
.events
.MouseAdapter
;
83 import org
.eclipse
.swt
.events
.MouseEvent
;
84 import org
.eclipse
.swt
.events
.SelectionAdapter
;
85 import org
.eclipse
.swt
.events
.SelectionEvent
;
86 import org
.eclipse
.swt
.graphics
.Color
;
87 import org
.eclipse
.swt
.graphics
.Font
;
88 import org
.eclipse
.swt
.graphics
.Image
;
89 import org
.eclipse
.swt
.graphics
.Point
;
90 import org
.eclipse
.swt
.graphics
.Rectangle
;
91 import org
.eclipse
.swt
.layout
.FillLayout
;
92 import org
.eclipse
.swt
.layout
.GridData
;
93 import org
.eclipse
.swt
.layout
.GridLayout
;
94 import org
.eclipse
.swt
.widgets
.Composite
;
95 import org
.eclipse
.swt
.widgets
.Display
;
96 import org
.eclipse
.swt
.widgets
.Event
;
97 import org
.eclipse
.swt
.widgets
.Label
;
98 import org
.eclipse
.swt
.widgets
.Listener
;
99 import org
.eclipse
.swt
.widgets
.Menu
;
100 import org
.eclipse
.swt
.widgets
.MessageBox
;
101 import org
.eclipse
.swt
.widgets
.Shell
;
102 import org
.eclipse
.swt
.widgets
.TableColumn
;
103 import org
.eclipse
.swt
.widgets
.TableItem
;
104 import org
.eclipse
.swt
.widgets
.Text
;
105 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
106 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
107 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
108 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
109 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
110 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
111 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
112 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
113 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
114 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
115 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
116 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
117 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
118 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
119 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
120 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
121 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
122 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
123 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
124 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
137 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
138 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
139 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableFieldColumn
;
140 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
141 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
142 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
143 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
144 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
145 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
146 import org
.eclipse
.ui
.IWorkbenchPage
;
147 import org
.eclipse
.ui
.PlatformUI
;
148 import org
.eclipse
.ui
.commands
.ICommandService
;
149 import org
.eclipse
.ui
.dialogs
.ListDialog
;
150 import org
.eclipse
.ui
.handlers
.IHandlerService
;
151 import org
.eclipse
.ui
.ide
.IDE
;
152 import org
.eclipse
.ui
.ide
.IGotoMarker
;
153 import org
.eclipse
.ui
.themes
.ColorUtil
;
155 import com
.google
.common
.base
.Joiner
;
156 import com
.google
.common
.collect
.HashMultimap
;
157 import com
.google
.common
.collect
.ImmutableList
;
158 import com
.google
.common
.collect
.Multimap
;
161 * The generic TMF Events table
163 * This is a view that will list events that are read from a trace.
165 * @author Francois Chouinard
166 * @author Patrick Tasse
169 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
172 * Empty string array, used by {@link #getItemStrings}.
175 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
181 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
183 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
185 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
186 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
187 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
188 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
189 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
190 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
191 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
192 private static final Image FILTER_IMAGE
= Activator
.getDefault()
193 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
194 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
195 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
196 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
197 private static final int MAX_CACHE_SIZE
= 1000;
199 private static final int MARGIN_COLUMN_INDEX
= 0;
200 private static final int FILTER_SUMMARY_INDEX
= 1;
201 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
204 * Default set of columns to use for trace types that do not specify
208 public static final Collection
<TmfEventTableColumn
> DEFAULT_COLUMNS
= ImmutableList
.of(
209 TmfEventTableColumn
.BaseColumns
.TIMESTAMP
,
210 TmfEventTableColumn
.BaseColumns
.SOURCE
,
211 TmfEventTableColumn
.BaseColumns
.EVENT_TYPE
,
212 TmfEventTableColumn
.BaseColumns
.REFERENCE
,
213 TmfEventTableColumn
.BaseColumns
.CONTENTS
217 * The events table search/filter keys
220 * @author Patrick Tasse
222 public interface Key
{
224 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
227 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
230 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
233 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
236 String TIMESTAMP
= "$time"; //$NON-NLS-1$
239 String RANK
= "$rank"; //$NON-NLS-1$
242 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
244 /** Bookmark indicator */
245 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
249 * The events table search/filter state
252 * @author Patrick Tasse
254 public static enum HeaderState
{
255 /** A search is being run */
258 /** A filter is applied */
262 interface Direction
{
267 // ------------------------------------------------------------------------
269 // ------------------------------------------------------------------------
271 /** The virtual event table */
272 protected TmfVirtualTable fTable
;
274 private Composite fComposite
;
275 private SashForm fSashForm
;
276 private TmfRawEventViewer fRawViewer
;
277 private ITmfTrace fTrace
;
278 volatile private boolean fPackDone
= false;
279 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
280 private long fSelectedRank
= 0;
281 private ITmfTimestamp fSelectedBeginTimestamp
= null;
282 private IStatusLineManager fStatusLineManager
= null;
285 private long fFilterMatchCount
;
286 private long fFilterCheckCount
;
287 private FilterThread fFilterThread
;
288 private boolean fFilterThreadResume
= false;
289 private final Object fFilterSyncObj
= new Object();
290 private SearchThread fSearchThread
;
291 private final Object fSearchSyncObj
= new Object();
294 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
296 * @see #fireSelectionChanged
298 private ListenerList selectionChangedListeners
= new ListenerList();
300 // Bookmark map <Rank, MarkerId>
301 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
302 private IFile fBookmarksFile
;
303 private long fPendingGotoRank
= -1;
306 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
307 private Color fGrayColor
;
308 private Color fGreenColor
;
309 private Font fBoldFont
;
311 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
314 private final TmfEventsCache fCache
;
315 private boolean fCacheUpdateBusy
= false;
316 private boolean fCacheUpdatePending
= false;
317 private boolean fCacheUpdateCompleted
= false;
318 private final Object fCacheUpdateSyncObj
= new Object();
320 private boolean fDisposeOnClose
;
322 // ------------------------------------------------------------------------
324 // ------------------------------------------------------------------------
327 * Basic constructor, using the default set of columns
330 * The parent composite UI object
332 * The size of the event table cache
334 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
335 this(parent
, cacheSize
, DEFAULT_COLUMNS
);
339 * Legacy constructor, using ColumnData to define columns
342 * The parent composite UI object
344 * The size of the event table cache
347 * @deprecated Deprecated constructor, use
348 * {@link #TmfEventsTable(Composite, int, Collection)}
351 public TmfEventsTable(final Composite parent
, int cacheSize
,
352 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
354 * We'll do a "best-effort" to keep trace types still using this API to
355 * keep working, by defining a TmfEventTableFieldColumn for each
356 * ColumnData they passed.
358 this(parent
, cacheSize
, convertFromColumnData(columnData
));
362 private static Collection
<TmfEventTableColumn
> convertFromColumnData(
363 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
365 ImmutableList
.Builder
<TmfEventTableColumn
> builder
= new ImmutableList
.Builder
<>();
366 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
367 String header
= col
.header
;
368 if (header
!= null) {
369 builder
.add(new TmfEventTableFieldColumn(header
));
372 return builder
.build();
376 * Standard constructor, where we define which columns to use.
379 * The parent composite UI object
381 * The size of the event table cache
383 * The columns to use in this table.
385 * The iteration order of this collection will correspond to the
386 * initial ordering of this series of columns in the table.
390 public TmfEventsTable(final Composite parent
, int cacheSize
,
391 Collection
<?
extends TmfEventTableColumn
> columns
) {
392 super("TmfEventsTable"); //$NON-NLS-1$
394 fComposite
= new Composite(parent
, SWT
.NONE
);
395 final GridLayout gl
= new GridLayout(1, false);
398 gl
.verticalSpacing
= 0;
399 fComposite
.setLayout(gl
);
401 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
402 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
404 // Create a virtual table
405 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
406 fTable
= new TmfVirtualTable(fSashForm
, style
);
408 // Set the table layout
409 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
410 fTable
.setLayoutData(layoutData
);
412 // Some cosmetic enhancements
413 fTable
.setHeaderVisible(true);
414 fTable
.setLinesVisible(true);
417 if (columns
!= null) {
418 fColumns
.addAll(columns
);
421 TmfMarginColumn collapseCol
= new TmfMarginColumn();
422 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
424 // Create the UI columns in the table
425 for (TmfEventTableColumn col
: fColumns
) {
426 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
427 column
.setText(col
.getHeaderName());
428 column
.setToolTipText(col
.getHeaderTooltip());
429 column
.setData(Key
.FIELD_ID
, col
.getFilterFieldId());
431 if (col
instanceof TmfMarginColumn
) {
432 column
.setResizable(false);
436 // Set the frozen row for header row
437 fTable
.setFrozenRowCount(1);
439 // Create the header row cell editor
440 createHeaderEditor();
442 // Handle the table item selection
443 fTable
.addSelectionListener(new SelectionAdapter() {
445 public void widgetSelected(final SelectionEvent e
) {
446 if (e
.item
== null) {
449 updateStatusLine(null);
450 if (fTable
.getSelectionIndices().length
> 0) {
451 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
452 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
453 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
455 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
456 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
457 if (fTable
.getSelectionIndices().length
== 1) {
458 fSelectedBeginTimestamp
= ts
;
460 if (fSelectedBeginTimestamp
!= null) {
461 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
462 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
463 if (fTable
.getSelectionIndices().length
== 2) {
464 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
467 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
468 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
472 if (fTable
.getSelectionIndices().length
== 1) {
473 fSelectedBeginTimestamp
= null;
477 if (e
.item
.getData() instanceof ITmfEvent
) {
478 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
479 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
481 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
486 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
487 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
488 fCache
= new TmfEventsCache(realCacheSize
, this);
490 // Handle the table item requests
491 fTable
.addListener(SWT
.SetData
, new Listener() {
494 public void handleEvent(final Event event
) {
496 final TableItem item
= (TableItem
) event
.item
;
497 int index
= event
.index
- 1; // -1 for the header row
499 if (event
.index
== 0) {
500 setHeaderRowItemData(item
);
504 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
505 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
506 setFilterStatusRowItemData(item
);
509 index
= index
- 1; // -1 for top filter status row
512 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
513 if (cachedEvent
!= null) {
514 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
518 // Else, fill the cache asynchronously (and off the UI thread)
523 fTable
.addMouseListener(new MouseAdapter() {
525 public void mouseDoubleClick(final MouseEvent event
) {
526 if (event
.button
!= 1) {
529 // Identify the selected row
530 final Point point
= new Point(event
.x
, event
.y
);
531 final TableItem item
= fTable
.getItem(point
);
533 final Rectangle imageBounds
= item
.getImageBounds(0);
534 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
535 if (imageBounds
.contains(point
)) {
536 final Long rank
= (Long
) item
.getData(Key
.RANK
);
538 toggleBookmark(rank
);
545 final Listener tooltipListener
= new Listener () {
546 Shell tooltipShell
= null;
548 public void handleEvent(final Event event
) {
549 switch (event
.type
) {
551 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
555 final Long rank
= (Long
) item
.getData(Key
.RANK
);
559 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
560 final Rectangle bounds
= item
.getImageBounds(0);
561 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
562 if (!bounds
.contains(event
.x
,event
.y
)) {
565 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
566 tooltipShell
.dispose();
568 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
569 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
570 final FillLayout layout
= new FillLayout();
571 layout
.marginWidth
= 2;
572 tooltipShell
.setLayout(layout
);
573 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
574 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
575 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
576 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
578 label
.addListener(SWT
.MouseExit
, this);
579 label
.addListener(SWT
.MouseDown
, this);
580 label
.addListener(SWT
.MouseWheel
, this);
581 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
583 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
584 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
588 y
+= fTable
.getHeaderHeight();
590 Point pt
= fTable
.toDisplay(event
.x
, y
);
591 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
592 pt
.y
+= item
.getBounds().height
;
593 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
594 tooltipShell
.setVisible(true);
602 if (tooltipShell
!= null) {
603 tooltipShell
.dispose();
613 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
614 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
615 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
616 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
617 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
618 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
619 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
624 ColorSettingsManager
.addColorSettingsListener(this);
626 fTable
.setItemCount(1); // +1 for header row
628 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
630 fRawViewer
.addSelectionListener(new Listener() {
632 public void handleEvent(final Event e
) {
633 if (e
.data
instanceof Long
) {
634 final long rank
= (Long
) e
.data
;
635 int index
= (int) rank
;
636 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
637 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
639 fTable
.setSelection(index
+ 1); // +1 for header row
640 fSelectedRank
= rank
;
641 updateStatusLine(null);
642 } else if (e
.data
instanceof ITmfLocation
) {
643 // DOES NOT WORK: rank undefined in context from seekLocation()
644 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
645 // TmfContext context = fTrace.seekLocation(location);
646 // fTable.setSelection((int) context.getRank());
651 final TableItem
[] selection
= fTable
.getSelection();
652 if ((selection
!= null) && (selection
.length
> 0)) {
653 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
655 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
661 fSashForm
.setWeights(new int[] { 1, 1 });
662 fRawViewer
.setVisible(false);
667 // ------------------------------------------------------------------------
669 // ------------------------------------------------------------------------
672 * Create a pop-up menu.
674 protected void createPopupMenu() {
675 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
678 fTable
.setVisible(true);
683 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
686 fTable
.setVisible(false);
691 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
694 fRawViewer
.setVisible(true);
696 final int index
= fTable
.getSelectionIndex();
698 fRawViewer
.selectAndReveal(index
- 1);
703 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
706 fRawViewer
.setVisible(false);
711 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
714 final TableItem items
[] = fTable
.getSelection();
715 if (items
.length
!= 1) {
718 final TableItem item
= items
[0];
720 final Object data
= item
.getData();
721 if (data
instanceof ITmfSourceLookup
) {
722 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
723 ITmfCallsite cs
= event
.getCallsite();
724 if (cs
== null || cs
.getFileName() == null) {
727 IMarker marker
= null;
729 String fileName
= cs
.getFileName();
730 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
731 final ArrayList
<IFile
> files
= new ArrayList
<>();
732 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
734 public boolean visit(IResource resource
) throws CoreException
{
735 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
736 files
.add((IFile
) resource
);
742 if (files
.size() > 1) {
743 ListDialog dialog
= new ListDialog(getTable().getShell());
744 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
745 dialog
.setLabelProvider(new LabelProvider() {
747 public String
getText(Object element
) {
748 return ((IFile
) element
).getFullPath().toString();
751 dialog
.setInput(files
);
752 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
753 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
755 Object
[] result
= dialog
.getResult();
756 if (result
!= null && result
.length
> 0) {
757 file
= (IFile
) result
[0];
759 } else if (files
.size() == 1) {
763 marker
= file
.createMarker(IMarker
.MARKER
);
764 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
765 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
767 } else if (files
.size() == 0){
768 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
770 } catch (CoreException e
) {
777 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
781 final TableItem items
[] = fTable
.getSelection();
782 if (items
.length
!= 1) {
785 final TableItem item
= items
[0];
787 final Object eventData
= item
.getData();
788 if (eventData
instanceof ITmfModelLookup
) {
789 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
791 if (modelURI
!= null) {
792 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
795 final URI uri
= URI
.createURI(modelURI
);
796 if (uri
.isPlatformResource()) {
797 IPath path
= new Path(uri
.toPlatformString(true));
798 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
799 } else if (uri
.isFile() && !uri
.isRelative()) {
800 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
801 new Path(uri
.toFileString()));
807 * create a temporary validation marker on the
808 * model file, remove it afterwards thus,
809 * navigation works with all model editors
810 * supporting the navigation to a marker
812 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
813 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
814 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
816 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
819 catch (CoreException e
) {
823 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
830 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
833 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
834 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
835 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
836 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
837 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
839 HashMap
<String
, Object
> parameters
= new HashMap
<>();
840 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
841 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
843 IEvaluationContext context
= handlerService
.getCurrentState();
844 // Omit the margin column
845 List
<TmfEventTableColumn
> exportColumns
= fColumns
.subList(EVENT_COLUMNS_START_INDEX
, fColumns
.size());
846 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
848 handlerService
.executeCommandInContext(cmd
, null, context
);
849 } catch (ExecutionException e
) {
851 } catch (NotDefinedException e
) {
853 } catch (NotEnabledException e
) {
855 } catch (NotHandledException e
) {
861 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
864 fHeaderState
= HeaderState
.SEARCH
;
869 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
872 fHeaderState
= HeaderState
.FILTER
;
877 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
884 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
887 applyFilter(new TmfCollapseFilter());
891 class ToggleBookmarkAction
extends Action
{
894 public ToggleBookmarkAction(final String text
, final Long rank
) {
901 toggleBookmark(fRank
);
905 final MenuManager tablePopupMenu
= new MenuManager();
906 tablePopupMenu
.setRemoveAllWhenShown(true);
907 tablePopupMenu
.addMenuListener(new IMenuListener() {
909 public void menuAboutToShow(final IMenuManager manager
) {
910 if (fTable
.getSelectionIndex() == 0) {
911 // Right-click on header row
912 if (fHeaderState
== HeaderState
.FILTER
) {
913 tablePopupMenu
.add(showSearchBarAction
);
915 tablePopupMenu
.add(showFilterBarAction
);
919 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
920 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
922 final Rectangle imageBounds
= item
.getImageBounds(0);
923 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
924 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
925 // Right-click on left margin
926 final Long rank
= (Long
) item
.getData(Key
.RANK
);
927 if ((rank
!= null) && (fBookmarksFile
!= null)) {
928 if (fBookmarksMap
.containsKey(rank
)) {
929 tablePopupMenu
.add(new ToggleBookmarkAction(
930 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
932 tablePopupMenu
.add(new ToggleBookmarkAction(
933 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
940 // Right-click on table
941 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
942 tablePopupMenu
.add(hideTableAction
);
943 tablePopupMenu
.add(hideRawAction
);
944 } else if (!fTable
.isVisible()) {
945 tablePopupMenu
.add(showTableAction
);
946 } else if (!fRawViewer
.isVisible()) {
947 tablePopupMenu
.add(showRawAction
);
949 tablePopupMenu
.add(exportToTextAction
);
950 tablePopupMenu
.add(new Separator());
953 final Object data
= item
.getData();
954 Separator separator
= null;
955 if (data
instanceof ITmfSourceLookup
) {
956 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
957 if (event
.getCallsite() != null) {
958 tablePopupMenu
.add(openCallsiteAction
);
959 separator
= new Separator();
963 if (data
instanceof ITmfModelLookup
) {
964 ITmfModelLookup event
= (ITmfModelLookup
) data
;
965 if (event
.getModelUri() != null) {
966 tablePopupMenu
.add(openModelAction
);
967 separator
= new Separator();
970 if (separator
!= null) {
971 tablePopupMenu
.add(separator
);
976 // only show collapse filter if at least one trace can be collapsed
977 boolean isCollapsible
= false;
978 if (fTrace
!= null) {
979 ITmfTrace traces
[] = TmfTraceManager
.getTraceSet(fTrace
);
980 for (ITmfTrace trace
: traces
) {
981 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
982 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
989 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
990 tablePopupMenu
.add(collapseAction
);
991 tablePopupMenu
.add(new Separator());
994 tablePopupMenu
.add(clearFiltersAction
);
995 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
996 if (savedFilters
.length
> 0) {
997 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
998 for (final ITmfFilterTreeNode node
: savedFilters
) {
999 if (node
instanceof TmfFilterNode
) {
1000 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1001 subMenu
.add(new Action(filter
.getFilterName()) {
1004 applyFilter(filter
);
1009 tablePopupMenu
.add(subMenu
);
1011 appendToTablePopupMenu(tablePopupMenu
, item
);
1015 final MenuManager rawViewerPopupMenu
= new MenuManager();
1016 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1017 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1019 public void menuAboutToShow(final IMenuManager manager
) {
1020 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1021 rawViewerPopupMenu
.add(hideTableAction
);
1022 rawViewerPopupMenu
.add(hideRawAction
);
1023 } else if (!fTable
.isVisible()) {
1024 rawViewerPopupMenu
.add(showTableAction
);
1025 } else if (!fRawViewer
.isVisible()) {
1026 rawViewerPopupMenu
.add(showRawAction
);
1028 appendToRawPopupMenu(tablePopupMenu
);
1032 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1033 fTable
.setMenu(menu
);
1035 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1036 fRawViewer
.setMenu(menu
);
1041 * Append an item to the event table's pop-up menu.
1043 * @param tablePopupMenu
1045 * @param selectedItem
1046 * The item to append
1048 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1049 // override to append more actions
1053 * Append an item to the raw viewer's pop-up menu.
1055 * @param rawViewerPopupMenu
1058 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1059 // override to append more actions
1063 public void dispose() {
1066 ColorSettingsManager
.removeColorSettingsListener(this);
1067 fComposite
.dispose();
1068 if ((fTrace
!= null) && fDisposeOnClose
) {
1071 fResourceManager
.dispose();
1072 fRawViewer
.dispose();
1077 * Assign a layout data object to this view.
1080 * The layout data to assign
1082 public void setLayoutData(final Object layoutData
) {
1083 fComposite
.setLayoutData(layoutData
);
1087 * Get the virtual table contained in this event table.
1089 * @return The TMF virtual table
1091 public TmfVirtualTable
getTable() {
1098 * @deprecated The column headers are now set at the constructor, this
1099 * shouldn't be called anymore.
1102 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1107 * Set a table item's data.
1112 * Which trace event to link with this entry
1114 * Which rank this event has in the trace/experiment
1116 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1117 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1118 item
.setText(itemStrings
);
1119 item
.setData(event
);
1120 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1121 item
.setData(Key
.RANK
, rank
);
1123 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1124 if (!markerIds
.isEmpty()) {
1125 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1126 List
<Object
> parts
= new ArrayList
<>();
1127 if (markerIds
.size() > 1) {
1128 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1131 for (long markerId
: markerIds
) {
1132 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1133 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1135 } catch (CoreException e
) {
1136 displayException(e
);
1138 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1140 item
.setData(Key
.BOOKMARK
, null);
1143 boolean searchMatch
= false;
1144 boolean searchNoMatch
= false;
1145 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1146 if (searchFilter
!= null) {
1147 if (searchFilter
.matches(event
)) {
1150 searchNoMatch
= true;
1154 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1155 if (searchNoMatch
) {
1156 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1157 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1159 item
.setForeground(colorSetting
.getForegroundColor());
1160 item
.setBackground(colorSetting
.getBackgroundColor());
1164 if (!markerIds
.isEmpty()) {
1165 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1167 item
.setImage(SEARCH_MATCH_IMAGE
);
1169 } else if (!markerIds
.isEmpty()) {
1170 item
.setImage(BOOKMARK_IMAGE
);
1172 item
.setImage((Image
) null);
1175 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1181 * Set the item data of the header row.
1184 * The item to use as table header
1186 protected void setHeaderRowItemData(final TableItem item
) {
1187 String txtKey
= null;
1188 if (fHeaderState
== HeaderState
.SEARCH
) {
1189 item
.setImage(SEARCH_IMAGE
);
1190 txtKey
= Key
.SEARCH_TXT
;
1191 } else if (fHeaderState
== HeaderState
.FILTER
) {
1192 item
.setImage(FILTER_IMAGE
);
1193 txtKey
= Key
.FILTER_TXT
;
1195 item
.setForeground(fGrayColor
);
1196 // Ignore collapse and image column
1197 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1198 final TableColumn column
= fTable
.getColumns()[i
];
1199 final String filter
= (String
) column
.getData(txtKey
);
1200 if (filter
== null) {
1201 if (fHeaderState
== HeaderState
.SEARCH
) {
1202 item
.setText(i
, SEARCH_HINT
);
1203 } else if (fHeaderState
== HeaderState
.FILTER
) {
1204 item
.setText(i
, FILTER_HINT
);
1206 item
.setForeground(i
, fGrayColor
);
1207 item
.setFont(i
, fTable
.getFont());
1209 item
.setText(i
, filter
);
1210 item
.setForeground(i
, fGreenColor
);
1211 item
.setFont(i
, fBoldFont
);
1217 * Set the item data of the "filter status" row.
1220 * The item to use as filter status row
1222 protected void setFilterStatusRowItemData(final TableItem item
) {
1223 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1224 if (i
== MARGIN_COLUMN_INDEX
) {
1225 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1226 item
.setImage(FILTER_IMAGE
);
1228 item
.setImage(STOP_IMAGE
);
1232 if (i
== FILTER_SUMMARY_INDEX
) {
1233 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1235 item
.setText(i
, EMPTY_STRING
);
1239 item
.setData(Key
.TIMESTAMP
, null);
1240 item
.setData(Key
.RANK
, null);
1241 item
.setForeground(null);
1242 item
.setBackground(null);
1246 * Create an editor for the header.
1248 protected void createHeaderEditor() {
1249 final TableEditor tableEditor
= fTable
.createTableEditor();
1250 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1251 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1252 tableEditor
.grabHorizontal
= true;
1253 tableEditor
.minimumWidth
= 50;
1255 // Handle the header row selection
1256 fTable
.addMouseListener(new MouseAdapter() {
1262 public void mouseDown(final MouseEvent event
) {
1263 if (event
.button
!= 1) {
1266 // Identify the selected row
1267 final Point point
= new Point(event
.x
, event
.y
);
1268 item
= fTable
.getItem(point
);
1270 // Header row selected
1271 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1274 if (item
.getImageBounds(0).contains(point
)) {
1275 if (fHeaderState
== HeaderState
.SEARCH
) {
1276 fHeaderState
= HeaderState
.FILTER
;
1277 } else if (fHeaderState
== HeaderState
.FILTER
) {
1278 fHeaderState
= HeaderState
.SEARCH
;
1280 fTable
.setSelection(0);
1285 // Identify the selected column
1287 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1288 final Rectangle rect
= item
.getBounds(i
);
1289 if (rect
.contains(point
)) {
1295 if (columnIndex
== -1) {
1299 column
= fTable
.getColumns()[columnIndex
];
1301 String txtKey
= null;
1302 if (fHeaderState
== HeaderState
.SEARCH
) {
1303 txtKey
= Key
.SEARCH_TXT
;
1304 } else if (fHeaderState
== HeaderState
.FILTER
) {
1305 txtKey
= Key
.FILTER_TXT
;
1308 // The control that will be the editor must be a child of the Table
1309 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1310 final String headerString
= (String
) column
.getData(txtKey
);
1311 if (headerString
!= null) {
1312 newEditor
.setText(headerString
);
1314 newEditor
.addFocusListener(new FocusAdapter() {
1316 public void focusLost(final FocusEvent e
) {
1317 final boolean changed
= updateHeader(newEditor
.getText());
1323 newEditor
.addKeyListener(new KeyAdapter() {
1325 public void keyPressed(final KeyEvent e
) {
1326 if (e
.character
== SWT
.CR
) {
1327 updateHeader(newEditor
.getText());
1330 // Set focus on the table so that the next carriage return goes to the next result
1331 TmfEventsTable
.this.getTable().setFocus();
1332 } else if (e
.character
== SWT
.ESC
) {
1333 tableEditor
.getEditor().dispose();
1337 newEditor
.selectAll();
1338 newEditor
.setFocus();
1339 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1344 * returns true is value was changed
1346 private boolean updateHeader(final String text
) {
1347 String objKey
= null;
1348 String txtKey
= null;
1349 if (fHeaderState
== HeaderState
.SEARCH
) {
1350 objKey
= Key
.SEARCH_OBJ
;
1351 txtKey
= Key
.SEARCH_TXT
;
1352 } else if (fHeaderState
== HeaderState
.FILTER
) {
1353 objKey
= Key
.FILTER_OBJ
;
1354 txtKey
= Key
.FILTER_TXT
;
1356 if (text
.trim().length() > 0) {
1358 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1359 Pattern
.compile(regex
);
1360 if (regex
.equals(column
.getData(txtKey
))) {
1361 tableEditor
.getEditor().dispose();
1364 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1365 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1366 if (fieldId
== null) {
1367 fieldId
= column
.getText();
1369 filter
.setField(fieldId
);
1370 filter
.setRegex(regex
);
1371 column
.setData(objKey
, filter
);
1372 column
.setData(txtKey
, regex
);
1373 } catch (final PatternSyntaxException ex
) {
1374 tableEditor
.getEditor().dispose();
1375 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1376 ex
.getDescription(), ex
.getMessage());
1380 if (column
.getData(txtKey
) == null) {
1381 tableEditor
.getEditor().dispose();
1384 column
.setData(objKey
, null);
1385 column
.setData(txtKey
, null);
1390 private void applyHeader() {
1391 if (fHeaderState
== HeaderState
.SEARCH
) {
1393 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1394 for (final TableColumn col
: fTable
.getColumns()) {
1395 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1396 if (filterObj
instanceof ITmfFilterTreeNode
) {
1397 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1400 if (filter
.getChildrenCount() > 0) {
1401 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1404 fireSearchApplied(filter
);
1406 fTable
.setData(Key
.SEARCH_OBJ
, null);
1408 fireSearchApplied(null);
1410 } else if (fHeaderState
== HeaderState
.FILTER
) {
1411 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1412 for (final TableColumn col
: fTable
.getColumns()) {
1413 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1414 if (filterObj
instanceof ITmfFilterTreeNode
) {
1415 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1418 if (filter
.getChildrenCount() > 0) {
1419 applyFilter(filter
);
1425 tableEditor
.getEditor().dispose();
1429 fTable
.addKeyListener(new KeyAdapter() {
1431 public void keyPressed(final KeyEvent e
) {
1433 if (e
.character
== SWT
.ESC
) {
1437 } else if (e
.character
== SWT
.DEL
) {
1438 if (fHeaderState
== HeaderState
.SEARCH
) {
1440 for (final TableColumn column
: fTable
.getColumns()) {
1441 column
.setData(Key
.SEARCH_OBJ
, null);
1442 column
.setData(Key
.SEARCH_TXT
, null);
1444 fTable
.setData(Key
.SEARCH_OBJ
, null);
1446 fireSearchApplied(null);
1447 } else if (fHeaderState
== HeaderState
.FILTER
) {
1450 } else if (e
.character
== SWT
.CR
) {
1451 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1462 * Send an event indicating a filter has been applied.
1465 * The filter that was just applied
1467 protected void fireFilterApplied(final ITmfFilter filter
) {
1468 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1472 * Send an event indicating that a search has been applied.
1475 * The search filter that was just applied
1477 protected void fireSearchApplied(final ITmfFilter filter
) {
1478 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1482 * Start the filtering thread.
1484 protected void startFilterThread() {
1485 synchronized (fFilterSyncObj
) {
1486 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1487 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1488 if (fFilterThread
!= null) {
1489 fFilterThread
.cancel();
1490 fFilterThreadResume
= false;
1492 fFilterThread
= new FilterThread(filter
);
1493 fFilterThread
.start();
1495 fFilterThreadResume
= true;
1501 * Stop the filtering thread.
1503 protected void stopFilterThread() {
1504 synchronized (fFilterSyncObj
) {
1505 if (fFilterThread
!= null) {
1506 fFilterThread
.cancel();
1507 fFilterThread
= null;
1508 fFilterThreadResume
= false;
1517 * The filter to apply
1520 protected void applyFilter(ITmfFilter filter
) {
1523 fFilterMatchCount
= 0;
1524 fFilterCheckCount
= 0;
1525 fCache
.applyFilter(filter
);
1527 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1528 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1529 startFilterThread();
1530 fireFilterApplied(filter
);
1534 * Clear all currently active filters.
1536 protected void clearFilters() {
1537 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1542 fCache
.clearFilter();
1544 for (final TableColumn column
: fTable
.getColumns()) {
1545 column
.setData(Key
.FILTER_OBJ
, null);
1546 column
.setData(Key
.FILTER_TXT
, null);
1548 fTable
.setData(Key
.FILTER_OBJ
, null);
1549 if (fTrace
!= null) {
1550 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1552 fTable
.setItemCount(1); // +1 for header row
1554 fFilterMatchCount
= 0;
1555 fFilterCheckCount
= 0;
1556 if (fSelectedRank
>= 0) {
1557 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1559 fTable
.setSelection(0);
1561 fireFilterApplied(null);
1562 updateStatusLine(null);
1564 // Set original width
1565 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1570 * Wrapper Thread object for the filtering thread.
1572 protected class FilterThread
extends Thread
{
1573 private final ITmfFilterTreeNode filter
;
1574 private TmfEventRequest request
;
1575 private boolean refreshBusy
= false;
1576 private boolean refreshPending
= false;
1577 private final Object syncObj
= new Object();
1583 * The filter this thread will be processing
1585 public FilterThread(final ITmfFilterTreeNode filter
) {
1586 super("Filter Thread"); //$NON-NLS-1$
1587 this.filter
= filter
;
1592 if (fTrace
== null) {
1595 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1596 if (nbRequested
<= 0) {
1599 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1600 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1602 public void handleData(final ITmfEvent event
) {
1603 super.handleData(event
);
1604 if (request
.isCancelled()) {
1607 boolean refresh
= false;
1608 if (filter
.matches(event
)) {
1609 final long rank
= fFilterCheckCount
;
1610 final int index
= (int) fFilterMatchCount
;
1611 fFilterMatchCount
++;
1612 fCache
.storeEvent(event
, rank
, index
);
1615 if (filter
instanceof TmfCollapseFilter
) {
1616 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1620 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1623 fFilterCheckCount
++;
1626 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1628 request
.waitForCompletion();
1629 } catch (final InterruptedException e
) {
1632 synchronized (fFilterSyncObj
) {
1633 fFilterThread
= null;
1634 if (fFilterThreadResume
) {
1635 fFilterThreadResume
= false;
1636 fFilterThread
= new FilterThread(filter
);
1637 fFilterThread
.start();
1643 * Refresh the filter.
1645 public void refreshTable() {
1646 synchronized (syncObj
) {
1648 refreshPending
= true;
1653 Display
.getDefault().asyncExec(new Runnable() {
1656 if (request
.isCancelled()) {
1659 if (fTable
.isDisposed()) {
1662 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1664 synchronized (syncObj
) {
1665 refreshBusy
= false;
1666 if (refreshPending
) {
1667 refreshPending
= false;
1676 * Cancel this filtering thread.
1678 public void cancel() {
1679 if (request
!= null) {
1686 * Go to the next item of a search.
1688 protected void searchNext() {
1689 synchronized (fSearchSyncObj
) {
1690 if (fSearchThread
!= null) {
1693 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1694 if (searchFilter
== null) {
1697 final int selectionIndex
= fTable
.getSelectionIndex();
1699 if (selectionIndex
> 0) {
1700 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1702 // header row is selected, start at top event
1703 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1705 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1706 if (eventFilter
!= null) {
1707 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1709 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1710 fSearchThread
.schedule();
1715 * Go to the previous item of a search.
1717 protected void searchPrevious() {
1718 synchronized (fSearchSyncObj
) {
1719 if (fSearchThread
!= null) {
1722 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1723 if (searchFilter
== null) {
1726 final int selectionIndex
= fTable
.getSelectionIndex();
1728 if (selectionIndex
> 0) {
1729 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1731 // header row is selected, start at precedent of top event
1732 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1734 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1735 if (eventFilter
!= null) {
1736 startIndex
= startIndex
- 1; // -1 for top filter status row
1738 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1739 fSearchThread
.schedule();
1744 * Stop the search thread.
1746 protected void stopSearchThread() {
1747 fPendingGotoRank
= -1;
1748 synchronized (fSearchSyncObj
) {
1749 if (fSearchThread
!= null) {
1750 fSearchThread
.cancel();
1751 fSearchThread
= null;
1757 * Wrapper for the search thread.
1759 protected class SearchThread
extends Job
{
1761 private ITmfFilterTreeNode searchFilter
;
1762 private ITmfFilterTreeNode eventFilter
;
1763 private int startIndex
;
1764 private int direction
;
1766 private long foundRank
= -1;
1767 private TmfEventRequest request
;
1768 private ITmfTimestamp foundTimestamp
= null;
1773 * @param searchFilter
1775 * @param eventFilter
1778 * The index at which we should start searching
1779 * @param currentRank
1782 * In which direction should we search, forward or backwards
1784 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1785 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1786 final long currentRank
, final int direction
) {
1787 super(Messages
.TmfEventsTable_SearchingJobName
);
1788 this.searchFilter
= searchFilter
;
1789 this.eventFilter
= eventFilter
;
1790 this.startIndex
= startIndex
;
1791 this.rank
= currentRank
;
1792 this.direction
= direction
;
1796 protected IStatus
run(final IProgressMonitor monitor
) {
1797 if (fTrace
== null) {
1798 return Status
.OK_STATUS
;
1800 final Display display
= Display
.getDefault();
1801 if (startIndex
< 0) {
1802 rank
= (int) fTrace
.getNbEvents() - 1;
1803 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1806 int idx
= startIndex
;
1807 while (foundRank
== -1) {
1808 final CachedEvent event
= fCache
.peekEvent(idx
);
1809 if (event
== null) {
1813 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1814 foundRank
= event
.rank
;
1815 foundTimestamp
= event
.event
.getTimestamp();
1818 if (direction
== Direction
.FORWARD
) {
1824 if (foundRank
== -1) {
1825 if (direction
== Direction
.FORWARD
) {
1827 if (rank
> (fTrace
.getNbEvents() - 1)) {
1833 rank
= (int) fTrace
.getNbEvents() - 1;
1838 final int startRank
= (int) rank
;
1839 boolean wrapped
= false;
1840 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1841 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1842 if (direction
== Direction
.BACKWARD
) {
1843 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1845 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1846 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1847 long currentRank
= rank
;
1850 public void handleData(final ITmfEvent event
) {
1851 super.handleData(event
);
1852 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1853 foundRank
= currentRank
;
1854 foundTimestamp
= event
.getTimestamp();
1855 if (direction
== Direction
.FORWARD
) {
1863 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1865 request
.waitForCompletion();
1866 if (request
.isCancelled()) {
1867 return Status
.OK_STATUS
;
1869 } catch (final InterruptedException e
) {
1870 synchronized (fSearchSyncObj
) {
1871 fSearchThread
= null;
1873 return Status
.OK_STATUS
;
1875 if (foundRank
== -1) {
1876 if (direction
== Direction
.FORWARD
) {
1878 synchronized (fSearchSyncObj
) {
1879 fSearchThread
= null;
1881 return Status
.OK_STATUS
;
1883 nbRequested
= (int) rank
;
1889 rank
= (int) fTrace
.getNbEvents() - 1;
1892 if ((rank
<= startRank
) && wrapped
) {
1893 synchronized (fSearchSyncObj
) {
1894 fSearchThread
= null;
1896 return Status
.OK_STATUS
;
1901 int index
= (int) foundRank
;
1902 if (eventFilter
!= null) {
1903 index
= fCache
.getFilteredEventIndex(foundRank
);
1905 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1907 display
.asyncExec(new Runnable() {
1910 if (monitor
.isCanceled()) {
1913 if (fTable
.isDisposed()) {
1916 fTable
.setSelection(selection
);
1917 fSelectedRank
= foundRank
;
1918 fRawViewer
.selectAndReveal(fSelectedRank
);
1919 if (foundTimestamp
!= null) {
1920 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1922 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1923 synchronized (fSearchSyncObj
) {
1924 fSearchThread
= null;
1926 updateStatusLine(null);
1929 return Status
.OK_STATUS
;
1933 protected void canceling() {
1935 synchronized (fSearchSyncObj
) {
1936 fSearchThread
= null;
1942 * Create the resources.
1944 protected void createResources() {
1945 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1946 .getForeground().getRGB()));
1947 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1948 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1954 protected void packColumns() {
1958 fTable
.setRedraw(false);
1960 TableColumn tableColumns
[] = fTable
.getColumns();
1961 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1962 final TableColumn column
= tableColumns
[i
];
1963 packSingleColumn(i
, column
);
1966 // Make sure that redraw is always enabled.
1967 fTable
.setRedraw(true);
1973 private void packMarginColumn() {
1974 TableColumn
[] columns
= fTable
.getColumns();
1975 if (columns
.length
> 0) {
1976 packSingleColumn(0, columns
[0]);
1980 private void packSingleColumn(int i
, final TableColumn column
) {
1981 final int headerWidth
= column
.getWidth();
1983 // Workaround for Linux which doesn't consider the image width of
1984 // search/filter row in TableColumn.pack() after having executed
1985 // TableItem.setImage((Image)null) for other rows than search/filter row.
1986 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
1987 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
1988 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1991 if (column
.getWidth() < headerWidth
) {
1992 column
.setWidth(headerWidth
);
1997 * Get the array of item strings (e.g., what to display in each cell of the
1998 * table row) corresponding to the columns and trace event passed in
1999 * parameter. The order of the Strings in the returned array will correspond
2000 * to the iteration order of 'columns'.
2003 * To ensure consistent results, make sure only call this within a scope
2004 * synchronized on 'columns'! If the order of 'columns' changes right after
2005 * this method is called, the returned value won't be ordered correctly
2008 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2009 if (event
== null) {
2010 return EMPTY_STRING_ARRAY
;
2012 synchronized (columns
) {
2013 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2014 for (TmfEventTableColumn column
: columns
) {
2015 ITmfEvent passedEvent
= event
;
2016 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2017 // Make sure that the event object from the trace is passed
2018 // to all columns but the TmfMarginColumn
2019 passedEvent
= ((CachedEvent
) event
).event
;
2021 if (passedEvent
== null) {
2022 itemStrings
.add(EMPTY_STRING
);
2024 itemStrings
.add(column
.getItemString(passedEvent
));
2028 return itemStrings
.toArray(new String
[0]);
2033 * Get the contents of the row in the events table corresponding to an
2034 * event. The order of the elements corresponds to the current order of the
2038 * The event printed in this row
2039 * @return The event row entries
2042 public String
[] getItemStrings(ITmfEvent event
) {
2043 return getItemStrings(fColumns
, event
);
2047 * Notify this table that is got the UI focus.
2049 public void setFocus() {
2054 * Assign a new trace to this event table.
2057 * The trace to assign to this event table
2058 * @param disposeOnClose
2059 * true if the trace should be disposed when the table is
2062 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2063 if ((fTrace
!= null) && fDisposeOnClose
) {
2069 fDisposeOnClose
= disposeOnClose
;
2071 // Perform the updates on the UI thread
2072 fTable
.getDisplay().syncExec(new Runnable() {
2076 fCache
.setTrace(fTrace
); // Clear the cache
2077 if (fTrace
!= null) {
2078 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2079 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2080 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2083 fFilterMatchCount
= 0;
2084 fFilterCheckCount
= 0;
2085 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2086 startFilterThread();
2090 fRawViewer
.setTrace(fTrace
);
2096 * Assign the status line manager
2098 * @param statusLineManager
2099 * The status line manager, or null to disable status line messages
2102 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2103 if (fStatusLineManager
!= null && statusLineManager
== null) {
2104 fStatusLineManager
.setMessage(EMPTY_STRING
);
2106 fStatusLineManager
= statusLineManager
;
2109 private void updateStatusLine(ITmfTimestamp delta
) {
2110 if (fStatusLineManager
!= null) {
2111 if (delta
!= null) {
2112 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2114 fStatusLineManager
.setMessage(null);
2119 // ------------------------------------------------------------------------
2121 // ------------------------------------------------------------------------
2124 * Notify that the event cache has been updated
2127 * Also notify if the populating of the cache is complete, or
2130 public void cacheUpdated(final boolean completed
) {
2131 synchronized (fCacheUpdateSyncObj
) {
2132 if (fCacheUpdateBusy
) {
2133 fCacheUpdatePending
= true;
2134 fCacheUpdateCompleted
= completed
;
2137 fCacheUpdateBusy
= true;
2139 // Event cache is now updated. Perform update on the UI thread
2140 if (!fTable
.isDisposed()) {
2141 fTable
.getDisplay().asyncExec(new Runnable() {
2144 if (!fTable
.isDisposed()) {
2149 populateCompleted();
2151 synchronized (fCacheUpdateSyncObj
) {
2152 fCacheUpdateBusy
= false;
2153 if (fCacheUpdatePending
) {
2154 fCacheUpdatePending
= false;
2155 cacheUpdated(fCacheUpdateCompleted
);
2164 * Callback for when populating the table is complete.
2166 protected void populateCompleted() {
2167 // Nothing by default;
2170 // ------------------------------------------------------------------------
2171 // ISelectionProvider
2172 // ------------------------------------------------------------------------
2178 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2179 selectionChangedListeners
.add(listener
);
2186 public ISelection
getSelection() {
2187 if (fTable
== null || fTable
.isDisposed()) {
2188 return StructuredSelection
.EMPTY
;
2190 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2191 for (TableItem item
: fTable
.getSelection()) {
2192 if (item
.getData() != null) {
2193 list
.add(item
.getData());
2196 return new StructuredSelection(list
);
2203 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2204 selectionChangedListeners
.remove(listener
);
2211 public void setSelection(ISelection selection
) {
2216 * Notifies any selection changed listeners that the viewer's selection has changed.
2217 * Only listeners registered at the time this method is called are notified.
2219 * @param event a selection changed event
2221 * @see ISelectionChangedListener#selectionChanged
2224 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2225 Object
[] listeners
= selectionChangedListeners
.getListeners();
2226 for (int i
= 0; i
< listeners
.length
; ++i
) {
2227 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2228 SafeRunnable
.run(new SafeRunnable() {
2231 l
.selectionChanged(event
);
2237 // ------------------------------------------------------------------------
2238 // Bookmark handling
2239 // ------------------------------------------------------------------------
2242 * Add a bookmark to this event table.
2244 * @param bookmarksFile
2245 * The file to use for the bookmarks
2247 public void addBookmark(final IFile bookmarksFile
) {
2248 fBookmarksFile
= bookmarksFile
;
2249 final TableItem
[] selection
= fTable
.getSelection();
2250 if (selection
.length
> 0) {
2251 final TableItem tableItem
= selection
[0];
2252 if (tableItem
.getData(Key
.RANK
) != null) {
2253 final StringBuffer defaultMessage
= new StringBuffer();
2254 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2256 defaultMessage
.append(", "); //$NON-NLS-1$
2258 defaultMessage
.append(tableItem
.getText(i
));
2260 final InputDialog dialog
= new MultiLineInputDialog(
2261 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2262 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2263 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2264 defaultMessage
.toString());
2265 if (dialog
.open() == Window
.OK
) {
2266 final String message
= dialog
.getValue();
2268 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2269 if (bookmark
.exists()) {
2270 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2271 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2272 final int location
= rank
.intValue();
2273 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2274 fBookmarksMap
.put(rank
, bookmark
.getId());
2277 } catch (final CoreException e
) {
2278 displayException(e
);
2287 * Remove a bookmark from this event table.
2290 * The bookmark to remove
2292 public void removeBookmark(final IMarker bookmark
) {
2293 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2294 if (entry
.getValue().equals(bookmark
.getId())) {
2295 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2302 private void toggleBookmark(final Long rank
) {
2303 if (fBookmarksFile
== null) {
2306 if (fBookmarksMap
.containsKey(rank
)) {
2307 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2310 for (long markerId
: markerIds
) {
2311 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2312 if (bookmark
!= null) {
2316 } catch (final CoreException e
) {
2317 displayException(e
);
2320 addBookmark(fBookmarksFile
);
2325 * Refresh the bookmarks assigned to this trace, from the contents of a
2328 * @param bookmarksFile
2329 * The bookmark file to use
2331 public void refreshBookmarks(final IFile bookmarksFile
) {
2332 fBookmarksFile
= bookmarksFile
;
2333 if (bookmarksFile
== null) {
2334 fBookmarksMap
.clear();
2339 fBookmarksMap
.clear();
2340 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2341 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2342 if (location
!= -1) {
2343 final long rank
= location
;
2344 fBookmarksMap
.put(rank
, bookmark
.getId());
2348 } catch (final CoreException e
) {
2349 displayException(e
);
2354 public void gotoMarker(final IMarker marker
) {
2355 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2358 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2359 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2360 } else if (rank
>= fTable
.getItemCount()) {
2361 fPendingGotoRank
= rank
;
2363 fSelectedRank
= rank
;
2364 fTable
.setSelection(index
+ 1); // +1 for header row
2365 updateStatusLine(null);
2369 // ------------------------------------------------------------------------
2371 // ------------------------------------------------------------------------
2374 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2378 // ------------------------------------------------------------------------
2380 // ------------------------------------------------------------------------
2383 * Handler for the trace updated signal
2386 * The incoming signal
2389 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2390 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2393 // Perform the refresh on the UI thread
2394 Display
.getDefault().asyncExec(new Runnable() {
2397 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2398 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2399 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2400 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2401 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2402 fPendingGotoRank
= -1;
2403 updateStatusLine(null);
2406 startFilterThread();
2409 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2410 fRawViewer
.refreshEventCount();
2417 * Handler for the time synch signal.
2420 * The incoming signal
2423 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2424 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2426 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2427 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2428 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2429 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2430 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2432 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2435 public void handleData(final ITmfEvent event
) {
2436 super.handleData(event
);
2440 public void handleCompleted() {
2441 super.handleCompleted();
2442 if (fTrace
== null) {
2446 // Verify if the event is within the trace range and adjust if necessary
2447 ITmfTimestamp timestamp
= ts
;
2448 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2449 timestamp
= fTrace
.getStartTime();
2451 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2452 timestamp
= fTrace
.getEndTime();
2455 // Get the rank of the selected event in the table
2456 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2457 final long rank
= context
.getRank();
2459 fSelectedRank
= rank
;
2461 fTable
.getDisplay().asyncExec(new Runnable() {
2464 // Return if table is disposed
2465 if (fTable
.isDisposed()) {
2469 int index
= (int) rank
;
2470 if (fTable
.isDisposed()) {
2473 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2474 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2476 fTable
.setSelection(index
+ 1); // +1 for header row
2477 fRawViewer
.selectAndReveal(rank
);
2478 updateStatusLine(null);
2484 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2488 // ------------------------------------------------------------------------
2490 // ------------------------------------------------------------------------
2493 * Display an exception in a message box
2495 * @param e the exception
2497 private static void displayException(final Exception e
) {
2498 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2499 mb
.setText(e
.getClass().getSimpleName());
2500 mb
.setMessage(e
.getMessage());
2507 public void refresh() {
2514 * Margin column for images and special text (e.g. collapse count)
2516 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2518 private static final @NonNull String HEADER
= EMPTY_STRING
;
2523 public TmfMarginColumn() {
2528 public String
getItemString(ITmfEvent event
) {
2529 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2530 return EMPTY_STRING
;
2532 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2536 public String
getFilterFieldId() {