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
11 * Patrick Tasse - Factored out from events view
12 * Francois Chouinard - Replaced Table by TmfVirtualTable
13 * Patrick Tasse - Filter implementation (inspired by www.eclipse.org/mat)
14 * Ansgar Radermacher - Support navigation to model URIs (Bug 396956)
15 * Bernd Hufmann - Updated call site and model URI implementation
16 *******************************************************************************/
18 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
;
20 import java
.io
.FileNotFoundException
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Arrays
;
23 import java
.util
.Collection
;
24 import java
.util
.HashMap
;
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
.views
.colors
.ColorSetting
;
105 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
106 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
107 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
108 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
109 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
;
110 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
111 import org
.eclipse
.swt
.SWT
;
112 import org
.eclipse
.swt
.custom
.SashForm
;
113 import org
.eclipse
.swt
.custom
.TableEditor
;
114 import org
.eclipse
.swt
.events
.FocusAdapter
;
115 import org
.eclipse
.swt
.events
.FocusEvent
;
116 import org
.eclipse
.swt
.events
.KeyAdapter
;
117 import org
.eclipse
.swt
.events
.KeyEvent
;
118 import org
.eclipse
.swt
.events
.MouseAdapter
;
119 import org
.eclipse
.swt
.events
.MouseEvent
;
120 import org
.eclipse
.swt
.events
.SelectionAdapter
;
121 import org
.eclipse
.swt
.events
.SelectionEvent
;
122 import org
.eclipse
.swt
.graphics
.Color
;
123 import org
.eclipse
.swt
.graphics
.Font
;
124 import org
.eclipse
.swt
.graphics
.Image
;
125 import org
.eclipse
.swt
.graphics
.Point
;
126 import org
.eclipse
.swt
.graphics
.Rectangle
;
127 import org
.eclipse
.swt
.layout
.FillLayout
;
128 import org
.eclipse
.swt
.layout
.GridData
;
129 import org
.eclipse
.swt
.layout
.GridLayout
;
130 import org
.eclipse
.swt
.widgets
.Composite
;
131 import org
.eclipse
.swt
.widgets
.Display
;
132 import org
.eclipse
.swt
.widgets
.Event
;
133 import org
.eclipse
.swt
.widgets
.Label
;
134 import org
.eclipse
.swt
.widgets
.Listener
;
135 import org
.eclipse
.swt
.widgets
.Menu
;
136 import org
.eclipse
.swt
.widgets
.MessageBox
;
137 import org
.eclipse
.swt
.widgets
.Shell
;
138 import org
.eclipse
.swt
.widgets
.TableColumn
;
139 import org
.eclipse
.swt
.widgets
.TableItem
;
140 import org
.eclipse
.swt
.widgets
.Text
;
141 import org
.eclipse
.ui
.IWorkbenchPage
;
142 import org
.eclipse
.ui
.PlatformUI
;
143 import org
.eclipse
.ui
.commands
.ICommandService
;
144 import org
.eclipse
.ui
.dialogs
.ListDialog
;
145 import org
.eclipse
.ui
.handlers
.IHandlerService
;
146 import org
.eclipse
.ui
.ide
.IDE
;
147 import org
.eclipse
.ui
.ide
.IGotoMarker
;
148 import org
.eclipse
.ui
.themes
.ColorUtil
;
150 import com
.google
.common
.base
.Joiner
;
151 import com
.google
.common
.collect
.HashMultimap
;
152 import com
.google
.common
.collect
.Multimap
;
155 * The generic TMF Events table
157 * This is a view that will list events that are read from a trace.
160 * @author Francois Chouinard
161 * @author Patrick Tasse
164 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
167 * Empty string array, used by {@link #getItemStrings}.
170 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
172 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
173 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
174 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
175 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
176 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
177 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
178 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
179 private static final Image FILTER_IMAGE
= Activator
.getDefault()
180 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
181 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
182 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
183 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
184 private static final int MAX_CACHE_SIZE
= 1000;
187 * The events table search/filter keys
190 * @author Patrick Tasse
192 public interface Key
{
194 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
197 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
200 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
203 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
206 String TIMESTAMP
= "$time"; //$NON-NLS-1$
209 String RANK
= "$rank"; //$NON-NLS-1$
212 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
214 /** Bookmark indicator */
215 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
219 * The events table search/filter state
222 * @author Patrick Tasse
224 public static enum HeaderState
{
225 /** A search is being run */
228 /** A filter is applied */
232 interface Direction
{
237 // ------------------------------------------------------------------------
239 // ------------------------------------------------------------------------
241 /** The virtual event table */
242 protected TmfVirtualTable fTable
;
244 private Composite fComposite
;
245 private SashForm fSashForm
;
246 private TmfRawEventViewer fRawViewer
;
247 private ITmfTrace fTrace
;
248 private boolean fPackDone
= false;
249 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
250 private long fSelectedRank
= 0;
251 private ITmfTimestamp fSelectedBeginTimestamp
= null;
252 private IStatusLineManager fStatusLineManager
= null;
255 private long fFilterMatchCount
;
256 private long fFilterCheckCount
;
257 private FilterThread fFilterThread
;
258 private boolean fFilterThreadResume
= false;
259 private final Object fFilterSyncObj
= new Object();
260 private SearchThread fSearchThread
;
261 private final Object fSearchSyncObj
= new Object();
264 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
266 * @see #fireSelectionChanged
268 private ListenerList selectionChangedListeners
= new ListenerList();
270 // Bookmark map <Rank, MarkerId>
271 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
272 private IFile fBookmarksFile
;
273 private long fPendingGotoRank
= -1;
276 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
277 private Color fGrayColor
;
278 private Color fGreenColor
;
279 private Font fBoldFont
;
281 // Table column names
282 private static final String
[] COLUMN_NAMES
= new String
[] { Messages
.TmfEventsTable_TimestampColumnHeader
,
283 Messages
.TmfEventsTable_SourceColumnHeader
, Messages
.TmfEventsTable_TypeColumnHeader
,
284 Messages
.TmfEventsTable_ReferenceColumnHeader
, Messages
.TmfEventsTable_ContentColumnHeader
};
286 private static final ColumnData
[] COLUMN_DATA
= new ColumnData
[] { new ColumnData(COLUMN_NAMES
[0], 100, SWT
.LEFT
),
287 new ColumnData(COLUMN_NAMES
[1], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[2], 100, SWT
.LEFT
),
288 new ColumnData(COLUMN_NAMES
[3], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[4], 100, SWT
.LEFT
) };
291 private final TmfEventsCache fCache
;
292 private boolean fCacheUpdateBusy
= false;
293 private boolean fCacheUpdatePending
= false;
294 private boolean fCacheUpdateCompleted
= false;
295 private final Object fCacheUpdateSyncObj
= new Object();
297 private boolean fDisposeOnClose
;
299 // ------------------------------------------------------------------------
301 // ------------------------------------------------------------------------
304 * Basic constructor, will use default column data.
307 * The parent composite UI object
309 * The size of the event table cache
311 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
312 this(parent
, cacheSize
, COLUMN_DATA
);
316 * Advanced constructor, where we also define which column data to use.
319 * The parent composite UI object
321 * The size of the event table cache
323 * The column data to use for this table
325 public TmfEventsTable(final Composite parent
, int cacheSize
, final ColumnData
[] columnData
) {
326 super("TmfEventsTable"); //$NON-NLS-1$
328 fComposite
= new Composite(parent
, SWT
.NONE
);
329 final GridLayout gl
= new GridLayout(1, false);
332 gl
.verticalSpacing
= 0;
333 fComposite
.setLayout(gl
);
335 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
336 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
338 // Create a virtual table
339 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
340 fTable
= new TmfVirtualTable(fSashForm
, style
);
342 // Set the table layout
343 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
344 fTable
.setLayoutData(layoutData
);
346 // Some cosmetic enhancements
347 fTable
.setHeaderVisible(true);
348 fTable
.setLinesVisible(true);
351 setColumnHeaders(columnData
);
353 // Set the default column field ids if this is not a subclass
354 if (Arrays
.equals(columnData
, COLUMN_DATA
)) {
355 fTable
.getColumns()[0].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
356 fTable
.getColumns()[1].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_SOURCE
);
357 fTable
.getColumns()[2].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TYPE
);
358 fTable
.getColumns()[3].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_REFERENCE
);
359 fTable
.getColumns()[4].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_CONTENT
);
362 // Set the frozen row for header row
363 fTable
.setFrozenRowCount(1);
365 // Create the header row cell editor
366 createHeaderEditor();
368 // Handle the table item selection
369 fTable
.addSelectionListener(new SelectionAdapter() {
371 public void widgetSelected(final SelectionEvent e
) {
372 if (e
.item
== null) {
375 updateStatusLine(null);
376 if (fTable
.getSelectionIndices().length
> 0) {
377 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
378 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
379 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
381 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
382 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
383 if (fTable
.getSelectionIndices().length
== 1) {
384 fSelectedBeginTimestamp
= ts
;
386 if (fSelectedBeginTimestamp
!= null) {
387 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
388 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
389 if (fTable
.getSelectionIndices().length
== 2) {
390 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
393 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
394 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
398 if (fTable
.getSelectionIndices().length
== 1) {
399 fSelectedBeginTimestamp
= null;
403 if (e
.item
.getData() != null) {
404 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
406 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
411 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
412 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
413 fCache
= new TmfEventsCache(realCacheSize
, this);
415 // Handle the table item requests
416 fTable
.addListener(SWT
.SetData
, new Listener() {
419 public void handleEvent(final Event event
) {
421 final TableItem item
= (TableItem
) event
.item
;
422 int index
= event
.index
- 1; // -1 for the header row
424 if (event
.index
== 0) {
425 setHeaderRowItemData(item
);
429 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
430 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
431 setFilterStatusRowItemData(item
);
434 index
= index
- 1; // -1 for top filter status row
437 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
438 if (cachedEvent
!= null) {
439 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
443 // Else, fill the cache asynchronously (and off the UI thread)
448 fTable
.addMouseListener(new MouseAdapter() {
450 public void mouseDoubleClick(final MouseEvent event
) {
451 if (event
.button
!= 1) {
454 // Identify the selected row
455 final Point point
= new Point(event
.x
, event
.y
);
456 final TableItem item
= fTable
.getItem(point
);
458 final Rectangle imageBounds
= item
.getImageBounds(0);
459 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
460 if (imageBounds
.contains(point
)) {
461 final Long rank
= (Long
) item
.getData(Key
.RANK
);
463 toggleBookmark(rank
);
470 final Listener tooltipListener
= new Listener () {
471 Shell tooltipShell
= null;
473 public void handleEvent(final Event event
) {
474 switch (event
.type
) {
476 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
480 final Long rank
= (Long
) item
.getData(Key
.RANK
);
484 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
485 final Rectangle bounds
= item
.getImageBounds(0);
486 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
487 if (!bounds
.contains(event
.x
,event
.y
)) {
490 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
491 tooltipShell
.dispose();
493 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
494 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
495 final FillLayout layout
= new FillLayout();
496 layout
.marginWidth
= 2;
497 tooltipShell
.setLayout(layout
);
498 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
499 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: ""); //$NON-NLS-1$ //$NON-NLS-2$
500 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
501 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
503 label
.addListener(SWT
.MouseExit
, this);
504 label
.addListener(SWT
.MouseDown
, this);
505 label
.addListener(SWT
.MouseWheel
, this);
506 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
508 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
509 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
512 if (System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
513 y
+= fTable
.getHeaderHeight();
515 Point pt
= fTable
.toDisplay(event
.x
, y
);
516 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
517 pt
.y
+= item
.getBounds().height
;
518 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
519 tooltipShell
.setVisible(true);
527 if (tooltipShell
!= null) {
528 tooltipShell
.dispose();
538 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
539 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
540 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
541 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
542 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
543 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
544 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
549 ColorSettingsManager
.addColorSettingsListener(this);
551 fTable
.setItemCount(1); // +1 for header row
553 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
555 fRawViewer
.addSelectionListener(new Listener() {
557 public void handleEvent(final Event e
) {
558 if (e
.data
instanceof Long
) {
559 final long rank
= (Long
) e
.data
;
560 int index
= (int) rank
;
561 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
562 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
564 fTable
.setSelection(index
+ 1); // +1 for header row
565 fSelectedRank
= rank
;
566 updateStatusLine(null);
567 } else if (e
.data
instanceof ITmfLocation
) {
568 // DOES NOT WORK: rank undefined in context from seekLocation()
569 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
570 // TmfContext context = fTrace.seekLocation(location);
571 // fTable.setSelection((int) context.getRank());
576 final TableItem
[] selection
= fTable
.getSelection();
577 if ((selection
!= null) && (selection
.length
> 0)) {
578 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
580 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
586 fSashForm
.setWeights(new int[] { 1, 1 });
587 fRawViewer
.setVisible(false);
593 * Create a pop-up menu.
595 protected void createPopupMenu() {
596 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
599 fTable
.setVisible(true);
604 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
607 fTable
.setVisible(false);
612 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
615 fRawViewer
.setVisible(true);
617 final int index
= fTable
.getSelectionIndex();
619 fRawViewer
.selectAndReveal(index
- 1);
624 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
627 fRawViewer
.setVisible(false);
632 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
635 final TableItem items
[] = fTable
.getSelection();
636 if (items
.length
!= 1) {
639 final TableItem item
= items
[0];
641 final Object data
= item
.getData();
642 if (data
instanceof ITmfSourceLookup
) {
643 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
644 ITmfCallsite cs
= event
.getCallsite();
645 if (cs
== null || cs
.getFileName() == null) {
648 IMarker marker
= null;
650 String fileName
= cs
.getFileName();
651 final String trimmedPath
= fileName
.replaceAll("\\.\\./", ""); //$NON-NLS-1$ //$NON-NLS-2$
652 final ArrayList
<IFile
> files
= new ArrayList
<>();
653 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
655 public boolean visit(IResource resource
) throws CoreException
{
656 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
657 files
.add((IFile
) resource
);
663 if (files
.size() > 1) {
664 ListDialog dialog
= new ListDialog(getTable().getShell());
665 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
666 dialog
.setLabelProvider(new LabelProvider() {
668 public String
getText(Object element
) {
669 return ((IFile
) element
).getFullPath().toString();
672 dialog
.setInput(files
);
673 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
674 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
676 Object
[] result
= dialog
.getResult();
677 if (result
!= null && result
.length
> 0) {
678 file
= (IFile
) result
[0];
680 } else if (files
.size() == 1) {
684 marker
= file
.createMarker(IMarker
.MARKER
);
685 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
686 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
688 } else if (files
.size() == 0){
689 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
691 } catch (CoreException e
) {
698 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
702 final TableItem items
[] = fTable
.getSelection();
703 if (items
.length
!= 1) {
706 final TableItem item
= items
[0];
708 final Object eventData
= item
.getData();
709 if (eventData
instanceof ITmfModelLookup
) {
710 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
712 if (modelURI
!= null) {
713 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
716 final URI uri
= URI
.createURI(modelURI
);
717 if (uri
.isPlatformResource()) {
718 IPath path
= new Path(uri
.toPlatformString(true));
719 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
720 } else if (uri
.isFile() && !uri
.isRelative()) {
721 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
722 new Path(uri
.toFileString()));
728 * create a temporary validation marker on the
729 * model file, remove it afterwards thus,
730 * navigation works with all model editors
731 * supporting the navigation to a marker
733 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
734 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
735 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
737 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
740 catch (CoreException e
) {
744 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
751 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
754 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
755 IHandlerService handlerService
= (IHandlerService
) activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
756 ICommandService cmdService
= (ICommandService
) activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
758 HashMap
<String
, Object
> parameters
= new HashMap
<>();
759 StringBuilder header
= new StringBuilder();
760 boolean needTab
= false;
761 for (TableColumn tc
: fTable
.getColumns()) {
765 header
.append(tc
.getText());
768 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
769 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
,parameters
);
770 IEvaluationContext context
= handlerService
.getCurrentState();
771 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_HEADER_ID
, header
.toString());
772 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_PARAMETER_ID
, TmfEventsTable
.this);
773 handlerService
.executeCommandInContext(cmd
, null, context
);
774 } catch (ExecutionException e
) {
776 } catch (NotDefinedException e
) {
778 } catch (NotEnabledException e
) {
780 } catch (NotHandledException e
) {
786 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
789 fHeaderState
= HeaderState
.SEARCH
;
794 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
797 fHeaderState
= HeaderState
.FILTER
;
802 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
809 class ToggleBookmarkAction
extends Action
{
812 public ToggleBookmarkAction(final String text
, final Long rank
) {
819 toggleBookmark(fRank
);
823 final MenuManager tablePopupMenu
= new MenuManager();
824 tablePopupMenu
.setRemoveAllWhenShown(true);
825 tablePopupMenu
.addMenuListener(new IMenuListener() {
827 public void menuAboutToShow(final IMenuManager manager
) {
828 if (fTable
.getSelectionIndex() == 0) {
829 // Right-click on header row
830 if (fHeaderState
== HeaderState
.FILTER
) {
831 tablePopupMenu
.add(showSearchBarAction
);
833 tablePopupMenu
.add(showFilterBarAction
);
837 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
838 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
840 final Rectangle imageBounds
= item
.getImageBounds(0);
841 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
842 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
843 // Right-click on left margin
844 final Long rank
= (Long
) item
.getData(Key
.RANK
);
845 if ((rank
!= null) && (fBookmarksFile
!= null)) {
846 if (fBookmarksMap
.containsKey(rank
)) {
847 tablePopupMenu
.add(new ToggleBookmarkAction(
848 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
850 tablePopupMenu
.add(new ToggleBookmarkAction(
851 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
858 // Right-click on table
859 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
860 tablePopupMenu
.add(hideTableAction
);
861 tablePopupMenu
.add(hideRawAction
);
862 } else if (!fTable
.isVisible()) {
863 tablePopupMenu
.add(showTableAction
);
864 } else if (!fRawViewer
.isVisible()) {
865 tablePopupMenu
.add(showRawAction
);
867 tablePopupMenu
.add(exportToTextAction
);
868 tablePopupMenu
.add(new Separator());
871 final Object data
= item
.getData();
872 Separator separator
= null;
873 if (data
instanceof ITmfSourceLookup
) {
874 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
875 if (event
.getCallsite() != null) {
876 tablePopupMenu
.add(openCallsiteAction
);
877 separator
= new Separator();
881 if (data
instanceof ITmfModelLookup
) {
882 ITmfModelLookup event
= (ITmfModelLookup
) data
;
883 if (event
.getModelUri() != null) {
884 tablePopupMenu
.add(openModelAction
);
885 separator
= new Separator();
888 if (separator
!= null) {
889 tablePopupMenu
.add(separator
);
894 tablePopupMenu
.add(clearFiltersAction
);
895 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
896 if (savedFilters
.length
> 0) {
897 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
898 for (final ITmfFilterTreeNode node
: savedFilters
) {
899 if (node
instanceof TmfFilterNode
) {
900 final TmfFilterNode filter
= (TmfFilterNode
) node
;
901 subMenu
.add(new Action(filter
.getFilterName()) {
909 tablePopupMenu
.add(subMenu
);
911 appendToTablePopupMenu(tablePopupMenu
, item
);
915 final MenuManager rawViewerPopupMenu
= new MenuManager();
916 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
917 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
919 public void menuAboutToShow(final IMenuManager manager
) {
920 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
921 rawViewerPopupMenu
.add(hideTableAction
);
922 rawViewerPopupMenu
.add(hideRawAction
);
923 } else if (!fTable
.isVisible()) {
924 rawViewerPopupMenu
.add(showTableAction
);
925 } else if (!fRawViewer
.isVisible()) {
926 rawViewerPopupMenu
.add(showRawAction
);
928 appendToRawPopupMenu(tablePopupMenu
);
932 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
933 fTable
.setMenu(menu
);
935 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
936 fRawViewer
.setMenu(menu
);
941 * Append an item to the event table's pop-up menu.
943 * @param tablePopupMenu
945 * @param selectedItem
948 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
949 // override to append more actions
953 * Append an item to the raw viewer's pop-up menu.
955 * @param rawViewerPopupMenu
958 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
959 // override to append more actions
963 public void dispose() {
966 ColorSettingsManager
.removeColorSettingsListener(this);
967 fComposite
.dispose();
968 if ((fTrace
!= null) && fDisposeOnClose
) {
971 fResourceManager
.dispose();
972 fRawViewer
.dispose();
977 * Assign a layout data object to this view.
980 * The layout data to assign
982 public void setLayoutData(final Object layoutData
) {
983 fComposite
.setLayoutData(layoutData
);
987 * Get the virtual table contained in this event table.
989 * @return The TMF virtual table
991 public TmfVirtualTable
getTable() {
998 * FIXME: Add support for column selection
1000 protected void setColumnHeaders(final ColumnData
[] columnData
) {
1001 fTable
.setColumnHeaders(columnData
);
1005 * Set a table item's data.
1010 * Which trace event to link with this entry
1012 * Which rank this event has in the trace/experiment
1014 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1015 item
.setText(getItemStrings(event
));
1016 item
.setData(event
);
1017 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1018 item
.setData(Key
.RANK
, rank
);
1020 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1021 if (!markerIds
.isEmpty()) {
1022 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1023 List
<Object
> parts
= new ArrayList
<>();
1024 if (markerIds
.size() > 1) {
1025 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1028 for (long markerId
: markerIds
) {
1029 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1030 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1032 } catch (CoreException e
) {
1033 displayException(e
);
1035 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1037 item
.setData(Key
.BOOKMARK
, null);
1040 boolean searchMatch
= false;
1041 boolean searchNoMatch
= false;
1042 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1043 if (searchFilter
!= null) {
1044 if (searchFilter
.matches(event
)) {
1047 searchNoMatch
= true;
1051 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1052 if (searchNoMatch
) {
1053 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1054 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1056 item
.setForeground(colorSetting
.getForegroundColor());
1057 item
.setBackground(colorSetting
.getBackgroundColor());
1061 if (!markerIds
.isEmpty()) {
1062 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1064 item
.setImage(SEARCH_MATCH_IMAGE
);
1066 } else if (!markerIds
.isEmpty()) {
1067 item
.setImage(BOOKMARK_IMAGE
);
1069 item
.setImage((Image
) null);
1074 * Set the item data of the header row.
1077 * The item to use as table header
1079 protected void setHeaderRowItemData(final TableItem item
) {
1080 String txtKey
= null;
1081 if (fHeaderState
== HeaderState
.SEARCH
) {
1082 item
.setImage(SEARCH_IMAGE
);
1083 txtKey
= Key
.SEARCH_TXT
;
1084 } else if (fHeaderState
== HeaderState
.FILTER
) {
1085 item
.setImage(FILTER_IMAGE
);
1086 txtKey
= Key
.FILTER_TXT
;
1088 item
.setForeground(fGrayColor
);
1089 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1090 final TableColumn column
= fTable
.getColumns()[i
];
1091 final String filter
= (String
) column
.getData(txtKey
);
1092 if (filter
== null) {
1093 if (fHeaderState
== HeaderState
.SEARCH
) {
1094 item
.setText(i
, SEARCH_HINT
);
1095 } else if (fHeaderState
== HeaderState
.FILTER
) {
1096 item
.setText(i
, FILTER_HINT
);
1098 item
.setForeground(i
, fGrayColor
);
1099 item
.setFont(i
, fTable
.getFont());
1101 item
.setText(i
, filter
);
1102 item
.setForeground(i
, fGreenColor
);
1103 item
.setFont(i
, fBoldFont
);
1109 * Set the item data of the "filter status" row.
1112 * The item to use as filter status row
1114 protected void setFilterStatusRowItemData(final TableItem item
) {
1115 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1117 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1118 item
.setImage(FILTER_IMAGE
);
1120 item
.setImage(STOP_IMAGE
);
1122 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1124 item
.setText(i
, ""); //$NON-NLS-1$
1128 item
.setData(Key
.TIMESTAMP
, null);
1129 item
.setData(Key
.RANK
, null);
1130 item
.setForeground(null);
1131 item
.setBackground(null);
1135 * Create an editor for the header.
1137 protected void createHeaderEditor() {
1138 final TableEditor tableEditor
= fTable
.createTableEditor();
1139 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1140 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1141 tableEditor
.grabHorizontal
= true;
1142 tableEditor
.minimumWidth
= 50;
1144 // Handle the header row selection
1145 fTable
.addMouseListener(new MouseAdapter() {
1151 public void mouseDown(final MouseEvent event
) {
1152 if (event
.button
!= 1) {
1155 // Identify the selected row
1156 final Point point
= new Point(event
.x
, event
.y
);
1157 item
= fTable
.getItem(point
);
1159 // Header row selected
1160 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1163 if (item
.getImageBounds(0).contains(point
)) {
1164 if (fHeaderState
== HeaderState
.SEARCH
) {
1165 fHeaderState
= HeaderState
.FILTER
;
1166 } else if (fHeaderState
== HeaderState
.FILTER
) {
1167 fHeaderState
= HeaderState
.SEARCH
;
1169 fTable
.setSelection(0);
1174 // Identify the selected column
1176 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1177 final Rectangle rect
= item
.getBounds(i
);
1178 if (rect
.contains(point
)) {
1184 if (columnIndex
== -1) {
1188 column
= fTable
.getColumns()[columnIndex
];
1190 String txtKey
= null;
1191 if (fHeaderState
== HeaderState
.SEARCH
) {
1192 txtKey
= Key
.SEARCH_TXT
;
1193 } else if (fHeaderState
== HeaderState
.FILTER
) {
1194 txtKey
= Key
.FILTER_TXT
;
1197 // The control that will be the editor must be a child of the Table
1198 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1199 final String headerString
= (String
) column
.getData(txtKey
);
1200 if (headerString
!= null) {
1201 newEditor
.setText(headerString
);
1203 newEditor
.addFocusListener(new FocusAdapter() {
1205 public void focusLost(final FocusEvent e
) {
1206 final boolean changed
= updateHeader(newEditor
.getText());
1212 newEditor
.addKeyListener(new KeyAdapter() {
1214 public void keyPressed(final KeyEvent e
) {
1215 if (e
.character
== SWT
.CR
) {
1216 updateHeader(newEditor
.getText());
1219 // Set focus on the table so that the next carriage return goes to the next result
1220 TmfEventsTable
.this.getTable().setFocus();
1221 } else if (e
.character
== SWT
.ESC
) {
1222 tableEditor
.getEditor().dispose();
1226 newEditor
.selectAll();
1227 newEditor
.setFocus();
1228 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1233 * returns true is value was changed
1235 private boolean updateHeader(final String text
) {
1236 String objKey
= null;
1237 String txtKey
= null;
1238 if (fHeaderState
== HeaderState
.SEARCH
) {
1239 objKey
= Key
.SEARCH_OBJ
;
1240 txtKey
= Key
.SEARCH_TXT
;
1241 } else if (fHeaderState
== HeaderState
.FILTER
) {
1242 objKey
= Key
.FILTER_OBJ
;
1243 txtKey
= Key
.FILTER_TXT
;
1245 if (text
.trim().length() > 0) {
1247 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1248 Pattern
.compile(regex
);
1249 if (regex
.equals(column
.getData(txtKey
))) {
1250 tableEditor
.getEditor().dispose();
1253 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1254 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1255 if (fieldId
== null) {
1256 fieldId
= column
.getText();
1258 filter
.setField(fieldId
);
1259 filter
.setRegex(regex
);
1260 column
.setData(objKey
, filter
);
1261 column
.setData(txtKey
, regex
);
1262 } catch (final PatternSyntaxException ex
) {
1263 tableEditor
.getEditor().dispose();
1264 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1265 ex
.getDescription(), ex
.getMessage());
1269 if (column
.getData(txtKey
) == null) {
1270 tableEditor
.getEditor().dispose();
1273 column
.setData(objKey
, null);
1274 column
.setData(txtKey
, null);
1279 private void applyHeader() {
1280 if (fHeaderState
== HeaderState
.SEARCH
) {
1282 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1283 for (final TableColumn col
: fTable
.getColumns()) {
1284 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1285 if (filterObj
instanceof ITmfFilterTreeNode
) {
1286 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1289 if (filter
.getChildrenCount() > 0) {
1290 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1293 fireSearchApplied(filter
);
1295 fTable
.setData(Key
.SEARCH_OBJ
, null);
1297 fireSearchApplied(null);
1299 } else if (fHeaderState
== HeaderState
.FILTER
) {
1300 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1301 for (final TableColumn col
: fTable
.getColumns()) {
1302 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1303 if (filterObj
instanceof ITmfFilterTreeNode
) {
1304 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1307 if (filter
.getChildrenCount() > 0) {
1308 applyFilter(filter
);
1314 tableEditor
.getEditor().dispose();
1318 fTable
.addKeyListener(new KeyAdapter() {
1320 public void keyPressed(final KeyEvent e
) {
1322 if (e
.character
== SWT
.ESC
) {
1326 } else if (e
.character
== SWT
.DEL
) {
1327 if (fHeaderState
== HeaderState
.SEARCH
) {
1329 for (final TableColumn column
: fTable
.getColumns()) {
1330 column
.setData(Key
.SEARCH_OBJ
, null);
1331 column
.setData(Key
.SEARCH_TXT
, null);
1333 fTable
.setData(Key
.SEARCH_OBJ
, null);
1335 fireSearchApplied(null);
1336 } else if (fHeaderState
== HeaderState
.FILTER
) {
1339 } else if (e
.character
== SWT
.CR
) {
1340 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1351 * Send an event indicating a filter has been applied.
1354 * The filter that was just applied
1356 protected void fireFilterApplied(final ITmfFilter filter
) {
1357 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1361 * Send an event indicating that a search has been applied.
1364 * The search filter that was just applied
1366 protected void fireSearchApplied(final ITmfFilter filter
) {
1367 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1371 * Start the filtering thread.
1373 protected void startFilterThread() {
1374 synchronized (fFilterSyncObj
) {
1375 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1376 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1377 if (fFilterThread
!= null) {
1378 fFilterThread
.cancel();
1379 fFilterThreadResume
= false;
1381 fFilterThread
= new FilterThread(filter
);
1382 fFilterThread
.start();
1384 fFilterThreadResume
= true;
1390 * Stop the filtering thread.
1392 protected void stopFilterThread() {
1393 synchronized (fFilterSyncObj
) {
1394 if (fFilterThread
!= null) {
1395 fFilterThread
.cancel();
1396 fFilterThread
= null;
1397 fFilterThreadResume
= false;
1406 * The filter to apply
1409 protected void applyFilter(ITmfFilter filter
) {
1412 fFilterMatchCount
= 0;
1413 fFilterCheckCount
= 0;
1414 fCache
.applyFilter(filter
);
1416 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1417 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1418 startFilterThread();
1419 fireFilterApplied(filter
);
1423 * Clear all currently active filters.
1425 protected void clearFilters() {
1426 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1431 fCache
.clearFilter();
1433 for (final TableColumn column
: fTable
.getColumns()) {
1434 column
.setData(Key
.FILTER_OBJ
, null);
1435 column
.setData(Key
.FILTER_TXT
, null);
1437 fTable
.setData(Key
.FILTER_OBJ
, null);
1438 if (fTrace
!= null) {
1439 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1441 fTable
.setItemCount(1); // +1 for header row
1443 fFilterMatchCount
= 0;
1444 fFilterCheckCount
= 0;
1445 if (fSelectedRank
>= 0) {
1446 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1448 fTable
.setSelection(0);
1450 fireFilterApplied(null);
1451 updateStatusLine(null);
1455 * Wrapper Thread object for the filtering thread.
1457 protected class FilterThread
extends Thread
{
1458 private final ITmfFilterTreeNode filter
;
1459 private TmfEventRequest request
;
1460 private boolean refreshBusy
= false;
1461 private boolean refreshPending
= false;
1462 private final Object syncObj
= new Object();
1468 * The filter this thread will be processing
1470 public FilterThread(final ITmfFilterTreeNode filter
) {
1471 super("Filter Thread"); //$NON-NLS-1$
1472 this.filter
= filter
;
1477 if (fTrace
== null) {
1480 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1481 if (nbRequested
<= 0) {
1484 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1485 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1487 public void handleData(final ITmfEvent event
) {
1488 super.handleData(event
);
1489 if (request
.isCancelled()) {
1492 if (filter
.matches(event
)) {
1493 final long rank
= fFilterCheckCount
;
1494 final int index
= (int) fFilterMatchCount
;
1495 fFilterMatchCount
++;
1496 fCache
.storeEvent(event
, rank
, index
);
1498 } else if ((fFilterCheckCount
% 100) == 0) {
1501 fFilterCheckCount
++;
1504 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1506 request
.waitForCompletion();
1507 } catch (final InterruptedException e
) {
1510 synchronized (fFilterSyncObj
) {
1511 fFilterThread
= null;
1512 if (fFilterThreadResume
) {
1513 fFilterThreadResume
= false;
1514 fFilterThread
= new FilterThread(filter
);
1515 fFilterThread
.start();
1521 * Refresh the filter.
1523 public void refreshTable() {
1524 synchronized (syncObj
) {
1526 refreshPending
= true;
1531 Display
.getDefault().asyncExec(new Runnable() {
1534 if (request
.isCancelled()) {
1537 if (fTable
.isDisposed()) {
1540 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1542 synchronized (syncObj
) {
1543 refreshBusy
= false;
1544 if (refreshPending
) {
1545 refreshPending
= false;
1554 * Cancel this filtering thread.
1556 public void cancel() {
1557 if (request
!= null) {
1564 * Go to the next item of a search.
1566 protected void searchNext() {
1567 synchronized (fSearchSyncObj
) {
1568 if (fSearchThread
!= null) {
1571 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1572 if (searchFilter
== null) {
1575 final int selectionIndex
= fTable
.getSelectionIndex();
1577 if (selectionIndex
> 0) {
1578 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1580 // header row is selected, start at top event
1581 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1583 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1584 if (eventFilter
!= null) {
1585 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1587 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1588 fSearchThread
.schedule();
1593 * Go to the previous item of a search.
1595 protected void searchPrevious() {
1596 synchronized (fSearchSyncObj
) {
1597 if (fSearchThread
!= null) {
1600 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1601 if (searchFilter
== null) {
1604 final int selectionIndex
= fTable
.getSelectionIndex();
1606 if (selectionIndex
> 0) {
1607 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1609 // header row is selected, start at precedent of top event
1610 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1612 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1613 if (eventFilter
!= null) {
1614 startIndex
= startIndex
- 1; // -1 for top filter status row
1616 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1617 fSearchThread
.schedule();
1622 * Stop the search thread.
1624 protected void stopSearchThread() {
1625 fPendingGotoRank
= -1;
1626 synchronized (fSearchSyncObj
) {
1627 if (fSearchThread
!= null) {
1628 fSearchThread
.cancel();
1629 fSearchThread
= null;
1635 * Wrapper for the search thread.
1637 protected class SearchThread
extends Job
{
1639 private ITmfFilterTreeNode searchFilter
;
1640 private ITmfFilterTreeNode eventFilter
;
1641 private int startIndex
;
1642 private int direction
;
1644 private long foundRank
= -1;
1645 private TmfEventRequest request
;
1646 private ITmfTimestamp foundTimestamp
= null;
1651 * @param searchFilter
1653 * @param eventFilter
1656 * The index at which we should start searching
1657 * @param currentRank
1660 * In which direction should we search, forward or backwards
1662 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1663 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1664 final long currentRank
, final int direction
) {
1665 super(Messages
.TmfEventsTable_SearchingJobName
);
1666 this.searchFilter
= searchFilter
;
1667 this.eventFilter
= eventFilter
;
1668 this.startIndex
= startIndex
;
1669 this.rank
= currentRank
;
1670 this.direction
= direction
;
1674 protected IStatus
run(final IProgressMonitor monitor
) {
1675 if (fTrace
== null) {
1676 return Status
.OK_STATUS
;
1678 final Display display
= Display
.getDefault();
1679 if (startIndex
< 0) {
1680 rank
= (int) fTrace
.getNbEvents() - 1;
1681 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1684 int idx
= startIndex
;
1685 while (foundRank
== -1) {
1686 final CachedEvent event
= fCache
.peekEvent(idx
);
1687 if (event
== null) {
1691 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1692 foundRank
= event
.rank
;
1693 foundTimestamp
= event
.event
.getTimestamp();
1696 if (direction
== Direction
.FORWARD
) {
1702 if (foundRank
== -1) {
1703 if (direction
== Direction
.FORWARD
) {
1705 if (rank
> (fTrace
.getNbEvents() - 1)) {
1711 rank
= (int) fTrace
.getNbEvents() - 1;
1716 final int startRank
= (int) rank
;
1717 boolean wrapped
= false;
1718 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1719 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1720 if (direction
== Direction
.BACKWARD
) {
1721 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1723 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1724 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1725 long currentRank
= rank
;
1728 public void handleData(final ITmfEvent event
) {
1729 super.handleData(event
);
1730 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1731 foundRank
= currentRank
;
1732 foundTimestamp
= event
.getTimestamp();
1733 if (direction
== Direction
.FORWARD
) {
1741 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1743 request
.waitForCompletion();
1744 if (request
.isCancelled()) {
1745 return Status
.OK_STATUS
;
1747 } catch (final InterruptedException e
) {
1748 synchronized (fSearchSyncObj
) {
1749 fSearchThread
= null;
1751 return Status
.OK_STATUS
;
1753 if (foundRank
== -1) {
1754 if (direction
== Direction
.FORWARD
) {
1756 synchronized (fSearchSyncObj
) {
1757 fSearchThread
= null;
1759 return Status
.OK_STATUS
;
1761 nbRequested
= (int) rank
;
1767 rank
= (int) fTrace
.getNbEvents() - 1;
1770 if ((rank
<= startRank
) && wrapped
) {
1771 synchronized (fSearchSyncObj
) {
1772 fSearchThread
= null;
1774 return Status
.OK_STATUS
;
1779 int index
= (int) foundRank
;
1780 if (eventFilter
!= null) {
1781 index
= fCache
.getFilteredEventIndex(foundRank
);
1783 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1785 display
.asyncExec(new Runnable() {
1788 if (monitor
.isCanceled()) {
1791 if (fTable
.isDisposed()) {
1794 fTable
.setSelection(selection
);
1795 fSelectedRank
= foundRank
;
1796 fRawViewer
.selectAndReveal(fSelectedRank
);
1797 if (foundTimestamp
!= null) {
1798 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1800 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1801 synchronized (fSearchSyncObj
) {
1802 fSearchThread
= null;
1804 updateStatusLine(null);
1807 return Status
.OK_STATUS
;
1811 protected void canceling() {
1813 synchronized (fSearchSyncObj
) {
1814 fSearchThread
= null;
1820 * Create the resources.
1822 protected void createResources() {
1823 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1824 .getForeground().getRGB()));
1825 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1826 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1832 protected void packColumns() {
1836 fTable
.setRedraw(false);
1838 boolean isLinux
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
1840 TableColumn tableColumns
[] = fTable
.getColumns();
1841 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1842 final TableColumn column
= tableColumns
[i
];
1843 final int headerWidth
= column
.getWidth();
1845 // Workaround for Linux which doesn't consider the image width of
1846 // search/filter row in TableColumn.pack() after having executed
1847 // TableItem.setImage((Image)null) for other rows than search/filter row.
1848 if (isLinux
&& (i
== 0)) {
1849 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1852 if (column
.getWidth() < headerWidth
) {
1853 column
.setWidth(headerWidth
);
1857 fTable
.setRedraw(true);
1862 * Get the contents of the row in the events table corresponding to an
1863 * event. The order of the elements corresponds to the order of the columns.
1865 * TODO Use column IDs, not indexes, so that the column order can be
1869 * The event printed in this row
1870 * @return The event row entries
1873 public String
[] getItemStrings(ITmfEvent event
) {
1874 if (event
== null) {
1875 return EMPTY_STRING_ARRAY
;
1877 return new String
[] {
1878 event
.getTimestamp().toString(),
1880 event
.getType().getName(),
1881 event
.getReference(),
1882 event
.getContent().toString()
1887 * Notify this table that is got the UI focus.
1889 public void setFocus() {
1894 * Assign a new trace to this event table.
1897 * The trace to assign to this event table
1898 * @param disposeOnClose
1899 * true if the trace should be disposed when the table is
1902 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1903 if ((fTrace
!= null) && fDisposeOnClose
) {
1909 fDisposeOnClose
= disposeOnClose
;
1911 // Perform the updates on the UI thread
1912 fTable
.getDisplay().syncExec(new Runnable() {
1916 fCache
.setTrace(fTrace
); // Clear the cache
1917 if (fTrace
!= null) {
1918 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1919 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1920 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1923 fFilterMatchCount
= 0;
1924 fFilterCheckCount
= 0;
1925 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1926 startFilterThread();
1930 fRawViewer
.setTrace(fTrace
);
1936 * Assign the status line manager
1938 * @param statusLineManager
1939 * The status line manager, or null to disable status line messages
1942 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
1943 if (fStatusLineManager
!= null && statusLineManager
== null) {
1944 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
1946 fStatusLineManager
= statusLineManager
;
1949 private void updateStatusLine(ITmfTimestamp delta
) {
1950 if (fStatusLineManager
!= null) {
1951 if (delta
!= null) {
1952 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
1954 fStatusLineManager
.setMessage(null);
1959 // ------------------------------------------------------------------------
1961 // ------------------------------------------------------------------------
1964 * Notify that the event cache has been updated
1967 * Also notify if the populating of the cache is complete, or
1970 public void cacheUpdated(final boolean completed
) {
1971 synchronized (fCacheUpdateSyncObj
) {
1972 if (fCacheUpdateBusy
) {
1973 fCacheUpdatePending
= true;
1974 fCacheUpdateCompleted
= completed
;
1977 fCacheUpdateBusy
= true;
1979 // Event cache is now updated. Perform update on the UI thread
1980 if (!fTable
.isDisposed()) {
1981 fTable
.getDisplay().asyncExec(new Runnable() {
1984 if (!fTable
.isDisposed()) {
1989 populateCompleted();
1991 synchronized (fCacheUpdateSyncObj
) {
1992 fCacheUpdateBusy
= false;
1993 if (fCacheUpdatePending
) {
1994 fCacheUpdatePending
= false;
1995 cacheUpdated(fCacheUpdateCompleted
);
2004 * Callback for when populating the table is complete.
2006 protected void populateCompleted() {
2007 // Nothing by default;
2010 // ------------------------------------------------------------------------
2011 // ISelectionProvider
2012 // ------------------------------------------------------------------------
2018 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2019 selectionChangedListeners
.add(listener
);
2026 public ISelection
getSelection() {
2027 if (fTable
== null || fTable
.isDisposed()) {
2028 return StructuredSelection
.EMPTY
;
2030 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2031 for (TableItem item
: fTable
.getSelection()) {
2032 if (item
.getData() != null) {
2033 list
.add(item
.getData());
2036 return new StructuredSelection(list
);
2043 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2044 selectionChangedListeners
.remove(listener
);
2051 public void setSelection(ISelection selection
) {
2056 * Notifies any selection changed listeners that the viewer's selection has changed.
2057 * Only listeners registered at the time this method is called are notified.
2059 * @param event a selection changed event
2061 * @see ISelectionChangedListener#selectionChanged
2064 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2065 Object
[] listeners
= selectionChangedListeners
.getListeners();
2066 for (int i
= 0; i
< listeners
.length
; ++i
) {
2067 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2068 SafeRunnable
.run(new SafeRunnable() {
2071 l
.selectionChanged(event
);
2077 // ------------------------------------------------------------------------
2078 // Bookmark handling
2079 // ------------------------------------------------------------------------
2082 * Add a bookmark to this event table.
2084 * @param bookmarksFile
2085 * The file to use for the bookmarks
2087 public void addBookmark(final IFile bookmarksFile
) {
2088 fBookmarksFile
= bookmarksFile
;
2089 final TableItem
[] selection
= fTable
.getSelection();
2090 if (selection
.length
> 0) {
2091 final TableItem tableItem
= selection
[0];
2092 if (tableItem
.getData(Key
.RANK
) != null) {
2093 final StringBuffer defaultMessage
= new StringBuffer();
2094 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2096 defaultMessage
.append(", "); //$NON-NLS-1$
2098 defaultMessage
.append(tableItem
.getText(i
));
2100 final InputDialog dialog
= new MultiLineInputDialog(
2101 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2102 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2103 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2104 defaultMessage
.toString());
2105 if (dialog
.open() == Window
.OK
) {
2106 final String message
= dialog
.getValue();
2108 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2109 if (bookmark
.exists()) {
2110 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2111 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2112 final int location
= rank
.intValue();
2113 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2114 fBookmarksMap
.put(rank
, bookmark
.getId());
2117 } catch (final CoreException e
) {
2118 displayException(e
);
2127 * Remove a bookmark from this event table.
2130 * The bookmark to remove
2132 public void removeBookmark(final IMarker bookmark
) {
2133 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2134 if (entry
.getValue().equals(bookmark
.getId())) {
2135 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2142 private void toggleBookmark(final Long rank
) {
2143 if (fBookmarksFile
== null) {
2146 if (fBookmarksMap
.containsKey(rank
)) {
2147 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2150 for (long markerId
: markerIds
) {
2151 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2152 if (bookmark
!= null) {
2156 } catch (final CoreException e
) {
2157 displayException(e
);
2160 addBookmark(fBookmarksFile
);
2165 * Refresh the bookmarks assigned to this trace, from the contents of a
2168 * @param bookmarksFile
2169 * The bookmark file to use
2171 public void refreshBookmarks(final IFile bookmarksFile
) {
2172 fBookmarksFile
= bookmarksFile
;
2173 if (bookmarksFile
== null) {
2174 fBookmarksMap
.clear();
2179 fBookmarksMap
.clear();
2180 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2181 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2182 if (location
!= -1) {
2183 final long rank
= location
;
2184 fBookmarksMap
.put(rank
, bookmark
.getId());
2188 } catch (final CoreException e
) {
2189 displayException(e
);
2194 public void gotoMarker(final IMarker marker
) {
2195 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2198 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2199 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2200 } else if (rank
>= fTable
.getItemCount()) {
2201 fPendingGotoRank
= rank
;
2203 fSelectedRank
= rank
;
2204 fTable
.setSelection(index
+ 1); // +1 for header row
2205 updateStatusLine(null);
2209 // ------------------------------------------------------------------------
2211 // ------------------------------------------------------------------------
2214 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2218 // ------------------------------------------------------------------------
2220 // ------------------------------------------------------------------------
2223 * Handler for the trace updated signal
2226 * The incoming signal
2229 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2230 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2233 // Perform the refresh on the UI thread
2234 Display
.getDefault().asyncExec(new Runnable() {
2237 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2238 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2239 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2240 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2241 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2242 fPendingGotoRank
= -1;
2243 updateStatusLine(null);
2246 startFilterThread();
2249 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2250 fRawViewer
.refreshEventCount();
2257 * Handler for the time synch signal.
2260 * The incoming signal
2263 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2264 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2266 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2267 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2268 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2269 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2270 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2272 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2275 public void handleData(final ITmfEvent event
) {
2276 super.handleData(event
);
2280 public void handleCompleted() {
2281 super.handleCompleted();
2282 if (fTrace
== null) {
2286 // Verify if the event is within the trace range and adjust if necessary
2287 ITmfTimestamp timestamp
= ts
;
2288 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2289 timestamp
= fTrace
.getStartTime();
2291 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2292 timestamp
= fTrace
.getEndTime();
2295 // Get the rank of the selected event in the table
2296 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2297 final long rank
= context
.getRank();
2299 fSelectedRank
= rank
;
2301 fTable
.getDisplay().asyncExec(new Runnable() {
2304 // Return if table is disposed
2305 if (fTable
.isDisposed()) {
2309 int index
= (int) rank
;
2310 if (fTable
.isDisposed()) {
2313 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2314 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2316 fTable
.setSelection(index
+ 1); // +1 for header row
2317 fRawViewer
.selectAndReveal(rank
);
2318 updateStatusLine(null);
2324 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2328 // ------------------------------------------------------------------------
2330 // ------------------------------------------------------------------------
2333 * Display an exception in a message box
2335 * @param e the exception
2337 private static void displayException(final Exception e
) {
2338 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2339 mb
.setText(e
.getClass().getSimpleName());
2340 mb
.setMessage(e
.getMessage());
2347 public void refresh() {