1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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
.HashMap
;
24 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
.jface
.action
.Action
;
53 import org
.eclipse
.jface
.action
.IAction
;
54 import org
.eclipse
.jface
.action
.IMenuListener
;
55 import org
.eclipse
.jface
.action
.IMenuManager
;
56 import org
.eclipse
.jface
.action
.IStatusLineManager
;
57 import org
.eclipse
.jface
.action
.MenuManager
;
58 import org
.eclipse
.jface
.action
.Separator
;
59 import org
.eclipse
.jface
.dialogs
.InputDialog
;
60 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
61 import org
.eclipse
.jface
.resource
.FontDescriptor
;
62 import org
.eclipse
.jface
.resource
.JFaceResources
;
63 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
64 import org
.eclipse
.jface
.util
.OpenStrategy
;
65 import org
.eclipse
.jface
.util
.SafeRunnable
;
66 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
67 import org
.eclipse
.jface
.viewers
.ISelection
;
68 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
69 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
70 import org
.eclipse
.jface
.viewers
.LabelProvider
;
71 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
72 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
73 import org
.eclipse
.jface
.window
.Window
;
74 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
75 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
76 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
77 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
78 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfEventProvider
;
79 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
80 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
81 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
82 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
83 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfCallsite
;
84 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
85 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
86 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
87 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
88 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
89 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
90 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
91 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
92 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
93 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
94 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
95 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
96 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
97 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
98 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
99 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
100 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
101 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
102 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
103 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
104 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
105 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSetting
;
106 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
107 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
108 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
109 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
110 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
;
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
;
152 * The generic TMF Events table
154 * This is a view that will list events that are read from a trace.
157 * @author Francois Chouinard
158 * @author Patrick Tasse
161 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
163 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
164 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
165 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
166 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
167 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
168 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
169 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
170 private static final Image FILTER_IMAGE
= Activator
.getDefault()
171 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
172 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
173 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
174 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
175 private static final int MAX_CACHE_SIZE
= 1000;
177 * Empty ITmfEventField array, used by {@link #extractItemFields(ITmfEvent)}
180 public static final ITmfEventField
[] EMPTY_FIELD_ARRAY
= new TmfEventField
[0];
183 * The events table search/filter keys
186 * @author Patrick Tasse
188 public interface Key
{
190 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
193 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
196 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
199 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
202 String TIMESTAMP
= "$time"; //$NON-NLS-1$
205 String RANK
= "$rank"; //$NON-NLS-1$
208 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
210 /** Bookmark indicator */
211 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
215 * The events table search/filter state
218 * @author Patrick Tasse
220 public static enum HeaderState
{
221 /** A search is being run */
224 /** A filter is applied */
228 interface Direction
{
233 // ------------------------------------------------------------------------
235 // ------------------------------------------------------------------------
237 /** The virtual event table */
238 protected TmfVirtualTable fTable
;
240 private Composite fComposite
;
241 private SashForm fSashForm
;
242 private TmfRawEventViewer fRawViewer
;
243 private ITmfTrace fTrace
;
244 private boolean fPackDone
= false;
245 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
246 private long fSelectedRank
= 0;
247 private ITmfTimestamp fSelectedBeginTimestamp
= null;
248 private IStatusLineManager fStatusLineManager
= null;
251 private long fFilterMatchCount
;
252 private long fFilterCheckCount
;
253 private FilterThread fFilterThread
;
254 private boolean fFilterThreadResume
= false;
255 private final Object fFilterSyncObj
= new Object();
256 private SearchThread fSearchThread
;
257 private final Object fSearchSyncObj
= new Object();
260 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
262 * @see #fireSelectionChanged
264 private ListenerList selectionChangedListeners
= new ListenerList();
266 // Bookmark map <Rank, MarkerId>
267 private Map
<Long
, Long
> fBookmarksMap
= new HashMap
<>();
268 private IFile fBookmarksFile
;
269 private long fPendingGotoRank
= -1;
272 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
273 private Color fGrayColor
;
274 private Color fGreenColor
;
275 private Font fBoldFont
;
277 // Table column names
278 private static final String
[] COLUMN_NAMES
= new String
[] { Messages
.TmfEventsTable_TimestampColumnHeader
,
279 Messages
.TmfEventsTable_SourceColumnHeader
, Messages
.TmfEventsTable_TypeColumnHeader
,
280 Messages
.TmfEventsTable_ReferenceColumnHeader
, Messages
.TmfEventsTable_ContentColumnHeader
};
282 private static final ColumnData
[] COLUMN_DATA
= new ColumnData
[] { new ColumnData(COLUMN_NAMES
[0], 100, SWT
.LEFT
),
283 new ColumnData(COLUMN_NAMES
[1], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[2], 100, SWT
.LEFT
),
284 new ColumnData(COLUMN_NAMES
[3], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[4], 100, SWT
.LEFT
) };
287 private final TmfEventsCache fCache
;
288 private boolean fCacheUpdateBusy
= false;
289 private boolean fCacheUpdatePending
= false;
290 private boolean fCacheUpdateCompleted
= false;
291 private final Object fCacheUpdateSyncObj
= new Object();
293 private boolean fDisposeOnClose
;
295 // ------------------------------------------------------------------------
297 // ------------------------------------------------------------------------
300 * Basic constructor, will use default column data.
303 * The parent composite UI object
305 * The size of the event table cache
307 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
308 this(parent
, cacheSize
, COLUMN_DATA
);
312 * Advanced constructor, where we also define which column data to use.
315 * The parent composite UI object
317 * The size of the event table cache
319 * The column data to use for this table
321 public TmfEventsTable(final Composite parent
, int cacheSize
, final ColumnData
[] columnData
) {
322 super("TmfEventsTable"); //$NON-NLS-1$
324 fComposite
= new Composite(parent
, SWT
.NONE
);
325 final GridLayout gl
= new GridLayout(1, false);
328 gl
.verticalSpacing
= 0;
329 fComposite
.setLayout(gl
);
331 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
332 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
334 // Create a virtual table
335 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
336 fTable
= new TmfVirtualTable(fSashForm
, style
);
338 // Set the table layout
339 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
340 fTable
.setLayoutData(layoutData
);
342 // Some cosmetic enhancements
343 fTable
.setHeaderVisible(true);
344 fTable
.setLinesVisible(true);
347 setColumnHeaders(columnData
);
349 // Set the default column field ids if this is not a subclass
350 if (Arrays
.equals(columnData
, COLUMN_DATA
)) {
351 fTable
.getColumns()[0].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
352 fTable
.getColumns()[1].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_SOURCE
);
353 fTable
.getColumns()[2].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TYPE
);
354 fTable
.getColumns()[3].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_REFERENCE
);
355 fTable
.getColumns()[4].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_CONTENT
);
358 // Set the frozen row for header row
359 fTable
.setFrozenRowCount(1);
361 // Create the header row cell editor
362 createHeaderEditor();
364 // Handle the table item selection
365 fTable
.addSelectionListener(new SelectionAdapter() {
367 public void widgetSelected(final SelectionEvent e
) {
368 if (e
.item
== null) {
371 updateStatusLine(null);
372 if (fTable
.getSelectionIndices().length
> 0) {
373 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
374 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
375 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
377 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
378 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
379 if (fTable
.getSelectionIndices().length
== 1) {
380 fSelectedBeginTimestamp
= ts
;
382 if (fSelectedBeginTimestamp
!= null) {
383 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
384 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
385 if (fTable
.getSelectionIndices().length
== 2) {
386 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
389 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
390 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
394 if (fTable
.getSelectionIndices().length
== 1) {
395 fSelectedBeginTimestamp
= null;
399 if (e
.item
.getData() != null) {
400 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
402 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
407 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
408 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
409 fCache
= new TmfEventsCache(realCacheSize
, this);
411 // Handle the table item requests
412 fTable
.addListener(SWT
.SetData
, new Listener() {
415 public void handleEvent(final Event event
) {
417 final TableItem item
= (TableItem
) event
.item
;
418 int index
= event
.index
- 1; // -1 for the header row
420 if (event
.index
== 0) {
421 setHeaderRowItemData(item
);
425 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
426 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
427 setFilterStatusRowItemData(item
);
430 index
= index
- 1; // -1 for top filter status row
433 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
434 if (cachedEvent
!= null) {
435 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
439 // Else, fill the cache asynchronously (and off the UI thread)
444 fTable
.addMouseListener(new MouseAdapter() {
446 public void mouseDoubleClick(final MouseEvent event
) {
447 if (event
.button
!= 1) {
450 // Identify the selected row
451 final Point point
= new Point(event
.x
, event
.y
);
452 final TableItem item
= fTable
.getItem(point
);
454 final Rectangle imageBounds
= item
.getImageBounds(0);
455 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
456 if (imageBounds
.contains(point
)) {
457 final Long rank
= (Long
) item
.getData(Key
.RANK
);
459 toggleBookmark(rank
);
466 final Listener tooltipListener
= new Listener () {
467 Shell tooltipShell
= null;
469 public void handleEvent(final Event event
) {
470 switch (event
.type
) {
472 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
476 final Long rank
= (Long
) item
.getData(Key
.RANK
);
480 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
481 final Rectangle bounds
= item
.getImageBounds(0);
482 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
483 if (!bounds
.contains(event
.x
,event
.y
)) {
486 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
487 tooltipShell
.dispose();
489 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
490 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
491 final FillLayout layout
= new FillLayout();
492 layout
.marginWidth
= 2;
493 tooltipShell
.setLayout(layout
);
494 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
495 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: ""); //$NON-NLS-1$ //$NON-NLS-2$
496 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
497 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
499 label
.addListener(SWT
.MouseExit
, this);
500 label
.addListener(SWT
.MouseDown
, this);
501 label
.addListener(SWT
.MouseWheel
, this);
502 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
504 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
505 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
508 if (System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
509 y
+= fTable
.getHeaderHeight();
511 Point pt
= fTable
.toDisplay(event
.x
, y
);
512 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
513 pt
.y
+= item
.getBounds().height
;
514 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
515 tooltipShell
.setVisible(true);
523 if (tooltipShell
!= null) {
524 tooltipShell
.dispose();
534 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
535 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
536 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
537 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
538 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
539 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
540 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
545 ColorSettingsManager
.addColorSettingsListener(this);
547 fTable
.setItemCount(1); // +1 for header row
549 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
551 fRawViewer
.addSelectionListener(new Listener() {
553 public void handleEvent(final Event e
) {
554 if (e
.data
instanceof Long
) {
555 final long rank
= (Long
) e
.data
;
556 int index
= (int) rank
;
557 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
558 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
560 fTable
.setSelection(index
+ 1); // +1 for header row
561 fSelectedRank
= rank
;
562 updateStatusLine(null);
563 } else if (e
.data
instanceof ITmfLocation
) {
564 // DOES NOT WORK: rank undefined in context from seekLocation()
565 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
566 // TmfContext context = fTrace.seekLocation(location);
567 // fTable.setSelection((int) context.getRank());
572 final TableItem
[] selection
= fTable
.getSelection();
573 if ((selection
!= null) && (selection
.length
> 0)) {
574 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
576 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
582 fSashForm
.setWeights(new int[] { 1, 1 });
583 fRawViewer
.setVisible(false);
589 * Create a pop-up menu.
591 protected void createPopupMenu() {
592 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
595 fTable
.setVisible(true);
600 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
603 fTable
.setVisible(false);
608 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
611 fRawViewer
.setVisible(true);
613 final int index
= fTable
.getSelectionIndex();
615 fRawViewer
.selectAndReveal(index
- 1);
620 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
623 fRawViewer
.setVisible(false);
628 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
631 final TableItem items
[] = fTable
.getSelection();
632 if (items
.length
!= 1) {
635 final TableItem item
= items
[0];
637 final Object data
= item
.getData();
638 if (data
instanceof ITmfSourceLookup
) {
639 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
640 ITmfCallsite cs
= event
.getCallsite();
641 if (cs
== null || cs
.getFileName() == null) {
644 IMarker marker
= null;
646 String fileName
= cs
.getFileName();
647 final String trimmedPath
= fileName
.replaceAll("\\.\\./", ""); //$NON-NLS-1$ //$NON-NLS-2$
648 final ArrayList
<IFile
> files
= new ArrayList
<>();
649 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
651 public boolean visit(IResource resource
) throws CoreException
{
652 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
653 files
.add((IFile
) resource
);
659 if (files
.size() > 1) {
660 ListDialog dialog
= new ListDialog(getTable().getShell());
661 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
662 dialog
.setLabelProvider(new LabelProvider() {
664 public String
getText(Object element
) {
665 return ((IFile
) element
).getFullPath().toString();
668 dialog
.setInput(files
);
669 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
670 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
672 Object
[] result
= dialog
.getResult();
673 if (result
!= null && result
.length
> 0) {
674 file
= (IFile
) result
[0];
676 } else if (files
.size() == 1) {
680 marker
= file
.createMarker(IMarker
.MARKER
);
681 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
682 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
684 } else if (files
.size() == 0){
685 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
687 } catch (CoreException e
) {
694 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
698 final TableItem items
[] = fTable
.getSelection();
699 if (items
.length
!= 1) {
702 final TableItem item
= items
[0];
704 final Object eventData
= item
.getData();
705 if (eventData
instanceof ITmfModelLookup
) {
706 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
708 if (modelURI
!= null) {
709 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
712 final URI uri
= URI
.createURI(modelURI
);
713 if (uri
.isPlatformResource()) {
714 IPath path
= new Path(uri
.toPlatformString(true));
715 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
716 } else if (uri
.isFile() && !uri
.isRelative()) {
717 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
718 new Path(uri
.toFileString()));
724 * create a temporary validation marker on the
725 * model file, remove it afterwards thus,
726 * navigation works with all model editors
727 * supporting the navigation to a marker
729 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
730 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
731 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
733 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
736 catch (CoreException e
) {
740 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
747 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
750 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
751 IHandlerService handlerService
= (IHandlerService
) activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
752 ICommandService cmdService
= (ICommandService
) activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
754 HashMap
<String
, Object
> parameters
= new HashMap
<>();
755 StringBuilder header
= new StringBuilder();
756 boolean needTab
= false;
757 for (TableColumn tc
: fTable
.getColumns()) {
761 header
.append(tc
.getText());
764 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
765 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
,parameters
);
766 IEvaluationContext context
= handlerService
.getCurrentState();
767 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_HEADER_ID
, header
.toString());
768 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_PARAMETER_ID
, TmfEventsTable
.this);
769 handlerService
.executeCommandInContext(cmd
, null, context
);
770 } catch (ExecutionException e
) {
772 } catch (NotDefinedException e
) {
774 } catch (NotEnabledException e
) {
776 } catch (NotHandledException e
) {
782 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
785 fHeaderState
= HeaderState
.SEARCH
;
790 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
793 fHeaderState
= HeaderState
.FILTER
;
798 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
805 class ToggleBookmarkAction
extends Action
{
808 public ToggleBookmarkAction(final String text
, final Long rank
) {
815 toggleBookmark(fRank
);
819 final MenuManager tablePopupMenu
= new MenuManager();
820 tablePopupMenu
.setRemoveAllWhenShown(true);
821 tablePopupMenu
.addMenuListener(new IMenuListener() {
823 public void menuAboutToShow(final IMenuManager manager
) {
824 if (fTable
.getSelectionIndex() == 0) {
825 // Right-click on header row
826 if (fHeaderState
== HeaderState
.FILTER
) {
827 tablePopupMenu
.add(showSearchBarAction
);
829 tablePopupMenu
.add(showFilterBarAction
);
833 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
834 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
836 final Rectangle imageBounds
= item
.getImageBounds(0);
837 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
838 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
839 // Right-click on left margin
840 final Long rank
= (Long
) item
.getData(Key
.RANK
);
841 if ((rank
!= null) && (fBookmarksFile
!= null)) {
842 if (fBookmarksMap
.containsKey(rank
)) {
843 tablePopupMenu
.add(new ToggleBookmarkAction(
844 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
846 tablePopupMenu
.add(new ToggleBookmarkAction(
847 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
854 // Right-click on table
855 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
856 tablePopupMenu
.add(hideTableAction
);
857 tablePopupMenu
.add(hideRawAction
);
858 } else if (!fTable
.isVisible()) {
859 tablePopupMenu
.add(showTableAction
);
860 } else if (!fRawViewer
.isVisible()) {
861 tablePopupMenu
.add(showRawAction
);
863 tablePopupMenu
.add(exportToTextAction
);
864 tablePopupMenu
.add(new Separator());
867 final Object data
= item
.getData();
868 Separator separator
= null;
869 if (data
instanceof ITmfSourceLookup
) {
870 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
871 if (event
.getCallsite() != null) {
872 tablePopupMenu
.add(openCallsiteAction
);
873 separator
= new Separator();
877 if (data
instanceof ITmfModelLookup
) {
878 ITmfModelLookup event
= (ITmfModelLookup
) data
;
879 if (event
.getModelUri() != null) {
880 tablePopupMenu
.add(openModelAction
);
881 separator
= new Separator();
884 if (separator
!= null) {
885 tablePopupMenu
.add(separator
);
890 tablePopupMenu
.add(clearFiltersAction
);
891 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
892 if (savedFilters
.length
> 0) {
893 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
894 for (final ITmfFilterTreeNode node
: savedFilters
) {
895 if (node
instanceof TmfFilterNode
) {
896 final TmfFilterNode filter
= (TmfFilterNode
) node
;
897 subMenu
.add(new Action(filter
.getFilterName()) {
905 tablePopupMenu
.add(subMenu
);
907 appendToTablePopupMenu(tablePopupMenu
, item
);
911 final MenuManager rawViewerPopupMenu
= new MenuManager();
912 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
913 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
915 public void menuAboutToShow(final IMenuManager manager
) {
916 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
917 rawViewerPopupMenu
.add(hideTableAction
);
918 rawViewerPopupMenu
.add(hideRawAction
);
919 } else if (!fTable
.isVisible()) {
920 rawViewerPopupMenu
.add(showTableAction
);
921 } else if (!fRawViewer
.isVisible()) {
922 rawViewerPopupMenu
.add(showRawAction
);
924 appendToRawPopupMenu(tablePopupMenu
);
928 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
929 fTable
.setMenu(menu
);
931 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
932 fRawViewer
.setMenu(menu
);
937 * Append an item to the event table's pop-up menu.
939 * @param tablePopupMenu
941 * @param selectedItem
944 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
945 // override to append more actions
949 * Append an item to the raw viewer's pop-up menu.
951 * @param rawViewerPopupMenu
954 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
955 // override to append more actions
959 public void dispose() {
962 ColorSettingsManager
.removeColorSettingsListener(this);
963 fComposite
.dispose();
964 if ((fTrace
!= null) && fDisposeOnClose
) {
967 fResourceManager
.dispose();
972 * Assign a layout data object to this view.
975 * The layout data to assign
977 public void setLayoutData(final Object layoutData
) {
978 fComposite
.setLayoutData(layoutData
);
982 * Get the virtual table contained in this event table.
984 * @return The TMF virtual table
986 public TmfVirtualTable
getTable() {
993 * FIXME: Add support for column selection
995 protected void setColumnHeaders(final ColumnData
[] columnData
) {
996 fTable
.setColumnHeaders(columnData
);
1000 * Set a table item's data.
1005 * Which trace event to link with this entry
1007 * Which rank this event has in the trace/experiment
1009 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1010 final ITmfEventField
[] fields
= extractItemFields(event
);
1011 final String
[] content
= new String
[fields
.length
];
1012 for (int i
= 0; i
< fields
.length
; i
++) {
1013 content
[i
] = fields
[i
].getValue() != null ? fields
[i
].getValue().toString() : ""; //$NON-NLS-1$
1015 item
.setText(content
);
1016 item
.setData(event
);
1017 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1018 item
.setData(Key
.RANK
, rank
);
1020 boolean bookmark
= false;
1021 final Long markerId
= fBookmarksMap
.get(rank
);
1022 if (markerId
!= null) {
1025 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1026 item
.setData(Key
.BOOKMARK
, marker
.getAttribute(IMarker
.MESSAGE
));
1027 } catch (final CoreException e
) {
1028 displayException(e
);
1031 item
.setData(Key
.BOOKMARK
, null);
1034 boolean searchMatch
= false;
1035 boolean searchNoMatch
= false;
1036 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1037 if (searchFilter
!= null) {
1038 if (searchFilter
.matches(event
)) {
1041 searchNoMatch
= true;
1045 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1046 if (searchNoMatch
) {
1047 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1048 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1050 item
.setForeground(colorSetting
.getForegroundColor());
1051 item
.setBackground(colorSetting
.getBackgroundColor());
1056 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1058 item
.setImage(SEARCH_MATCH_IMAGE
);
1060 } else if (bookmark
) {
1061 item
.setImage(BOOKMARK_IMAGE
);
1063 item
.setImage((Image
) null);
1068 * Set the item data of the header row.
1071 * The item to use as table header
1073 protected void setHeaderRowItemData(final TableItem item
) {
1074 String txtKey
= null;
1075 if (fHeaderState
== HeaderState
.SEARCH
) {
1076 item
.setImage(SEARCH_IMAGE
);
1077 txtKey
= Key
.SEARCH_TXT
;
1078 } else if (fHeaderState
== HeaderState
.FILTER
) {
1079 item
.setImage(FILTER_IMAGE
);
1080 txtKey
= Key
.FILTER_TXT
;
1082 item
.setForeground(fGrayColor
);
1083 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1084 final TableColumn column
= fTable
.getColumns()[i
];
1085 final String filter
= (String
) column
.getData(txtKey
);
1086 if (filter
== null) {
1087 if (fHeaderState
== HeaderState
.SEARCH
) {
1088 item
.setText(i
, SEARCH_HINT
);
1089 } else if (fHeaderState
== HeaderState
.FILTER
) {
1090 item
.setText(i
, FILTER_HINT
);
1092 item
.setForeground(i
, fGrayColor
);
1093 item
.setFont(i
, fTable
.getFont());
1095 item
.setText(i
, filter
);
1096 item
.setForeground(i
, fGreenColor
);
1097 item
.setFont(i
, fBoldFont
);
1103 * Set the item data of the "filter status" row.
1106 * The item to use as filter status row
1108 protected void setFilterStatusRowItemData(final TableItem item
) {
1109 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1111 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1112 item
.setImage(FILTER_IMAGE
);
1114 item
.setImage(STOP_IMAGE
);
1116 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1118 item
.setText(i
, ""); //$NON-NLS-1$
1122 item
.setData(Key
.TIMESTAMP
, null);
1123 item
.setData(Key
.RANK
, null);
1124 item
.setForeground(null);
1125 item
.setBackground(null);
1129 * Create an editor for the header.
1131 protected void createHeaderEditor() {
1132 final TableEditor tableEditor
= fTable
.createTableEditor();
1133 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1134 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1135 tableEditor
.grabHorizontal
= true;
1136 tableEditor
.minimumWidth
= 50;
1138 // Handle the header row selection
1139 fTable
.addMouseListener(new MouseAdapter() {
1145 public void mouseDown(final MouseEvent event
) {
1146 if (event
.button
!= 1) {
1149 // Identify the selected row
1150 final Point point
= new Point(event
.x
, event
.y
);
1151 item
= fTable
.getItem(point
);
1153 // Header row selected
1154 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1157 if (item
.getImageBounds(0).contains(point
)) {
1158 if (fHeaderState
== HeaderState
.SEARCH
) {
1159 fHeaderState
= HeaderState
.FILTER
;
1160 } else if (fHeaderState
== HeaderState
.FILTER
) {
1161 fHeaderState
= HeaderState
.SEARCH
;
1163 fTable
.setSelection(0);
1168 // Identify the selected column
1170 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1171 final Rectangle rect
= item
.getBounds(i
);
1172 if (rect
.contains(point
)) {
1178 if (columnIndex
== -1) {
1182 column
= fTable
.getColumns()[columnIndex
];
1184 String txtKey
= null;
1185 if (fHeaderState
== HeaderState
.SEARCH
) {
1186 txtKey
= Key
.SEARCH_TXT
;
1187 } else if (fHeaderState
== HeaderState
.FILTER
) {
1188 txtKey
= Key
.FILTER_TXT
;
1191 // The control that will be the editor must be a child of the Table
1192 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1193 final String headerString
= (String
) column
.getData(txtKey
);
1194 if (headerString
!= null) {
1195 newEditor
.setText(headerString
);
1197 newEditor
.addFocusListener(new FocusAdapter() {
1199 public void focusLost(final FocusEvent e
) {
1200 final boolean changed
= updateHeader(newEditor
.getText());
1206 newEditor
.addKeyListener(new KeyAdapter() {
1208 public void keyPressed(final KeyEvent e
) {
1209 if (e
.character
== SWT
.CR
) {
1210 updateHeader(newEditor
.getText());
1212 } else if (e
.character
== SWT
.ESC
) {
1213 tableEditor
.getEditor().dispose();
1217 newEditor
.selectAll();
1218 newEditor
.setFocus();
1219 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1224 * returns true is value was changed
1226 private boolean updateHeader(final String text
) {
1227 String objKey
= null;
1228 String txtKey
= null;
1229 if (fHeaderState
== HeaderState
.SEARCH
) {
1230 objKey
= Key
.SEARCH_OBJ
;
1231 txtKey
= Key
.SEARCH_TXT
;
1232 } else if (fHeaderState
== HeaderState
.FILTER
) {
1233 objKey
= Key
.FILTER_OBJ
;
1234 txtKey
= Key
.FILTER_TXT
;
1236 if (text
.trim().length() > 0) {
1238 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1239 Pattern
.compile(regex
);
1240 if (regex
.equals(column
.getData(txtKey
))) {
1241 tableEditor
.getEditor().dispose();
1244 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1245 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1246 if (fieldId
== null) {
1247 fieldId
= column
.getText();
1249 filter
.setField(fieldId
);
1250 filter
.setRegex(regex
);
1251 column
.setData(objKey
, filter
);
1252 column
.setData(txtKey
, regex
);
1253 } catch (final PatternSyntaxException ex
) {
1254 tableEditor
.getEditor().dispose();
1255 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1256 ex
.getDescription(), ex
.getMessage());
1260 if (column
.getData(txtKey
) == null) {
1261 tableEditor
.getEditor().dispose();
1264 column
.setData(objKey
, null);
1265 column
.setData(txtKey
, null);
1270 private void applyHeader() {
1271 if (fHeaderState
== HeaderState
.SEARCH
) {
1273 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1274 for (final TableColumn col
: fTable
.getColumns()) {
1275 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1276 if (filterObj
instanceof ITmfFilterTreeNode
) {
1277 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1280 if (filter
.getChildrenCount() > 0) {
1281 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1284 fireSearchApplied(filter
);
1286 fTable
.setData(Key
.SEARCH_OBJ
, null);
1288 fireSearchApplied(null);
1290 } else if (fHeaderState
== HeaderState
.FILTER
) {
1291 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1292 for (final TableColumn col
: fTable
.getColumns()) {
1293 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1294 if (filterObj
instanceof ITmfFilterTreeNode
) {
1295 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1298 if (filter
.getChildrenCount() > 0) {
1299 applyFilter(filter
);
1305 tableEditor
.getEditor().dispose();
1309 fTable
.addKeyListener(new KeyAdapter() {
1311 public void keyPressed(final KeyEvent e
) {
1313 if (e
.character
== SWT
.ESC
) {
1317 } else if (e
.character
== SWT
.DEL
) {
1318 if (fHeaderState
== HeaderState
.SEARCH
) {
1320 for (final TableColumn column
: fTable
.getColumns()) {
1321 column
.setData(Key
.SEARCH_OBJ
, null);
1322 column
.setData(Key
.SEARCH_TXT
, null);
1324 fTable
.setData(Key
.SEARCH_OBJ
, null);
1326 fireSearchApplied(null);
1327 } else if (fHeaderState
== HeaderState
.FILTER
) {
1330 } else if (e
.character
== SWT
.CR
) {
1331 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1342 * Send an event indicating a filter has been applied.
1345 * The filter that was just applied
1347 protected void fireFilterApplied(final ITmfFilter filter
) {
1348 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1352 * Send an event indicating that a search has been applied.
1355 * The search filter that was just applied
1357 protected void fireSearchApplied(final ITmfFilter filter
) {
1358 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1362 * Start the filtering thread.
1364 protected void startFilterThread() {
1365 synchronized (fFilterSyncObj
) {
1366 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1367 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1368 if (fFilterThread
!= null) {
1369 fFilterThread
.cancel();
1370 fFilterThreadResume
= false;
1372 fFilterThread
= new FilterThread(filter
);
1373 fFilterThread
.start();
1375 fFilterThreadResume
= true;
1381 * Stop the filtering thread.
1383 protected void stopFilterThread() {
1384 synchronized (fFilterSyncObj
) {
1385 if (fFilterThread
!= null) {
1386 fFilterThread
.cancel();
1387 fFilterThread
= null;
1388 fFilterThreadResume
= false;
1397 * The filter to apply
1400 protected void applyFilter(ITmfFilter filter
) {
1403 fFilterMatchCount
= 0;
1404 fFilterCheckCount
= 0;
1405 fCache
.applyFilter(filter
);
1407 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1408 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1409 startFilterThread();
1410 fireFilterApplied(filter
);
1414 * Clear all currently active filters.
1416 protected void clearFilters() {
1417 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1422 fCache
.clearFilter();
1424 for (final TableColumn column
: fTable
.getColumns()) {
1425 column
.setData(Key
.FILTER_OBJ
, null);
1426 column
.setData(Key
.FILTER_TXT
, null);
1428 fTable
.setData(Key
.FILTER_OBJ
, null);
1429 if (fTrace
!= null) {
1430 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1432 fTable
.setItemCount(1); // +1 for header row
1434 fFilterMatchCount
= 0;
1435 fFilterCheckCount
= 0;
1436 if (fSelectedRank
>= 0) {
1437 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1439 fTable
.setSelection(0);
1441 fireFilterApplied(null);
1442 updateStatusLine(null);
1446 * Wrapper Thread object for the filtering thread.
1448 protected class FilterThread
extends Thread
{
1449 private final ITmfFilterTreeNode filter
;
1450 private TmfEventRequest request
;
1451 private boolean refreshBusy
= false;
1452 private boolean refreshPending
= false;
1453 private final Object syncObj
= new Object();
1459 * The filter this thread will be processing
1461 public FilterThread(final ITmfFilterTreeNode filter
) {
1462 super("Filter Thread"); //$NON-NLS-1$
1463 this.filter
= filter
;
1468 if (fTrace
== null) {
1471 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1472 if (nbRequested
<= 0) {
1475 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1476 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1478 public void handleData(final ITmfEvent event
) {
1479 super.handleData(event
);
1480 if (request
.isCancelled()) {
1483 if (filter
.matches(event
)) {
1484 final long rank
= fFilterCheckCount
;
1485 final int index
= (int) fFilterMatchCount
;
1486 fFilterMatchCount
++;
1487 fCache
.storeEvent(event
, rank
, index
);
1489 } else if ((fFilterCheckCount
% 100) == 0) {
1492 fFilterCheckCount
++;
1495 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1497 request
.waitForCompletion();
1498 } catch (final InterruptedException e
) {
1501 synchronized (fFilterSyncObj
) {
1502 fFilterThread
= null;
1503 if (fFilterThreadResume
) {
1504 fFilterThreadResume
= false;
1505 fFilterThread
= new FilterThread(filter
);
1506 fFilterThread
.start();
1512 * Refresh the filter.
1514 public void refreshTable() {
1515 synchronized (syncObj
) {
1517 refreshPending
= true;
1522 Display
.getDefault().asyncExec(new Runnable() {
1525 if (request
.isCancelled()) {
1528 if (fTable
.isDisposed()) {
1531 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1533 synchronized (syncObj
) {
1534 refreshBusy
= false;
1535 if (refreshPending
) {
1536 refreshPending
= false;
1545 * Cancel this filtering thread.
1547 public void cancel() {
1548 if (request
!= null) {
1555 * Go to the next item of a search.
1557 protected void searchNext() {
1558 synchronized (fSearchSyncObj
) {
1559 if (fSearchThread
!= null) {
1562 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1563 if (searchFilter
== null) {
1566 final int selectionIndex
= fTable
.getSelectionIndex();
1568 if (selectionIndex
> 0) {
1569 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1571 // header row is selected, start at top event
1572 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1574 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1575 if (eventFilter
!= null) {
1576 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1578 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1579 fSearchThread
.schedule();
1584 * Go to the previous item of a search.
1586 protected void searchPrevious() {
1587 synchronized (fSearchSyncObj
) {
1588 if (fSearchThread
!= null) {
1591 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1592 if (searchFilter
== null) {
1595 final int selectionIndex
= fTable
.getSelectionIndex();
1597 if (selectionIndex
> 0) {
1598 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1600 // header row is selected, start at precedent of top event
1601 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1603 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1604 if (eventFilter
!= null) {
1605 startIndex
= startIndex
- 1; // -1 for top filter status row
1607 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1608 fSearchThread
.schedule();
1613 * Stop the search thread.
1615 protected void stopSearchThread() {
1616 fPendingGotoRank
= -1;
1617 synchronized (fSearchSyncObj
) {
1618 if (fSearchThread
!= null) {
1619 fSearchThread
.cancel();
1620 fSearchThread
= null;
1626 * Wrapper for the search thread.
1628 protected class SearchThread
extends Job
{
1630 private ITmfFilterTreeNode searchFilter
;
1631 private ITmfFilterTreeNode eventFilter
;
1632 private int startIndex
;
1633 private int direction
;
1635 private long foundRank
= -1;
1636 private TmfEventRequest request
;
1637 private ITmfTimestamp foundTimestamp
= null;
1642 * @param searchFilter
1644 * @param eventFilter
1647 * The index at which we should start searching
1648 * @param currentRank
1651 * In which direction should we search, forward or backwards
1653 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1654 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1655 final long currentRank
, final int direction
) {
1656 super(Messages
.TmfEventsTable_SearchingJobName
);
1657 this.searchFilter
= searchFilter
;
1658 this.eventFilter
= eventFilter
;
1659 this.startIndex
= startIndex
;
1660 this.rank
= currentRank
;
1661 this.direction
= direction
;
1665 protected IStatus
run(final IProgressMonitor monitor
) {
1666 if (fTrace
== null) {
1667 return Status
.OK_STATUS
;
1669 final Display display
= Display
.getDefault();
1670 if (startIndex
< 0) {
1671 rank
= (int) fTrace
.getNbEvents() - 1;
1672 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1675 int idx
= startIndex
;
1676 while (foundRank
== -1) {
1677 final CachedEvent event
= fCache
.peekEvent(idx
);
1678 if (event
== null) {
1682 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1683 foundRank
= event
.rank
;
1684 foundTimestamp
= event
.event
.getTimestamp();
1687 if (direction
== Direction
.FORWARD
) {
1693 if (foundRank
== -1) {
1694 if (direction
== Direction
.FORWARD
) {
1696 if (rank
> (fTrace
.getNbEvents() - 1)) {
1702 rank
= (int) fTrace
.getNbEvents() - 1;
1707 final int startRank
= (int) rank
;
1708 boolean wrapped
= false;
1709 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1710 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1711 if (direction
== Direction
.BACKWARD
) {
1712 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1714 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1715 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1716 long currentRank
= rank
;
1719 public void handleData(final ITmfEvent event
) {
1720 super.handleData(event
);
1721 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1722 foundRank
= currentRank
;
1723 foundTimestamp
= event
.getTimestamp();
1724 if (direction
== Direction
.FORWARD
) {
1732 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1734 request
.waitForCompletion();
1735 if (request
.isCancelled()) {
1736 return Status
.OK_STATUS
;
1738 } catch (final InterruptedException e
) {
1739 synchronized (fSearchSyncObj
) {
1740 fSearchThread
= null;
1742 return Status
.OK_STATUS
;
1744 if (foundRank
== -1) {
1745 if (direction
== Direction
.FORWARD
) {
1747 synchronized (fSearchSyncObj
) {
1748 fSearchThread
= null;
1750 return Status
.OK_STATUS
;
1752 nbRequested
= (int) rank
;
1758 rank
= (int) fTrace
.getNbEvents() - 1;
1761 if ((rank
<= startRank
) && wrapped
) {
1762 synchronized (fSearchSyncObj
) {
1763 fSearchThread
= null;
1765 return Status
.OK_STATUS
;
1770 int index
= (int) foundRank
;
1771 if (eventFilter
!= null) {
1772 index
= fCache
.getFilteredEventIndex(foundRank
);
1774 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1776 display
.asyncExec(new Runnable() {
1779 if (monitor
.isCanceled()) {
1782 if (fTable
.isDisposed()) {
1785 fTable
.setSelection(selection
);
1786 fSelectedRank
= foundRank
;
1787 fRawViewer
.selectAndReveal(fSelectedRank
);
1788 if (foundTimestamp
!= null) {
1789 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1791 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1792 synchronized (fSearchSyncObj
) {
1793 fSearchThread
= null;
1795 updateStatusLine(null);
1798 return Status
.OK_STATUS
;
1802 protected void canceling() {
1804 synchronized (fSearchSyncObj
) {
1805 fSearchThread
= null;
1811 * Create the resources.
1813 protected void createResources() {
1814 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1815 .getForeground().getRGB()));
1816 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1817 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1823 protected void packColumns() {
1827 fTable
.setRedraw(false);
1829 boolean isLinux
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
1831 TableColumn tableColumns
[] = fTable
.getColumns();
1832 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1833 final TableColumn column
= tableColumns
[i
];
1834 final int headerWidth
= column
.getWidth();
1836 // Workaround for Linux which doesn't consider the image width of
1837 // search/filter row in TableColumn.pack() after having executed
1838 // TableItem.setImage((Image)null) for other rows than search/filter row.
1839 if (isLinux
&& (i
== 0)) {
1840 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1843 if (column
.getWidth() < headerWidth
) {
1844 column
.setWidth(headerWidth
);
1848 fTable
.setRedraw(true);
1853 * Extract the fields of an event (item in the table).
1856 * The event to extract from
1857 * @return The array of fields
1860 public final ITmfEventField
[] getItemFields(final ITmfEvent event
) {
1861 return extractItemFields(event
);
1865 * Extract the fields of an event (item in the table).
1868 * The event to extract from
1869 * @return The array of fields
1871 * FIXME: Add support for column selection
1873 protected ITmfEventField
[] extractItemFields(final ITmfEvent event
) {
1874 ITmfEventField
[] fields
= EMPTY_FIELD_ARRAY
;
1875 if (event
!= null) {
1876 final String timestamp
= event
.getTimestamp().toString();
1877 final String source
= event
.getSource();
1878 final String type
= event
.getType().getName();
1879 final String reference
= event
.getReference();
1880 final String content
= event
.getContent().toString();
1881 fields
= new TmfEventField
[] {
1882 new TmfEventField(ITmfEvent
.EVENT_FIELD_TIMESTAMP
, timestamp
, null),
1883 new TmfEventField(ITmfEvent
.EVENT_FIELD_SOURCE
, source
, null),
1884 new TmfEventField(ITmfEvent
.EVENT_FIELD_TYPE
, type
, null),
1885 new TmfEventField(ITmfEvent
.EVENT_FIELD_REFERENCE
, reference
, null),
1886 new TmfEventField(ITmfEvent
.EVENT_FIELD_CONTENT
, content
, null)
1893 * Notify this table that is got the UI focus.
1895 public void setFocus() {
1900 * Assign a new trace to this event table.
1903 * The trace to assign to this event table
1904 * @param disposeOnClose
1905 * true if the trace should be disposed when the table is
1908 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1909 if ((fTrace
!= null) && fDisposeOnClose
) {
1915 fDisposeOnClose
= disposeOnClose
;
1917 // Perform the updates on the UI thread
1918 fTable
.getDisplay().syncExec(new Runnable() {
1922 fCache
.setTrace(fTrace
); // Clear the cache
1923 if (fTrace
!= null) {
1924 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1925 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1926 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1929 fFilterMatchCount
= 0;
1930 fFilterCheckCount
= 0;
1931 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1932 startFilterThread();
1936 fRawViewer
.setTrace(fTrace
);
1942 * Assign the status line manager
1944 * @param statusLineManager
1945 * The status line manager, or null to disable status line messages
1948 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
1949 if (fStatusLineManager
!= null && statusLineManager
== null) {
1950 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
1952 fStatusLineManager
= statusLineManager
;
1955 private void updateStatusLine(ITmfTimestamp delta
) {
1956 if (fStatusLineManager
!= null) {
1957 if (delta
!= null) {
1958 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
1960 fStatusLineManager
.setMessage(null);
1965 // ------------------------------------------------------------------------
1967 // ------------------------------------------------------------------------
1970 * Notify that the event cache has been updated
1973 * Also notify if the populating of the cache is complete, or
1976 public void cacheUpdated(final boolean completed
) {
1977 synchronized (fCacheUpdateSyncObj
) {
1978 if (fCacheUpdateBusy
) {
1979 fCacheUpdatePending
= true;
1980 fCacheUpdateCompleted
= completed
;
1983 fCacheUpdateBusy
= true;
1985 // Event cache is now updated. Perform update on the UI thread
1986 if (!fTable
.isDisposed()) {
1987 fTable
.getDisplay().asyncExec(new Runnable() {
1990 if (!fTable
.isDisposed()) {
1995 populateCompleted();
1997 synchronized (fCacheUpdateSyncObj
) {
1998 fCacheUpdateBusy
= false;
1999 if (fCacheUpdatePending
) {
2000 fCacheUpdatePending
= false;
2001 cacheUpdated(fCacheUpdateCompleted
);
2010 * Callback for when populating the table is complete.
2012 protected void populateCompleted() {
2013 // Nothing by default;
2016 // ------------------------------------------------------------------------
2017 // ISelectionProvider
2018 // ------------------------------------------------------------------------
2024 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2025 selectionChangedListeners
.add(listener
);
2032 public ISelection
getSelection() {
2033 if (fTable
== null || fTable
.isDisposed()) {
2034 return StructuredSelection
.EMPTY
;
2036 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2037 for (TableItem item
: fTable
.getSelection()) {
2038 if (item
.getData() != null) {
2039 list
.add(item
.getData());
2042 return new StructuredSelection(list
);
2049 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2050 selectionChangedListeners
.remove(listener
);
2057 public void setSelection(ISelection selection
) {
2062 * Notifies any selection changed listeners that the viewer's selection has changed.
2063 * Only listeners registered at the time this method is called are notified.
2065 * @param event a selection changed event
2067 * @see ISelectionChangedListener#selectionChanged
2070 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2071 Object
[] listeners
= selectionChangedListeners
.getListeners();
2072 for (int i
= 0; i
< listeners
.length
; ++i
) {
2073 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2074 SafeRunnable
.run(new SafeRunnable() {
2077 l
.selectionChanged(event
);
2083 // ------------------------------------------------------------------------
2084 // Bookmark handling
2085 // ------------------------------------------------------------------------
2088 * Add a bookmark to this event table.
2090 * @param bookmarksFile
2091 * The file to use for the bookmarks
2093 public void addBookmark(final IFile bookmarksFile
) {
2094 fBookmarksFile
= bookmarksFile
;
2095 final TableItem
[] selection
= fTable
.getSelection();
2096 if (selection
.length
> 0) {
2097 final TableItem tableItem
= selection
[0];
2098 if (tableItem
.getData(Key
.RANK
) != null) {
2099 final StringBuffer defaultMessage
= new StringBuffer();
2100 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2102 defaultMessage
.append(", "); //$NON-NLS-1$
2104 defaultMessage
.append(tableItem
.getText(i
));
2106 final InputDialog dialog
= new MultiLineInputDialog(
2107 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2108 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2109 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2110 defaultMessage
.toString());
2111 if (dialog
.open() == Window
.OK
) {
2112 final String message
= dialog
.getValue();
2114 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2115 if (bookmark
.exists()) {
2116 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2117 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2118 final int location
= rank
.intValue();
2119 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2120 fBookmarksMap
.put(rank
, bookmark
.getId());
2123 } catch (final CoreException e
) {
2124 displayException(e
);
2133 * Remove a bookmark from this event table.
2136 * The bookmark to remove
2138 public void removeBookmark(final IMarker bookmark
) {
2139 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entrySet()) {
2140 if (entry
.getValue().equals(bookmark
.getId())) {
2141 fBookmarksMap
.remove(entry
.getKey());
2148 private void toggleBookmark(final Long rank
) {
2149 if (fBookmarksFile
== null) {
2152 if (fBookmarksMap
.containsKey(rank
)) {
2153 final Long markerId
= fBookmarksMap
.remove(rank
);
2156 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2157 if (bookmark
!= null) {
2160 } catch (final CoreException e
) {
2161 displayException(e
);
2164 addBookmark(fBookmarksFile
);
2169 * Refresh the bookmarks assigned to this trace, from the contents of a
2172 * @param bookmarksFile
2173 * The bookmark file to use
2175 public void refreshBookmarks(final IFile bookmarksFile
) {
2176 fBookmarksFile
= bookmarksFile
;
2177 if (bookmarksFile
== null) {
2178 fBookmarksMap
.clear();
2183 fBookmarksMap
.clear();
2184 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2185 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2186 if (location
!= -1) {
2187 final long rank
= location
;
2188 fBookmarksMap
.put(rank
, bookmark
.getId());
2192 } catch (final CoreException e
) {
2193 displayException(e
);
2198 public void gotoMarker(final IMarker marker
) {
2199 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2202 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2203 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2204 } else if (rank
>= fTable
.getItemCount()) {
2205 fPendingGotoRank
= rank
;
2207 fSelectedRank
= rank
;
2208 fTable
.setSelection(index
+ 1); // +1 for header row
2209 updateStatusLine(null);
2213 // ------------------------------------------------------------------------
2215 // ------------------------------------------------------------------------
2218 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2222 // ------------------------------------------------------------------------
2224 // ------------------------------------------------------------------------
2227 * Handler for the trace updated signal
2230 * The incoming signal
2233 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2234 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2237 // Perform the refresh on the UI thread
2238 Display
.getDefault().asyncExec(new Runnable() {
2241 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2242 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2243 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2244 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2245 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2246 fPendingGotoRank
= -1;
2247 updateStatusLine(null);
2250 startFilterThread();
2253 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2254 fRawViewer
.refreshEventCount();
2261 * Handler for the time synch signal.
2264 * The incoming signal
2267 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2268 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2270 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2271 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2272 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2273 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2274 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2276 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2279 public void handleData(final ITmfEvent event
) {
2280 super.handleData(event
);
2284 public void handleCompleted() {
2285 super.handleCompleted();
2286 if (fTrace
== null) {
2290 // Verify if the event is within the trace range and adjust if necessary
2291 ITmfTimestamp timestamp
= ts
;
2292 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2293 timestamp
= fTrace
.getStartTime();
2295 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2296 timestamp
= fTrace
.getEndTime();
2299 // Get the rank of the selected event in the table
2300 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2301 final long rank
= context
.getRank();
2303 fSelectedRank
= rank
;
2305 fTable
.getDisplay().asyncExec(new Runnable() {
2308 // Return if table is disposed
2309 if (fTable
.isDisposed()) {
2313 int index
= (int) rank
;
2314 if (fTable
.isDisposed()) {
2317 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2318 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2320 fTable
.setSelection(index
+ 1); // +1 for header row
2321 fRawViewer
.selectAndReveal(rank
);
2322 updateStatusLine(null);
2328 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2332 // ------------------------------------------------------------------------
2334 // ------------------------------------------------------------------------
2337 * Display an exception in a message box
2339 * @param e the exception
2341 private static void displayException(final Exception e
) {
2342 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2343 mb
.setText(e
.getClass().getSimpleName());
2344 mb
.setMessage(e
.getMessage());
2351 public void refresh() {