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
.linuxtools
.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
.linuxtools
.internal
.tmf
.ui
.Activator
;
76 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
77 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
78 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
79 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfEventProvider
;
80 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
81 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
82 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfCallsite
;
83 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
84 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
85 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
86 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
87 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
88 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
89 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
90 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
91 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
92 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
93 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
94 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
95 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
96 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
97 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
98 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
99 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
100 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
101 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
102 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
103 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
104 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
105 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableFieldColumn
;
106 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSetting
;
107 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
108 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
109 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
110 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
111 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
112 import org
.eclipse
.swt
.SWT
;
113 import org
.eclipse
.swt
.custom
.SashForm
;
114 import org
.eclipse
.swt
.custom
.TableEditor
;
115 import org
.eclipse
.swt
.events
.FocusAdapter
;
116 import org
.eclipse
.swt
.events
.FocusEvent
;
117 import org
.eclipse
.swt
.events
.KeyAdapter
;
118 import org
.eclipse
.swt
.events
.KeyEvent
;
119 import org
.eclipse
.swt
.events
.MouseAdapter
;
120 import org
.eclipse
.swt
.events
.MouseEvent
;
121 import org
.eclipse
.swt
.events
.SelectionAdapter
;
122 import org
.eclipse
.swt
.events
.SelectionEvent
;
123 import org
.eclipse
.swt
.graphics
.Color
;
124 import org
.eclipse
.swt
.graphics
.Font
;
125 import org
.eclipse
.swt
.graphics
.Image
;
126 import org
.eclipse
.swt
.graphics
.Point
;
127 import org
.eclipse
.swt
.graphics
.Rectangle
;
128 import org
.eclipse
.swt
.layout
.FillLayout
;
129 import org
.eclipse
.swt
.layout
.GridData
;
130 import org
.eclipse
.swt
.layout
.GridLayout
;
131 import org
.eclipse
.swt
.widgets
.Composite
;
132 import org
.eclipse
.swt
.widgets
.Display
;
133 import org
.eclipse
.swt
.widgets
.Event
;
134 import org
.eclipse
.swt
.widgets
.Label
;
135 import org
.eclipse
.swt
.widgets
.Listener
;
136 import org
.eclipse
.swt
.widgets
.Menu
;
137 import org
.eclipse
.swt
.widgets
.MessageBox
;
138 import org
.eclipse
.swt
.widgets
.Shell
;
139 import org
.eclipse
.swt
.widgets
.TableColumn
;
140 import org
.eclipse
.swt
.widgets
.TableItem
;
141 import org
.eclipse
.swt
.widgets
.Text
;
142 import org
.eclipse
.ui
.IWorkbenchPage
;
143 import org
.eclipse
.ui
.PlatformUI
;
144 import org
.eclipse
.ui
.commands
.ICommandService
;
145 import org
.eclipse
.ui
.dialogs
.ListDialog
;
146 import org
.eclipse
.ui
.handlers
.IHandlerService
;
147 import org
.eclipse
.ui
.ide
.IDE
;
148 import org
.eclipse
.ui
.ide
.IGotoMarker
;
149 import org
.eclipse
.ui
.themes
.ColorUtil
;
151 import com
.google
.common
.base
.Joiner
;
152 import com
.google
.common
.collect
.HashMultimap
;
153 import com
.google
.common
.collect
.ImmutableList
;
154 import com
.google
.common
.collect
.Multimap
;
157 * The generic TMF Events table
159 * This is a view that will list events that are read from a trace.
161 * @author Francois Chouinard
162 * @author Patrick Tasse
165 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
168 * Empty string array, used by {@link #getItemStrings}.
171 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
177 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
179 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
180 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
181 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
182 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
183 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
184 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
185 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
186 private static final Image FILTER_IMAGE
= Activator
.getDefault()
187 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
188 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
189 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
190 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
191 private static final int MAX_CACHE_SIZE
= 1000;
194 * Default set of columns to use for trace types that do not specify
198 public static final Collection
<TmfEventTableColumn
> DEFAULT_COLUMNS
= ImmutableList
.of(
199 TmfEventTableColumn
.BaseColumns
.TIMESTAMP
,
200 TmfEventTableColumn
.BaseColumns
.SOURCE
,
201 TmfEventTableColumn
.BaseColumns
.EVENT_TYPE
,
202 TmfEventTableColumn
.BaseColumns
.REFERENCE
,
203 TmfEventTableColumn
.BaseColumns
.CONTENTS
207 * The events table search/filter keys
210 * @author Patrick Tasse
212 public interface Key
{
214 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
217 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
220 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
223 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
226 String TIMESTAMP
= "$time"; //$NON-NLS-1$
229 String RANK
= "$rank"; //$NON-NLS-1$
232 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
234 /** Bookmark indicator */
235 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
239 * The events table search/filter state
242 * @author Patrick Tasse
244 public static enum HeaderState
{
245 /** A search is being run */
248 /** A filter is applied */
252 interface Direction
{
257 // ------------------------------------------------------------------------
259 // ------------------------------------------------------------------------
261 /** The virtual event table */
262 protected TmfVirtualTable fTable
;
264 private Composite fComposite
;
265 private SashForm fSashForm
;
266 private TmfRawEventViewer fRawViewer
;
267 private ITmfTrace fTrace
;
268 private boolean fPackDone
= false;
269 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
270 private long fSelectedRank
= 0;
271 private ITmfTimestamp fSelectedBeginTimestamp
= null;
272 private IStatusLineManager fStatusLineManager
= null;
275 private long fFilterMatchCount
;
276 private long fFilterCheckCount
;
277 private FilterThread fFilterThread
;
278 private boolean fFilterThreadResume
= false;
279 private final Object fFilterSyncObj
= new Object();
280 private SearchThread fSearchThread
;
281 private final Object fSearchSyncObj
= new Object();
284 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
286 * @see #fireSelectionChanged
288 private ListenerList selectionChangedListeners
= new ListenerList();
290 // Bookmark map <Rank, MarkerId>
291 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
292 private IFile fBookmarksFile
;
293 private long fPendingGotoRank
= -1;
296 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
297 private Color fGrayColor
;
298 private Color fGreenColor
;
299 private Font fBoldFont
;
301 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
304 private final TmfEventsCache fCache
;
305 private boolean fCacheUpdateBusy
= false;
306 private boolean fCacheUpdatePending
= false;
307 private boolean fCacheUpdateCompleted
= false;
308 private final Object fCacheUpdateSyncObj
= new Object();
310 private boolean fDisposeOnClose
;
312 // ------------------------------------------------------------------------
314 // ------------------------------------------------------------------------
317 * Basic constructor, using the default set of columns
320 * The parent composite UI object
322 * The size of the event table cache
324 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
325 this(parent
, cacheSize
, DEFAULT_COLUMNS
);
329 * Legacy constructor, using ColumnData to define columns
332 * The parent composite UI object
334 * The size of the event table cache
337 * @deprecated Deprecated constructor, use
338 * {@link #TmfEventsTable(Composite, int, Collection)}
341 public TmfEventsTable(final Composite parent
, int cacheSize
,
342 final org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
344 * We'll do a "best-effort" to keep trace types still using this API to
345 * keep working, by defining a TmfEventTableFieldColumn for each
346 * ColumnData they passed.
348 this(parent
, cacheSize
, convertFromColumnData(columnData
));
352 private static Collection
<TmfEventTableColumn
> convertFromColumnData(
353 org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
355 ImmutableList
.Builder
<TmfEventTableColumn
> builder
= new ImmutableList
.Builder
<>();
356 for (org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
357 String header
= col
.header
;
358 if (header
!= null) {
359 builder
.add(new TmfEventTableFieldColumn(header
));
362 return builder
.build();
366 * Standard constructor, where we define which columns to use.
369 * The parent composite UI object
371 * The size of the event table cache
373 * The columns to use in this table.
375 * The iteration order of this collection will correspond to the
376 * initial ordering of this series of columns in the table.
380 public TmfEventsTable(final Composite parent
, int cacheSize
,
381 Collection
<?
extends TmfEventTableColumn
> columns
) {
382 super("TmfEventsTable"); //$NON-NLS-1$
384 fComposite
= new Composite(parent
, SWT
.NONE
);
385 final GridLayout gl
= new GridLayout(1, false);
388 gl
.verticalSpacing
= 0;
389 fComposite
.setLayout(gl
);
391 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
392 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
394 // Create a virtual table
395 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
396 fTable
= new TmfVirtualTable(fSashForm
, style
);
398 // Set the table layout
399 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
400 fTable
.setLayoutData(layoutData
);
402 // Some cosmetic enhancements
403 fTable
.setHeaderVisible(true);
404 fTable
.setLinesVisible(true);
407 if (columns
!= null) {
408 fColumns
.addAll(columns
);
411 // Create the UI columns in the table
412 for (TmfEventTableColumn col
: fColumns
) {
413 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
414 column
.setText(col
.getHeaderName());
415 column
.setToolTipText(col
.getHeaderTooltip());
416 column
.setData(Key
.FIELD_ID
, col
.getFilterFieldId());
420 // Set the frozen row for header row
421 fTable
.setFrozenRowCount(1);
423 // Create the header row cell editor
424 createHeaderEditor();
426 // Handle the table item selection
427 fTable
.addSelectionListener(new SelectionAdapter() {
429 public void widgetSelected(final SelectionEvent e
) {
430 if (e
.item
== null) {
433 updateStatusLine(null);
434 if (fTable
.getSelectionIndices().length
> 0) {
435 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
436 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
437 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
439 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
440 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
441 if (fTable
.getSelectionIndices().length
== 1) {
442 fSelectedBeginTimestamp
= ts
;
444 if (fSelectedBeginTimestamp
!= null) {
445 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
446 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
447 if (fTable
.getSelectionIndices().length
== 2) {
448 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
451 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
452 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
456 if (fTable
.getSelectionIndices().length
== 1) {
457 fSelectedBeginTimestamp
= null;
461 if (e
.item
.getData() != null) {
462 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
464 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
469 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
470 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
471 fCache
= new TmfEventsCache(realCacheSize
, this);
473 // Handle the table item requests
474 fTable
.addListener(SWT
.SetData
, new Listener() {
477 public void handleEvent(final Event event
) {
479 final TableItem item
= (TableItem
) event
.item
;
480 int index
= event
.index
- 1; // -1 for the header row
482 if (event
.index
== 0) {
483 setHeaderRowItemData(item
);
487 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
488 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
489 setFilterStatusRowItemData(item
);
492 index
= index
- 1; // -1 for top filter status row
495 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
496 if (cachedEvent
!= null) {
497 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
501 // Else, fill the cache asynchronously (and off the UI thread)
506 fTable
.addMouseListener(new MouseAdapter() {
508 public void mouseDoubleClick(final MouseEvent event
) {
509 if (event
.button
!= 1) {
512 // Identify the selected row
513 final Point point
= new Point(event
.x
, event
.y
);
514 final TableItem item
= fTable
.getItem(point
);
516 final Rectangle imageBounds
= item
.getImageBounds(0);
517 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
518 if (imageBounds
.contains(point
)) {
519 final Long rank
= (Long
) item
.getData(Key
.RANK
);
521 toggleBookmark(rank
);
528 final Listener tooltipListener
= new Listener () {
529 Shell tooltipShell
= null;
531 public void handleEvent(final Event event
) {
532 switch (event
.type
) {
534 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
538 final Long rank
= (Long
) item
.getData(Key
.RANK
);
542 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
543 final Rectangle bounds
= item
.getImageBounds(0);
544 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
545 if (!bounds
.contains(event
.x
,event
.y
)) {
548 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
549 tooltipShell
.dispose();
551 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
552 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
553 final FillLayout layout
= new FillLayout();
554 layout
.marginWidth
= 2;
555 tooltipShell
.setLayout(layout
);
556 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
557 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: ""); //$NON-NLS-1$ //$NON-NLS-2$
558 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
559 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
561 label
.addListener(SWT
.MouseExit
, this);
562 label
.addListener(SWT
.MouseDown
, this);
563 label
.addListener(SWT
.MouseWheel
, this);
564 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
566 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
567 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
570 if (System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
571 y
+= fTable
.getHeaderHeight();
573 Point pt
= fTable
.toDisplay(event
.x
, y
);
574 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
575 pt
.y
+= item
.getBounds().height
;
576 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
577 tooltipShell
.setVisible(true);
585 if (tooltipShell
!= null) {
586 tooltipShell
.dispose();
596 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
597 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
598 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
599 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
600 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
601 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
602 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
607 ColorSettingsManager
.addColorSettingsListener(this);
609 fTable
.setItemCount(1); // +1 for header row
611 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
613 fRawViewer
.addSelectionListener(new Listener() {
615 public void handleEvent(final Event e
) {
616 if (e
.data
instanceof Long
) {
617 final long rank
= (Long
) e
.data
;
618 int index
= (int) rank
;
619 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
620 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
622 fTable
.setSelection(index
+ 1); // +1 for header row
623 fSelectedRank
= rank
;
624 updateStatusLine(null);
625 } else if (e
.data
instanceof ITmfLocation
) {
626 // DOES NOT WORK: rank undefined in context from seekLocation()
627 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
628 // TmfContext context = fTrace.seekLocation(location);
629 // fTable.setSelection((int) context.getRank());
634 final TableItem
[] selection
= fTable
.getSelection();
635 if ((selection
!= null) && (selection
.length
> 0)) {
636 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
638 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
644 fSashForm
.setWeights(new int[] { 1, 1 });
645 fRawViewer
.setVisible(false);
650 // ------------------------------------------------------------------------
652 // ------------------------------------------------------------------------
655 * Create a pop-up menu.
657 protected void createPopupMenu() {
658 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
661 fTable
.setVisible(true);
666 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
669 fTable
.setVisible(false);
674 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
677 fRawViewer
.setVisible(true);
679 final int index
= fTable
.getSelectionIndex();
681 fRawViewer
.selectAndReveal(index
- 1);
686 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
689 fRawViewer
.setVisible(false);
694 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
697 final TableItem items
[] = fTable
.getSelection();
698 if (items
.length
!= 1) {
701 final TableItem item
= items
[0];
703 final Object data
= item
.getData();
704 if (data
instanceof ITmfSourceLookup
) {
705 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
706 ITmfCallsite cs
= event
.getCallsite();
707 if (cs
== null || cs
.getFileName() == null) {
710 IMarker marker
= null;
712 String fileName
= cs
.getFileName();
713 final String trimmedPath
= fileName
.replaceAll("\\.\\./", ""); //$NON-NLS-1$ //$NON-NLS-2$
714 final ArrayList
<IFile
> files
= new ArrayList
<>();
715 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
717 public boolean visit(IResource resource
) throws CoreException
{
718 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
719 files
.add((IFile
) resource
);
725 if (files
.size() > 1) {
726 ListDialog dialog
= new ListDialog(getTable().getShell());
727 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
728 dialog
.setLabelProvider(new LabelProvider() {
730 public String
getText(Object element
) {
731 return ((IFile
) element
).getFullPath().toString();
734 dialog
.setInput(files
);
735 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
736 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
738 Object
[] result
= dialog
.getResult();
739 if (result
!= null && result
.length
> 0) {
740 file
= (IFile
) result
[0];
742 } else if (files
.size() == 1) {
746 marker
= file
.createMarker(IMarker
.MARKER
);
747 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
748 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
750 } else if (files
.size() == 0){
751 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
753 } catch (CoreException e
) {
760 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
764 final TableItem items
[] = fTable
.getSelection();
765 if (items
.length
!= 1) {
768 final TableItem item
= items
[0];
770 final Object eventData
= item
.getData();
771 if (eventData
instanceof ITmfModelLookup
) {
772 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
774 if (modelURI
!= null) {
775 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
778 final URI uri
= URI
.createURI(modelURI
);
779 if (uri
.isPlatformResource()) {
780 IPath path
= new Path(uri
.toPlatformString(true));
781 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
782 } else if (uri
.isFile() && !uri
.isRelative()) {
783 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
784 new Path(uri
.toFileString()));
790 * create a temporary validation marker on the
791 * model file, remove it afterwards thus,
792 * navigation works with all model editors
793 * supporting the navigation to a marker
795 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
796 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
797 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
799 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
802 catch (CoreException e
) {
806 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
813 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
816 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
817 IHandlerService handlerService
= (IHandlerService
) activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
818 ICommandService cmdService
= (ICommandService
) activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
820 HashMap
<String
, Object
> parameters
= new HashMap
<>();
821 StringBuilder header
= new StringBuilder();
822 boolean needTab
= false;
823 for (TableColumn tc
: fTable
.getColumns()) {
827 header
.append(tc
.getText());
830 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
831 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
,parameters
);
832 IEvaluationContext context
= handlerService
.getCurrentState();
833 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_HEADER_ID
, header
.toString());
834 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_PARAMETER_ID
, TmfEventsTable
.this);
835 handlerService
.executeCommandInContext(cmd
, null, context
);
836 } catch (ExecutionException e
) {
838 } catch (NotDefinedException e
) {
840 } catch (NotEnabledException e
) {
842 } catch (NotHandledException e
) {
848 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
851 fHeaderState
= HeaderState
.SEARCH
;
856 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
859 fHeaderState
= HeaderState
.FILTER
;
864 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
871 class ToggleBookmarkAction
extends Action
{
874 public ToggleBookmarkAction(final String text
, final Long rank
) {
881 toggleBookmark(fRank
);
885 final MenuManager tablePopupMenu
= new MenuManager();
886 tablePopupMenu
.setRemoveAllWhenShown(true);
887 tablePopupMenu
.addMenuListener(new IMenuListener() {
889 public void menuAboutToShow(final IMenuManager manager
) {
890 if (fTable
.getSelectionIndex() == 0) {
891 // Right-click on header row
892 if (fHeaderState
== HeaderState
.FILTER
) {
893 tablePopupMenu
.add(showSearchBarAction
);
895 tablePopupMenu
.add(showFilterBarAction
);
899 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
900 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
902 final Rectangle imageBounds
= item
.getImageBounds(0);
903 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
904 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
905 // Right-click on left margin
906 final Long rank
= (Long
) item
.getData(Key
.RANK
);
907 if ((rank
!= null) && (fBookmarksFile
!= null)) {
908 if (fBookmarksMap
.containsKey(rank
)) {
909 tablePopupMenu
.add(new ToggleBookmarkAction(
910 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
912 tablePopupMenu
.add(new ToggleBookmarkAction(
913 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
920 // Right-click on table
921 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
922 tablePopupMenu
.add(hideTableAction
);
923 tablePopupMenu
.add(hideRawAction
);
924 } else if (!fTable
.isVisible()) {
925 tablePopupMenu
.add(showTableAction
);
926 } else if (!fRawViewer
.isVisible()) {
927 tablePopupMenu
.add(showRawAction
);
929 tablePopupMenu
.add(exportToTextAction
);
930 tablePopupMenu
.add(new Separator());
933 final Object data
= item
.getData();
934 Separator separator
= null;
935 if (data
instanceof ITmfSourceLookup
) {
936 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
937 if (event
.getCallsite() != null) {
938 tablePopupMenu
.add(openCallsiteAction
);
939 separator
= new Separator();
943 if (data
instanceof ITmfModelLookup
) {
944 ITmfModelLookup event
= (ITmfModelLookup
) data
;
945 if (event
.getModelUri() != null) {
946 tablePopupMenu
.add(openModelAction
);
947 separator
= new Separator();
950 if (separator
!= null) {
951 tablePopupMenu
.add(separator
);
956 tablePopupMenu
.add(clearFiltersAction
);
957 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
958 if (savedFilters
.length
> 0) {
959 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
960 for (final ITmfFilterTreeNode node
: savedFilters
) {
961 if (node
instanceof TmfFilterNode
) {
962 final TmfFilterNode filter
= (TmfFilterNode
) node
;
963 subMenu
.add(new Action(filter
.getFilterName()) {
971 tablePopupMenu
.add(subMenu
);
973 appendToTablePopupMenu(tablePopupMenu
, item
);
977 final MenuManager rawViewerPopupMenu
= new MenuManager();
978 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
979 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
981 public void menuAboutToShow(final IMenuManager manager
) {
982 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
983 rawViewerPopupMenu
.add(hideTableAction
);
984 rawViewerPopupMenu
.add(hideRawAction
);
985 } else if (!fTable
.isVisible()) {
986 rawViewerPopupMenu
.add(showTableAction
);
987 } else if (!fRawViewer
.isVisible()) {
988 rawViewerPopupMenu
.add(showRawAction
);
990 appendToRawPopupMenu(tablePopupMenu
);
994 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
995 fTable
.setMenu(menu
);
997 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
998 fRawViewer
.setMenu(menu
);
1003 * Append an item to the event table's pop-up menu.
1005 * @param tablePopupMenu
1007 * @param selectedItem
1008 * The item to append
1010 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1011 // override to append more actions
1015 * Append an item to the raw viewer's pop-up menu.
1017 * @param rawViewerPopupMenu
1020 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1021 // override to append more actions
1025 public void dispose() {
1028 ColorSettingsManager
.removeColorSettingsListener(this);
1029 fComposite
.dispose();
1030 if ((fTrace
!= null) && fDisposeOnClose
) {
1033 fResourceManager
.dispose();
1034 fRawViewer
.dispose();
1039 * Assign a layout data object to this view.
1042 * The layout data to assign
1044 public void setLayoutData(final Object layoutData
) {
1045 fComposite
.setLayoutData(layoutData
);
1049 * Get the virtual table contained in this event table.
1051 * @return The TMF virtual table
1053 public TmfVirtualTable
getTable() {
1060 * @deprecated The column headers are now set at the constructor, this
1061 * shouldn't be called anymore.
1064 protected void setColumnHeaders(final org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1069 * Set a table item's data.
1074 * Which trace event to link with this entry
1076 * Which rank this event has in the trace/experiment
1078 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1079 item
.setText(getItemStrings(fColumns
, event
));
1080 item
.setData(event
);
1081 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1082 item
.setData(Key
.RANK
, rank
);
1084 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1085 if (!markerIds
.isEmpty()) {
1086 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1087 List
<Object
> parts
= new ArrayList
<>();
1088 if (markerIds
.size() > 1) {
1089 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1092 for (long markerId
: markerIds
) {
1093 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1094 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1096 } catch (CoreException e
) {
1097 displayException(e
);
1099 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1101 item
.setData(Key
.BOOKMARK
, null);
1104 boolean searchMatch
= false;
1105 boolean searchNoMatch
= false;
1106 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1107 if (searchFilter
!= null) {
1108 if (searchFilter
.matches(event
)) {
1111 searchNoMatch
= true;
1115 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1116 if (searchNoMatch
) {
1117 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1118 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1120 item
.setForeground(colorSetting
.getForegroundColor());
1121 item
.setBackground(colorSetting
.getBackgroundColor());
1125 if (!markerIds
.isEmpty()) {
1126 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1128 item
.setImage(SEARCH_MATCH_IMAGE
);
1130 } else if (!markerIds
.isEmpty()) {
1131 item
.setImage(BOOKMARK_IMAGE
);
1133 item
.setImage((Image
) null);
1138 * Set the item data of the header row.
1141 * The item to use as table header
1143 protected void setHeaderRowItemData(final TableItem item
) {
1144 String txtKey
= null;
1145 if (fHeaderState
== HeaderState
.SEARCH
) {
1146 item
.setImage(SEARCH_IMAGE
);
1147 txtKey
= Key
.SEARCH_TXT
;
1148 } else if (fHeaderState
== HeaderState
.FILTER
) {
1149 item
.setImage(FILTER_IMAGE
);
1150 txtKey
= Key
.FILTER_TXT
;
1152 item
.setForeground(fGrayColor
);
1153 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1154 final TableColumn column
= fTable
.getColumns()[i
];
1155 final String filter
= (String
) column
.getData(txtKey
);
1156 if (filter
== null) {
1157 if (fHeaderState
== HeaderState
.SEARCH
) {
1158 item
.setText(i
, SEARCH_HINT
);
1159 } else if (fHeaderState
== HeaderState
.FILTER
) {
1160 item
.setText(i
, FILTER_HINT
);
1162 item
.setForeground(i
, fGrayColor
);
1163 item
.setFont(i
, fTable
.getFont());
1165 item
.setText(i
, filter
);
1166 item
.setForeground(i
, fGreenColor
);
1167 item
.setFont(i
, fBoldFont
);
1173 * Set the item data of the "filter status" row.
1176 * The item to use as filter status row
1178 protected void setFilterStatusRowItemData(final TableItem item
) {
1179 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1181 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1182 item
.setImage(FILTER_IMAGE
);
1184 item
.setImage(STOP_IMAGE
);
1186 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1188 item
.setText(i
, ""); //$NON-NLS-1$
1192 item
.setData(Key
.TIMESTAMP
, null);
1193 item
.setData(Key
.RANK
, null);
1194 item
.setForeground(null);
1195 item
.setBackground(null);
1199 * Create an editor for the header.
1201 protected void createHeaderEditor() {
1202 final TableEditor tableEditor
= fTable
.createTableEditor();
1203 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1204 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1205 tableEditor
.grabHorizontal
= true;
1206 tableEditor
.minimumWidth
= 50;
1208 // Handle the header row selection
1209 fTable
.addMouseListener(new MouseAdapter() {
1215 public void mouseDown(final MouseEvent event
) {
1216 if (event
.button
!= 1) {
1219 // Identify the selected row
1220 final Point point
= new Point(event
.x
, event
.y
);
1221 item
= fTable
.getItem(point
);
1223 // Header row selected
1224 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1227 if (item
.getImageBounds(0).contains(point
)) {
1228 if (fHeaderState
== HeaderState
.SEARCH
) {
1229 fHeaderState
= HeaderState
.FILTER
;
1230 } else if (fHeaderState
== HeaderState
.FILTER
) {
1231 fHeaderState
= HeaderState
.SEARCH
;
1233 fTable
.setSelection(0);
1238 // Identify the selected column
1240 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1241 final Rectangle rect
= item
.getBounds(i
);
1242 if (rect
.contains(point
)) {
1248 if (columnIndex
== -1) {
1252 column
= fTable
.getColumns()[columnIndex
];
1254 String txtKey
= null;
1255 if (fHeaderState
== HeaderState
.SEARCH
) {
1256 txtKey
= Key
.SEARCH_TXT
;
1257 } else if (fHeaderState
== HeaderState
.FILTER
) {
1258 txtKey
= Key
.FILTER_TXT
;
1261 // The control that will be the editor must be a child of the Table
1262 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1263 final String headerString
= (String
) column
.getData(txtKey
);
1264 if (headerString
!= null) {
1265 newEditor
.setText(headerString
);
1267 newEditor
.addFocusListener(new FocusAdapter() {
1269 public void focusLost(final FocusEvent e
) {
1270 final boolean changed
= updateHeader(newEditor
.getText());
1276 newEditor
.addKeyListener(new KeyAdapter() {
1278 public void keyPressed(final KeyEvent e
) {
1279 if (e
.character
== SWT
.CR
) {
1280 updateHeader(newEditor
.getText());
1283 // Set focus on the table so that the next carriage return goes to the next result
1284 TmfEventsTable
.this.getTable().setFocus();
1285 } else if (e
.character
== SWT
.ESC
) {
1286 tableEditor
.getEditor().dispose();
1290 newEditor
.selectAll();
1291 newEditor
.setFocus();
1292 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1297 * returns true is value was changed
1299 private boolean updateHeader(final String text
) {
1300 String objKey
= null;
1301 String txtKey
= null;
1302 if (fHeaderState
== HeaderState
.SEARCH
) {
1303 objKey
= Key
.SEARCH_OBJ
;
1304 txtKey
= Key
.SEARCH_TXT
;
1305 } else if (fHeaderState
== HeaderState
.FILTER
) {
1306 objKey
= Key
.FILTER_OBJ
;
1307 txtKey
= Key
.FILTER_TXT
;
1309 if (text
.trim().length() > 0) {
1311 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1312 Pattern
.compile(regex
);
1313 if (regex
.equals(column
.getData(txtKey
))) {
1314 tableEditor
.getEditor().dispose();
1317 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1318 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1319 if (fieldId
== null) {
1320 fieldId
= column
.getText();
1322 filter
.setField(fieldId
);
1323 filter
.setRegex(regex
);
1324 column
.setData(objKey
, filter
);
1325 column
.setData(txtKey
, regex
);
1326 } catch (final PatternSyntaxException ex
) {
1327 tableEditor
.getEditor().dispose();
1328 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1329 ex
.getDescription(), ex
.getMessage());
1333 if (column
.getData(txtKey
) == null) {
1334 tableEditor
.getEditor().dispose();
1337 column
.setData(objKey
, null);
1338 column
.setData(txtKey
, null);
1343 private void applyHeader() {
1344 if (fHeaderState
== HeaderState
.SEARCH
) {
1346 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1347 for (final TableColumn col
: fTable
.getColumns()) {
1348 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1349 if (filterObj
instanceof ITmfFilterTreeNode
) {
1350 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1353 if (filter
.getChildrenCount() > 0) {
1354 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1357 fireSearchApplied(filter
);
1359 fTable
.setData(Key
.SEARCH_OBJ
, null);
1361 fireSearchApplied(null);
1363 } else if (fHeaderState
== HeaderState
.FILTER
) {
1364 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1365 for (final TableColumn col
: fTable
.getColumns()) {
1366 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1367 if (filterObj
instanceof ITmfFilterTreeNode
) {
1368 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1371 if (filter
.getChildrenCount() > 0) {
1372 applyFilter(filter
);
1378 tableEditor
.getEditor().dispose();
1382 fTable
.addKeyListener(new KeyAdapter() {
1384 public void keyPressed(final KeyEvent e
) {
1386 if (e
.character
== SWT
.ESC
) {
1390 } else if (e
.character
== SWT
.DEL
) {
1391 if (fHeaderState
== HeaderState
.SEARCH
) {
1393 for (final TableColumn column
: fTable
.getColumns()) {
1394 column
.setData(Key
.SEARCH_OBJ
, null);
1395 column
.setData(Key
.SEARCH_TXT
, null);
1397 fTable
.setData(Key
.SEARCH_OBJ
, null);
1399 fireSearchApplied(null);
1400 } else if (fHeaderState
== HeaderState
.FILTER
) {
1403 } else if (e
.character
== SWT
.CR
) {
1404 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1415 * Send an event indicating a filter has been applied.
1418 * The filter that was just applied
1420 protected void fireFilterApplied(final ITmfFilter filter
) {
1421 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1425 * Send an event indicating that a search has been applied.
1428 * The search filter that was just applied
1430 protected void fireSearchApplied(final ITmfFilter filter
) {
1431 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1435 * Start the filtering thread.
1437 protected void startFilterThread() {
1438 synchronized (fFilterSyncObj
) {
1439 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1440 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1441 if (fFilterThread
!= null) {
1442 fFilterThread
.cancel();
1443 fFilterThreadResume
= false;
1445 fFilterThread
= new FilterThread(filter
);
1446 fFilterThread
.start();
1448 fFilterThreadResume
= true;
1454 * Stop the filtering thread.
1456 protected void stopFilterThread() {
1457 synchronized (fFilterSyncObj
) {
1458 if (fFilterThread
!= null) {
1459 fFilterThread
.cancel();
1460 fFilterThread
= null;
1461 fFilterThreadResume
= false;
1470 * The filter to apply
1473 protected void applyFilter(ITmfFilter filter
) {
1476 fFilterMatchCount
= 0;
1477 fFilterCheckCount
= 0;
1478 fCache
.applyFilter(filter
);
1480 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1481 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1482 startFilterThread();
1483 fireFilterApplied(filter
);
1487 * Clear all currently active filters.
1489 protected void clearFilters() {
1490 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1495 fCache
.clearFilter();
1497 for (final TableColumn column
: fTable
.getColumns()) {
1498 column
.setData(Key
.FILTER_OBJ
, null);
1499 column
.setData(Key
.FILTER_TXT
, null);
1501 fTable
.setData(Key
.FILTER_OBJ
, null);
1502 if (fTrace
!= null) {
1503 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1505 fTable
.setItemCount(1); // +1 for header row
1507 fFilterMatchCount
= 0;
1508 fFilterCheckCount
= 0;
1509 if (fSelectedRank
>= 0) {
1510 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1512 fTable
.setSelection(0);
1514 fireFilterApplied(null);
1515 updateStatusLine(null);
1519 * Wrapper Thread object for the filtering thread.
1521 protected class FilterThread
extends Thread
{
1522 private final ITmfFilterTreeNode filter
;
1523 private TmfEventRequest request
;
1524 private boolean refreshBusy
= false;
1525 private boolean refreshPending
= false;
1526 private final Object syncObj
= new Object();
1532 * The filter this thread will be processing
1534 public FilterThread(final ITmfFilterTreeNode filter
) {
1535 super("Filter Thread"); //$NON-NLS-1$
1536 this.filter
= filter
;
1541 if (fTrace
== null) {
1544 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1545 if (nbRequested
<= 0) {
1548 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1549 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1551 public void handleData(final ITmfEvent event
) {
1552 super.handleData(event
);
1553 if (request
.isCancelled()) {
1556 if (filter
.matches(event
)) {
1557 final long rank
= fFilterCheckCount
;
1558 final int index
= (int) fFilterMatchCount
;
1559 fFilterMatchCount
++;
1560 fCache
.storeEvent(event
, rank
, index
);
1562 } else if ((fFilterCheckCount
% 100) == 0) {
1565 fFilterCheckCount
++;
1568 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1570 request
.waitForCompletion();
1571 } catch (final InterruptedException e
) {
1574 synchronized (fFilterSyncObj
) {
1575 fFilterThread
= null;
1576 if (fFilterThreadResume
) {
1577 fFilterThreadResume
= false;
1578 fFilterThread
= new FilterThread(filter
);
1579 fFilterThread
.start();
1585 * Refresh the filter.
1587 public void refreshTable() {
1588 synchronized (syncObj
) {
1590 refreshPending
= true;
1595 Display
.getDefault().asyncExec(new Runnable() {
1598 if (request
.isCancelled()) {
1601 if (fTable
.isDisposed()) {
1604 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1606 synchronized (syncObj
) {
1607 refreshBusy
= false;
1608 if (refreshPending
) {
1609 refreshPending
= false;
1618 * Cancel this filtering thread.
1620 public void cancel() {
1621 if (request
!= null) {
1628 * Go to the next item of a search.
1630 protected void searchNext() {
1631 synchronized (fSearchSyncObj
) {
1632 if (fSearchThread
!= null) {
1635 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1636 if (searchFilter
== null) {
1639 final int selectionIndex
= fTable
.getSelectionIndex();
1641 if (selectionIndex
> 0) {
1642 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1644 // header row is selected, start at top event
1645 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1647 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1648 if (eventFilter
!= null) {
1649 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1651 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1652 fSearchThread
.schedule();
1657 * Go to the previous item of a search.
1659 protected void searchPrevious() {
1660 synchronized (fSearchSyncObj
) {
1661 if (fSearchThread
!= null) {
1664 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1665 if (searchFilter
== null) {
1668 final int selectionIndex
= fTable
.getSelectionIndex();
1670 if (selectionIndex
> 0) {
1671 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1673 // header row is selected, start at precedent of top event
1674 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1676 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1677 if (eventFilter
!= null) {
1678 startIndex
= startIndex
- 1; // -1 for top filter status row
1680 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1681 fSearchThread
.schedule();
1686 * Stop the search thread.
1688 protected void stopSearchThread() {
1689 fPendingGotoRank
= -1;
1690 synchronized (fSearchSyncObj
) {
1691 if (fSearchThread
!= null) {
1692 fSearchThread
.cancel();
1693 fSearchThread
= null;
1699 * Wrapper for the search thread.
1701 protected class SearchThread
extends Job
{
1703 private ITmfFilterTreeNode searchFilter
;
1704 private ITmfFilterTreeNode eventFilter
;
1705 private int startIndex
;
1706 private int direction
;
1708 private long foundRank
= -1;
1709 private TmfEventRequest request
;
1710 private ITmfTimestamp foundTimestamp
= null;
1715 * @param searchFilter
1717 * @param eventFilter
1720 * The index at which we should start searching
1721 * @param currentRank
1724 * In which direction should we search, forward or backwards
1726 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1727 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1728 final long currentRank
, final int direction
) {
1729 super(Messages
.TmfEventsTable_SearchingJobName
);
1730 this.searchFilter
= searchFilter
;
1731 this.eventFilter
= eventFilter
;
1732 this.startIndex
= startIndex
;
1733 this.rank
= currentRank
;
1734 this.direction
= direction
;
1738 protected IStatus
run(final IProgressMonitor monitor
) {
1739 if (fTrace
== null) {
1740 return Status
.OK_STATUS
;
1742 final Display display
= Display
.getDefault();
1743 if (startIndex
< 0) {
1744 rank
= (int) fTrace
.getNbEvents() - 1;
1745 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1748 int idx
= startIndex
;
1749 while (foundRank
== -1) {
1750 final CachedEvent event
= fCache
.peekEvent(idx
);
1751 if (event
== null) {
1755 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1756 foundRank
= event
.rank
;
1757 foundTimestamp
= event
.event
.getTimestamp();
1760 if (direction
== Direction
.FORWARD
) {
1766 if (foundRank
== -1) {
1767 if (direction
== Direction
.FORWARD
) {
1769 if (rank
> (fTrace
.getNbEvents() - 1)) {
1775 rank
= (int) fTrace
.getNbEvents() - 1;
1780 final int startRank
= (int) rank
;
1781 boolean wrapped
= false;
1782 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1783 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1784 if (direction
== Direction
.BACKWARD
) {
1785 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1787 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1788 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1789 long currentRank
= rank
;
1792 public void handleData(final ITmfEvent event
) {
1793 super.handleData(event
);
1794 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1795 foundRank
= currentRank
;
1796 foundTimestamp
= event
.getTimestamp();
1797 if (direction
== Direction
.FORWARD
) {
1805 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1807 request
.waitForCompletion();
1808 if (request
.isCancelled()) {
1809 return Status
.OK_STATUS
;
1811 } catch (final InterruptedException e
) {
1812 synchronized (fSearchSyncObj
) {
1813 fSearchThread
= null;
1815 return Status
.OK_STATUS
;
1817 if (foundRank
== -1) {
1818 if (direction
== Direction
.FORWARD
) {
1820 synchronized (fSearchSyncObj
) {
1821 fSearchThread
= null;
1823 return Status
.OK_STATUS
;
1825 nbRequested
= (int) rank
;
1831 rank
= (int) fTrace
.getNbEvents() - 1;
1834 if ((rank
<= startRank
) && wrapped
) {
1835 synchronized (fSearchSyncObj
) {
1836 fSearchThread
= null;
1838 return Status
.OK_STATUS
;
1843 int index
= (int) foundRank
;
1844 if (eventFilter
!= null) {
1845 index
= fCache
.getFilteredEventIndex(foundRank
);
1847 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1849 display
.asyncExec(new Runnable() {
1852 if (monitor
.isCanceled()) {
1855 if (fTable
.isDisposed()) {
1858 fTable
.setSelection(selection
);
1859 fSelectedRank
= foundRank
;
1860 fRawViewer
.selectAndReveal(fSelectedRank
);
1861 if (foundTimestamp
!= null) {
1862 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1864 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1865 synchronized (fSearchSyncObj
) {
1866 fSearchThread
= null;
1868 updateStatusLine(null);
1871 return Status
.OK_STATUS
;
1875 protected void canceling() {
1877 synchronized (fSearchSyncObj
) {
1878 fSearchThread
= null;
1884 * Create the resources.
1886 protected void createResources() {
1887 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1888 .getForeground().getRGB()));
1889 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1890 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1896 protected void packColumns() {
1900 fTable
.setRedraw(false);
1902 boolean isLinux
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
1904 TableColumn tableColumns
[] = fTable
.getColumns();
1905 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1906 final TableColumn column
= tableColumns
[i
];
1907 final int headerWidth
= column
.getWidth();
1909 // Workaround for Linux which doesn't consider the image width of
1910 // search/filter row in TableColumn.pack() after having executed
1911 // TableItem.setImage((Image)null) for other rows than search/filter row.
1912 if (isLinux
&& (i
== 0)) {
1913 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1916 if (column
.getWidth() < headerWidth
) {
1917 column
.setWidth(headerWidth
);
1921 fTable
.setRedraw(true);
1926 * Get the array of item strings (e.g., what to display in each cell of the
1927 * table row) corresponding to the columns and trace event passed in
1928 * parameter. The order of the Strings in the returned array will correspond
1929 * to the iteration order of 'columns'.
1932 * To ensure consistent results, make sure only call this within a scope
1933 * synchronized on 'columns'! If the order of 'columns' changes right after
1934 * this method is called, the returned value won't be ordered correctly
1937 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
1938 if (event
== null) {
1939 return EMPTY_STRING_ARRAY
;
1941 synchronized (columns
) {
1942 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
1943 for (TmfEventTableColumn column
: columns
) {
1944 itemStrings
.add(column
.getItemString(event
));
1946 return itemStrings
.toArray(new String
[0]);
1951 * Get the contents of the row in the events table corresponding to an
1952 * event. The order of the elements corresponds to the current order of the
1956 * The event printed in this row
1957 * @return The event row entries
1960 public String
[] getItemStrings(ITmfEvent event
) {
1961 return getItemStrings(fColumns
, event
);
1965 * Notify this table that is got the UI focus.
1967 public void setFocus() {
1972 * Assign a new trace to this event table.
1975 * The trace to assign to this event table
1976 * @param disposeOnClose
1977 * true if the trace should be disposed when the table is
1980 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1981 if ((fTrace
!= null) && fDisposeOnClose
) {
1987 fDisposeOnClose
= disposeOnClose
;
1989 // Perform the updates on the UI thread
1990 fTable
.getDisplay().syncExec(new Runnable() {
1994 fCache
.setTrace(fTrace
); // Clear the cache
1995 if (fTrace
!= null) {
1996 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1997 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1998 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2001 fFilterMatchCount
= 0;
2002 fFilterCheckCount
= 0;
2003 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
2004 startFilterThread();
2008 fRawViewer
.setTrace(fTrace
);
2014 * Assign the status line manager
2016 * @param statusLineManager
2017 * The status line manager, or null to disable status line messages
2020 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2021 if (fStatusLineManager
!= null && statusLineManager
== null) {
2022 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
2024 fStatusLineManager
= statusLineManager
;
2027 private void updateStatusLine(ITmfTimestamp delta
) {
2028 if (fStatusLineManager
!= null) {
2029 if (delta
!= null) {
2030 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2032 fStatusLineManager
.setMessage(null);
2037 // ------------------------------------------------------------------------
2039 // ------------------------------------------------------------------------
2042 * Notify that the event cache has been updated
2045 * Also notify if the populating of the cache is complete, or
2048 public void cacheUpdated(final boolean completed
) {
2049 synchronized (fCacheUpdateSyncObj
) {
2050 if (fCacheUpdateBusy
) {
2051 fCacheUpdatePending
= true;
2052 fCacheUpdateCompleted
= completed
;
2055 fCacheUpdateBusy
= true;
2057 // Event cache is now updated. Perform update on the UI thread
2058 if (!fTable
.isDisposed()) {
2059 fTable
.getDisplay().asyncExec(new Runnable() {
2062 if (!fTable
.isDisposed()) {
2067 populateCompleted();
2069 synchronized (fCacheUpdateSyncObj
) {
2070 fCacheUpdateBusy
= false;
2071 if (fCacheUpdatePending
) {
2072 fCacheUpdatePending
= false;
2073 cacheUpdated(fCacheUpdateCompleted
);
2082 * Callback for when populating the table is complete.
2084 protected void populateCompleted() {
2085 // Nothing by default;
2088 // ------------------------------------------------------------------------
2089 // ISelectionProvider
2090 // ------------------------------------------------------------------------
2096 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2097 selectionChangedListeners
.add(listener
);
2104 public ISelection
getSelection() {
2105 if (fTable
== null || fTable
.isDisposed()) {
2106 return StructuredSelection
.EMPTY
;
2108 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2109 for (TableItem item
: fTable
.getSelection()) {
2110 if (item
.getData() != null) {
2111 list
.add(item
.getData());
2114 return new StructuredSelection(list
);
2121 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2122 selectionChangedListeners
.remove(listener
);
2129 public void setSelection(ISelection selection
) {
2134 * Notifies any selection changed listeners that the viewer's selection has changed.
2135 * Only listeners registered at the time this method is called are notified.
2137 * @param event a selection changed event
2139 * @see ISelectionChangedListener#selectionChanged
2142 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2143 Object
[] listeners
= selectionChangedListeners
.getListeners();
2144 for (int i
= 0; i
< listeners
.length
; ++i
) {
2145 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2146 SafeRunnable
.run(new SafeRunnable() {
2149 l
.selectionChanged(event
);
2155 // ------------------------------------------------------------------------
2156 // Bookmark handling
2157 // ------------------------------------------------------------------------
2160 * Add a bookmark to this event table.
2162 * @param bookmarksFile
2163 * The file to use for the bookmarks
2165 public void addBookmark(final IFile bookmarksFile
) {
2166 fBookmarksFile
= bookmarksFile
;
2167 final TableItem
[] selection
= fTable
.getSelection();
2168 if (selection
.length
> 0) {
2169 final TableItem tableItem
= selection
[0];
2170 if (tableItem
.getData(Key
.RANK
) != null) {
2171 final StringBuffer defaultMessage
= new StringBuffer();
2172 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2174 defaultMessage
.append(", "); //$NON-NLS-1$
2176 defaultMessage
.append(tableItem
.getText(i
));
2178 final InputDialog dialog
= new MultiLineInputDialog(
2179 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2180 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2181 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2182 defaultMessage
.toString());
2183 if (dialog
.open() == Window
.OK
) {
2184 final String message
= dialog
.getValue();
2186 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2187 if (bookmark
.exists()) {
2188 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2189 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2190 final int location
= rank
.intValue();
2191 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2192 fBookmarksMap
.put(rank
, bookmark
.getId());
2195 } catch (final CoreException e
) {
2196 displayException(e
);
2205 * Remove a bookmark from this event table.
2208 * The bookmark to remove
2210 public void removeBookmark(final IMarker bookmark
) {
2211 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2212 if (entry
.getValue().equals(bookmark
.getId())) {
2213 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2220 private void toggleBookmark(final Long rank
) {
2221 if (fBookmarksFile
== null) {
2224 if (fBookmarksMap
.containsKey(rank
)) {
2225 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2228 for (long markerId
: markerIds
) {
2229 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2230 if (bookmark
!= null) {
2234 } catch (final CoreException e
) {
2235 displayException(e
);
2238 addBookmark(fBookmarksFile
);
2243 * Refresh the bookmarks assigned to this trace, from the contents of a
2246 * @param bookmarksFile
2247 * The bookmark file to use
2249 public void refreshBookmarks(final IFile bookmarksFile
) {
2250 fBookmarksFile
= bookmarksFile
;
2251 if (bookmarksFile
== null) {
2252 fBookmarksMap
.clear();
2257 fBookmarksMap
.clear();
2258 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2259 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2260 if (location
!= -1) {
2261 final long rank
= location
;
2262 fBookmarksMap
.put(rank
, bookmark
.getId());
2266 } catch (final CoreException e
) {
2267 displayException(e
);
2272 public void gotoMarker(final IMarker marker
) {
2273 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2276 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2277 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2278 } else if (rank
>= fTable
.getItemCount()) {
2279 fPendingGotoRank
= rank
;
2281 fSelectedRank
= rank
;
2282 fTable
.setSelection(index
+ 1); // +1 for header row
2283 updateStatusLine(null);
2287 // ------------------------------------------------------------------------
2289 // ------------------------------------------------------------------------
2292 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2296 // ------------------------------------------------------------------------
2298 // ------------------------------------------------------------------------
2301 * Handler for the trace updated signal
2304 * The incoming signal
2307 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2308 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2311 // Perform the refresh on the UI thread
2312 Display
.getDefault().asyncExec(new Runnable() {
2315 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2316 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2317 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2318 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2319 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2320 fPendingGotoRank
= -1;
2321 updateStatusLine(null);
2324 startFilterThread();
2327 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2328 fRawViewer
.refreshEventCount();
2335 * Handler for the time synch signal.
2338 * The incoming signal
2341 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2342 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2344 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2345 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2346 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2347 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2348 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2350 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2353 public void handleData(final ITmfEvent event
) {
2354 super.handleData(event
);
2358 public void handleCompleted() {
2359 super.handleCompleted();
2360 if (fTrace
== null) {
2364 // Verify if the event is within the trace range and adjust if necessary
2365 ITmfTimestamp timestamp
= ts
;
2366 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2367 timestamp
= fTrace
.getStartTime();
2369 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2370 timestamp
= fTrace
.getEndTime();
2373 // Get the rank of the selected event in the table
2374 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2375 final long rank
= context
.getRank();
2377 fSelectedRank
= rank
;
2379 fTable
.getDisplay().asyncExec(new Runnable() {
2382 // Return if table is disposed
2383 if (fTable
.isDisposed()) {
2387 int index
= (int) rank
;
2388 if (fTable
.isDisposed()) {
2391 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2392 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2394 fTable
.setSelection(index
+ 1); // +1 for header row
2395 fRawViewer
.selectAndReveal(rank
);
2396 updateStatusLine(null);
2402 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2406 // ------------------------------------------------------------------------
2408 // ------------------------------------------------------------------------
2411 * Display an exception in a message box
2413 * @param e the exception
2415 private static void displayException(final Exception e
) {
2416 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2417 mb
.setText(e
.getClass().getSimpleName());
2418 mb
.setMessage(e
.getMessage());
2425 public void refresh() {