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
.ITmfDataProvider
;
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
.ITmfDataRequest
.ExecutionType
;
92 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
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
.TmfTimestamp
;
100 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
101 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
102 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
103 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
104 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSetting
;
105 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
106 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
107 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
108 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
109 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
;
110 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
111 import org
.eclipse
.swt
.SWT
;
112 import org
.eclipse
.swt
.custom
.SashForm
;
113 import org
.eclipse
.swt
.custom
.TableEditor
;
114 import org
.eclipse
.swt
.events
.FocusAdapter
;
115 import org
.eclipse
.swt
.events
.FocusEvent
;
116 import org
.eclipse
.swt
.events
.KeyAdapter
;
117 import org
.eclipse
.swt
.events
.KeyEvent
;
118 import org
.eclipse
.swt
.events
.MouseAdapter
;
119 import org
.eclipse
.swt
.events
.MouseEvent
;
120 import org
.eclipse
.swt
.events
.SelectionAdapter
;
121 import org
.eclipse
.swt
.events
.SelectionEvent
;
122 import org
.eclipse
.swt
.graphics
.Color
;
123 import org
.eclipse
.swt
.graphics
.Font
;
124 import org
.eclipse
.swt
.graphics
.Image
;
125 import org
.eclipse
.swt
.graphics
.Point
;
126 import org
.eclipse
.swt
.graphics
.Rectangle
;
127 import org
.eclipse
.swt
.layout
.FillLayout
;
128 import org
.eclipse
.swt
.layout
.GridData
;
129 import org
.eclipse
.swt
.layout
.GridLayout
;
130 import org
.eclipse
.swt
.widgets
.Composite
;
131 import org
.eclipse
.swt
.widgets
.Display
;
132 import org
.eclipse
.swt
.widgets
.Event
;
133 import org
.eclipse
.swt
.widgets
.Label
;
134 import org
.eclipse
.swt
.widgets
.Listener
;
135 import org
.eclipse
.swt
.widgets
.Menu
;
136 import org
.eclipse
.swt
.widgets
.MessageBox
;
137 import org
.eclipse
.swt
.widgets
.Shell
;
138 import org
.eclipse
.swt
.widgets
.TableColumn
;
139 import org
.eclipse
.swt
.widgets
.TableItem
;
140 import org
.eclipse
.swt
.widgets
.Text
;
141 import org
.eclipse
.ui
.IWorkbenchPage
;
142 import org
.eclipse
.ui
.PlatformUI
;
143 import org
.eclipse
.ui
.commands
.ICommandService
;
144 import org
.eclipse
.ui
.dialogs
.ListDialog
;
145 import org
.eclipse
.ui
.handlers
.IHandlerService
;
146 import org
.eclipse
.ui
.ide
.IDE
;
147 import org
.eclipse
.ui
.ide
.IGotoMarker
;
148 import org
.eclipse
.ui
.themes
.ColorUtil
;
151 * The generic TMF Events table
153 * This is a view that will list events that are read from a trace.
156 * @author Francois Chouinard
157 * @author Patrick Tasse
160 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
162 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
163 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
164 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
165 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
166 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
167 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
168 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
169 private static final Image FILTER_IMAGE
= Activator
.getDefault()
170 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
171 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
172 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
173 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
174 private static final int MAX_CACHE_SIZE
= 1000;
176 * Empty ITmfEventField array, used by {@link #extractItemFields(ITmfEvent)}
179 public static final ITmfEventField
[] EMPTY_FIELD_ARRAY
= new TmfEventField
[0];
182 * The events table search/filter keys
185 * @author Patrick Tasse
187 public interface Key
{
189 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
192 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
195 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
198 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
201 String TIMESTAMP
= "$time"; //$NON-NLS-1$
204 String RANK
= "$rank"; //$NON-NLS-1$
207 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
209 /** Bookmark indicator */
210 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
214 * The events table search/filter state
217 * @author Patrick Tasse
219 public static enum HeaderState
{
220 /** A search is being run */
223 /** A filter is applied */
227 interface Direction
{
232 // ------------------------------------------------------------------------
234 // ------------------------------------------------------------------------
236 /** The virtual event table */
237 protected TmfVirtualTable fTable
;
239 private Composite fComposite
;
240 private SashForm fSashForm
;
241 private TmfRawEventViewer fRawViewer
;
242 private ITmfTrace fTrace
;
243 private boolean fPackDone
= false;
244 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
245 private long fSelectedRank
= 0;
246 private ITmfTimestamp fSelectedBeginTimestamp
= null;
247 private IStatusLineManager fStatusLineManager
= null;
250 private long fFilterMatchCount
;
251 private long fFilterCheckCount
;
252 private FilterThread fFilterThread
;
253 private boolean fFilterThreadResume
= false;
254 private final Object fFilterSyncObj
= new Object();
255 private SearchThread fSearchThread
;
256 private final Object fSearchSyncObj
= new Object();
259 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
261 * @see #fireSelectionChanged
263 private ListenerList selectionChangedListeners
= new ListenerList();
265 // Bookmark map <Rank, MarkerId>
266 private Map
<Long
, Long
> fBookmarksMap
= new HashMap
<Long
, Long
>();
267 private IFile fBookmarksFile
;
268 private long fPendingGotoRank
= -1;
271 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
272 private Color fGrayColor
;
273 private Color fGreenColor
;
274 private Font fBoldFont
;
276 // Table column names
277 private static final String
[] COLUMN_NAMES
= new String
[] { Messages
.TmfEventsTable_TimestampColumnHeader
,
278 Messages
.TmfEventsTable_SourceColumnHeader
, Messages
.TmfEventsTable_TypeColumnHeader
,
279 Messages
.TmfEventsTable_ReferenceColumnHeader
, Messages
.TmfEventsTable_ContentColumnHeader
};
281 private static final ColumnData
[] COLUMN_DATA
= new ColumnData
[] { new ColumnData(COLUMN_NAMES
[0], 100, SWT
.LEFT
),
282 new ColumnData(COLUMN_NAMES
[1], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[2], 100, SWT
.LEFT
),
283 new ColumnData(COLUMN_NAMES
[3], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[4], 100, SWT
.LEFT
) };
286 private final TmfEventsCache fCache
;
287 private boolean fCacheUpdateBusy
= false;
288 private boolean fCacheUpdatePending
= false;
289 private boolean fCacheUpdateCompleted
= false;
290 private final Object fCacheUpdateSyncObj
= new Object();
292 private boolean fDisposeOnClose
;
294 // ------------------------------------------------------------------------
296 // ------------------------------------------------------------------------
299 * Basic constructor, will use default column data.
302 * The parent composite UI object
304 * The size of the event table cache
306 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
307 this(parent
, cacheSize
, COLUMN_DATA
);
311 * Advanced constructor, where we also define which column data to use.
314 * The parent composite UI object
316 * The size of the event table cache
318 * The column data to use for this table
320 public TmfEventsTable(final Composite parent
, int cacheSize
, final ColumnData
[] columnData
) {
321 super("TmfEventsTable"); //$NON-NLS-1$
323 fComposite
= new Composite(parent
, SWT
.NONE
);
324 final GridLayout gl
= new GridLayout(1, false);
327 gl
.verticalSpacing
= 0;
328 fComposite
.setLayout(gl
);
330 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
331 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
333 // Create a virtual table
334 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
335 fTable
= new TmfVirtualTable(fSashForm
, style
);
337 // Set the table layout
338 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
339 fTable
.setLayoutData(layoutData
);
341 // Some cosmetic enhancements
342 fTable
.setHeaderVisible(true);
343 fTable
.setLinesVisible(true);
346 setColumnHeaders(columnData
);
348 // Set the default column field ids if this is not a subclass
349 if (Arrays
.equals(columnData
, COLUMN_DATA
)) {
350 fTable
.getColumns()[0].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
351 fTable
.getColumns()[1].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_SOURCE
);
352 fTable
.getColumns()[2].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TYPE
);
353 fTable
.getColumns()[3].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_REFERENCE
);
354 fTable
.getColumns()[4].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_CONTENT
);
357 // Set the frozen row for header row
358 fTable
.setFrozenRowCount(1);
360 // Create the header row cell editor
361 createHeaderEditor();
363 // Handle the table item selection
364 fTable
.addSelectionListener(new SelectionAdapter() {
366 public void widgetSelected(final SelectionEvent e
) {
367 if (e
.item
== null) {
370 updateStatusLine(null);
371 if (fTable
.getSelectionIndices().length
> 0) {
372 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
373 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
374 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
376 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
377 final ITmfTimestamp ts
= (ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
);
378 if (fTable
.getSelectionIndices().length
== 1) {
379 fSelectedBeginTimestamp
= ts
;
381 if (fSelectedBeginTimestamp
!= null) {
382 if (fSelectedBeginTimestamp
.compareTo(ts
) <= 0) {
383 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, fSelectedBeginTimestamp
, ts
));
384 if (fTable
.getSelectionIndices().length
== 2) {
385 updateStatusLine(ts
.getDelta(fSelectedBeginTimestamp
));
388 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
, fSelectedBeginTimestamp
));
389 if (fStatusLineManager
!= null) {
390 updateStatusLine(fSelectedBeginTimestamp
.getDelta(ts
));
395 if (fTable
.getSelectionIndices().length
== 1) {
396 fSelectedBeginTimestamp
= null;
400 if (e
.item
.getData() != null) {
401 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
403 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
408 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
409 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
410 fCache
= new TmfEventsCache(realCacheSize
, this);
412 // Handle the table item requests
413 fTable
.addListener(SWT
.SetData
, new Listener() {
416 public void handleEvent(final Event event
) {
418 final TableItem item
= (TableItem
) event
.item
;
419 int index
= event
.index
- 1; // -1 for the header row
421 if (event
.index
== 0) {
422 setHeaderRowItemData(item
);
426 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
427 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
428 setFilterStatusRowItemData(item
);
431 index
= index
- 1; // -1 for top filter status row
434 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
435 if (cachedEvent
!= null) {
436 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
440 // Else, fill the cache asynchronously (and off the UI thread)
445 fTable
.addMouseListener(new MouseAdapter() {
447 public void mouseDoubleClick(final MouseEvent event
) {
448 if (event
.button
!= 1) {
451 // Identify the selected row
452 final Point point
= new Point(event
.x
, event
.y
);
453 final TableItem item
= fTable
.getItem(point
);
455 final Rectangle imageBounds
= item
.getImageBounds(0);
456 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
457 if (imageBounds
.contains(point
)) {
458 final Long rank
= (Long
) item
.getData(Key
.RANK
);
460 toggleBookmark(rank
);
467 final Listener tooltipListener
= new Listener () {
468 Shell tooltipShell
= null;
470 public void handleEvent(final Event event
) {
471 switch (event
.type
) {
473 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
477 final Long rank
= (Long
) item
.getData(Key
.RANK
);
481 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
482 final Rectangle bounds
= item
.getImageBounds(0);
483 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
484 if (!bounds
.contains(event
.x
,event
.y
)) {
487 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
488 tooltipShell
.dispose();
490 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
491 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
492 final FillLayout layout
= new FillLayout();
493 layout
.marginWidth
= 2;
494 tooltipShell
.setLayout(layout
);
495 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
496 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: ""); //$NON-NLS-1$ //$NON-NLS-2$
497 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
498 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
500 label
.addListener(SWT
.MouseExit
, this);
501 label
.addListener(SWT
.MouseDown
, this);
502 label
.addListener(SWT
.MouseWheel
, this);
503 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
505 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
506 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
509 if (System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
510 y
+= fTable
.getHeaderHeight();
512 Point pt
= fTable
.toDisplay(event
.x
, y
);
513 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
514 pt
.y
+= item
.getBounds().height
;
515 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
516 tooltipShell
.setVisible(true);
524 if (tooltipShell
!= null) {
525 tooltipShell
.dispose();
535 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
536 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
537 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
538 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
539 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
540 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
541 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
546 ColorSettingsManager
.addColorSettingsListener(this);
548 fTable
.setItemCount(1); // +1 for header row
550 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
552 fRawViewer
.addSelectionListener(new Listener() {
554 public void handleEvent(final Event e
) {
555 if (e
.data
instanceof Long
) {
556 final long rank
= (Long
) e
.data
;
557 int index
= (int) rank
;
558 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
559 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
561 fTable
.setSelection(index
+ 1); // +1 for header row
562 fSelectedRank
= rank
;
563 updateStatusLine(null);
564 } else if (e
.data
instanceof ITmfLocation
) {
565 // DOES NOT WORK: rank undefined in context from seekLocation()
566 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
567 // TmfContext context = fTrace.seekLocation(location);
568 // fTable.setSelection((int) context.getRank());
573 final TableItem
[] selection
= fTable
.getSelection();
574 if ((selection
!= null) && (selection
.length
> 0)) {
575 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
577 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
583 fSashForm
.setWeights(new int[] { 1, 1 });
584 fRawViewer
.setVisible(false);
590 * Create a pop-up menu.
592 protected void createPopupMenu() {
593 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
596 fTable
.setVisible(true);
601 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
604 fTable
.setVisible(false);
609 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
612 fRawViewer
.setVisible(true);
614 final int index
= fTable
.getSelectionIndex();
616 fRawViewer
.selectAndReveal(index
- 1);
621 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
624 fRawViewer
.setVisible(false);
629 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
632 final TableItem items
[] = fTable
.getSelection();
633 if (items
.length
!= 1) {
636 final TableItem item
= items
[0];
638 final Object data
= item
.getData();
639 if (data
instanceof ITmfSourceLookup
) {
640 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
641 ITmfCallsite cs
= event
.getCallsite();
642 if (cs
== null || cs
.getFileName() == null) {
645 IMarker marker
= null;
647 String fileName
= cs
.getFileName();
648 final String trimmedPath
= fileName
.replaceAll("\\.\\./", ""); //$NON-NLS-1$ //$NON-NLS-2$
649 final ArrayList
<IFile
> files
= new ArrayList
<IFile
>();
650 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
652 public boolean visit(IResource resource
) throws CoreException
{
653 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
654 files
.add((IFile
) resource
);
660 if (files
.size() > 1) {
661 ListDialog dialog
= new ListDialog(getTable().getShell());
662 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
663 dialog
.setLabelProvider(new LabelProvider() {
665 public String
getText(Object element
) {
666 return ((IFile
) element
).getFullPath().toString();
669 dialog
.setInput(files
);
670 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
671 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
673 Object
[] result
= dialog
.getResult();
674 if (result
!= null && result
.length
> 0) {
675 file
= (IFile
) result
[0];
677 } else if (files
.size() == 1) {
681 marker
= file
.createMarker(IMarker
.MARKER
);
682 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
683 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
685 } else if (files
.size() == 0){
686 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
688 } catch (CoreException e
) {
695 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
699 final TableItem items
[] = fTable
.getSelection();
700 if (items
.length
!= 1) {
703 final TableItem item
= items
[0];
705 final Object eventData
= item
.getData();
706 if (eventData
instanceof ITmfModelLookup
) {
707 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
709 if (modelURI
!= null) {
710 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
713 final URI uri
= URI
.createURI(modelURI
);
714 if (uri
.isPlatformResource()) {
715 IPath path
= new Path(uri
.toPlatformString(true));
716 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
717 } else if (uri
.isFile() && !uri
.isRelative()) {
718 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
719 new Path(uri
.toFileString()));
725 * create a temporary validation marker on the
726 * model file, remove it afterwards thus,
727 * navigation works with all model editors
728 * supporting the navigation to a marker
730 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
731 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
732 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
734 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
737 catch (CoreException e
) {
741 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
748 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
751 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
752 IHandlerService handlerService
= (IHandlerService
) activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
753 ICommandService cmdService
= (ICommandService
) activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
755 HashMap
<String
, Object
> parameters
= new HashMap
<String
, Object
>();
756 StringBuilder header
= new StringBuilder();
757 boolean needTab
= false;
758 for (TableColumn tc
: fTable
.getColumns()) {
762 header
.append(tc
.getText());
765 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
766 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
,parameters
);
767 IEvaluationContext context
= handlerService
.getCurrentState();
768 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_HEADER_ID
, header
.toString());
769 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_PARAMETER_ID
, TmfEventsTable
.this);
770 handlerService
.executeCommandInContext(cmd
, null, context
);
771 } catch (ExecutionException e
) {
773 } catch (NotDefinedException e
) {
775 } catch (NotEnabledException e
) {
777 } catch (NotHandledException e
) {
783 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
786 fHeaderState
= HeaderState
.SEARCH
;
791 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
794 fHeaderState
= HeaderState
.FILTER
;
799 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
806 class ToggleBookmarkAction
extends Action
{
809 public ToggleBookmarkAction(final String text
, final long rank
) {
816 toggleBookmark(fRank
);
820 final MenuManager tablePopupMenu
= new MenuManager();
821 tablePopupMenu
.setRemoveAllWhenShown(true);
822 tablePopupMenu
.addMenuListener(new IMenuListener() {
824 public void menuAboutToShow(final IMenuManager manager
) {
825 if (fTable
.getSelectionIndex() == 0) {
826 // Right-click on header row
827 if (fHeaderState
== HeaderState
.FILTER
) {
828 tablePopupMenu
.add(showSearchBarAction
);
830 tablePopupMenu
.add(showFilterBarAction
);
834 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
835 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
837 final Rectangle imageBounds
= item
.getImageBounds(0);
838 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
839 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
840 // Right-click on left margin
841 final Long rank
= (Long
) item
.getData(Key
.RANK
);
842 if ((rank
!= null) && (fBookmarksFile
!= null)) {
843 if (fBookmarksMap
.containsKey(rank
)) {
844 tablePopupMenu
.add(new ToggleBookmarkAction(
845 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
847 tablePopupMenu
.add(new ToggleBookmarkAction(
848 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
855 // Right-click on table
856 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
857 tablePopupMenu
.add(hideTableAction
);
858 tablePopupMenu
.add(hideRawAction
);
859 } else if (!fTable
.isVisible()) {
860 tablePopupMenu
.add(showTableAction
);
861 } else if (!fRawViewer
.isVisible()) {
862 tablePopupMenu
.add(showRawAction
);
864 tablePopupMenu
.add(exportToTextAction
);
865 tablePopupMenu
.add(new Separator());
868 final Object data
= item
.getData();
869 Separator separator
= null;
870 if (data
instanceof ITmfSourceLookup
) {
871 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
872 if (event
.getCallsite() != null) {
873 tablePopupMenu
.add(openCallsiteAction
);
874 separator
= new Separator();
878 if (data
instanceof ITmfModelLookup
) {
879 ITmfModelLookup event
= (ITmfModelLookup
) data
;
880 if (event
.getModelUri() != null) {
881 tablePopupMenu
.add(openModelAction
);
882 separator
= new Separator();
885 if (separator
!= null) {
886 tablePopupMenu
.add(separator
);
891 tablePopupMenu
.add(clearFiltersAction
);
892 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
893 if (savedFilters
.length
> 0) {
894 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
895 for (final ITmfFilterTreeNode node
: savedFilters
) {
896 if (node
instanceof TmfFilterNode
) {
897 final TmfFilterNode filter
= (TmfFilterNode
) node
;
898 subMenu
.add(new Action(filter
.getFilterName()) {
906 tablePopupMenu
.add(subMenu
);
908 appendToTablePopupMenu(tablePopupMenu
, item
);
912 final MenuManager rawViewerPopupMenu
= new MenuManager();
913 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
914 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
916 public void menuAboutToShow(final IMenuManager manager
) {
917 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
918 rawViewerPopupMenu
.add(hideTableAction
);
919 rawViewerPopupMenu
.add(hideRawAction
);
920 } else if (!fTable
.isVisible()) {
921 rawViewerPopupMenu
.add(showTableAction
);
922 } else if (!fRawViewer
.isVisible()) {
923 rawViewerPopupMenu
.add(showRawAction
);
925 appendToRawPopupMenu(tablePopupMenu
);
929 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
930 fTable
.setMenu(menu
);
932 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
933 fRawViewer
.setMenu(menu
);
938 * Append an item to the event table's pop-up menu.
940 * @param tablePopupMenu
942 * @param selectedItem
945 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
946 // override to append more actions
950 * Append an item to the raw viewer's pop-up menu.
952 * @param rawViewerPopupMenu
955 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
956 // override to append more actions
960 public void dispose() {
963 ColorSettingsManager
.removeColorSettingsListener(this);
964 fComposite
.dispose();
965 if ((fTrace
!= null) && fDisposeOnClose
) {
968 fResourceManager
.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 TmfDataRequest 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 TmfDataRequest(ITmfEvent
.class, (int) fFilterCheckCount
,
1477 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 ((ITmfDataProvider
) 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 TmfDataRequest 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 TmfDataRequest(ITmfEvent
.class, (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 ((ITmfDataProvider
) 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 boolean isLinux
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
1829 TableColumn tableColumns
[] = fTable
.getColumns();
1830 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1831 final TableColumn column
= tableColumns
[i
];
1832 final int headerWidth
= column
.getWidth();
1834 // Workaround for Linux which doesn't consider the image width of
1835 // search/filter row in TableColumn.pack() after having executed
1836 // TableItem.setImage((Image)null) for other rows than search/filter row.
1837 if (isLinux
&& (i
== 0)) {
1838 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1841 if (column
.getWidth() < headerWidth
) {
1842 column
.setWidth(headerWidth
);
1849 * Extract the fields of an event (item in the table).
1852 * The event to extract from
1853 * @return The array of fields
1856 public final ITmfEventField
[] getItemFields(final ITmfEvent event
) {
1857 return extractItemFields(event
);
1861 * Extract the fields of an event (item in the table).
1864 * The event to extract from
1865 * @return The array of fields
1867 * FIXME: Add support for column selection
1869 protected ITmfEventField
[] extractItemFields(final ITmfEvent event
) {
1870 ITmfEventField
[] fields
= EMPTY_FIELD_ARRAY
;
1871 if (event
!= null) {
1872 final String timestamp
= event
.getTimestamp().toString();
1873 final String source
= event
.getSource();
1874 final String type
= event
.getType().getName();
1875 final String reference
= event
.getReference();
1876 final String content
= event
.getContent().toString();
1877 fields
= new TmfEventField
[] {
1878 new TmfEventField(ITmfEvent
.EVENT_FIELD_TIMESTAMP
, timestamp
, null),
1879 new TmfEventField(ITmfEvent
.EVENT_FIELD_SOURCE
, source
, null),
1880 new TmfEventField(ITmfEvent
.EVENT_FIELD_TYPE
, type
, null),
1881 new TmfEventField(ITmfEvent
.EVENT_FIELD_REFERENCE
, reference
, null),
1882 new TmfEventField(ITmfEvent
.EVENT_FIELD_CONTENT
, content
, null)
1889 * Notify this table that is got the UI focus.
1891 public void setFocus() {
1896 * Assign a new trace to this event table.
1899 * The trace to assign to this event table
1900 * @param disposeOnClose
1901 * true if the trace should be disposed when the table is
1904 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1905 if ((fTrace
!= null) && fDisposeOnClose
) {
1911 fDisposeOnClose
= disposeOnClose
;
1913 // Perform the updates on the UI thread
1914 fTable
.getDisplay().syncExec(new Runnable() {
1918 fCache
.setTrace(fTrace
); // Clear the cache
1919 if (fTrace
!= null) {
1920 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1921 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1922 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1925 fFilterMatchCount
= 0;
1926 fFilterCheckCount
= 0;
1927 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1928 startFilterThread();
1932 fRawViewer
.setTrace(fTrace
);
1938 * Assign the status line manager
1940 * @param statusLineManager
1941 * The status line manager, or null to disable status line messages
1944 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
1945 if (fStatusLineManager
!= null && statusLineManager
== null) {
1946 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
1948 fStatusLineManager
= statusLineManager
;
1951 private void updateStatusLine(ITmfTimestamp delta
) {
1952 if (fStatusLineManager
!= null) {
1953 if (delta
!= null) {
1954 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
1956 fStatusLineManager
.setMessage(null);
1961 // ------------------------------------------------------------------------
1963 // ------------------------------------------------------------------------
1966 * Notify that the event cache has been updated
1969 * Also notify if the populating of the cache is complete, or
1972 public void cacheUpdated(final boolean completed
) {
1973 synchronized (fCacheUpdateSyncObj
) {
1974 if (fCacheUpdateBusy
) {
1975 fCacheUpdatePending
= true;
1976 fCacheUpdateCompleted
= completed
;
1979 fCacheUpdateBusy
= true;
1981 // Event cache is now updated. Perform update on the UI thread
1982 if (!fTable
.isDisposed()) {
1983 fTable
.getDisplay().asyncExec(new Runnable() {
1986 if (!fTable
.isDisposed()) {
1991 populateCompleted();
1993 synchronized (fCacheUpdateSyncObj
) {
1994 fCacheUpdateBusy
= false;
1995 if (fCacheUpdatePending
) {
1996 fCacheUpdatePending
= false;
1997 cacheUpdated(fCacheUpdateCompleted
);
2006 * Callback for when populating the table is complete.
2008 protected void populateCompleted() {
2009 // Nothing by default;
2012 // ------------------------------------------------------------------------
2013 // ISelectionProvider
2014 // ------------------------------------------------------------------------
2020 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2021 selectionChangedListeners
.add(listener
);
2028 public ISelection
getSelection() {
2029 if (fTable
== null || fTable
.isDisposed()) {
2030 return StructuredSelection
.EMPTY
;
2032 List
<Object
> list
= new ArrayList
<Object
>(fTable
.getSelection().length
);
2033 for (TableItem item
: fTable
.getSelection()) {
2034 if (item
.getData() != null) {
2035 list
.add(item
.getData());
2038 return new StructuredSelection(list
);
2045 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2046 selectionChangedListeners
.remove(listener
);
2053 public void setSelection(ISelection selection
) {
2058 * Notifies any selection changed listeners that the viewer's selection has changed.
2059 * Only listeners registered at the time this method is called are notified.
2061 * @param event a selection changed event
2063 * @see ISelectionChangedListener#selectionChanged
2066 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2067 Object
[] listeners
= selectionChangedListeners
.getListeners();
2068 for (int i
= 0; i
< listeners
.length
; ++i
) {
2069 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2070 SafeRunnable
.run(new SafeRunnable() {
2073 l
.selectionChanged(event
);
2079 // ------------------------------------------------------------------------
2080 // Bookmark handling
2081 // ------------------------------------------------------------------------
2084 * Add a bookmark to this event table.
2086 * @param bookmarksFile
2087 * The file to use for the bookmarks
2089 public void addBookmark(final IFile bookmarksFile
) {
2090 fBookmarksFile
= bookmarksFile
;
2091 final TableItem
[] selection
= fTable
.getSelection();
2092 if (selection
.length
> 0) {
2093 final TableItem tableItem
= selection
[0];
2094 if (tableItem
.getData(Key
.RANK
) != null) {
2095 final StringBuffer defaultMessage
= new StringBuffer();
2096 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2098 defaultMessage
.append(", "); //$NON-NLS-1$
2100 defaultMessage
.append(tableItem
.getText(i
));
2102 final InputDialog dialog
= new MultiLineInputDialog(
2103 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2104 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2105 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2106 defaultMessage
.toString());
2107 if (dialog
.open() == Window
.OK
) {
2108 final String message
= dialog
.getValue();
2110 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2111 if (bookmark
.exists()) {
2112 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2113 final long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2114 final int location
= (int) rank
;
2115 bookmark
.setAttribute(IMarker
.LOCATION
, (Integer
) location
);
2116 fBookmarksMap
.put(rank
, bookmark
.getId());
2119 } catch (final CoreException e
) {
2120 displayException(e
);
2129 * Remove a bookmark from this event table.
2132 * The bookmark to remove
2134 public void removeBookmark(final IMarker bookmark
) {
2135 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entrySet()) {
2136 if (entry
.getValue().equals(bookmark
.getId())) {
2137 fBookmarksMap
.remove(entry
.getKey());
2144 private void toggleBookmark(final long rank
) {
2145 if (fBookmarksFile
== null) {
2148 if (fBookmarksMap
.containsKey(rank
)) {
2149 final Long markerId
= fBookmarksMap
.remove(rank
);
2152 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2153 if (bookmark
!= null) {
2156 } catch (final CoreException e
) {
2157 displayException(e
);
2160 addBookmark(fBookmarksFile
);
2165 * Refresh the bookmarks assigned to this trace, from the contents of a
2168 * @param bookmarksFile
2169 * The bookmark file to use
2171 public void refreshBookmarks(final IFile bookmarksFile
) {
2172 fBookmarksFile
= bookmarksFile
;
2173 if (bookmarksFile
== null) {
2174 fBookmarksMap
.clear();
2179 fBookmarksMap
.clear();
2180 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2181 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2182 if (location
!= -1) {
2183 final long rank
= location
;
2184 fBookmarksMap
.put(rank
, bookmark
.getId());
2188 } catch (final CoreException e
) {
2189 displayException(e
);
2194 public void gotoMarker(final IMarker marker
) {
2195 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2198 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2199 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2200 } else if (rank
>= fTable
.getItemCount()) {
2201 fPendingGotoRank
= rank
;
2203 fSelectedRank
= rank
;
2204 fTable
.setSelection(index
+ 1); // +1 for header row
2205 updateStatusLine(null);
2209 // ------------------------------------------------------------------------
2211 // ------------------------------------------------------------------------
2214 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2218 // ------------------------------------------------------------------------
2220 // ------------------------------------------------------------------------
2223 * Handler for the trace updated signal
2226 * The incoming signal
2229 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2230 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2233 // Perform the refresh on the UI thread
2234 Display
.getDefault().asyncExec(new Runnable() {
2237 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2238 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2239 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2240 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2241 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2242 fPendingGotoRank
= -1;
2243 updateStatusLine(null);
2246 startFilterThread();
2249 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2250 fRawViewer
.refreshEventCount();
2257 * Handler for the time synch signal.
2260 * The incoming signal
2263 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2264 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2266 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2267 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2268 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2269 final TmfDataRequest subRequest
= new TmfDataRequest(ITmfEvent
.class,
2270 0, 1, ExecutionType
.FOREGROUND
) {
2272 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2275 public void handleData(final ITmfEvent event
) {
2276 super.handleData(event
);
2280 public void handleCompleted() {
2281 super.handleCompleted();
2282 if (fTrace
== null) {
2286 // Verify if the event is within the trace range and adjust if necessary
2287 ITmfTimestamp timestamp
= ts
;
2288 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2289 timestamp
= fTrace
.getStartTime();
2291 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2292 timestamp
= fTrace
.getEndTime();
2295 // Get the rank of the selected event in the table
2296 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2297 final long rank
= context
.getRank();
2299 fSelectedRank
= rank
;
2301 fTable
.getDisplay().asyncExec(new Runnable() {
2304 // Return if table is disposed
2305 if (fTable
.isDisposed()) {
2309 int index
= (int) rank
;
2310 if (fTable
.isDisposed()) {
2313 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2314 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2316 fTable
.setSelection(index
+ 1); // +1 for header row
2317 fRawViewer
.selectAndReveal(rank
);
2318 updateStatusLine(null);
2324 ((ITmfDataProvider
) fTrace
).sendRequest(subRequest
);
2328 // ------------------------------------------------------------------------
2330 // ------------------------------------------------------------------------
2333 * Display an exception in a message box
2335 * @param e the exception
2337 private static void displayException(final Exception e
) {
2338 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2339 mb
.setText(e
.getClass().getSimpleName());
2340 mb
.setMessage(e
.getMessage());
2347 public void refresh() {