1 /*******************************************************************************
2 * Copyright (c) 2010, 2011, 2012 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 *******************************************************************************/
17 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Arrays
;
21 import java
.util
.HashMap
;
22 import java
.util
.List
;
24 import java
.util
.Map
.Entry
;
25 import java
.util
.regex
.Pattern
;
26 import java
.util
.regex
.PatternSyntaxException
;
28 import org
.eclipse
.core
.resources
.IFile
;
29 import org
.eclipse
.core
.resources
.IMarker
;
30 import org
.eclipse
.core
.resources
.IResource
;
31 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
32 import org
.eclipse
.core
.runtime
.CoreException
;
33 import org
.eclipse
.core
.runtime
.IPath
;
34 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
35 import org
.eclipse
.core
.runtime
.IStatus
;
36 import org
.eclipse
.core
.runtime
.ListenerList
;
37 import org
.eclipse
.core
.runtime
.Path
;
38 import org
.eclipse
.core
.runtime
.Status
;
39 import org
.eclipse
.core
.runtime
.jobs
.Job
;
40 import org
.eclipse
.emf
.common
.util
.URI
;
41 import org
.eclipse
.emf
.ecore
.EValidator
;
42 import org
.eclipse
.jface
.action
.Action
;
43 import org
.eclipse
.jface
.action
.IAction
;
44 import org
.eclipse
.jface
.action
.IMenuListener
;
45 import org
.eclipse
.jface
.action
.IMenuManager
;
46 import org
.eclipse
.jface
.action
.MenuManager
;
47 import org
.eclipse
.jface
.action
.Separator
;
48 import org
.eclipse
.jface
.dialogs
.InputDialog
;
49 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
50 import org
.eclipse
.jface
.resource
.FontDescriptor
;
51 import org
.eclipse
.jface
.resource
.JFaceResources
;
52 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
53 import org
.eclipse
.jface
.util
.OpenStrategy
;
54 import org
.eclipse
.jface
.util
.SafeRunnable
;
55 import org
.eclipse
.jface
.viewers
.ISelection
;
56 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
57 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
58 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
59 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
60 import org
.eclipse
.jface
.window
.Window
;
61 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
62 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
63 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
64 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
65 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
66 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfCustomAttributes
;
67 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
68 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
69 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
70 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
71 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
72 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
73 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
74 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
75 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
76 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
77 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
78 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
.ExecutionType
;
79 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
80 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
81 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
82 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
83 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
84 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
85 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
86 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
87 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
88 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
89 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSetting
;
90 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
91 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
92 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
93 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
94 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
;
95 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
96 import org
.eclipse
.swt
.SWT
;
97 import org
.eclipse
.swt
.custom
.SashForm
;
98 import org
.eclipse
.swt
.custom
.TableEditor
;
99 import org
.eclipse
.swt
.events
.FocusAdapter
;
100 import org
.eclipse
.swt
.events
.FocusEvent
;
101 import org
.eclipse
.swt
.events
.KeyAdapter
;
102 import org
.eclipse
.swt
.events
.KeyEvent
;
103 import org
.eclipse
.swt
.events
.MouseAdapter
;
104 import org
.eclipse
.swt
.events
.MouseEvent
;
105 import org
.eclipse
.swt
.events
.SelectionAdapter
;
106 import org
.eclipse
.swt
.events
.SelectionEvent
;
107 import org
.eclipse
.swt
.graphics
.Color
;
108 import org
.eclipse
.swt
.graphics
.Font
;
109 import org
.eclipse
.swt
.graphics
.Image
;
110 import org
.eclipse
.swt
.graphics
.Point
;
111 import org
.eclipse
.swt
.graphics
.Rectangle
;
112 import org
.eclipse
.swt
.layout
.FillLayout
;
113 import org
.eclipse
.swt
.layout
.GridData
;
114 import org
.eclipse
.swt
.layout
.GridLayout
;
115 import org
.eclipse
.swt
.widgets
.Composite
;
116 import org
.eclipse
.swt
.widgets
.Display
;
117 import org
.eclipse
.swt
.widgets
.Event
;
118 import org
.eclipse
.swt
.widgets
.Label
;
119 import org
.eclipse
.swt
.widgets
.Listener
;
120 import org
.eclipse
.swt
.widgets
.Menu
;
121 import org
.eclipse
.swt
.widgets
.MessageBox
;
122 import org
.eclipse
.swt
.widgets
.Shell
;
123 import org
.eclipse
.swt
.widgets
.TableColumn
;
124 import org
.eclipse
.swt
.widgets
.TableItem
;
125 import org
.eclipse
.swt
.widgets
.Text
;
126 import org
.eclipse
.ui
.IWorkbenchPage
;
127 import org
.eclipse
.ui
.PlatformUI
;
128 import org
.eclipse
.ui
.ide
.IDE
;
129 import org
.eclipse
.ui
.ide
.IGotoMarker
;
130 import org
.eclipse
.ui
.themes
.ColorUtil
;
133 * The generic TMF Events table
135 * This is a view that will list events that are read from a trace.
138 * @author Francois Chouinard
139 * @author Patrick Tasse
142 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
144 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
145 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
146 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
147 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
148 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
149 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
150 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
151 private static final Image FILTER_IMAGE
= Activator
.getDefault()
152 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
153 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
154 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
155 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
156 private static final int MAX_CACHE_SIZE
= 1000;
159 * The events table search/filter keys
162 * @author Patrick Tasse
164 public interface Key
{
166 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
169 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
172 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
175 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
178 String TIMESTAMP
= "$time"; //$NON-NLS-1$
181 String RANK
= "$rank"; //$NON-NLS-1$
184 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
186 /** Bookmark indicator */
187 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
191 * The events table search/filter state
194 * @author Patrick Tasse
196 public static enum HeaderState
{
197 /** A search is being run */
200 /** A filter is applied */
204 interface Direction
{
209 // ------------------------------------------------------------------------
211 // ------------------------------------------------------------------------
213 /** The virtual event table */
214 protected TmfVirtualTable fTable
;
216 private Composite fComposite
;
217 private SashForm fSashForm
;
218 private TmfRawEventViewer fRawViewer
;
219 private ITmfTrace fTrace
;
220 private boolean fPackDone
= false;
221 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
222 private long fSelectedRank
= 0;
225 private long fFilterMatchCount
;
226 private long fFilterCheckCount
;
227 private FilterThread fFilterThread
;
228 private boolean fFilterThreadResume
= false;
229 private final Object fFilterSyncObj
= new Object();
230 private SearchThread fSearchThread
;
231 private final Object fSearchSyncObj
= new Object();
234 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
236 * @see #fireSelectionChanged
238 private ListenerList selectionChangedListeners
= new ListenerList();
240 // Bookmark map <Rank, MarkerId>
241 private Map
<Long
, Long
> fBookmarksMap
= new HashMap
<Long
, Long
>();
242 private IFile fBookmarksFile
;
243 private long fPendingGotoRank
= -1;
246 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
247 private Color fGrayColor
;
248 private Color fGreenColor
;
249 private Font fBoldFont
;
251 // Table column names
252 private static final String
[] COLUMN_NAMES
= new String
[] { Messages
.TmfEventsTable_TimestampColumnHeader
,
253 Messages
.TmfEventsTable_SourceColumnHeader
, Messages
.TmfEventsTable_TypeColumnHeader
,
254 Messages
.TmfEventsTable_ReferenceColumnHeader
, Messages
.TmfEventsTable_ContentColumnHeader
};
256 private static final ColumnData
[] COLUMN_DATA
= new ColumnData
[] { new ColumnData(COLUMN_NAMES
[0], 100, SWT
.LEFT
),
257 new ColumnData(COLUMN_NAMES
[1], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[2], 100, SWT
.LEFT
),
258 new ColumnData(COLUMN_NAMES
[3], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[4], 100, SWT
.LEFT
) };
261 private final TmfEventsCache fCache
;
262 private boolean fCacheUpdateBusy
= false;
263 private boolean fCacheUpdatePending
= false;
264 private boolean fCacheUpdateCompleted
= false;
265 private final Object fCacheUpdateSyncObj
= new Object();
267 private boolean fDisposeOnClose
;
269 // ------------------------------------------------------------------------
271 // ------------------------------------------------------------------------
274 * Basic constructor, will use default column data.
277 * The parent composite UI object
279 * The size of the event table cache
281 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
282 this(parent
, cacheSize
, COLUMN_DATA
);
286 * Advanced constructor, where we also define which column data to use.
289 * The parent composite UI object
291 * The size of the event table cache
293 * The column data to use for this table
295 public TmfEventsTable(final Composite parent
, int cacheSize
, final ColumnData
[] columnData
) {
296 super("TmfEventsTable"); //$NON-NLS-1$
298 fComposite
= new Composite(parent
, SWT
.NONE
);
299 final GridLayout gl
= new GridLayout(1, false);
302 gl
.verticalSpacing
= 0;
303 fComposite
.setLayout(gl
);
305 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
306 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
308 // Create a virtual table
309 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.SINGLE
| SWT
.FULL_SELECTION
;
310 fTable
= new TmfVirtualTable(fSashForm
, style
);
312 // Set the table layout
313 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
314 fTable
.setLayoutData(layoutData
);
316 // Some cosmetic enhancements
317 fTable
.setHeaderVisible(true);
318 fTable
.setLinesVisible(true);
321 setColumnHeaders(columnData
);
323 // Set the default column field ids if this is not a subclass
324 if (Arrays
.equals(columnData
, COLUMN_DATA
)) {
325 fTable
.getColumns()[0].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
326 fTable
.getColumns()[1].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_SOURCE
);
327 fTable
.getColumns()[2].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TYPE
);
328 fTable
.getColumns()[3].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_REFERENCE
);
329 fTable
.getColumns()[4].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_CONTENT
);
332 // Set the frozen row for header row
333 fTable
.setFrozenRowCount(1);
335 // Create the header row cell editor
336 createHeaderEditor();
338 // Handle the table item selection
339 fTable
.addSelectionListener(new SelectionAdapter() {
341 public void widgetSelected(final SelectionEvent e
) {
342 final TableItem
[] selection
= fTable
.getSelection();
343 if (selection
.length
> 0) {
344 final TableItem selectedTableItem
= selection
[0];
345 if (selectedTableItem
!= null) {
346 if (selectedTableItem
.getData(Key
.RANK
) instanceof Long
) {
347 fSelectedRank
= (Long
) selectedTableItem
.getData(Key
.RANK
);
348 fRawViewer
.selectAndReveal((Long
) selectedTableItem
.getData(Key
.RANK
));
350 if (selectedTableItem
.getData(Key
.TIMESTAMP
) instanceof TmfTimestamp
) {
351 final TmfTimestamp ts
= (TmfTimestamp
) selectedTableItem
.getData(Key
.TIMESTAMP
);
352 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
356 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
360 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
361 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
362 fCache
= new TmfEventsCache(realCacheSize
, this);
364 // Handle the table item requests
365 fTable
.addListener(SWT
.SetData
, new Listener() {
368 public void handleEvent(final Event event
) {
370 final TableItem item
= (TableItem
) event
.item
;
371 int index
= event
.index
- 1; // -1 for the header row
373 if (event
.index
== 0) {
374 setHeaderRowItemData(item
);
378 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
379 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
380 setFilterStatusRowItemData(item
);
383 index
= index
- 1; // -1 for top filter status row
386 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
387 if (cachedEvent
!= null) {
388 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
392 // Else, fill the cache asynchronously (and off the UI thread)
397 fTable
.addMouseListener(new MouseAdapter() {
399 public void mouseDoubleClick(final MouseEvent event
) {
400 if (event
.button
!= 1) {
403 // Identify the selected row
404 final Point point
= new Point(event
.x
, event
.y
);
405 final TableItem item
= fTable
.getItem(point
);
407 final Rectangle imageBounds
= item
.getImageBounds(0);
408 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
409 if (imageBounds
.contains(point
)) {
410 final Long rank
= (Long
) item
.getData(Key
.RANK
);
412 toggleBookmark(rank
);
419 final Listener tooltipListener
= new Listener () {
420 Shell tooltipShell
= null;
422 public void handleEvent(final Event event
) {
423 switch (event
.type
) {
425 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
429 final Long rank
= (Long
) item
.getData(Key
.RANK
);
433 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
434 final Rectangle bounds
= item
.getImageBounds(0);
435 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
436 if (!bounds
.contains(event
.x
,event
.y
)) {
439 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
440 tooltipShell
.dispose();
442 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
443 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
444 final FillLayout layout
= new FillLayout();
445 layout
.marginWidth
= 2;
446 tooltipShell
.setLayout(layout
);
447 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
448 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: ""); //$NON-NLS-1$ //$NON-NLS-2$
449 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
450 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
452 label
.addListener(SWT
.MouseExit
, this);
453 label
.addListener(SWT
.MouseDown
, this);
454 label
.addListener(SWT
.MouseWheel
, this);
455 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
457 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
458 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
461 if (System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
462 y
+= fTable
.getHeaderHeight();
464 Point pt
= fTable
.toDisplay(event
.x
, y
);
465 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
466 pt
.y
+= item
.getBounds().height
;
467 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
468 tooltipShell
.setVisible(true);
476 if (tooltipShell
!= null) {
477 tooltipShell
.dispose();
487 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
488 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
489 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
490 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
491 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
492 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
493 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
498 ColorSettingsManager
.addColorSettingsListener(this);
500 fTable
.setItemCount(1); // +1 for header row
502 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
504 fRawViewer
.addSelectionListener(new Listener() {
506 public void handleEvent(final Event e
) {
507 if (e
.data
instanceof Long
) {
508 final long rank
= (Long
) e
.data
;
509 int index
= (int) rank
;
510 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
511 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
513 fTable
.setSelection(index
+ 1); // +1 for header row
514 fSelectedRank
= rank
;
515 } else if (e
.data
instanceof ITmfLocation
) {
516 // DOES NOT WORK: rank undefined in context from seekLocation()
517 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
518 // TmfContext context = fTrace.seekLocation(location);
519 // fTable.setSelection((int) context.getRank());
524 final TableItem
[] selection
= fTable
.getSelection();
525 if ((selection
!= null) && (selection
.length
> 0)) {
526 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
528 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
534 fSashForm
.setWeights(new int[] { 1, 1 });
535 fRawViewer
.setVisible(false);
541 * Create a pop-up menu.
543 protected void createPopupMenu() {
544 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
547 fTable
.setVisible(true);
552 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
555 fTable
.setVisible(false);
560 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
563 fRawViewer
.setVisible(true);
565 final int index
= fTable
.getSelectionIndex();
567 fRawViewer
.selectAndReveal(index
- 1);
572 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
575 fRawViewer
.setVisible(false);
580 final IAction navigateToEventAction
= new Action(Messages
.TmfEventsTable_NavigateToModelActionText
) {
584 final TableItem items
[] = fTable
.getSelection();
585 if (items
.length
!= 1) {
588 final TableItem item
= items
[0];
590 final Object eventData
= item
.getData();
591 if (eventData
instanceof CtfTmfEvent
) {
592 String modelURI
= ((CtfTmfEvent
) eventData
).getCustomAttribute(CtfCustomAttributes
.MODEL_URI_KEY
);
594 if (modelURI
!= null) {
595 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
598 final URI uri
= URI
.createURI(modelURI
);
599 if (uri
.isPlatformResource()) {
600 IPath path
= new Path(uri
.toPlatformString(true));
601 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
602 } else if (uri
.isFile() && !uri
.isRelative()) {
603 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
604 new Path(uri
.toFileString()));
610 * create a temporary validation marker on the
611 * model file, remove it afterwards thus,
612 * navigation works with all model editors
613 * supporting the navigation to a marker
615 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
616 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
617 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
619 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
622 catch (CoreException e
) {
630 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
633 fHeaderState
= HeaderState
.SEARCH
;
638 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
641 fHeaderState
= HeaderState
.FILTER
;
646 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
653 class ToggleBookmarkAction
extends Action
{
656 public ToggleBookmarkAction(final String text
, final long rank
) {
663 toggleBookmark(fRank
);
667 final MenuManager tablePopupMenu
= new MenuManager();
668 tablePopupMenu
.setRemoveAllWhenShown(true);
669 tablePopupMenu
.addMenuListener(new IMenuListener() {
671 public void menuAboutToShow(final IMenuManager manager
) {
672 if (fTable
.getSelectionIndex() == 0) {
673 // Right-click on header row
674 if (fHeaderState
== HeaderState
.FILTER
) {
675 tablePopupMenu
.add(showSearchBarAction
);
677 tablePopupMenu
.add(showFilterBarAction
);
681 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
682 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
684 final Rectangle imageBounds
= item
.getImageBounds(0);
685 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
686 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
687 // Right-click on left margin
688 final Long rank
= (Long
) item
.getData(Key
.RANK
);
689 if ((rank
!= null) && (fBookmarksFile
!= null)) {
690 if (fBookmarksMap
.containsKey(rank
)) {
691 tablePopupMenu
.add(new ToggleBookmarkAction(
692 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
694 tablePopupMenu
.add(new ToggleBookmarkAction(
695 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
701 // Right-click on table
702 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
703 tablePopupMenu
.add(hideTableAction
);
704 tablePopupMenu
.add(hideRawAction
);
705 } else if (!fTable
.isVisible()) {
706 tablePopupMenu
.add(showTableAction
);
707 } else if (!fRawViewer
.isVisible()) {
708 tablePopupMenu
.add(showRawAction
);
710 tablePopupMenu
.add(new Separator());
712 // add navigation action, if event meta data contain a model URI
713 final Object eventData
= item
.getData();
714 if (eventData
instanceof CtfTmfEvent
) {
715 if (((CtfTmfEvent
) eventData
).listCustomAttributes().contains(CtfCustomAttributes
.MODEL_URI_KEY
)) {
716 tablePopupMenu
.add(navigateToEventAction
);
717 tablePopupMenu
.add(new Separator());
721 tablePopupMenu
.add(clearFiltersAction
);
722 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
723 if (savedFilters
.length
> 0) {
724 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
725 for (final ITmfFilterTreeNode node
: savedFilters
) {
726 if (node
instanceof TmfFilterNode
) {
727 final TmfFilterNode filter
= (TmfFilterNode
) node
;
728 subMenu
.add(new Action(filter
.getFilterName()) {
736 tablePopupMenu
.add(subMenu
);
738 appendToTablePopupMenu(tablePopupMenu
, item
);
742 final MenuManager rawViewerPopupMenu
= new MenuManager();
743 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
744 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
746 public void menuAboutToShow(final IMenuManager manager
) {
747 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
748 rawViewerPopupMenu
.add(hideTableAction
);
749 rawViewerPopupMenu
.add(hideRawAction
);
750 } else if (!fTable
.isVisible()) {
751 rawViewerPopupMenu
.add(showTableAction
);
752 } else if (!fRawViewer
.isVisible()) {
753 rawViewerPopupMenu
.add(showRawAction
);
755 appendToRawPopupMenu(tablePopupMenu
);
759 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
760 fTable
.setMenu(menu
);
762 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
763 fRawViewer
.setMenu(menu
);
768 * Append an item to the event table's pop-up menu.
770 * @param tablePopupMenu
772 * @param selectedItem
775 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
776 // override to append more actions
780 * Append an item to the raw viewer's pop-up menu.
782 * @param rawViewerPopupMenu
785 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
786 // override to append more actions
790 public void dispose() {
793 ColorSettingsManager
.removeColorSettingsListener(this);
794 fComposite
.dispose();
795 if ((fTrace
!= null) && fDisposeOnClose
) {
798 fResourceManager
.dispose();
803 * Assign a layout data object to this view.
806 * The layout data to assign
808 public void setLayoutData(final Object layoutData
) {
809 fComposite
.setLayoutData(layoutData
);
813 * Get the virtual table contained in this event table.
815 * @return The TMF virtual table
817 public TmfVirtualTable
getTable() {
824 * FIXME: Add support for column selection
826 protected void setColumnHeaders(final ColumnData
[] columnData
) {
827 fTable
.setColumnHeaders(columnData
);
831 * Set a table item's data.
836 * Which trace event to link with this entry
838 * Which rank this event has in the trace/experiment
840 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
841 final ITmfEventField
[] fields
= extractItemFields(event
);
842 final String
[] content
= new String
[fields
.length
];
843 for (int i
= 0; i
< fields
.length
; i
++) {
844 content
[i
] = fields
[i
].getValue() != null ? fields
[i
].getValue().toString() : ""; //$NON-NLS-1$
846 item
.setText(content
);
848 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
849 item
.setData(Key
.RANK
, rank
);
851 boolean bookmark
= false;
852 final Long markerId
= fBookmarksMap
.get(rank
);
853 if (markerId
!= null) {
856 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
857 item
.setData(Key
.BOOKMARK
, marker
.getAttribute(IMarker
.MESSAGE
));
858 } catch (final CoreException e
) {
862 item
.setData(Key
.BOOKMARK
, null);
865 boolean searchMatch
= false;
866 boolean searchNoMatch
= false;
867 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
868 if (searchFilter
!= null) {
869 if (searchFilter
.matches(event
)) {
872 searchNoMatch
= true;
876 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
878 item
.setForeground(colorSetting
.getDimmedForegroundColor());
879 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
881 item
.setForeground(colorSetting
.getForegroundColor());
882 item
.setBackground(colorSetting
.getBackgroundColor());
887 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
889 item
.setImage(SEARCH_MATCH_IMAGE
);
891 } else if (bookmark
) {
892 item
.setImage(BOOKMARK_IMAGE
);
894 item
.setImage((Image
) null);
899 * Set the item data of the header row.
902 * The item to use as table header
904 protected void setHeaderRowItemData(final TableItem item
) {
905 String txtKey
= null;
906 if (fHeaderState
== HeaderState
.SEARCH
) {
907 item
.setImage(SEARCH_IMAGE
);
908 txtKey
= Key
.SEARCH_TXT
;
909 } else if (fHeaderState
== HeaderState
.FILTER
) {
910 item
.setImage(FILTER_IMAGE
);
911 txtKey
= Key
.FILTER_TXT
;
913 item
.setForeground(fGrayColor
);
914 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
915 final TableColumn column
= fTable
.getColumns()[i
];
916 final String filter
= (String
) column
.getData(txtKey
);
917 if (filter
== null) {
918 if (fHeaderState
== HeaderState
.SEARCH
) {
919 item
.setText(i
, SEARCH_HINT
);
920 } else if (fHeaderState
== HeaderState
.FILTER
) {
921 item
.setText(i
, FILTER_HINT
);
923 item
.setForeground(i
, fGrayColor
);
924 item
.setFont(i
, fTable
.getFont());
926 item
.setText(i
, filter
);
927 item
.setForeground(i
, fGreenColor
);
928 item
.setFont(i
, fBoldFont
);
934 * Set the item data of the "filter status" row.
937 * The item to use as filter status row
939 protected void setFilterStatusRowItemData(final TableItem item
) {
940 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
942 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
943 item
.setImage(FILTER_IMAGE
);
945 item
.setImage(STOP_IMAGE
);
947 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
949 item
.setText(i
, ""); //$NON-NLS-1$
953 item
.setData(Key
.TIMESTAMP
, null);
954 item
.setData(Key
.RANK
, null);
955 item
.setForeground(null);
956 item
.setBackground(null);
960 * Create an editor for the header.
962 protected void createHeaderEditor() {
963 final TableEditor tableEditor
= fTable
.createTableEditor();
964 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
965 tableEditor
.verticalAlignment
= SWT
.CENTER
;
966 tableEditor
.grabHorizontal
= true;
967 tableEditor
.minimumWidth
= 50;
969 // Handle the header row selection
970 fTable
.addMouseListener(new MouseAdapter() {
976 public void mouseDown(final MouseEvent event
) {
977 if (event
.button
!= 1) {
980 // Identify the selected row
981 final Point point
= new Point(event
.x
, event
.y
);
982 item
= fTable
.getItem(point
);
984 // Header row selected
985 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
988 if (item
.getImageBounds(0).contains(point
)) {
989 if (fHeaderState
== HeaderState
.SEARCH
) {
990 fHeaderState
= HeaderState
.FILTER
;
991 } else if (fHeaderState
== HeaderState
.FILTER
) {
992 fHeaderState
= HeaderState
.SEARCH
;
998 // Identify the selected column
1000 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1001 final Rectangle rect
= item
.getBounds(i
);
1002 if (rect
.contains(point
)) {
1008 if (columnIndex
== -1) {
1012 column
= fTable
.getColumns()[columnIndex
];
1014 String txtKey
= null;
1015 if (fHeaderState
== HeaderState
.SEARCH
) {
1016 txtKey
= Key
.SEARCH_TXT
;
1017 } else if (fHeaderState
== HeaderState
.FILTER
) {
1018 txtKey
= Key
.FILTER_TXT
;
1021 // The control that will be the editor must be a child of the Table
1022 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1023 final String headerString
= (String
) column
.getData(txtKey
);
1024 if (headerString
!= null) {
1025 newEditor
.setText(headerString
);
1027 newEditor
.addFocusListener(new FocusAdapter() {
1029 public void focusLost(final FocusEvent e
) {
1030 final boolean changed
= updateHeader(newEditor
.getText());
1036 newEditor
.addKeyListener(new KeyAdapter() {
1038 public void keyPressed(final KeyEvent e
) {
1039 if (e
.character
== SWT
.CR
) {
1040 updateHeader(newEditor
.getText());
1042 } else if (e
.character
== SWT
.ESC
) {
1043 tableEditor
.getEditor().dispose();
1047 newEditor
.selectAll();
1048 newEditor
.setFocus();
1049 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1054 * returns true is value was changed
1056 private boolean updateHeader(final String text
) {
1057 String objKey
= null;
1058 String txtKey
= null;
1059 if (fHeaderState
== HeaderState
.SEARCH
) {
1060 objKey
= Key
.SEARCH_OBJ
;
1061 txtKey
= Key
.SEARCH_TXT
;
1062 } else if (fHeaderState
== HeaderState
.FILTER
) {
1063 objKey
= Key
.FILTER_OBJ
;
1064 txtKey
= Key
.FILTER_TXT
;
1066 if (text
.trim().length() > 0) {
1068 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
1069 Pattern
.compile(regex
);
1070 if (regex
.equals(column
.getData(txtKey
))) {
1071 tableEditor
.getEditor().dispose();
1074 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1075 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
1076 if (fieldId
== null) {
1077 fieldId
= column
.getText();
1079 filter
.setField(fieldId
);
1080 filter
.setRegex(regex
);
1081 column
.setData(objKey
, filter
);
1082 column
.setData(txtKey
, regex
);
1083 } catch (final PatternSyntaxException ex
) {
1084 tableEditor
.getEditor().dispose();
1085 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1086 ex
.getDescription(), ex
.getMessage());
1090 if (column
.getData(txtKey
) == null) {
1091 tableEditor
.getEditor().dispose();
1094 column
.setData(objKey
, null);
1095 column
.setData(txtKey
, null);
1100 private void applyHeader() {
1101 if (fHeaderState
== HeaderState
.SEARCH
) {
1103 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1104 for (final TableColumn col
: fTable
.getColumns()) {
1105 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1106 if (filterObj
instanceof ITmfFilterTreeNode
) {
1107 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1110 if (filter
.getChildrenCount() > 0) {
1111 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1114 fireSearchApplied(filter
);
1116 fTable
.setData(Key
.SEARCH_OBJ
, null);
1118 fireSearchApplied(null);
1120 } else if (fHeaderState
== HeaderState
.FILTER
) {
1121 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1122 for (final TableColumn col
: fTable
.getColumns()) {
1123 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1124 if (filterObj
instanceof ITmfFilterTreeNode
) {
1125 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1128 if (filter
.getChildrenCount() > 0) {
1129 applyFilter(filter
);
1135 tableEditor
.getEditor().dispose();
1139 fTable
.addKeyListener(new KeyAdapter() {
1141 public void keyPressed(final KeyEvent e
) {
1143 if (e
.character
== SWT
.ESC
) {
1147 } else if (e
.character
== SWT
.DEL
) {
1148 if (fHeaderState
== HeaderState
.SEARCH
) {
1150 for (final TableColumn column
: fTable
.getColumns()) {
1151 column
.setData(Key
.SEARCH_OBJ
, null);
1152 column
.setData(Key
.SEARCH_TXT
, null);
1154 fTable
.setData(Key
.SEARCH_OBJ
, null);
1156 fireSearchApplied(null);
1157 } else if (fHeaderState
== HeaderState
.FILTER
) {
1160 } else if (e
.character
== SWT
.CR
) {
1161 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1172 * Send an event indicating a filter has been applied.
1175 * The filter that was just applied
1177 protected void fireFilterApplied(final ITmfFilter filter
) {
1178 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1182 * Send an event indicating that a search has been applied.
1185 * The search filter that was just applied
1187 protected void fireSearchApplied(final ITmfFilter filter
) {
1188 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1192 * Start the filtering thread.
1194 protected void startFilterThread() {
1195 synchronized (fFilterSyncObj
) {
1196 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1197 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1198 if (fFilterThread
!= null) {
1199 fFilterThread
.cancel();
1200 fFilterThreadResume
= false;
1202 fFilterThread
= new FilterThread(filter
);
1203 fFilterThread
.start();
1205 fFilterThreadResume
= true;
1211 * Stop the filtering thread.
1213 protected void stopFilterThread() {
1214 synchronized (fFilterSyncObj
) {
1215 if (fFilterThread
!= null) {
1216 fFilterThread
.cancel();
1217 fFilterThread
= null;
1218 fFilterThreadResume
= false;
1227 * The filter to apply
1230 protected void applyFilter(ITmfFilter filter
) {
1233 fFilterMatchCount
= 0;
1234 fFilterCheckCount
= 0;
1235 fCache
.applyFilter(filter
);
1237 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1238 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1239 startFilterThread();
1240 fireFilterApplied(filter
);
1244 * Clear all currently active filters.
1246 protected void clearFilters() {
1247 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1252 fCache
.clearFilter();
1254 for (final TableColumn column
: fTable
.getColumns()) {
1255 column
.setData(Key
.FILTER_OBJ
, null);
1256 column
.setData(Key
.FILTER_TXT
, null);
1258 fTable
.setData(Key
.FILTER_OBJ
, null);
1259 if (fTrace
!= null) {
1260 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1262 fTable
.setItemCount(1); // +1 for header row
1264 fFilterMatchCount
= 0;
1265 fFilterCheckCount
= 0;
1266 if (fSelectedRank
>= 0) {
1267 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1269 fTable
.setSelection(0);
1271 fireFilterApplied(null);
1275 * Wrapper Thread object for the filtering thread.
1277 protected class FilterThread
extends Thread
{
1278 private final ITmfFilterTreeNode filter
;
1279 private TmfDataRequest request
;
1280 private boolean refreshBusy
= false;
1281 private boolean refreshPending
= false;
1282 private final Object syncObj
= new Object();
1288 * The filter this thread will be processing
1290 public FilterThread(final ITmfFilterTreeNode filter
) {
1291 super("Filter Thread"); //$NON-NLS-1$
1292 this.filter
= filter
;
1297 if (fTrace
== null) {
1300 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1301 if (nbRequested
<= 0) {
1304 request
= new TmfDataRequest(ITmfEvent
.class, (int) fFilterCheckCount
,
1305 nbRequested
, fTrace
.getCacheSize(), ExecutionType
.BACKGROUND
) {
1307 public void handleData(final ITmfEvent event
) {
1308 super.handleData(event
);
1309 if (request
.isCancelled()) {
1312 if (filter
.matches(event
)) {
1313 final long rank
= fFilterCheckCount
;
1314 final int index
= (int) fFilterMatchCount
;
1315 fFilterMatchCount
++;
1316 fCache
.storeEvent(event
, rank
, index
);
1318 } else if ((fFilterCheckCount
% 100) == 0) {
1321 fFilterCheckCount
++;
1324 ((ITmfDataProvider
) fTrace
).sendRequest(request
);
1326 request
.waitForCompletion();
1327 } catch (final InterruptedException e
) {
1330 synchronized (fFilterSyncObj
) {
1331 fFilterThread
= null;
1332 if (fFilterThreadResume
) {
1333 fFilterThreadResume
= false;
1334 fFilterThread
= new FilterThread(filter
);
1335 fFilterThread
.start();
1341 * Refresh the filter.
1343 public void refreshTable() {
1344 synchronized (syncObj
) {
1346 refreshPending
= true;
1351 Display
.getDefault().asyncExec(new Runnable() {
1354 if (request
.isCancelled()) {
1357 if (fTable
.isDisposed()) {
1360 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1362 synchronized (syncObj
) {
1363 refreshBusy
= false;
1364 if (refreshPending
) {
1365 refreshPending
= false;
1374 * Cancel this filtering thread.
1376 public void cancel() {
1377 if (request
!= null) {
1384 * Go to the next item of a search.
1386 protected void searchNext() {
1387 synchronized (fSearchSyncObj
) {
1388 if (fSearchThread
!= null) {
1391 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1392 if (searchFilter
== null) {
1395 final int selectionIndex
= fTable
.getSelectionIndex();
1397 if (selectionIndex
> 0) {
1398 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1400 // header row is selected, start at top event
1401 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1403 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1404 if (eventFilter
!= null)
1406 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1408 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1409 fSearchThread
.schedule();
1414 * Go to the previous item of a search.
1416 protected void searchPrevious() {
1417 synchronized (fSearchSyncObj
) {
1418 if (fSearchThread
!= null) {
1421 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1422 if (searchFilter
== null) {
1425 final int selectionIndex
= fTable
.getSelectionIndex();
1427 if (selectionIndex
> 0) {
1428 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1430 // header row is selected, start at precedent of top event
1431 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1433 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1434 if (eventFilter
!= null)
1436 startIndex
= startIndex
- 1; // -1 for top filter status row
1438 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1439 fSearchThread
.schedule();
1444 * Stop the search thread.
1446 protected void stopSearchThread() {
1447 fPendingGotoRank
= -1;
1448 synchronized (fSearchSyncObj
) {
1449 if (fSearchThread
!= null) {
1450 fSearchThread
.cancel();
1451 fSearchThread
= null;
1457 * Wrapper for the search thread.
1459 protected class SearchThread
extends Job
{
1461 private ITmfFilterTreeNode searchFilter
;
1462 private ITmfFilterTreeNode eventFilter
;
1463 private int startIndex
;
1464 private int direction
;
1466 private long foundRank
= -1;
1467 private TmfDataRequest request
;
1468 private ITmfTimestamp foundTimestamp
= null;
1473 * @param searchFilter
1475 * @param eventFilter
1478 * The index at which we should start searching
1479 * @param currentRank
1482 * In which direction should we search, forward or backwards
1484 public SearchThread(final ITmfFilterTreeNode searchFilter
,
1485 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1486 final long currentRank
, final int direction
) {
1487 super(Messages
.TmfEventsTable_SearchingJobName
);
1488 this.searchFilter
= searchFilter
;
1489 this.eventFilter
= eventFilter
;
1490 this.startIndex
= startIndex
;
1491 this.rank
= currentRank
;
1492 this.direction
= direction
;
1496 protected IStatus
run(final IProgressMonitor monitor
) {
1497 if (fTrace
== null) {
1498 return Status
.OK_STATUS
;
1500 final Display display
= Display
.getDefault();
1501 if (startIndex
< 0) {
1502 rank
= (int) fTrace
.getNbEvents() - 1;
1503 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1506 int idx
= startIndex
;
1507 while (foundRank
== -1) {
1508 final CachedEvent event
= fCache
.peekEvent(idx
);
1509 if (event
== null) {
1513 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1514 foundRank
= event
.rank
;
1515 foundTimestamp
= event
.event
.getTimestamp();
1518 if (direction
== Direction
.FORWARD
) {
1524 if (foundRank
== -1) {
1525 if (direction
== Direction
.FORWARD
) {
1527 if (rank
> (fTrace
.getNbEvents() - 1)) {
1533 rank
= (int) fTrace
.getNbEvents() - 1;
1538 final int startRank
= (int) rank
;
1539 boolean wrapped
= false;
1540 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1541 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1542 if (direction
== Direction
.BACKWARD
) {
1543 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1545 request
= new TmfDataRequest(ITmfEvent
.class, (int) rank
, nbRequested
, fTrace
.getCacheSize(), ExecutionType
.BACKGROUND
) {
1546 long currentRank
= rank
;
1549 public void handleData(final ITmfEvent event
) {
1550 super.handleData(event
);
1551 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1552 foundRank
= currentRank
;
1553 foundTimestamp
= event
.getTimestamp();
1554 if (direction
== Direction
.FORWARD
) {
1562 ((ITmfDataProvider
) fTrace
).sendRequest(request
);
1564 request
.waitForCompletion();
1565 if (request
.isCancelled()) {
1566 return Status
.OK_STATUS
;
1568 } catch (final InterruptedException e
) {
1569 synchronized (fSearchSyncObj
) {
1570 fSearchThread
= null;
1572 return Status
.OK_STATUS
;
1574 if (foundRank
== -1) {
1575 if (direction
== Direction
.FORWARD
) {
1577 synchronized (fSearchSyncObj
) {
1578 fSearchThread
= null;
1580 return Status
.OK_STATUS
;
1582 nbRequested
= (int) rank
;
1588 rank
= (int) fTrace
.getNbEvents() - 1;
1591 if ((rank
<= startRank
) && wrapped
) {
1592 synchronized (fSearchSyncObj
) {
1593 fSearchThread
= null;
1595 return Status
.OK_STATUS
;
1600 int index
= (int) foundRank
;
1601 if (eventFilter
!= null) {
1602 index
= fCache
.getFilteredEventIndex(foundRank
);
1604 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1606 display
.asyncExec(new Runnable() {
1609 if (monitor
.isCanceled()) {
1612 if (fTable
.isDisposed()) {
1615 fTable
.setSelection(selection
);
1616 fSelectedRank
= foundRank
;
1617 fRawViewer
.selectAndReveal(fSelectedRank
);
1618 if (foundTimestamp
!= null) {
1619 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1621 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
1622 synchronized (fSearchSyncObj
) {
1623 fSearchThread
= null;
1627 return Status
.OK_STATUS
;
1631 protected void canceling() {
1633 synchronized (fSearchSyncObj
) {
1634 fSearchThread
= null;
1640 * Create the resources.
1642 protected void createResources() {
1643 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1644 .getForeground().getRGB()));
1645 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1646 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1652 protected void packColumns() {
1656 boolean isLinux
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
1658 TableColumn tableColumns
[] = fTable
.getColumns();
1659 for (int i
= 0; i
< tableColumns
.length
; i
++) {
1660 final TableColumn column
= tableColumns
[i
];
1661 final int headerWidth
= column
.getWidth();
1663 // Workaround for Linux which doesn't consider the image width of
1664 // search/filter row in TableColumn.pack() after having executed
1665 // TableItem.setImage((Image)null) for other rows than search/filter row.
1666 if (isLinux
&& (i
== 0)) {
1667 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
1670 if (column
.getWidth() < headerWidth
) {
1671 column
.setWidth(headerWidth
);
1678 * Extract the fields of an event (item in the table).
1681 * The event to extract from
1682 * @return The array of fields
1684 * FIXME: Add support for column selection
1686 protected ITmfEventField
[] extractItemFields(final ITmfEvent event
) {
1687 ITmfEventField
[] fields
= new TmfEventField
[0];
1688 if (event
!= null) {
1689 final String timestamp
= event
.getTimestamp().toString();
1690 final String source
= event
.getSource();
1691 final String type
= event
.getType().getName();
1692 final String reference
= event
.getReference();
1693 final String content
= event
.getContent().toString();
1694 fields
= new TmfEventField
[] {
1695 new TmfEventField(ITmfEvent
.EVENT_FIELD_TIMESTAMP
, timestamp
),
1696 new TmfEventField(ITmfEvent
.EVENT_FIELD_SOURCE
, source
),
1697 new TmfEventField(ITmfEvent
.EVENT_FIELD_TYPE
, type
),
1698 new TmfEventField(ITmfEvent
.EVENT_FIELD_REFERENCE
, reference
),
1699 new TmfEventField(ITmfEvent
.EVENT_FIELD_CONTENT
, content
)
1706 * Notify this table that is got the UI focus.
1708 public void setFocus() {
1713 * Assign a new trace to this event table.
1716 * The trace to assign to this event table
1717 * @param disposeOnClose
1718 * true if the trace should be disposed when the table is
1721 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1722 if ((fTrace
!= null) && fDisposeOnClose
) {
1728 fDisposeOnClose
= disposeOnClose
;
1730 // Perform the updates on the UI thread
1731 fTable
.getDisplay().syncExec(new Runnable() {
1735 fCache
.setTrace(fTrace
); // Clear the cache
1736 if (fTrace
!= null) {
1737 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1738 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1739 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1742 fFilterMatchCount
= 0;
1743 fFilterCheckCount
= 0;
1744 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1745 startFilterThread();
1749 fRawViewer
.setTrace(fTrace
);
1754 // ------------------------------------------------------------------------
1756 // ------------------------------------------------------------------------
1759 * Notify that the event cache has been updated
1762 * Also notify if the populating of the cache is complete, or
1765 public void cacheUpdated(final boolean completed
) {
1766 synchronized (fCacheUpdateSyncObj
) {
1767 if (fCacheUpdateBusy
) {
1768 fCacheUpdatePending
= true;
1769 fCacheUpdateCompleted
= completed
;
1772 fCacheUpdateBusy
= true;
1774 // Event cache is now updated. Perform update on the UI thread
1775 if (!fTable
.isDisposed()) {
1776 fTable
.getDisplay().asyncExec(new Runnable() {
1779 if (!fTable
.isDisposed()) {
1784 populateCompleted();
1786 synchronized (fCacheUpdateSyncObj
) {
1787 fCacheUpdateBusy
= false;
1788 if (fCacheUpdatePending
) {
1789 fCacheUpdatePending
= false;
1790 cacheUpdated(fCacheUpdateCompleted
);
1799 * Callback for when populating the table is complete.
1801 protected void populateCompleted() {
1802 // Nothing by default;
1805 // ------------------------------------------------------------------------
1806 // ISelectionProvider
1807 // ------------------------------------------------------------------------
1810 * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
1816 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
1817 selectionChangedListeners
.add(listener
);
1821 * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
1827 public ISelection
getSelection() {
1828 if (fTable
== null || fTable
.isDisposed()) {
1829 return StructuredSelection
.EMPTY
;
1831 List
<Object
> list
= new ArrayList
<Object
>(fTable
.getSelection().length
);
1832 for (TableItem item
: fTable
.getSelection()) {
1833 if (item
.getData() != null) {
1834 list
.add(item
.getData());
1837 return new StructuredSelection(list
);
1841 * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
1847 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
1848 selectionChangedListeners
.remove(listener
);
1852 * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
1858 public void setSelection(ISelection selection
) {
1863 * Notifies any selection changed listeners that the viewer's selection has changed.
1864 * Only listeners registered at the time this method is called are notified.
1866 * @param event a selection changed event
1868 * @see ISelectionChangedListener#selectionChanged
1871 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
1872 Object
[] listeners
= selectionChangedListeners
.getListeners();
1873 for (int i
= 0; i
< listeners
.length
; ++i
) {
1874 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
1875 SafeRunnable
.run(new SafeRunnable() {
1878 l
.selectionChanged(event
);
1884 // ------------------------------------------------------------------------
1885 // Bookmark handling
1886 // ------------------------------------------------------------------------
1889 * Add a bookmark to this event table.
1891 * @param bookmarksFile
1892 * The file to use for the bookmarks
1894 public void addBookmark(final IFile bookmarksFile
) {
1895 fBookmarksFile
= bookmarksFile
;
1896 final TableItem
[] selection
= fTable
.getSelection();
1897 if (selection
.length
> 0) {
1898 final TableItem tableItem
= selection
[0];
1899 if (tableItem
.getData(Key
.RANK
) != null) {
1900 final StringBuffer defaultMessage
= new StringBuffer();
1901 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1904 defaultMessage
.append(", "); //$NON-NLS-1$
1906 defaultMessage
.append(tableItem
.getText(i
));
1908 final InputDialog dialog
= new MultiLineInputDialog(
1909 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1910 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
1911 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
1912 defaultMessage
.toString());
1913 if (dialog
.open() == Window
.OK
) {
1914 final String message
= dialog
.getValue();
1916 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
1917 if (bookmark
.exists()) {
1918 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
1919 final long rank
= (Long
) tableItem
.getData(Key
.RANK
);
1920 final int location
= (int) rank
;
1921 bookmark
.setAttribute(IMarker
.LOCATION
, (Integer
) location
);
1922 fBookmarksMap
.put(rank
, bookmark
.getId());
1925 } catch (final CoreException e
) {
1926 displayException(e
);
1935 * Remove a bookmark from this event table.
1938 * The bookmark to remove
1940 public void removeBookmark(final IMarker bookmark
) {
1941 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entrySet()) {
1942 if (entry
.getValue().equals(bookmark
.getId())) {
1943 fBookmarksMap
.remove(entry
.getKey());
1950 private void toggleBookmark(final long rank
) {
1951 if (fBookmarksFile
== null) {
1954 if (fBookmarksMap
.containsKey(rank
)) {
1955 final Long markerId
= fBookmarksMap
.remove(rank
);
1958 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
1959 if (bookmark
!= null) {
1962 } catch (final CoreException e
) {
1963 displayException(e
);
1966 addBookmark(fBookmarksFile
);
1971 * Refresh the bookmarks assigned to this trace, from the contents of a
1974 * @param bookmarksFile
1975 * The bookmark file to use
1977 public void refreshBookmarks(final IFile bookmarksFile
) {
1978 fBookmarksFile
= bookmarksFile
;
1979 if (bookmarksFile
== null) {
1980 fBookmarksMap
.clear();
1985 fBookmarksMap
.clear();
1986 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
1987 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
1988 if (location
!= -1) {
1989 final long rank
= location
;
1990 fBookmarksMap
.put(rank
, bookmark
.getId());
1994 } catch (final CoreException e
) {
1995 displayException(e
);
2000 public void gotoMarker(final IMarker marker
) {
2001 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2004 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2005 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2006 } else if (rank
>= fTable
.getItemCount()) {
2007 fPendingGotoRank
= rank
;
2009 fSelectedRank
= rank
;
2010 fTable
.setSelection(index
+ 1); // +1 for header row
2014 // ------------------------------------------------------------------------
2016 // ------------------------------------------------------------------------
2021 * @see org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener#colorSettingsChanged(org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting[])
2024 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2028 // ------------------------------------------------------------------------
2030 // ------------------------------------------------------------------------
2033 * Handler for the trace updated signal
2036 * The incoming signal
2039 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2040 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2043 // Perform the refresh on the UI thread
2044 Display
.getDefault().asyncExec(new Runnable() {
2047 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2048 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2049 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
2050 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
2051 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
2052 fPendingGotoRank
= -1;
2055 startFilterThread();
2058 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2059 fRawViewer
.refreshEventCount();
2066 * Handler for the time synch signal.
2069 * The incoming signal
2072 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
2073 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2075 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
2076 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
2077 // the method fTrace.getRank() from interfering and delaying ongoing requests.
2078 final TmfDataRequest subRequest
= new TmfDataRequest(ITmfEvent
.class, 0, 1, ExecutionType
.FOREGROUND
) {
2080 TmfTimestamp ts
= new TmfTimestamp(signal
.getCurrentTime());
2083 public void handleData(final ITmfEvent event
) {
2084 super.handleData(event
);
2088 public void handleCompleted() {
2089 super.handleCompleted();
2090 if (fTrace
== null) {
2094 // Verify if the event is within the trace range and adjust if necessary
2095 ITmfTimestamp timestamp
= ts
;
2096 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
2097 timestamp
= fTrace
.getStartTime();
2099 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
2100 timestamp
= fTrace
.getEndTime();
2103 // Get the rank of the selected event in the table
2104 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2105 final long rank
= context
.getRank();
2107 fSelectedRank
= rank
;
2109 fTable
.getDisplay().asyncExec(new Runnable() {
2112 // Return if table is disposed
2113 if (fTable
.isDisposed()) {
2117 int index
= (int) rank
;
2118 if (fTable
.isDisposed()) {
2121 if (fTable
.getData(Key
.FILTER_OBJ
) != null)
2123 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
2125 fTable
.setSelection(index
+ 1); // +1 for header row
2126 fRawViewer
.selectAndReveal(rank
);
2132 ((ITmfDataProvider
) fTrace
).sendRequest(subRequest
);
2136 // ------------------------------------------------------------------------
2138 // ------------------------------------------------------------------------
2141 * Display an exception in a message box
2143 * @param e the exception
2145 private static void displayException(final Exception e
) {
2146 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2147 mb
.setText(e
.getClass().getName());
2148 mb
.setMessage(e
.getMessage());
2155 public void refresh() {