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
.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();
968 fRawViewer
.dispose();
973 * Assign a layout data object to this view.
976 * The layout data to assign
978 public void setLayoutData(final Object layoutData
) {
979 fComposite
.setLayoutData(layoutData
);
983 * Get the virtual table contained in this event table.
985 * @return The TMF virtual table
987 public TmfVirtualTable
getTable() {
994 * FIXME: Add support for column selection
996 protected void setColumnHeaders(final ColumnData
[] columnData
) {
997 fTable
.setColumnHeaders(columnData
);
1001 * Set a table item's data.
1006 * Which trace event to link with this entry
1008 * Which rank this event has in the trace/experiment
1010 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1011 final ITmfEventField
[] fields
= extractItemFields(event
);
1012 final String
[] content
= new String
[fields
.length
];
1013 for (int i
= 0; i
< fields
.length
; i
++) {
1014 content
[i
] = fields
[i
].getValue() != null ? fields
[i
].getValue().toString() : ""; //$NON-NLS-1$
1016 item
.setText(content
);
1017 item
.setData(event
);
1018 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
1019 item
.setData(Key
.RANK
, rank
);
1021 boolean bookmark
= false;
1022 final Long markerId
= fBookmarksMap
.get(rank
);
1023 if (markerId
!= null) {
1026 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1027 item
.setData(Key
.BOOKMARK
, marker
.getAttribute(IMarker
.MESSAGE
));
1028 } catch (final CoreException e
) {
1029 displayException(e
);
1032 item
.setData(Key
.BOOKMARK
, null);
1035 boolean searchMatch
= false;
1036 boolean searchNoMatch
= false;
1037 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1038 if (searchFilter
!= null) {
1039 if (searchFilter
.matches(event
)) {
1042 searchNoMatch
= true;
1046 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
1047 if (searchNoMatch
) {
1048 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1049 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1051 item
.setForeground(colorSetting
.getForegroundColor());
1052 item
.setBackground(colorSetting
.getBackgroundColor());
1057 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1059 item
.setImage(SEARCH_MATCH_IMAGE
);
1061 } else if (bookmark
) {
1062 item
.setImage(BOOKMARK_IMAGE
);
1064 item
.setImage((Image
) null);
1069 * Set the item data of the header row.
1072 * The item to use as table header
1074 protected void setHeaderRowItemData(final TableItem item
) {
1075 String txtKey
= null;
1076 if (fHeaderState
== HeaderState
.SEARCH
) {
1077 item
.setImage(SEARCH_IMAGE
);
1078 txtKey
= Key
.SEARCH_TXT
;
1079 } else if (fHeaderState
== HeaderState
.FILTER
) {
1080 item
.setImage(FILTER_IMAGE
);
1081 txtKey
= Key
.FILTER_TXT
;
1083 item
.setForeground(fGrayColor
);
1084 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1085 final TableColumn column
= fTable
.getColumns()[i
];
1086 final String filter
= (String
) column
.getData(txtKey
);
1087 if (filter
== null) {
1088 if (fHeaderState
== HeaderState
.SEARCH
) {
1089 item
.setText(i
, SEARCH_HINT
);
1090 } else if (fHeaderState
== HeaderState
.FILTER
) {
1091 item
.setText(i
, FILTER_HINT
);
1093 item
.setForeground(i
, fGrayColor
);
1094 item
.setFont(i
, fTable
.getFont());
1096 item
.setText(i
, filter
);
1097 item
.setForeground(i
, fGreenColor
);
1098 item
.setFont(i
, fBoldFont
);
1104 * Set the item data of the "filter status" row.
1107 * The item to use as filter status row
1109 protected void setFilterStatusRowItemData(final TableItem item
) {
1110 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1112 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1113 item
.setImage(FILTER_IMAGE
);
1115 item
.setImage(STOP_IMAGE
);
1117 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1119 item
.setText(i
, ""); //$NON-NLS-1$
1123 item
.setData(Key
.TIMESTAMP
, null);
1124 item
.setData(Key
.RANK
, null);
1125 item
.setForeground(null);
1126 item
.setBackground(null);
1130 * Create an editor for the header.
1132 protected void createHeaderEditor() {
1133 final TableEditor tableEditor
= fTable
.createTableEditor();
1134 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1135 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1136 tableEditor
.grabHorizontal
= true;
1137 tableEditor
.minimumWidth
= 50;
1139 // Handle the header row selection
1140 fTable
.addMouseListener(new MouseAdapter() {
1146 public void mouseDown(final MouseEvent event
) {
1147 if (event
.button
!= 1) {
1150 // Identify the selected row
1151 final Point point
= new Point(event
.x
, event
.y
);
1152 item
= fTable
.getItem(point
);
1154 // Header row selected
1155 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1158 if (item
.getImageBounds(0).contains(point
)) {
1159 if (fHeaderState
== HeaderState
.SEARCH
) {
1160 fHeaderState
= HeaderState
.FILTER
;
1161 } else if (fHeaderState
== HeaderState
.FILTER
) {
1162 fHeaderState
= HeaderState
.SEARCH
;
1164 fTable
.setSelection(0);
1169 // Identify the selected column
1171 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1172 final Rectangle rect
= item
.getBounds(i
);
1173 if (rect
.contains(point
)) {
1179 if (columnIndex
== -1) {
1183 column
= fTable
.getColumns()[columnIndex
];
1185 String txtKey
= null;
1186 if (fHeaderState
== HeaderState
.SEARCH
) {
1187 txtKey
= Key
.SEARCH_TXT
;
1188 } else if (fHeaderState
== HeaderState
.FILTER
) {
1189 txtKey
= Key
.FILTER_TXT
;
1192 // The control that will be the editor must be a child of the Table
1193 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1194 final String headerString
= (String
) column
.getData(txtKey
);
1195 if (headerString
!= null) {
1196 newEditor
.setText(headerString
);
1198 newEditor
.addFocusListener(new FocusAdapter() {
1200 public void focusLost(final FocusEvent e
) {
1201 final boolean changed
= updateHeader(newEditor
.getText());
1207 newEditor
.addKeyListener(new KeyAdapter() {
1209 public void keyPressed(final KeyEvent e
) {
1210 if (e
.character
== SWT
.CR
) {
1211 updateHeader(newEditor
.getText());
1213 } else if (e
.character
== SWT
.ESC
) {
1214 tableEditor
.getEditor().dispose();
1218 newEditor
.selectAll();
1219 newEditor
.setFocus();
1220 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1225 * returns true is value was changed
1227 private boolean updateHeader(final String text
) {
1228 String objKey
= null;
1229 String txtKey
= null;
1230 if (fHeaderState
== HeaderState
.SEARCH
) {
1231 objKey
= Key
.SEARCH_OBJ
;
1232 txtKey
= Key
.SEARCH_TXT
;
1233 } else if (fHeaderState
== HeaderState
.FILTER
) {
1234 objKey
= Key
.FILTER_OBJ
;
1235 txtKey
= Key
.FILTER_TXT
;
1237 if (text
.trim().length() > 0) {
1239 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1240 Pattern
.compile(regex
);
1241 if (regex
.equals(column
.getData(txtKey
))) {
1242 tableEditor
.getEditor().dispose();
1245 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1246 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1247 if (fieldId
== null) {
1248 fieldId
= column
.getText();
1250 filter
.setField(fieldId
);
1251 filter
.setRegex(regex
);
1252 column
.setData(objKey
, filter
);
1253 column
.setData(txtKey
, regex
);
1254 } catch (final PatternSyntaxException ex
) {
1255 tableEditor
.getEditor().dispose();
1256 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1257 ex
.getDescription(), ex
.getMessage());
1261 if (column
.getData(txtKey
) == null) {
1262 tableEditor
.getEditor().dispose();
1265 column
.setData(objKey
, null);
1266 column
.setData(txtKey
, null);
1271 private void applyHeader() {
1272 if (fHeaderState
== HeaderState
.SEARCH
) {
1274 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1275 for (final TableColumn col
: fTable
.getColumns()) {
1276 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1277 if (filterObj
instanceof ITmfFilterTreeNode
) {
1278 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1281 if (filter
.getChildrenCount() > 0) {
1282 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1285 fireSearchApplied(filter
);
1287 fTable
.setData(Key
.SEARCH_OBJ
, null);
1289 fireSearchApplied(null);
1291 } else if (fHeaderState
== HeaderState
.FILTER
) {
1292 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1293 for (final TableColumn col
: fTable
.getColumns()) {
1294 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1295 if (filterObj
instanceof ITmfFilterTreeNode
) {
1296 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1299 if (filter
.getChildrenCount() > 0) {
1300 applyFilter(filter
);
1306 tableEditor
.getEditor().dispose();
1310 fTable
.addKeyListener(new KeyAdapter() {
1312 public void keyPressed(final KeyEvent e
) {
1314 if (e
.character
== SWT
.ESC
) {
1318 } else if (e
.character
== SWT
.DEL
) {
1319 if (fHeaderState
== HeaderState
.SEARCH
) {
1321 for (final TableColumn column
: fTable
.getColumns()) {
1322 column
.setData(Key
.SEARCH_OBJ
, null);
1323 column
.setData(Key
.SEARCH_TXT
, null);
1325 fTable
.setData(Key
.SEARCH_OBJ
, null);
1327 fireSearchApplied(null);
1328 } else if (fHeaderState
== HeaderState
.FILTER
) {
1331 } else if (e
.character
== SWT
.CR
) {
1332 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1343 * Send an event indicating a filter has been applied.
1346 * The filter that was just applied
1348 protected void fireFilterApplied(final ITmfFilter filter
) {
1349 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1353 * Send an event indicating that a search has been applied.
1356 * The search filter that was just applied
1358 protected void fireSearchApplied(final ITmfFilter filter
) {
1359 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1363 * Start the filtering thread.
1365 protected void startFilterThread() {
1366 synchronized (fFilterSyncObj
) {
1367 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1368 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1369 if (fFilterThread
!= null) {
1370 fFilterThread
.cancel();
1371 fFilterThreadResume
= false;
1373 fFilterThread
= new FilterThread(filter
);
1374 fFilterThread
.start();
1376 fFilterThreadResume
= true;
1382 * Stop the filtering thread.
1384 protected void stopFilterThread() {
1385 synchronized (fFilterSyncObj
) {
1386 if (fFilterThread
!= null) {
1387 fFilterThread
.cancel();
1388 fFilterThread
= null;
1389 fFilterThreadResume
= false;
1398 * The filter to apply
1401 protected void applyFilter(ITmfFilter filter
) {
1404 fFilterMatchCount
= 0;
1405 fFilterCheckCount
= 0;
1406 fCache
.applyFilter(filter
);
1408 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1409 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1410 startFilterThread();
1411 fireFilterApplied(filter
);
1415 * Clear all currently active filters.
1417 protected void clearFilters() {
1418 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1423 fCache
.clearFilter();
1425 for (final TableColumn column
: fTable
.getColumns()) {
1426 column
.setData(Key
.FILTER_OBJ
, null);
1427 column
.setData(Key
.FILTER_TXT
, null);
1429 fTable
.setData(Key
.FILTER_OBJ
, null);
1430 if (fTrace
!= null) {
1431 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1433 fTable
.setItemCount(1); // +1 for header row
1435 fFilterMatchCount
= 0;
1436 fFilterCheckCount
= 0;
1437 if (fSelectedRank
>= 0) {
1438 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1440 fTable
.setSelection(0);
1442 fireFilterApplied(null);
1443 updateStatusLine(null);
1447 * Wrapper Thread object for the filtering thread.
1449 protected class FilterThread
extends Thread
{
1450 private final ITmfFilterTreeNode filter
;
1451 private TmfEventRequest request
;
1452 private boolean refreshBusy
= false;
1453 private boolean refreshPending
= false;
1454 private final Object syncObj
= new Object();
1460 * The filter this thread will be processing
1462 public FilterThread(final ITmfFilterTreeNode filter
) {
1463 super("Filter Thread"); //$NON-NLS-1$
1464 this.filter
= filter
;
1469 if (fTrace
== null) {
1472 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1473 if (nbRequested
<= 0) {
1476 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1477 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
1479 public void handleData(final ITmfEvent event
) {
1480 super.handleData(event
);
1481 if (request
.isCancelled()) {
1484 if (filter
.matches(event
)) {
1485 final long rank
= fFilterCheckCount
;
1486 final int index
= (int) fFilterMatchCount
;
1487 fFilterMatchCount
++;
1488 fCache
.storeEvent(event
, rank
, index
);
1490 } else if ((fFilterCheckCount
% 100) == 0) {
1493 fFilterCheckCount
++;
1496 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1498 request
.waitForCompletion();
1499 } catch (final InterruptedException e
) {
1502 synchronized (fFilterSyncObj
) {
1503 fFilterThread
= null;
1504 if (fFilterThreadResume
) {
1505 fFilterThreadResume
= false;
1506 fFilterThread
= new FilterThread(filter
);
1507 fFilterThread
.start();
1513 * Refresh the filter.
1515 public void refreshTable() {
1516 synchronized (syncObj
) {
1518 refreshPending
= true;
1523 Display
.getDefault().asyncExec(new Runnable() {
1526 if (request
.isCancelled()) {
1529 if (fTable
.isDisposed()) {
1532 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1534 synchronized (syncObj
) {
1535 refreshBusy
= false;
1536 if (refreshPending
) {
1537 refreshPending
= false;
1546 * Cancel this filtering thread.
1548 public void cancel() {
1549 if (request
!= null) {
1556 * Go to the next item of a search.
1558 protected void searchNext() {
1559 synchronized (fSearchSyncObj
) {
1560 if (fSearchThread
!= null) {
1563 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1564 if (searchFilter
== null) {
1567 final int selectionIndex
= fTable
.getSelectionIndex();
1569 if (selectionIndex
> 0) {
1570 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1572 // header row is selected, start at top event
1573 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1575 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1576 if (eventFilter
!= null) {
1577 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1579 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1580 fSearchThread
.schedule();
1585 * Go to the previous item of a search.
1587 protected void searchPrevious() {
1588 synchronized (fSearchSyncObj
) {
1589 if (fSearchThread
!= null) {
1592 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1593 if (searchFilter
== null) {
1596 final int selectionIndex
= fTable
.getSelectionIndex();
1598 if (selectionIndex
> 0) {
1599 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1601 // header row is selected, start at precedent of top event
1602 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1604 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1605 if (eventFilter
!= null) {
1606 startIndex
= startIndex
- 1; // -1 for top filter status row
1608 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1609 fSearchThread
.schedule();
1614 * Stop the search thread.
1616 protected void stopSearchThread() {
1617 fPendingGotoRank
= -1;
1618 synchronized (fSearchSyncObj
) {
1619 if (fSearchThread
!= null) {
1620 fSearchThread
.cancel();
1621 fSearchThread
= null;
1627 * Wrapper for the search thread.
1629 protected class SearchThread
extends Job
{
1631 private ITmfFilterTreeNode searchFilter
;
1632 private ITmfFilterTreeNode eventFilter
;
1633 private int startIndex
;
1634 private int direction
;
1636 private long foundRank
= -1;
1637 private TmfEventRequest request
;
1638 private ITmfTimestamp foundTimestamp
= null;
1643 * @param searchFilter
1645 * @param eventFilter
1648 * The index at which we should start searching
1649 * @param currentRank
1652 * In which direction should we search, forward or backwards
1654 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1655 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1656 final long currentRank
, final int direction
) {
1657 super(Messages
.TmfEventsTable_SearchingJobName
);
1658 this.searchFilter
= searchFilter
;
1659 this.eventFilter
= eventFilter
;
1660 this.startIndex
= startIndex
;
1661 this.rank
= currentRank
;
1662 this.direction
= direction
;
1666 protected IStatus
run(final IProgressMonitor monitor
) {
1667 if (fTrace
== null) {
1668 return Status
.OK_STATUS
;
1670 final Display display
= Display
.getDefault();
1671 if (startIndex
< 0) {
1672 rank
= (int) fTrace
.getNbEvents() - 1;
1673 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1676 int idx
= startIndex
;
1677 while (foundRank
== -1) {
1678 final CachedEvent event
= fCache
.peekEvent(idx
);
1679 if (event
== null) {
1683 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1684 foundRank
= event
.rank
;
1685 foundTimestamp
= event
.event
.getTimestamp();
1688 if (direction
== Direction
.FORWARD
) {
1694 if (foundRank
== -1) {
1695 if (direction
== Direction
.FORWARD
) {
1697 if (rank
> (fTrace
.getNbEvents() - 1)) {
1703 rank
= (int) fTrace
.getNbEvents() - 1;
1708 final int startRank
= (int) rank
;
1709 boolean wrapped
= false;
1710 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1711 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1712 if (direction
== Direction
.BACKWARD
) {
1713 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1715 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1716 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
1717 long currentRank
= rank
;
1720 public void handleData(final ITmfEvent event
) {
1721 super.handleData(event
);
1722 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1723 foundRank
= currentRank
;
1724 foundTimestamp
= event
.getTimestamp();
1725 if (direction
== Direction
.FORWARD
) {
1733 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
1735 request
.waitForCompletion();
1736 if (request
.isCancelled()) {
1737 return Status
.OK_STATUS
;
1739 } catch (final InterruptedException e
) {
1740 synchronized (fSearchSyncObj
) {
1741 fSearchThread
= null;
1743 return Status
.OK_STATUS
;
1745 if (foundRank
== -1) {
1746 if (direction
== Direction
.FORWARD
) {
1748 synchronized (fSearchSyncObj
) {
1749 fSearchThread
= null;
1751 return Status
.OK_STATUS
;
1753 nbRequested
= (int) rank
;
1759 rank
= (int) fTrace
.getNbEvents() - 1;
1762 if ((rank
<= startRank
) && wrapped
) {
1763 synchronized (fSearchSyncObj
) {
1764 fSearchThread
= null;
1766 return Status
.OK_STATUS
;
1771 int index
= (int) foundRank
;
1772 if (eventFilter
!= null) {
1773 index
= fCache
.getFilteredEventIndex(foundRank
);
1775 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1777 display
.asyncExec(new Runnable() {
1780 if (monitor
.isCanceled()) {
1783 if (fTable
.isDisposed()) {
1786 fTable
.setSelection(selection
);
1787 fSelectedRank
= foundRank
;
1788 fRawViewer
.selectAndReveal(fSelectedRank
);
1789 if (foundTimestamp
!= null) {
1790 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1792 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1793 synchronized (fSearchSyncObj
) {
1794 fSearchThread
= null;
1796 updateStatusLine(null);
1799 return Status
.OK_STATUS
;
1803 protected void canceling() {
1805 synchronized (fSearchSyncObj
) {
1806 fSearchThread
= null;
1812 * Create the resources.
1814 protected void createResources() {
1815 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1816 .getForeground().getRGB()));
1817 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1818 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1824 protected void packColumns() {
1828 fTable
.setRedraw(false);
1830 boolean isLinux
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
1832 TableColumn tableColumns
[] = fTable
.getColumns();
1833 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1834 final TableColumn column
= tableColumns
[i
];
1835 final int headerWidth
= column
.getWidth();
1837 // Workaround for Linux which doesn't consider the image width of
1838 // search/filter row in TableColumn.pack() after having executed
1839 // TableItem.setImage((Image)null) for other rows than search/filter row.
1840 if (isLinux
&& (i
== 0)) {
1841 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1844 if (column
.getWidth() < headerWidth
) {
1845 column
.setWidth(headerWidth
);
1849 fTable
.setRedraw(true);
1854 * Extract the fields of an event (item in the table).
1857 * The event to extract from
1858 * @return The array of fields
1861 public final ITmfEventField
[] getItemFields(final ITmfEvent event
) {
1862 return extractItemFields(event
);
1866 * Extract the fields of an event (item in the table).
1869 * The event to extract from
1870 * @return The array of fields
1872 * FIXME: Add support for column selection
1874 protected ITmfEventField
[] extractItemFields(final ITmfEvent event
) {
1875 ITmfEventField
[] fields
= EMPTY_FIELD_ARRAY
;
1876 if (event
!= null) {
1877 final String timestamp
= event
.getTimestamp().toString();
1878 final String source
= event
.getSource();
1879 final String type
= event
.getType().getName();
1880 final String reference
= event
.getReference();
1881 final String content
= event
.getContent().toString();
1882 fields
= new TmfEventField
[] {
1883 new TmfEventField(ITmfEvent
.EVENT_FIELD_TIMESTAMP
, timestamp
, null),
1884 new TmfEventField(ITmfEvent
.EVENT_FIELD_SOURCE
, source
, null),
1885 new TmfEventField(ITmfEvent
.EVENT_FIELD_TYPE
, type
, null),
1886 new TmfEventField(ITmfEvent
.EVENT_FIELD_REFERENCE
, reference
, null),
1887 new TmfEventField(ITmfEvent
.EVENT_FIELD_CONTENT
, content
, null)
1894 * Notify this table that is got the UI focus.
1896 public void setFocus() {
1901 * Assign a new trace to this event table.
1904 * The trace to assign to this event table
1905 * @param disposeOnClose
1906 * true if the trace should be disposed when the table is
1909 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1910 if ((fTrace
!= null) && fDisposeOnClose
) {
1916 fDisposeOnClose
= disposeOnClose
;
1918 // Perform the updates on the UI thread
1919 fTable
.getDisplay().syncExec(new Runnable() {
1923 fCache
.setTrace(fTrace
); // Clear the cache
1924 if (fTrace
!= null) {
1925 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1926 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1927 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1930 fFilterMatchCount
= 0;
1931 fFilterCheckCount
= 0;
1932 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1933 startFilterThread();
1937 fRawViewer
.setTrace(fTrace
);
1943 * Assign the status line manager
1945 * @param statusLineManager
1946 * The status line manager, or null to disable status line messages
1949 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
1950 if (fStatusLineManager
!= null && statusLineManager
== null) {
1951 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
1953 fStatusLineManager
= statusLineManager
;
1956 private void updateStatusLine(ITmfTimestamp delta
) {
1957 if (fStatusLineManager
!= null) {
1958 if (delta
!= null) {
1959 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
1961 fStatusLineManager
.setMessage(null);
1966 // ------------------------------------------------------------------------
1968 // ------------------------------------------------------------------------
1971 * Notify that the event cache has been updated
1974 * Also notify if the populating of the cache is complete, or
1977 public void cacheUpdated(final boolean completed
) {
1978 synchronized (fCacheUpdateSyncObj
) {
1979 if (fCacheUpdateBusy
) {
1980 fCacheUpdatePending
= true;
1981 fCacheUpdateCompleted
= completed
;
1984 fCacheUpdateBusy
= true;
1986 // Event cache is now updated. Perform update on the UI thread
1987 if (!fTable
.isDisposed()) {
1988 fTable
.getDisplay().asyncExec(new Runnable() {
1991 if (!fTable
.isDisposed()) {
1996 populateCompleted();
1998 synchronized (fCacheUpdateSyncObj
) {
1999 fCacheUpdateBusy
= false;
2000 if (fCacheUpdatePending
) {
2001 fCacheUpdatePending
= false;
2002 cacheUpdated(fCacheUpdateCompleted
);
2011 * Callback for when populating the table is complete.
2013 protected void populateCompleted() {
2014 // Nothing by default;
2017 // ------------------------------------------------------------------------
2018 // ISelectionProvider
2019 // ------------------------------------------------------------------------
2025 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2026 selectionChangedListeners
.add(listener
);
2033 public ISelection
getSelection() {
2034 if (fTable
== null || fTable
.isDisposed()) {
2035 return StructuredSelection
.EMPTY
;
2037 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2038 for (TableItem item
: fTable
.getSelection()) {
2039 if (item
.getData() != null) {
2040 list
.add(item
.getData());
2043 return new StructuredSelection(list
);
2050 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2051 selectionChangedListeners
.remove(listener
);
2058 public void setSelection(ISelection selection
) {
2063 * Notifies any selection changed listeners that the viewer's selection has changed.
2064 * Only listeners registered at the time this method is called are notified.
2066 * @param event a selection changed event
2068 * @see ISelectionChangedListener#selectionChanged
2071 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2072 Object
[] listeners
= selectionChangedListeners
.getListeners();
2073 for (int i
= 0; i
< listeners
.length
; ++i
) {
2074 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2075 SafeRunnable
.run(new SafeRunnable() {
2078 l
.selectionChanged(event
);
2084 // ------------------------------------------------------------------------
2085 // Bookmark handling
2086 // ------------------------------------------------------------------------
2089 * Add a bookmark to this event table.
2091 * @param bookmarksFile
2092 * The file to use for the bookmarks
2094 public void addBookmark(final IFile bookmarksFile
) {
2095 fBookmarksFile
= bookmarksFile
;
2096 final TableItem
[] selection
= fTable
.getSelection();
2097 if (selection
.length
> 0) {
2098 final TableItem tableItem
= selection
[0];
2099 if (tableItem
.getData(Key
.RANK
) != null) {
2100 final StringBuffer defaultMessage
= new StringBuffer();
2101 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2103 defaultMessage
.append(", "); //$NON-NLS-1$
2105 defaultMessage
.append(tableItem
.getText(i
));
2107 final InputDialog dialog
= new MultiLineInputDialog(
2108 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2109 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2110 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2111 defaultMessage
.toString());
2112 if (dialog
.open() == Window
.OK
) {
2113 final String message
= dialog
.getValue();
2115 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2116 if (bookmark
.exists()) {
2117 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2118 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2119 final int location
= rank
.intValue();
2120 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2121 fBookmarksMap
.put(rank
, bookmark
.getId());
2124 } catch (final CoreException e
) {
2125 displayException(e
);
2134 * Remove a bookmark from this event table.
2137 * The bookmark to remove
2139 public void removeBookmark(final IMarker bookmark
) {
2140 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entrySet()) {
2141 if (entry
.getValue().equals(bookmark
.getId())) {
2142 fBookmarksMap
.remove(entry
.getKey());
2149 private void toggleBookmark(final Long rank
) {
2150 if (fBookmarksFile
== null) {
2153 if (fBookmarksMap
.containsKey(rank
)) {
2154 final Long markerId
= fBookmarksMap
.remove(rank
);
2157 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2158 if (bookmark
!= null) {
2161 } catch (final CoreException e
) {
2162 displayException(e
);
2165 addBookmark(fBookmarksFile
);
2170 * Refresh the bookmarks assigned to this trace, from the contents of a
2173 * @param bookmarksFile
2174 * The bookmark file to use
2176 public void refreshBookmarks(final IFile bookmarksFile
) {
2177 fBookmarksFile
= bookmarksFile
;
2178 if (bookmarksFile
== null) {
2179 fBookmarksMap
.clear();
2184 fBookmarksMap
.clear();
2185 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2186 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2187 if (location
!= -1) {
2188 final long rank
= location
;
2189 fBookmarksMap
.put(rank
, bookmark
.getId());
2193 } catch (final CoreException e
) {
2194 displayException(e
);
2199 public void gotoMarker(final IMarker marker
) {
2200 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2203 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2204 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2205 } else if (rank
>= fTable
.getItemCount()) {
2206 fPendingGotoRank
= rank
;
2208 fSelectedRank
= rank
;
2209 fTable
.setSelection(index
+ 1); // +1 for header row
2210 updateStatusLine(null);
2214 // ------------------------------------------------------------------------
2216 // ------------------------------------------------------------------------
2219 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2223 // ------------------------------------------------------------------------
2225 // ------------------------------------------------------------------------
2228 * Handler for the trace updated signal
2231 * The incoming signal
2234 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2235 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2238 // Perform the refresh on the UI thread
2239 Display
.getDefault().asyncExec(new Runnable() {
2242 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2243 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2244 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2245 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2246 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2247 fPendingGotoRank
= -1;
2248 updateStatusLine(null);
2251 startFilterThread();
2254 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2255 fRawViewer
.refreshEventCount();
2262 * Handler for the time synch signal.
2265 * The incoming signal
2268 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2269 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2271 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2272 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2273 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2274 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2275 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2277 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2280 public void handleData(final ITmfEvent event
) {
2281 super.handleData(event
);
2285 public void handleCompleted() {
2286 super.handleCompleted();
2287 if (fTrace
== null) {
2291 // Verify if the event is within the trace range and adjust if necessary
2292 ITmfTimestamp timestamp
= ts
;
2293 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2294 timestamp
= fTrace
.getStartTime();
2296 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2297 timestamp
= fTrace
.getEndTime();
2300 // Get the rank of the selected event in the table
2301 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2302 final long rank
= context
.getRank();
2304 fSelectedRank
= rank
;
2306 fTable
.getDisplay().asyncExec(new Runnable() {
2309 // Return if table is disposed
2310 if (fTable
.isDisposed()) {
2314 int index
= (int) rank
;
2315 if (fTable
.isDisposed()) {
2318 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2319 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2321 fTable
.setSelection(index
+ 1); // +1 for header row
2322 fRawViewer
.selectAndReveal(rank
);
2323 updateStatusLine(null);
2329 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
2333 // ------------------------------------------------------------------------
2335 // ------------------------------------------------------------------------
2338 * Display an exception in a message box
2340 * @param e the exception
2342 private static void displayException(final Exception e
) {
2343 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2344 mb
.setText(e
.getClass().getSimpleName());
2345 mb
.setMessage(e
.getMessage());
2352 public void refresh() {