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 IHandlerService handlerService
= (IHandlerService
) activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
835 ICommandService cmdService
= (ICommandService
) activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
837 HashMap
<String
, Object
> parameters
= new HashMap
<>();
838 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
839 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
841 IEvaluationContext context
= handlerService
.getCurrentState();
842 // Omit the margin column
843 List
<TmfEventTableColumn
> exportColumns
= fColumns
.subList(EVENT_COLUMNS_START_INDEX
, fColumns
.size());
844 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
846 handlerService
.executeCommandInContext(cmd
, null, context
);
847 } catch (ExecutionException e
) {
849 } catch (NotDefinedException e
) {
851 } catch (NotEnabledException e
) {
853 } catch (NotHandledException e
) {
859 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
862 fHeaderState
= HeaderState
.SEARCH
;
867 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
870 fHeaderState
= HeaderState
.FILTER
;
875 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
882 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
885 applyFilter(new TmfCollapseFilter());
889 class ToggleBookmarkAction
extends Action
{
892 public ToggleBookmarkAction(final String text
, final Long rank
) {
899 toggleBookmark(fRank
);
903 final MenuManager tablePopupMenu
= new MenuManager();
904 tablePopupMenu
.setRemoveAllWhenShown(true);
905 tablePopupMenu
.addMenuListener(new IMenuListener() {
907 public void menuAboutToShow(final IMenuManager manager
) {
908 if (fTable
.getSelectionIndex() == 0) {
909 // Right-click on header row
910 if (fHeaderState
== HeaderState
.FILTER
) {
911 tablePopupMenu
.add(showSearchBarAction
);
913 tablePopupMenu
.add(showFilterBarAction
);
917 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
918 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
920 final Rectangle imageBounds
= item
.getImageBounds(0);
921 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
922 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
923 // Right-click on left margin
924 final Long rank
= (Long
) item
.getData(Key
.RANK
);
925 if ((rank
!= null) && (fBookmarksFile
!= null)) {
926 if (fBookmarksMap
.containsKey(rank
)) {
927 tablePopupMenu
.add(new ToggleBookmarkAction(
928 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
930 tablePopupMenu
.add(new ToggleBookmarkAction(
931 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
938 // Right-click on table
939 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
940 tablePopupMenu
.add(hideTableAction
);
941 tablePopupMenu
.add(hideRawAction
);
942 } else if (!fTable
.isVisible()) {
943 tablePopupMenu
.add(showTableAction
);
944 } else if (!fRawViewer
.isVisible()) {
945 tablePopupMenu
.add(showRawAction
);
947 tablePopupMenu
.add(exportToTextAction
);
948 tablePopupMenu
.add(new Separator());
951 final Object data
= item
.getData();
952 Separator separator
= null;
953 if (data
instanceof ITmfSourceLookup
) {
954 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
955 if (event
.getCallsite() != null) {
956 tablePopupMenu
.add(openCallsiteAction
);
957 separator
= new Separator();
961 if (data
instanceof ITmfModelLookup
) {
962 ITmfModelLookup event
= (ITmfModelLookup
) data
;
963 if (event
.getModelUri() != null) {
964 tablePopupMenu
.add(openModelAction
);
965 separator
= new Separator();
968 if (separator
!= null) {
969 tablePopupMenu
.add(separator
);
974 // only show collapse filter if at least one trace can be collapsed
975 boolean isCollapsible
= false;
976 if (fTrace
!= null) {
977 ITmfTrace traces
[] = TmfTraceManager
.getTraceSet(fTrace
);
978 for (ITmfTrace trace
: traces
) {
979 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
980 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
987 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
988 tablePopupMenu
.add(collapseAction
);
989 tablePopupMenu
.add(new Separator());
992 tablePopupMenu
.add(clearFiltersAction
);
993 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
994 if (savedFilters
.length
> 0) {
995 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
996 for (final ITmfFilterTreeNode node
: savedFilters
) {
997 if (node
instanceof TmfFilterNode
) {
998 final TmfFilterNode filter
= (TmfFilterNode
) node
;
999 subMenu
.add(new Action(filter
.getFilterName()) {
1002 applyFilter(filter
);
1007 tablePopupMenu
.add(subMenu
);
1009 appendToTablePopupMenu(tablePopupMenu
, item
);
1013 final MenuManager rawViewerPopupMenu
= new MenuManager();
1014 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
1015 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
1017 public void menuAboutToShow(final IMenuManager manager
) {
1018 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1019 rawViewerPopupMenu
.add(hideTableAction
);
1020 rawViewerPopupMenu
.add(hideRawAction
);
1021 } else if (!fTable
.isVisible()) {
1022 rawViewerPopupMenu
.add(showTableAction
);
1023 } else if (!fRawViewer
.isVisible()) {
1024 rawViewerPopupMenu
.add(showRawAction
);
1026 appendToRawPopupMenu(tablePopupMenu
);
1030 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
1031 fTable
.setMenu(menu
);
1033 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
1034 fRawViewer
.setMenu(menu
);
1039 * Append an item to the event table's pop-up menu.
1041 * @param tablePopupMenu
1043 * @param selectedItem
1044 * The item to append
1046 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1047 // override to append more actions
1051 * Append an item to the raw viewer's pop-up menu.
1053 * @param rawViewerPopupMenu
1056 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1057 // override to append more actions
1061 public void dispose() {
1064 ColorSettingsManager
.removeColorSettingsListener(this);
1065 fComposite
.dispose();
1066 if ((fTrace
!= null) && fDisposeOnClose
) {
1069 fResourceManager
.dispose();
1070 fRawViewer
.dispose();
1075 * Assign a layout data object to this view.
1078 * The layout data to assign
1080 public void setLayoutData(final Object layoutData
) {
1081 fComposite
.setLayoutData(layoutData
);
1085 * Get the virtual table contained in this event table.
1087 * @return The TMF virtual table
1089 public TmfVirtualTable
getTable() {
1096 * @deprecated The column headers are now set at the constructor, this
1097 * shouldn't be called anymore.
1100 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1105 * Set a table item's data.
1110 * Which trace event to link with this entry
1112 * Which rank this event has in the trace/experiment
1114 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1115 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1116 item
.setText(itemStrings
);
1117 item
.setData(event
);
1118 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1119 item
.setData(Key
.RANK
, rank
);
1121 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1122 if (!markerIds
.isEmpty()) {
1123 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1124 List
<Object
> parts
= new ArrayList
<>();
1125 if (markerIds
.size() > 1) {
1126 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1129 for (long markerId
: markerIds
) {
1130 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1131 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1133 } catch (CoreException e
) {
1134 displayException(e
);
1136 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1138 item
.setData(Key
.BOOKMARK
, null);
1141 boolean searchMatch
= false;
1142 boolean searchNoMatch
= false;
1143 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1144 if (searchFilter
!= null) {
1145 if (searchFilter
.matches(event
)) {
1148 searchNoMatch
= true;
1152 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1153 if (searchNoMatch
) {
1154 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1155 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1157 item
.setForeground(colorSetting
.getForegroundColor());
1158 item
.setBackground(colorSetting
.getBackgroundColor());
1162 if (!markerIds
.isEmpty()) {
1163 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1165 item
.setImage(SEARCH_MATCH_IMAGE
);
1167 } else if (!markerIds
.isEmpty()) {
1168 item
.setImage(BOOKMARK_IMAGE
);
1170 item
.setImage((Image
) null);
1173 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1179 * Set the item data of the header row.
1182 * The item to use as table header
1184 protected void setHeaderRowItemData(final TableItem item
) {
1185 String txtKey
= null;
1186 if (fHeaderState
== HeaderState
.SEARCH
) {
1187 item
.setImage(SEARCH_IMAGE
);
1188 txtKey
= Key
.SEARCH_TXT
;
1189 } else if (fHeaderState
== HeaderState
.FILTER
) {
1190 item
.setImage(FILTER_IMAGE
);
1191 txtKey
= Key
.FILTER_TXT
;
1193 item
.setForeground(fGrayColor
);
1194 // Ignore collapse and image column
1195 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1196 final TableColumn column
= fTable
.getColumns()[i
];
1197 final String filter
= (String
) column
.getData(txtKey
);
1198 if (filter
== null) {
1199 if (fHeaderState
== HeaderState
.SEARCH
) {
1200 item
.setText(i
, SEARCH_HINT
);
1201 } else if (fHeaderState
== HeaderState
.FILTER
) {
1202 item
.setText(i
, FILTER_HINT
);
1204 item
.setForeground(i
, fGrayColor
);
1205 item
.setFont(i
, fTable
.getFont());
1207 item
.setText(i
, filter
);
1208 item
.setForeground(i
, fGreenColor
);
1209 item
.setFont(i
, fBoldFont
);
1215 * Set the item data of the "filter status" row.
1218 * The item to use as filter status row
1220 protected void setFilterStatusRowItemData(final TableItem item
) {
1221 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1222 if (i
== MARGIN_COLUMN_INDEX
) {
1223 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1224 item
.setImage(FILTER_IMAGE
);
1226 item
.setImage(STOP_IMAGE
);
1230 if (i
== FILTER_SUMMARY_INDEX
) {
1231 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1233 item
.setText(i
, EMPTY_STRING
);
1237 item
.setData(Key
.TIMESTAMP
, null);
1238 item
.setData(Key
.RANK
, null);
1239 item
.setForeground(null);
1240 item
.setBackground(null);
1244 * Create an editor for the header.
1246 protected void createHeaderEditor() {
1247 final TableEditor tableEditor
= fTable
.createTableEditor();
1248 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1249 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1250 tableEditor
.grabHorizontal
= true;
1251 tableEditor
.minimumWidth
= 50;
1253 // Handle the header row selection
1254 fTable
.addMouseListener(new MouseAdapter() {
1260 public void mouseDown(final MouseEvent event
) {
1261 if (event
.button
!= 1) {
1264 // Identify the selected row
1265 final Point point
= new Point(event
.x
, event
.y
);
1266 item
= fTable
.getItem(point
);
1268 // Header row selected
1269 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1272 if (item
.getImageBounds(0).contains(point
)) {
1273 if (fHeaderState
== HeaderState
.SEARCH
) {
1274 fHeaderState
= HeaderState
.FILTER
;
1275 } else if (fHeaderState
== HeaderState
.FILTER
) {
1276 fHeaderState
= HeaderState
.SEARCH
;
1278 fTable
.setSelection(0);
1283 // Identify the selected column
1285 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1286 final Rectangle rect
= item
.getBounds(i
);
1287 if (rect
.contains(point
)) {
1293 if (columnIndex
== -1) {
1297 column
= fTable
.getColumns()[columnIndex
];
1299 String txtKey
= null;
1300 if (fHeaderState
== HeaderState
.SEARCH
) {
1301 txtKey
= Key
.SEARCH_TXT
;
1302 } else if (fHeaderState
== HeaderState
.FILTER
) {
1303 txtKey
= Key
.FILTER_TXT
;
1306 // The control that will be the editor must be a child of the Table
1307 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1308 final String headerString
= (String
) column
.getData(txtKey
);
1309 if (headerString
!= null) {
1310 newEditor
.setText(headerString
);
1312 newEditor
.addFocusListener(new FocusAdapter() {
1314 public void focusLost(final FocusEvent e
) {
1315 final boolean changed
= updateHeader(newEditor
.getText());
1321 newEditor
.addKeyListener(new KeyAdapter() {
1323 public void keyPressed(final KeyEvent e
) {
1324 if (e
.character
== SWT
.CR
) {
1325 updateHeader(newEditor
.getText());
1328 // Set focus on the table so that the next carriage return goes to the next result
1329 TmfEventsTable
.this.getTable().setFocus();
1330 } else if (e
.character
== SWT
.ESC
) {
1331 tableEditor
.getEditor().dispose();
1335 newEditor
.selectAll();
1336 newEditor
.setFocus();
1337 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1342 * returns true is value was changed
1344 private boolean updateHeader(final String text
) {
1345 String objKey
= null;
1346 String txtKey
= null;
1347 if (fHeaderState
== HeaderState
.SEARCH
) {
1348 objKey
= Key
.SEARCH_OBJ
;
1349 txtKey
= Key
.SEARCH_TXT
;
1350 } else if (fHeaderState
== HeaderState
.FILTER
) {
1351 objKey
= Key
.FILTER_OBJ
;
1352 txtKey
= Key
.FILTER_TXT
;
1354 if (text
.trim().length() > 0) {
1356 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1357 Pattern
.compile(regex
);
1358 if (regex
.equals(column
.getData(txtKey
))) {
1359 tableEditor
.getEditor().dispose();
1362 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1363 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1364 if (fieldId
== null) {
1365 fieldId
= column
.getText();
1367 filter
.setField(fieldId
);
1368 filter
.setRegex(regex
);
1369 column
.setData(objKey
, filter
);
1370 column
.setData(txtKey
, regex
);
1371 } catch (final PatternSyntaxException ex
) {
1372 tableEditor
.getEditor().dispose();
1373 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1374 ex
.getDescription(), ex
.getMessage());
1378 if (column
.getData(txtKey
) == null) {
1379 tableEditor
.getEditor().dispose();
1382 column
.setData(objKey
, null);
1383 column
.setData(txtKey
, null);
1388 private void applyHeader() {
1389 if (fHeaderState
== HeaderState
.SEARCH
) {
1391 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1392 for (final TableColumn col
: fTable
.getColumns()) {
1393 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1394 if (filterObj
instanceof ITmfFilterTreeNode
) {
1395 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1398 if (filter
.getChildrenCount() > 0) {
1399 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1402 fireSearchApplied(filter
);
1404 fTable
.setData(Key
.SEARCH_OBJ
, null);
1406 fireSearchApplied(null);
1408 } else if (fHeaderState
== HeaderState
.FILTER
) {
1409 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1410 for (final TableColumn col
: fTable
.getColumns()) {
1411 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1412 if (filterObj
instanceof ITmfFilterTreeNode
) {
1413 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1416 if (filter
.getChildrenCount() > 0) {
1417 applyFilter(filter
);
1423 tableEditor
.getEditor().dispose();
1427 fTable
.addKeyListener(new KeyAdapter() {
1429 public void keyPressed(final KeyEvent e
) {
1431 if (e
.character
== SWT
.ESC
) {
1435 } else if (e
.character
== SWT
.DEL
) {
1436 if (fHeaderState
== HeaderState
.SEARCH
) {
1438 for (final TableColumn column
: fTable
.getColumns()) {
1439 column
.setData(Key
.SEARCH_OBJ
, null);
1440 column
.setData(Key
.SEARCH_TXT
, null);
1442 fTable
.setData(Key
.SEARCH_OBJ
, null);
1444 fireSearchApplied(null);
1445 } else if (fHeaderState
== HeaderState
.FILTER
) {
1448 } else if (e
.character
== SWT
.CR
) {
1449 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1460 * Send an event indicating a filter has been applied.
1463 * The filter that was just applied
1465 protected void fireFilterApplied(final ITmfFilter filter
) {
1466 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1470 * Send an event indicating that a search has been applied.
1473 * The search filter that was just applied
1475 protected void fireSearchApplied(final ITmfFilter filter
) {
1476 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1480 * Start the filtering thread.
1482 protected void startFilterThread() {
1483 synchronized (fFilterSyncObj
) {
1484 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1485 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1486 if (fFilterThread
!= null) {
1487 fFilterThread
.cancel();
1488 fFilterThreadResume
= false;
1490 fFilterThread
= new FilterThread(filter
);
1491 fFilterThread
.start();
1493 fFilterThreadResume
= true;
1499 * Stop the filtering thread.
1501 protected void stopFilterThread() {
1502 synchronized (fFilterSyncObj
) {
1503 if (fFilterThread
!= null) {
1504 fFilterThread
.cancel();
1505 fFilterThread
= null;
1506 fFilterThreadResume
= false;
1515 * The filter to apply
1518 protected void applyFilter(ITmfFilter filter
) {
1521 fFilterMatchCount
= 0;
1522 fFilterCheckCount
= 0;
1523 fCache
.applyFilter(filter
);
1525 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1526 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1527 startFilterThread();
1528 fireFilterApplied(filter
);
1532 * Clear all currently active filters.
1534 protected void clearFilters() {
1535 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1540 fCache
.clearFilter();
1542 for (final TableColumn column
: fTable
.getColumns()) {
1543 column
.setData(Key
.FILTER_OBJ
, null);
1544 column
.setData(Key
.FILTER_TXT
, null);
1546 fTable
.setData(Key
.FILTER_OBJ
, null);
1547 if (fTrace
!= null) {
1548 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1550 fTable
.setItemCount(1); // +1 for header row
1552 fFilterMatchCount
= 0;
1553 fFilterCheckCount
= 0;
1554 if (fSelectedRank
>= 0) {
1555 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1557 fTable
.setSelection(0);
1559 fireFilterApplied(null);
1560 updateStatusLine(null);
1562 // Set original width
1563 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1568 * Wrapper Thread object for the filtering thread.
1570 protected class FilterThread
extends Thread
{
1571 private final ITmfFilterTreeNode filter
;
1572 private TmfEventRequest request
;
1573 private boolean refreshBusy
= false;
1574 private boolean refreshPending
= false;
1575 private final Object syncObj
= new Object();
1581 * The filter this thread will be processing
1583 public FilterThread(final ITmfFilterTreeNode filter
) {
1584 super("Filter Thread"); //$NON-NLS-1$
1585 this.filter
= filter
;
1590 if (fTrace
== null) {
1593 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1594 if (nbRequested
<= 0) {
1597 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1598 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1600 public void handleData(final ITmfEvent event
) {
1601 super.handleData(event
);
1602 if (request
.isCancelled()) {
1605 boolean refresh
= false;
1606 if (filter
.matches(event
)) {
1607 final long rank
= fFilterCheckCount
;
1608 final int index
= (int) fFilterMatchCount
;
1609 fFilterMatchCount
++;
1610 fCache
.storeEvent(event
, rank
, index
);
1613 if (filter
instanceof TmfCollapseFilter
) {
1614 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
1618 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
1621 fFilterCheckCount
++;
1624 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1626 request
.waitForCompletion();
1627 } catch (final InterruptedException e
) {
1630 synchronized (fFilterSyncObj
) {
1631 fFilterThread
= null;
1632 if (fFilterThreadResume
) {
1633 fFilterThreadResume
= false;
1634 fFilterThread
= new FilterThread(filter
);
1635 fFilterThread
.start();
1641 * Refresh the filter.
1643 public void refreshTable() {
1644 synchronized (syncObj
) {
1646 refreshPending
= true;
1651 Display
.getDefault().asyncExec(new Runnable() {
1654 if (request
.isCancelled()) {
1657 if (fTable
.isDisposed()) {
1660 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1662 synchronized (syncObj
) {
1663 refreshBusy
= false;
1664 if (refreshPending
) {
1665 refreshPending
= false;
1674 * Cancel this filtering thread.
1676 public void cancel() {
1677 if (request
!= null) {
1684 * Go to the next item of a search.
1686 protected void searchNext() {
1687 synchronized (fSearchSyncObj
) {
1688 if (fSearchThread
!= null) {
1691 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1692 if (searchFilter
== null) {
1695 final int selectionIndex
= fTable
.getSelectionIndex();
1697 if (selectionIndex
> 0) {
1698 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1700 // header row is selected, start at top event
1701 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1703 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1704 if (eventFilter
!= null) {
1705 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1707 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1708 fSearchThread
.schedule();
1713 * Go to the previous item of a search.
1715 protected void searchPrevious() {
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
- 2; // -1 for header row, -1 for previous event
1729 // header row is selected, start at precedent of top event
1730 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1732 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1733 if (eventFilter
!= null) {
1734 startIndex
= startIndex
- 1; // -1 for top filter status row
1736 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1737 fSearchThread
.schedule();
1742 * Stop the search thread.
1744 protected void stopSearchThread() {
1745 fPendingGotoRank
= -1;
1746 synchronized (fSearchSyncObj
) {
1747 if (fSearchThread
!= null) {
1748 fSearchThread
.cancel();
1749 fSearchThread
= null;
1755 * Wrapper for the search thread.
1757 protected class SearchThread
extends Job
{
1759 private ITmfFilterTreeNode searchFilter
;
1760 private ITmfFilterTreeNode eventFilter
;
1761 private int startIndex
;
1762 private int direction
;
1764 private long foundRank
= -1;
1765 private TmfEventRequest request
;
1766 private ITmfTimestamp foundTimestamp
= null;
1771 * @param searchFilter
1773 * @param eventFilter
1776 * The index at which we should start searching
1777 * @param currentRank
1780 * In which direction should we search, forward or backwards
1782 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1783 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1784 final long currentRank
, final int direction
) {
1785 super(Messages
.TmfEventsTable_SearchingJobName
);
1786 this.searchFilter
= searchFilter
;
1787 this.eventFilter
= eventFilter
;
1788 this.startIndex
= startIndex
;
1789 this.rank
= currentRank
;
1790 this.direction
= direction
;
1794 protected IStatus
run(final IProgressMonitor monitor
) {
1795 if (fTrace
== null) {
1796 return Status
.OK_STATUS
;
1798 final Display display
= Display
.getDefault();
1799 if (startIndex
< 0) {
1800 rank
= (int) fTrace
.getNbEvents() - 1;
1801 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1804 int idx
= startIndex
;
1805 while (foundRank
== -1) {
1806 final CachedEvent event
= fCache
.peekEvent(idx
);
1807 if (event
== null) {
1811 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1812 foundRank
= event
.rank
;
1813 foundTimestamp
= event
.event
.getTimestamp();
1816 if (direction
== Direction
.FORWARD
) {
1822 if (foundRank
== -1) {
1823 if (direction
== Direction
.FORWARD
) {
1825 if (rank
> (fTrace
.getNbEvents() - 1)) {
1831 rank
= (int) fTrace
.getNbEvents() - 1;
1836 final int startRank
= (int) rank
;
1837 boolean wrapped
= false;
1838 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1839 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1840 if (direction
== Direction
.BACKWARD
) {
1841 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1843 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1844 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1845 long currentRank
= rank
;
1848 public void handleData(final ITmfEvent event
) {
1849 super.handleData(event
);
1850 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1851 foundRank
= currentRank
;
1852 foundTimestamp
= event
.getTimestamp();
1853 if (direction
== Direction
.FORWARD
) {
1861 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1863 request
.waitForCompletion();
1864 if (request
.isCancelled()) {
1865 return Status
.OK_STATUS
;
1867 } catch (final InterruptedException e
) {
1868 synchronized (fSearchSyncObj
) {
1869 fSearchThread
= null;
1871 return Status
.OK_STATUS
;
1873 if (foundRank
== -1) {
1874 if (direction
== Direction
.FORWARD
) {
1876 synchronized (fSearchSyncObj
) {
1877 fSearchThread
= null;
1879 return Status
.OK_STATUS
;
1881 nbRequested
= (int) rank
;
1887 rank
= (int) fTrace
.getNbEvents() - 1;
1890 if ((rank
<= startRank
) && wrapped
) {
1891 synchronized (fSearchSyncObj
) {
1892 fSearchThread
= null;
1894 return Status
.OK_STATUS
;
1899 int index
= (int) foundRank
;
1900 if (eventFilter
!= null) {
1901 index
= fCache
.getFilteredEventIndex(foundRank
);
1903 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1905 display
.asyncExec(new Runnable() {
1908 if (monitor
.isCanceled()) {
1911 if (fTable
.isDisposed()) {
1914 fTable
.setSelection(selection
);
1915 fSelectedRank
= foundRank
;
1916 fRawViewer
.selectAndReveal(fSelectedRank
);
1917 if (foundTimestamp
!= null) {
1918 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1920 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1921 synchronized (fSearchSyncObj
) {
1922 fSearchThread
= null;
1924 updateStatusLine(null);
1927 return Status
.OK_STATUS
;
1931 protected void canceling() {
1933 synchronized (fSearchSyncObj
) {
1934 fSearchThread
= null;
1940 * Create the resources.
1942 protected void createResources() {
1943 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1944 .getForeground().getRGB()));
1945 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1946 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1952 protected void packColumns() {
1956 fTable
.setRedraw(false);
1958 TableColumn tableColumns
[] = fTable
.getColumns();
1959 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1960 final TableColumn column
= tableColumns
[i
];
1961 packSingleColumn(i
, column
);
1964 // Make sure that redraw is always enabled.
1965 fTable
.setRedraw(true);
1971 private void packMarginColumn() {
1972 TableColumn
[] columns
= fTable
.getColumns();
1973 if (columns
.length
> 0) {
1974 packSingleColumn(0, columns
[0]);
1978 private void packSingleColumn(int i
, final TableColumn column
) {
1979 final int headerWidth
= column
.getWidth();
1981 // Workaround for Linux which doesn't consider the image width of
1982 // search/filter row in TableColumn.pack() after having executed
1983 // TableItem.setImage((Image)null) for other rows than search/filter row.
1984 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
1985 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
1986 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1989 if (column
.getWidth() < headerWidth
) {
1990 column
.setWidth(headerWidth
);
1995 * Get the array of item strings (e.g., what to display in each cell of the
1996 * table row) corresponding to the columns and trace event passed in
1997 * parameter. The order of the Strings in the returned array will correspond
1998 * to the iteration order of 'columns'.
2001 * To ensure consistent results, make sure only call this within a scope
2002 * synchronized on 'columns'! If the order of 'columns' changes right after
2003 * this method is called, the returned value won't be ordered correctly
2006 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2007 if (event
== null) {
2008 return EMPTY_STRING_ARRAY
;
2010 synchronized (columns
) {
2011 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2012 for (TmfEventTableColumn column
: columns
) {
2013 ITmfEvent passedEvent
= event
;
2014 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2015 // Make sure that the event object from the trace is passed
2016 // to all columns but the TmfMarginColumn
2017 passedEvent
= ((CachedEvent
) event
).event
;
2019 if (passedEvent
== null) {
2020 itemStrings
.add(EMPTY_STRING
);
2022 itemStrings
.add(column
.getItemString(passedEvent
));
2026 return itemStrings
.toArray(new String
[0]);
2031 * Get the contents of the row in the events table corresponding to an
2032 * event. The order of the elements corresponds to the current order of the
2036 * The event printed in this row
2037 * @return The event row entries
2040 public String
[] getItemStrings(ITmfEvent event
) {
2041 return getItemStrings(fColumns
, event
);
2045 * Notify this table that is got the UI focus.
2047 public void setFocus() {
2052 * Assign a new trace to this event table.
2055 * The trace to assign to this event table
2056 * @param disposeOnClose
2057 * true if the trace should be disposed when the table is
2060 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2061 if ((fTrace
!= null) && fDisposeOnClose
) {
2067 fDisposeOnClose
= disposeOnClose
;
2069 // Perform the updates on the UI thread
2070 fTable
.getDisplay().syncExec(new Runnable() {
2074 fCache
.setTrace(fTrace
); // Clear the cache
2075 if (fTrace
!= null) {
2076 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2077 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2078 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2081 fFilterMatchCount
= 0;
2082 fFilterCheckCount
= 0;
2083 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2084 startFilterThread();
2088 fRawViewer
.setTrace(fTrace
);
2094 * Assign the status line manager
2096 * @param statusLineManager
2097 * The status line manager, or null to disable status line messages
2100 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2101 if (fStatusLineManager
!= null && statusLineManager
== null) {
2102 fStatusLineManager
.setMessage(EMPTY_STRING
);
2104 fStatusLineManager
= statusLineManager
;
2107 private void updateStatusLine(ITmfTimestamp delta
) {
2108 if (fStatusLineManager
!= null) {
2109 if (delta
!= null) {
2110 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2112 fStatusLineManager
.setMessage(null);
2117 // ------------------------------------------------------------------------
2119 // ------------------------------------------------------------------------
2122 * Notify that the event cache has been updated
2125 * Also notify if the populating of the cache is complete, or
2128 public void cacheUpdated(final boolean completed
) {
2129 synchronized (fCacheUpdateSyncObj
) {
2130 if (fCacheUpdateBusy
) {
2131 fCacheUpdatePending
= true;
2132 fCacheUpdateCompleted
= completed
;
2135 fCacheUpdateBusy
= true;
2137 // Event cache is now updated. Perform update on the UI thread
2138 if (!fTable
.isDisposed()) {
2139 fTable
.getDisplay().asyncExec(new Runnable() {
2142 if (!fTable
.isDisposed()) {
2147 populateCompleted();
2149 synchronized (fCacheUpdateSyncObj
) {
2150 fCacheUpdateBusy
= false;
2151 if (fCacheUpdatePending
) {
2152 fCacheUpdatePending
= false;
2153 cacheUpdated(fCacheUpdateCompleted
);
2162 * Callback for when populating the table is complete.
2164 protected void populateCompleted() {
2165 // Nothing by default;
2168 // ------------------------------------------------------------------------
2169 // ISelectionProvider
2170 // ------------------------------------------------------------------------
2176 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2177 selectionChangedListeners
.add(listener
);
2184 public ISelection
getSelection() {
2185 if (fTable
== null || fTable
.isDisposed()) {
2186 return StructuredSelection
.EMPTY
;
2188 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2189 for (TableItem item
: fTable
.getSelection()) {
2190 if (item
.getData() != null) {
2191 list
.add(item
.getData());
2194 return new StructuredSelection(list
);
2201 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2202 selectionChangedListeners
.remove(listener
);
2209 public void setSelection(ISelection selection
) {
2214 * Notifies any selection changed listeners that the viewer's selection has changed.
2215 * Only listeners registered at the time this method is called are notified.
2217 * @param event a selection changed event
2219 * @see ISelectionChangedListener#selectionChanged
2222 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2223 Object
[] listeners
= selectionChangedListeners
.getListeners();
2224 for (int i
= 0; i
< listeners
.length
; ++i
) {
2225 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2226 SafeRunnable
.run(new SafeRunnable() {
2229 l
.selectionChanged(event
);
2235 // ------------------------------------------------------------------------
2236 // Bookmark handling
2237 // ------------------------------------------------------------------------
2240 * Add a bookmark to this event table.
2242 * @param bookmarksFile
2243 * The file to use for the bookmarks
2245 public void addBookmark(final IFile bookmarksFile
) {
2246 fBookmarksFile
= bookmarksFile
;
2247 final TableItem
[] selection
= fTable
.getSelection();
2248 if (selection
.length
> 0) {
2249 final TableItem tableItem
= selection
[0];
2250 if (tableItem
.getData(Key
.RANK
) != null) {
2251 final StringBuffer defaultMessage
= new StringBuffer();
2252 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2254 defaultMessage
.append(", "); //$NON-NLS-1$
2256 defaultMessage
.append(tableItem
.getText(i
));
2258 final InputDialog dialog
= new MultiLineInputDialog(
2259 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2260 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2261 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2262 defaultMessage
.toString());
2263 if (dialog
.open() == Window
.OK
) {
2264 final String message
= dialog
.getValue();
2266 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2267 if (bookmark
.exists()) {
2268 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2269 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2270 final int location
= rank
.intValue();
2271 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2272 fBookmarksMap
.put(rank
, bookmark
.getId());
2275 } catch (final CoreException e
) {
2276 displayException(e
);
2285 * Remove a bookmark from this event table.
2288 * The bookmark to remove
2290 public void removeBookmark(final IMarker bookmark
) {
2291 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2292 if (entry
.getValue().equals(bookmark
.getId())) {
2293 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2300 private void toggleBookmark(final Long rank
) {
2301 if (fBookmarksFile
== null) {
2304 if (fBookmarksMap
.containsKey(rank
)) {
2305 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2308 for (long markerId
: markerIds
) {
2309 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2310 if (bookmark
!= null) {
2314 } catch (final CoreException e
) {
2315 displayException(e
);
2318 addBookmark(fBookmarksFile
);
2323 * Refresh the bookmarks assigned to this trace, from the contents of a
2326 * @param bookmarksFile
2327 * The bookmark file to use
2329 public void refreshBookmarks(final IFile bookmarksFile
) {
2330 fBookmarksFile
= bookmarksFile
;
2331 if (bookmarksFile
== null) {
2332 fBookmarksMap
.clear();
2337 fBookmarksMap
.clear();
2338 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2339 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2340 if (location
!= -1) {
2341 final long rank
= location
;
2342 fBookmarksMap
.put(rank
, bookmark
.getId());
2346 } catch (final CoreException e
) {
2347 displayException(e
);
2352 public void gotoMarker(final IMarker marker
) {
2353 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2356 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2357 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2358 } else if (rank
>= fTable
.getItemCount()) {
2359 fPendingGotoRank
= rank
;
2361 fSelectedRank
= rank
;
2362 fTable
.setSelection(index
+ 1); // +1 for header row
2363 updateStatusLine(null);
2367 // ------------------------------------------------------------------------
2369 // ------------------------------------------------------------------------
2372 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2376 // ------------------------------------------------------------------------
2378 // ------------------------------------------------------------------------
2381 * Handler for the trace updated signal
2384 * The incoming signal
2387 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2388 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2391 // Perform the refresh on the UI thread
2392 Display
.getDefault().asyncExec(new Runnable() {
2395 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2396 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2397 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2398 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2399 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2400 fPendingGotoRank
= -1;
2401 updateStatusLine(null);
2404 startFilterThread();
2407 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2408 fRawViewer
.refreshEventCount();
2415 * Handler for the time synch signal.
2418 * The incoming signal
2421 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2422 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2424 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2425 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2426 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2427 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2428 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2430 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2433 public void handleData(final ITmfEvent event
) {
2434 super.handleData(event
);
2438 public void handleCompleted() {
2439 super.handleCompleted();
2440 if (fTrace
== null) {
2444 // Verify if the event is within the trace range and adjust if necessary
2445 ITmfTimestamp timestamp
= ts
;
2446 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2447 timestamp
= fTrace
.getStartTime();
2449 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2450 timestamp
= fTrace
.getEndTime();
2453 // Get the rank of the selected event in the table
2454 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2455 final long rank
= context
.getRank();
2457 fSelectedRank
= rank
;
2459 fTable
.getDisplay().asyncExec(new Runnable() {
2462 // Return if table is disposed
2463 if (fTable
.isDisposed()) {
2467 int index
= (int) rank
;
2468 if (fTable
.isDisposed()) {
2471 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2472 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2474 fTable
.setSelection(index
+ 1); // +1 for header row
2475 fRawViewer
.selectAndReveal(rank
);
2476 updateStatusLine(null);
2482 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2486 // ------------------------------------------------------------------------
2488 // ------------------------------------------------------------------------
2491 * Display an exception in a message box
2493 * @param e the exception
2495 private static void displayException(final Exception e
) {
2496 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2497 mb
.setText(e
.getClass().getSimpleName());
2498 mb
.setMessage(e
.getMessage());
2505 public void refresh() {
2512 * Margin column for images and special text (e.g. collapse count)
2514 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
2516 private static final @NonNull String HEADER
= EMPTY_STRING
;
2521 public TmfMarginColumn() {
2526 public String
getItemString(ITmfEvent event
) {
2527 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
2528 return EMPTY_STRING
;
2530 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
2534 public String
getFilterFieldId() {