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 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.HashMap
;
21 import java
.util
.List
;
23 import java
.util
.Map
.Entry
;
24 import java
.util
.regex
.Pattern
;
25 import java
.util
.regex
.PatternSyntaxException
;
27 import org
.eclipse
.core
.resources
.IFile
;
28 import org
.eclipse
.core
.resources
.IMarker
;
29 import org
.eclipse
.core
.resources
.IResource
;
30 import org
.eclipse
.core
.runtime
.CoreException
;
31 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
32 import org
.eclipse
.core
.runtime
.IStatus
;
33 import org
.eclipse
.core
.runtime
.ListenerList
;
34 import org
.eclipse
.core
.runtime
.Status
;
35 import org
.eclipse
.core
.runtime
.jobs
.Job
;
36 import org
.eclipse
.jface
.action
.Action
;
37 import org
.eclipse
.jface
.action
.IAction
;
38 import org
.eclipse
.jface
.action
.IMenuListener
;
39 import org
.eclipse
.jface
.action
.IMenuManager
;
40 import org
.eclipse
.jface
.action
.MenuManager
;
41 import org
.eclipse
.jface
.action
.Separator
;
42 import org
.eclipse
.jface
.dialogs
.InputDialog
;
43 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
44 import org
.eclipse
.jface
.resource
.FontDescriptor
;
45 import org
.eclipse
.jface
.resource
.JFaceResources
;
46 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
47 import org
.eclipse
.jface
.util
.SafeRunnable
;
48 import org
.eclipse
.jface
.viewers
.ISelection
;
49 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
50 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
51 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
52 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
53 import org
.eclipse
.jface
.window
.Window
;
54 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
55 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
56 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
57 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
58 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
59 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
60 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
61 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
62 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
63 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
64 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
65 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
66 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
67 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
68 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
69 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
.ExecutionType
;
70 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
71 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
72 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
73 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
74 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
75 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
76 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
77 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
78 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
79 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
80 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSetting
;
81 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
82 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
83 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
84 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
85 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.ColumnData
;
86 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
87 import org
.eclipse
.swt
.SWT
;
88 import org
.eclipse
.swt
.custom
.SashForm
;
89 import org
.eclipse
.swt
.custom
.TableEditor
;
90 import org
.eclipse
.swt
.events
.FocusAdapter
;
91 import org
.eclipse
.swt
.events
.FocusEvent
;
92 import org
.eclipse
.swt
.events
.KeyAdapter
;
93 import org
.eclipse
.swt
.events
.KeyEvent
;
94 import org
.eclipse
.swt
.events
.MouseAdapter
;
95 import org
.eclipse
.swt
.events
.MouseEvent
;
96 import org
.eclipse
.swt
.events
.SelectionAdapter
;
97 import org
.eclipse
.swt
.events
.SelectionEvent
;
98 import org
.eclipse
.swt
.graphics
.Color
;
99 import org
.eclipse
.swt
.graphics
.Font
;
100 import org
.eclipse
.swt
.graphics
.Image
;
101 import org
.eclipse
.swt
.graphics
.Point
;
102 import org
.eclipse
.swt
.graphics
.Rectangle
;
103 import org
.eclipse
.swt
.layout
.FillLayout
;
104 import org
.eclipse
.swt
.layout
.GridData
;
105 import org
.eclipse
.swt
.layout
.GridLayout
;
106 import org
.eclipse
.swt
.widgets
.Composite
;
107 import org
.eclipse
.swt
.widgets
.Display
;
108 import org
.eclipse
.swt
.widgets
.Event
;
109 import org
.eclipse
.swt
.widgets
.Label
;
110 import org
.eclipse
.swt
.widgets
.Listener
;
111 import org
.eclipse
.swt
.widgets
.Menu
;
112 import org
.eclipse
.swt
.widgets
.MessageBox
;
113 import org
.eclipse
.swt
.widgets
.Shell
;
114 import org
.eclipse
.swt
.widgets
.TableColumn
;
115 import org
.eclipse
.swt
.widgets
.TableItem
;
116 import org
.eclipse
.swt
.widgets
.Text
;
117 import org
.eclipse
.ui
.PlatformUI
;
118 import org
.eclipse
.ui
.ide
.IGotoMarker
;
119 import org
.eclipse
.ui
.themes
.ColorUtil
;
122 * The generic TMF Events table
124 * This is a view that will list events that are read from a trace.
127 * @author Francois Chouinard
128 * @author Patrick Tasse
131 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
{
133 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
134 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
135 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
136 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
137 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
138 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
139 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
140 private static final Image FILTER_IMAGE
= Activator
.getDefault()
141 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
142 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
143 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
144 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
145 private static final int MAX_CACHE_SIZE
= 1000;
148 * The events table search/filter keys
151 * @author Patrick Tasse
153 public interface Key
{
155 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
158 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
161 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
164 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
167 String TIMESTAMP
= "$time"; //$NON-NLS-1$
170 String RANK
= "$rank"; //$NON-NLS-1$
173 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
175 /** Bookmark indicator */
176 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
180 * The events table search/filter state
183 * @author Patrick Tasse
185 public static enum HeaderState
{
186 /** A search is being run */
189 /** A filter is applied */
193 interface Direction
{
198 // ------------------------------------------------------------------------
200 // ------------------------------------------------------------------------
202 protected Composite fComposite
;
203 protected SashForm fSashForm
;
204 protected TmfVirtualTable fTable
;
205 protected TmfRawEventViewer fRawViewer
;
206 protected ITmfTrace fTrace
;
207 protected boolean fPackDone
= false;
208 protected HeaderState fHeaderState
= HeaderState
.SEARCH
;
209 protected long fSelectedRank
= 0;
212 protected long fFilterMatchCount
;
213 protected long fFilterCheckCount
;
214 protected FilterThread fFilterThread
;
215 protected boolean fFilterThreadResume
= false;
216 protected final Object fFilterSyncObj
= new Object();
217 protected SearchThread fSearchThread
;
218 protected final Object fSearchSyncObj
= new Object();
221 * List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
223 * @see #fireSelectionChanged
225 private ListenerList selectionChangedListeners
= new ListenerList();
227 // Bookmark map <Rank, MarkerId>
228 protected Map
<Long
, Long
> fBookmarksMap
= new HashMap
<Long
, Long
>();
229 protected IFile fBookmarksFile
;
230 protected long fPendingGotoRank
= -1;
233 protected LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
234 protected Color fGrayColor
;
235 protected Color fGreenColor
;
236 protected Font fBoldFont
;
238 // Table column names
239 static private final String
[] COLUMN_NAMES
= new String
[] { Messages
.TmfEventsTable_TimestampColumnHeader
,
240 Messages
.TmfEventsTable_SourceColumnHeader
, Messages
.TmfEventsTable_TypeColumnHeader
,
241 Messages
.TmfEventsTable_ReferenceColumnHeader
, Messages
.TmfEventsTable_ContentColumnHeader
};
243 static private final ColumnData
[] COLUMN_DATA
= new ColumnData
[] { new ColumnData(COLUMN_NAMES
[0], 100, SWT
.LEFT
),
244 new ColumnData(COLUMN_NAMES
[1], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[2], 100, SWT
.LEFT
),
245 new ColumnData(COLUMN_NAMES
[3], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[4], 100, SWT
.LEFT
) };
248 private final TmfEventsCache fCache
;
249 private boolean fCacheUpdateBusy
= false;
250 private boolean fCacheUpdatePending
= false;
251 private boolean fCacheUpdateCompleted
= false;
252 private final Object fCacheUpdateSyncObj
= new Object();
254 private boolean fDisposeOnClose
;
256 // ------------------------------------------------------------------------
258 // ------------------------------------------------------------------------
261 * Basic constructor, will use default column data.
264 * The parent composite UI object
266 * The size of the event table cache
268 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
269 this(parent
, cacheSize
, COLUMN_DATA
);
273 * Advanced constructor, where we also define which column data to use.
276 * The parent composite UI object
278 * The size of the event table cache
280 * The column data to use for this table
282 public TmfEventsTable(final Composite parent
, int cacheSize
, final ColumnData
[] columnData
) {
283 super("TmfEventsTable"); //$NON-NLS-1$
285 fComposite
= new Composite(parent
, SWT
.NONE
);
286 final GridLayout gl
= new GridLayout(1, false);
289 gl
.verticalSpacing
= 0;
290 fComposite
.setLayout(gl
);
292 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
293 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
295 // Create a virtual table
296 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.SINGLE
| SWT
.FULL_SELECTION
;
297 fTable
= new TmfVirtualTable(fSashForm
, style
);
299 // Set the table layout
300 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
301 fTable
.setLayoutData(layoutData
);
303 // Some cosmetic enhancements
304 fTable
.setHeaderVisible(true);
305 fTable
.setLinesVisible(true);
308 setColumnHeaders(columnData
);
310 // Set the default column field ids if this is not a subclass
311 if (Arrays
.equals(columnData
, COLUMN_DATA
)) {
312 fTable
.getColumns()[0].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
313 fTable
.getColumns()[1].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_SOURCE
);
314 fTable
.getColumns()[2].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TYPE
);
315 fTable
.getColumns()[3].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_REFERENCE
);
316 fTable
.getColumns()[4].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_CONTENT
);
319 // Set the frozen row for header row
320 fTable
.setFrozenRowCount(1);
322 // Create the header row cell editor
323 createHeaderEditor();
325 // Handle the table item selection
326 fTable
.addSelectionListener(new SelectionAdapter() {
328 public void widgetSelected(final SelectionEvent e
) {
329 final TableItem
[] selection
= fTable
.getSelection();
330 if (selection
.length
> 0) {
331 final TableItem selectedTableItem
= selection
[0];
332 if (selectedTableItem
!= null) {
333 if (selectedTableItem
.getData(Key
.RANK
) instanceof Long
) {
334 fSelectedRank
= (Long
) selectedTableItem
.getData(Key
.RANK
);
335 fRawViewer
.selectAndReveal((Long
) selectedTableItem
.getData(Key
.RANK
));
337 if (selectedTableItem
.getData(Key
.TIMESTAMP
) instanceof TmfTimestamp
) {
338 final TmfTimestamp ts
= (TmfTimestamp
) selectedTableItem
.getData(Key
.TIMESTAMP
);
339 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
343 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
347 cacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
348 cacheSize
= Math
.min(cacheSize
, MAX_CACHE_SIZE
);
349 fCache
= new TmfEventsCache(cacheSize
, this);
351 // Handle the table item requests
352 fTable
.addListener(SWT
.SetData
, new Listener() {
355 public void handleEvent(final Event event
) {
357 final TableItem item
= (TableItem
) event
.item
;
358 int index
= event
.index
- 1; // -1 for the header row
360 if (event
.index
== 0) {
361 setHeaderRowItemData(item
);
365 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
366 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
367 setFilterStatusRowItemData(item
);
370 index
= index
- 1; // -1 for top filter status row
373 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
374 if (cachedEvent
!= null) {
375 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
379 // Else, fill the cache asynchronously (and off the UI thread)
384 fTable
.addMouseListener(new MouseAdapter() {
386 public void mouseDoubleClick(final MouseEvent event
) {
387 if (event
.button
!= 1) {
390 // Identify the selected row
391 final Point point
= new Point(event
.x
, event
.y
);
392 final TableItem item
= fTable
.getItem(point
);
394 final Rectangle imageBounds
= item
.getImageBounds(0);
395 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
396 if (imageBounds
.contains(point
)) {
397 final Long rank
= (Long
) item
.getData(Key
.RANK
);
399 toggleBookmark(rank
);
406 final Listener tooltipListener
= new Listener () {
407 Shell tooltipShell
= null;
409 public void handleEvent(final Event event
) {
410 switch (event
.type
) {
412 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
416 final Long rank
= (Long
) item
.getData(Key
.RANK
);
420 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
421 final Rectangle bounds
= item
.getImageBounds(0);
422 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
423 if (!bounds
.contains(event
.x
,event
.y
)) {
426 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
427 tooltipShell
.dispose();
429 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
430 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
431 final FillLayout layout
= new FillLayout();
432 layout
.marginWidth
= 2;
433 tooltipShell
.setLayout(layout
);
434 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
435 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: ""); //$NON-NLS-1$ //$NON-NLS-2$
436 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
437 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
439 label
.addListener(SWT
.MouseExit
, this);
440 label
.addListener(SWT
.MouseDown
, this);
441 label
.addListener(SWT
.MouseWheel
, this);
442 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
444 * Bug in Linux. The coordinates of the event have an origin that excludes the table header but
445 * the method toDisplay() expects coordinates relative to an origin that includes the table header.
448 if (System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
449 y
+= fTable
.getHeaderHeight();
451 Point pt
= fTable
.toDisplay(event
.x
, y
);
452 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
453 pt
.y
+= item
.getBounds().height
;
454 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
455 tooltipShell
.setVisible(true);
463 if (tooltipShell
!= null) {
464 tooltipShell
.dispose();
474 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
475 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
476 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
477 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
478 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
479 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
480 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
485 ColorSettingsManager
.addColorSettingsListener(this);
487 fTable
.setItemCount(1); // +1 for header row
489 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
491 fRawViewer
.addSelectionListener(new Listener() {
493 public void handleEvent(final Event e
) {
494 if (e
.data
instanceof Long
) {
495 final long rank
= (Long
) e
.data
;
496 int index
= (int) rank
;
497 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
498 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
500 fTable
.setSelection(index
+ 1); // +1 for header row
501 fSelectedRank
= rank
;
502 } else if (e
.data
instanceof ITmfLocation
) {
503 // DOES NOT WORK: rank undefined in context from seekLocation()
504 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
505 // TmfContext context = fTrace.seekLocation(location);
506 // fTable.setSelection((int) context.getRank());
511 final TableItem
[] selection
= fTable
.getSelection();
512 if ((selection
!= null) && (selection
.length
> 0)) {
513 final TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
515 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, ts
));
521 fSashForm
.setWeights(new int[] { 1, 1 });
522 fRawViewer
.setVisible(false);
527 protected void createPopupMenu() {
528 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
531 fTable
.setVisible(true);
536 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
539 fTable
.setVisible(false);
544 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
547 fRawViewer
.setVisible(true);
549 final int index
= fTable
.getSelectionIndex();
551 fRawViewer
.selectAndReveal(index
- 1);
556 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
559 fRawViewer
.setVisible(false);
564 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
567 fHeaderState
= HeaderState
.SEARCH
;
572 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
575 fHeaderState
= HeaderState
.FILTER
;
580 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
587 class ToggleBookmarkAction
extends Action
{
590 public ToggleBookmarkAction(final String text
, final long rank
) {
597 toggleBookmark(fRank
);
601 final MenuManager tablePopupMenu
= new MenuManager();
602 tablePopupMenu
.setRemoveAllWhenShown(true);
603 tablePopupMenu
.addMenuListener(new IMenuListener() {
605 public void menuAboutToShow(final IMenuManager manager
) {
606 if (fTable
.getSelectionIndex() == 0) {
607 // Right-click on header row
608 if (fHeaderState
== HeaderState
.FILTER
) {
609 tablePopupMenu
.add(showSearchBarAction
);
611 tablePopupMenu
.add(showFilterBarAction
);
615 final Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
616 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
618 final Rectangle imageBounds
= item
.getImageBounds(0);
619 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
620 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
621 // Right-click on left margin
622 final Long rank
= (Long
) item
.getData(Key
.RANK
);
623 if ((rank
!= null) && (fBookmarksFile
!= null)) {
624 if (fBookmarksMap
.containsKey(rank
)) {
625 tablePopupMenu
.add(new ToggleBookmarkAction(
626 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
628 tablePopupMenu
.add(new ToggleBookmarkAction(
629 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
635 // Right-click on table
636 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
637 tablePopupMenu
.add(hideTableAction
);
638 tablePopupMenu
.add(hideRawAction
);
639 } else if (!fTable
.isVisible()) {
640 tablePopupMenu
.add(showTableAction
);
641 } else if (!fRawViewer
.isVisible()) {
642 tablePopupMenu
.add(showRawAction
);
644 tablePopupMenu
.add(new Separator());
645 tablePopupMenu
.add(clearFiltersAction
);
646 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
647 if (savedFilters
.length
> 0) {
648 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
649 for (final ITmfFilterTreeNode node
: savedFilters
) {
650 if (node
instanceof TmfFilterNode
) {
651 final TmfFilterNode filter
= (TmfFilterNode
) node
;
652 subMenu
.add(new Action(filter
.getFilterName()) {
660 tablePopupMenu
.add(subMenu
);
662 appendToTablePopupMenu(tablePopupMenu
, item
);
666 final MenuManager rawViewerPopupMenu
= new MenuManager();
667 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
668 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
670 public void menuAboutToShow(final IMenuManager manager
) {
671 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
672 rawViewerPopupMenu
.add(hideTableAction
);
673 rawViewerPopupMenu
.add(hideRawAction
);
674 } else if (!fTable
.isVisible()) {
675 rawViewerPopupMenu
.add(showTableAction
);
676 } else if (!fRawViewer
.isVisible()) {
677 rawViewerPopupMenu
.add(showRawAction
);
679 appendToRawPopupMenu(tablePopupMenu
);
683 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
684 fTable
.setMenu(menu
);
686 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
687 fRawViewer
.setMenu(menu
);
691 @SuppressWarnings("unused")
692 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
693 // override to append more actions
696 @SuppressWarnings("unused")
697 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
698 // override to append more actions
702 public void dispose() {
705 ColorSettingsManager
.removeColorSettingsListener(this);
706 fComposite
.dispose();
707 if ((fTrace
!= null) && fDisposeOnClose
) {
710 fResourceManager
.dispose();
715 * Assign a layout data object to this view.
718 * The layout data to assign
720 public void setLayoutData(final Object layoutData
) {
721 fComposite
.setLayoutData(layoutData
);
725 * Get the virtual table contained in this event table.
727 * @return The TMF virtual table
729 public TmfVirtualTable
getTable() {
736 * FIXME: Add support for column selection
738 protected void setColumnHeaders(final ColumnData
[] columnData
) {
739 fTable
.setColumnHeaders(columnData
);
742 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
743 final ITmfEventField
[] fields
= extractItemFields(event
);
744 final String
[] content
= new String
[fields
.length
];
745 for (int i
= 0; i
< fields
.length
; i
++) {
746 content
[i
] = fields
[i
].getValue() != null ? fields
[i
].getValue().toString() : ""; //$NON-NLS-1$
748 item
.setText(content
);
750 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
751 item
.setData(Key
.RANK
, rank
);
753 boolean bookmark
= false;
754 final Long markerId
= fBookmarksMap
.get(rank
);
755 if (markerId
!= null) {
758 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
759 item
.setData(Key
.BOOKMARK
, marker
.getAttribute(IMarker
.MESSAGE
));
760 } catch (final CoreException e
) {
764 item
.setData(Key
.BOOKMARK
, null);
767 boolean searchMatch
= false;
768 boolean searchNoMatch
= false;
769 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
770 if (searchFilter
!= null) {
771 if (searchFilter
.matches(event
)) {
774 searchNoMatch
= true;
778 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
780 item
.setForeground(colorSetting
.getDimmedForegroundColor());
781 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
783 item
.setForeground(colorSetting
.getForegroundColor());
784 item
.setBackground(colorSetting
.getBackgroundColor());
789 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
791 item
.setImage(SEARCH_MATCH_IMAGE
);
793 } else if (bookmark
) {
794 item
.setImage(BOOKMARK_IMAGE
);
796 item
.setImage((Image
) null);
800 protected void setHeaderRowItemData(final TableItem item
) {
801 String txtKey
= null;
802 if (fHeaderState
== HeaderState
.SEARCH
) {
803 item
.setImage(SEARCH_IMAGE
);
804 txtKey
= Key
.SEARCH_TXT
;
805 } else if (fHeaderState
== HeaderState
.FILTER
) {
806 item
.setImage(FILTER_IMAGE
);
807 txtKey
= Key
.FILTER_TXT
;
809 item
.setForeground(fGrayColor
);
810 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
811 final TableColumn column
= fTable
.getColumns()[i
];
812 final String filter
= (String
) column
.getData(txtKey
);
813 if (filter
== null) {
814 if (fHeaderState
== HeaderState
.SEARCH
) {
815 item
.setText(i
, SEARCH_HINT
);
816 } else if (fHeaderState
== HeaderState
.FILTER
) {
817 item
.setText(i
, FILTER_HINT
);
819 item
.setForeground(i
, fGrayColor
);
820 item
.setFont(i
, fTable
.getFont());
822 item
.setText(i
, filter
);
823 item
.setForeground(i
, fGreenColor
);
824 item
.setFont(i
, fBoldFont
);
829 protected void setFilterStatusRowItemData(final TableItem item
) {
830 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
832 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
833 item
.setImage(FILTER_IMAGE
);
835 item
.setImage(STOP_IMAGE
);
837 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
839 item
.setText(i
, ""); //$NON-NLS-1$
843 item
.setData(Key
.TIMESTAMP
, null);
844 item
.setData(Key
.RANK
, null);
845 item
.setForeground(null);
846 item
.setBackground(null);
849 protected void createHeaderEditor() {
850 final TableEditor tableEditor
= fTable
.createTableEditor();
851 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
852 tableEditor
.verticalAlignment
= SWT
.CENTER
;
853 tableEditor
.grabHorizontal
= true;
854 tableEditor
.minimumWidth
= 50;
856 // Handle the header row selection
857 fTable
.addMouseListener(new MouseAdapter() {
863 public void mouseDown(final MouseEvent event
) {
864 if (event
.button
!= 1) {
867 // Identify the selected row
868 final Point point
= new Point(event
.x
, event
.y
);
869 item
= fTable
.getItem(point
);
871 // Header row selected
872 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
875 if (item
.getImageBounds(0).contains(point
)) {
876 if (fHeaderState
== HeaderState
.SEARCH
) {
877 fHeaderState
= HeaderState
.FILTER
;
878 } else if (fHeaderState
== HeaderState
.FILTER
) {
879 fHeaderState
= HeaderState
.SEARCH
;
885 // Identify the selected column
887 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
888 final Rectangle rect
= item
.getBounds(i
);
889 if (rect
.contains(point
)) {
895 if (columnIndex
== -1) {
899 column
= fTable
.getColumns()[columnIndex
];
901 String txtKey
= null;
902 if (fHeaderState
== HeaderState
.SEARCH
) {
903 txtKey
= Key
.SEARCH_TXT
;
904 } else if (fHeaderState
== HeaderState
.FILTER
) {
905 txtKey
= Key
.FILTER_TXT
;
908 // The control that will be the editor must be a child of the Table
909 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
910 final String headerString
= (String
) column
.getData(txtKey
);
911 if (headerString
!= null) {
912 newEditor
.setText(headerString
);
914 newEditor
.addFocusListener(new FocusAdapter() {
916 public void focusLost(final FocusEvent e
) {
917 final boolean changed
= updateHeader(newEditor
.getText());
923 newEditor
.addKeyListener(new KeyAdapter() {
925 public void keyPressed(final KeyEvent e
) {
926 if (e
.character
== SWT
.CR
) {
927 updateHeader(newEditor
.getText());
929 } else if (e
.character
== SWT
.ESC
) {
930 tableEditor
.getEditor().dispose();
934 newEditor
.selectAll();
935 newEditor
.setFocus();
936 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
941 * returns true is value was changed
943 private boolean updateHeader(final String text
) {
944 String objKey
= null;
945 String txtKey
= null;
946 if (fHeaderState
== HeaderState
.SEARCH
) {
947 objKey
= Key
.SEARCH_OBJ
;
948 txtKey
= Key
.SEARCH_TXT
;
949 } else if (fHeaderState
== HeaderState
.FILTER
) {
950 objKey
= Key
.FILTER_OBJ
;
951 txtKey
= Key
.FILTER_TXT
;
953 if (text
.trim().length() > 0) {
955 final String regex
= TmfFilterMatchesNode
.regexFix(text
);
956 Pattern
.compile(regex
);
957 if (regex
.equals(column
.getData(txtKey
))) {
958 tableEditor
.getEditor().dispose();
961 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
962 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
963 if (fieldId
== null) {
964 fieldId
= column
.getText();
966 filter
.setField(fieldId
);
967 filter
.setRegex(regex
);
968 column
.setData(objKey
, filter
);
969 column
.setData(txtKey
, regex
);
970 } catch (final PatternSyntaxException ex
) {
971 tableEditor
.getEditor().dispose();
972 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
973 ex
.getDescription(), ex
.getMessage());
977 if (column
.getData(txtKey
) == null) {
978 tableEditor
.getEditor().dispose();
981 column
.setData(objKey
, null);
982 column
.setData(txtKey
, null);
987 private void applyHeader() {
988 if (fHeaderState
== HeaderState
.SEARCH
) {
990 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
991 for (final TableColumn column
: fTable
.getColumns()) {
992 final Object filterObj
= column
.getData(Key
.SEARCH_OBJ
);
993 if (filterObj
instanceof ITmfFilterTreeNode
) {
994 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
997 if (filter
.getChildrenCount() > 0) {
998 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1001 fireSearchApplied(filter
);
1003 fTable
.setData(Key
.SEARCH_OBJ
, null);
1005 fireSearchApplied(null);
1007 } else if (fHeaderState
== HeaderState
.FILTER
) {
1008 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1009 for (final TableColumn column
: fTable
.getColumns()) {
1010 final Object filterObj
= column
.getData(Key
.FILTER_OBJ
);
1011 if (filterObj
instanceof ITmfFilterTreeNode
) {
1012 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1015 if (filter
.getChildrenCount() > 0) {
1016 applyFilter(filter
);
1022 tableEditor
.getEditor().dispose();
1026 fTable
.addKeyListener(new KeyAdapter() {
1028 public void keyPressed(final KeyEvent e
) {
1030 if (e
.character
== SWT
.ESC
) {
1034 } else if (e
.character
== SWT
.DEL
) {
1035 if (fHeaderState
== HeaderState
.SEARCH
) {
1037 for (final TableColumn column
: fTable
.getColumns()) {
1038 column
.setData(Key
.SEARCH_OBJ
, null);
1039 column
.setData(Key
.SEARCH_TXT
, null);
1041 fTable
.setData(Key
.SEARCH_OBJ
, null);
1043 fireSearchApplied(null);
1044 } else if (fHeaderState
== HeaderState
.FILTER
) {
1047 } else if (e
.character
== SWT
.CR
) {
1048 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1058 protected void fireFilterApplied(final ITmfFilter filter
) {
1059 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1062 protected void fireSearchApplied(final ITmfFilter filter
) {
1063 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1066 protected void startFilterThread() {
1067 synchronized (fFilterSyncObj
) {
1068 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1069 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1070 if (fFilterThread
!= null) {
1071 fFilterThread
.cancel();
1072 fFilterThreadResume
= false;
1074 fFilterThread
= new FilterThread(filter
);
1075 fFilterThread
.start();
1077 fFilterThreadResume
= true;
1082 protected void stopFilterThread() {
1083 synchronized (fFilterSyncObj
) {
1084 if (fFilterThread
!= null) {
1085 fFilterThread
.cancel();
1086 fFilterThread
= null;
1087 fFilterThreadResume
= false;
1095 protected void applyFilter(ITmfFilter filter
) {
1098 fFilterMatchCount
= 0;
1099 fFilterCheckCount
= 0;
1100 fCache
.applyFilter(filter
);
1102 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1103 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1104 startFilterThread();
1105 fireFilterApplied(filter
);
1108 protected void clearFilters() {
1109 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1114 fCache
.clearFilter();
1116 for (final TableColumn column
: fTable
.getColumns()) {
1117 column
.setData(Key
.FILTER_OBJ
, null);
1118 column
.setData(Key
.FILTER_TXT
, null);
1120 fTable
.setData(Key
.FILTER_OBJ
, null);
1121 if (fTrace
!= null) {
1122 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1124 fTable
.setItemCount(1); // +1 for header row
1126 fFilterMatchCount
= 0;
1127 fFilterCheckCount
= 0;
1128 if (fSelectedRank
>= 0) {
1129 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1131 fTable
.setSelection(0);
1133 fireFilterApplied(null);
1136 protected class FilterThread
extends Thread
{
1137 private final ITmfFilterTreeNode filter
;
1138 private TmfDataRequest request
;
1139 private boolean refreshBusy
= false;
1140 private boolean refreshPending
= false;
1141 private final Object syncObj
= new Object();
1143 public FilterThread(final ITmfFilterTreeNode filter
) {
1144 super("Filter Thread"); //$NON-NLS-1$
1145 this.filter
= filter
;
1150 if (fTrace
== null) {
1153 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1154 if (nbRequested
<= 0) {
1157 request
= new TmfDataRequest(ITmfEvent
.class, (int) fFilterCheckCount
,
1158 nbRequested
, fTrace
.getCacheSize(), ExecutionType
.BACKGROUND
) {
1160 public void handleData(final ITmfEvent event
) {
1161 super.handleData(event
);
1162 if (request
.isCancelled()) {
1165 if (filter
.matches(event
)) {
1166 final long rank
= fFilterCheckCount
;
1167 final int index
= (int) fFilterMatchCount
;
1168 fFilterMatchCount
++;
1169 fCache
.storeEvent(event
.clone(), rank
, index
);
1171 } else if ((fFilterCheckCount
% 100) == 0) {
1174 fFilterCheckCount
++;
1177 ((ITmfDataProvider
) fTrace
).sendRequest(request
);
1179 request
.waitForCompletion();
1180 } catch (final InterruptedException e
) {
1183 synchronized (fFilterSyncObj
) {
1184 fFilterThread
= null;
1185 if (fFilterThreadResume
) {
1186 fFilterThreadResume
= false;
1187 fFilterThread
= new FilterThread(filter
);
1188 fFilterThread
.start();
1193 public void refreshTable() {
1194 synchronized (syncObj
) {
1196 refreshPending
= true;
1201 Display
.getDefault().asyncExec(new Runnable() {
1204 if (request
.isCancelled()) {
1207 if (fTable
.isDisposed()) {
1210 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter status rows
1212 synchronized (syncObj
) {
1213 refreshBusy
= false;
1214 if (refreshPending
) {
1215 refreshPending
= false;
1223 public void cancel() {
1224 if (request
!= null) {
1230 protected void searchNext() {
1231 synchronized (fSearchSyncObj
) {
1232 if (fSearchThread
!= null) {
1235 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1236 if (searchFilter
== null) {
1239 final int selectionIndex
= fTable
.getSelectionIndex();
1241 if (selectionIndex
> 0) {
1242 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1244 // header row is selected, start at top event
1245 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1247 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1248 if (eventFilter
!= null)
1250 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1252 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1253 fSearchThread
.schedule();
1257 protected void searchPrevious() {
1258 synchronized (fSearchSyncObj
) {
1259 if (fSearchThread
!= null) {
1262 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1263 if (searchFilter
== null) {
1266 final int selectionIndex
= fTable
.getSelectionIndex();
1268 if (selectionIndex
> 0) {
1269 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1271 // header row is selected, start at precedent of top event
1272 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1274 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1275 if (eventFilter
!= null)
1277 startIndex
= startIndex
- 1; // -1 for top filter status row
1279 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1280 fSearchThread
.schedule();
1284 protected void stopSearchThread() {
1285 fPendingGotoRank
= -1;
1286 synchronized (fSearchSyncObj
) {
1287 if (fSearchThread
!= null) {
1288 fSearchThread
.cancel();
1289 fSearchThread
= null;
1294 protected class SearchThread
extends Job
{
1295 protected ITmfFilterTreeNode searchFilter
;
1296 protected ITmfFilterTreeNode eventFilter
;
1297 protected int startIndex
;
1298 protected int direction
;
1299 protected long rank
;
1300 protected long foundRank
= -1;
1301 protected TmfDataRequest request
;
1302 private ITmfTimestamp foundTimestamp
= null;
1304 public SearchThread(final ITmfFilterTreeNode searchFilter
, final ITmfFilterTreeNode eventFilter
, final int startIndex
,
1305 final long currentRank
, final int direction
) {
1306 super(Messages
.TmfEventsTable_SearchingJobName
);
1307 this.searchFilter
= searchFilter
;
1308 this.eventFilter
= eventFilter
;
1309 this.startIndex
= startIndex
;
1310 this.rank
= currentRank
;
1311 this.direction
= direction
;
1315 protected IStatus
run(final IProgressMonitor monitor
) {
1316 if (fTrace
== null) {
1317 return Status
.OK_STATUS
;
1319 final Display display
= Display
.getDefault();
1320 if (startIndex
< 0) {
1321 rank
= (int) fTrace
.getNbEvents() - 1;
1322 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows
1325 int idx
= startIndex
;
1326 while (foundRank
== -1) {
1327 final CachedEvent event
= fCache
.peekEvent(idx
);
1328 if (event
== null) {
1332 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
1333 foundRank
= event
.rank
;
1334 foundTimestamp
= event
.event
.getTimestamp();
1337 if (direction
== Direction
.FORWARD
) {
1343 if (foundRank
== -1) {
1344 if (direction
== Direction
.FORWARD
) {
1346 if (rank
> (fTrace
.getNbEvents() - 1)) {
1352 rank
= (int) fTrace
.getNbEvents() - 1;
1357 final int startRank
= (int) rank
;
1358 boolean wrapped
= false;
1359 while (!monitor
.isCanceled() && (foundRank
== -1) && (fTrace
!= null)) {
1360 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, fTrace
.getCacheSize()));
1361 if (direction
== Direction
.BACKWARD
) {
1362 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1364 request
= new TmfDataRequest(ITmfEvent
.class, (int) rank
, nbRequested
, fTrace
.getCacheSize(), ExecutionType
.BACKGROUND
) {
1365 long currentRank
= rank
;
1368 public void handleData(final ITmfEvent event
) {
1369 super.handleData(event
);
1370 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
1371 foundRank
= currentRank
;
1372 foundTimestamp
= event
.getTimestamp();
1373 if (direction
== Direction
.FORWARD
) {
1381 ((ITmfDataProvider
) fTrace
).sendRequest(request
);
1383 request
.waitForCompletion();
1384 if (request
.isCancelled()) {
1385 return Status
.OK_STATUS
;
1387 } catch (final InterruptedException e
) {
1388 synchronized (fSearchSyncObj
) {
1389 fSearchThread
= null;
1391 return Status
.OK_STATUS
;
1393 if (foundRank
== -1) {
1394 if (direction
== Direction
.FORWARD
) {
1396 synchronized (fSearchSyncObj
) {
1397 fSearchThread
= null;
1399 return Status
.OK_STATUS
;
1401 nbRequested
= (int) rank
;
1407 rank
= (int) fTrace
.getNbEvents() - 1;
1410 if ((rank
<= startRank
) && wrapped
) {
1411 synchronized (fSearchSyncObj
) {
1412 fSearchThread
= null;
1414 return Status
.OK_STATUS
;
1419 int index
= (int) foundRank
;
1420 if (eventFilter
!= null) {
1421 index
= fCache
.getFilteredEventIndex(foundRank
);
1423 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter status row
1425 display
.asyncExec(new Runnable() {
1428 if (monitor
.isCanceled()) {
1431 if (fTable
.isDisposed()) {
1434 fTable
.setSelection(selection
);
1435 fSelectedRank
= foundRank
;
1436 fRawViewer
.selectAndReveal(fSelectedRank
);
1437 if (foundTimestamp
!= null) {
1438 broadcast(new TmfTimeSynchSignal(TmfEventsTable
.this, foundTimestamp
));
1440 synchronized (fSearchSyncObj
) {
1441 fSearchThread
= null;
1445 return Status
.OK_STATUS
;
1449 protected void canceling() {
1451 synchronized (fSearchSyncObj
) {
1452 fSearchThread
= null;
1457 protected void createResources() {
1458 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1459 .getForeground().getRGB()));
1460 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1461 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1464 protected void packColumns() {
1468 for (final TableColumn column
: fTable
.getColumns()) {
1469 final int headerWidth
= column
.getWidth();
1471 if (column
.getWidth() < headerWidth
) {
1472 column
.setWidth(headerWidth
);
1482 * FIXME: Add support for column selection
1484 protected ITmfEventField
[] extractItemFields(final ITmfEvent event
) {
1485 ITmfEventField
[] fields
= new TmfEventField
[0];
1486 if (event
!= null) {
1487 final String timestamp
= event
.getTimestamp().toString();
1488 final String source
= event
.getSource();
1489 final String type
= event
.getType().getName();
1490 final String reference
= event
.getReference();
1491 final String content
= event
.getContent().toString();
1492 fields
= new TmfEventField
[] {
1493 new TmfEventField(ITmfEvent
.EVENT_FIELD_TIMESTAMP
, timestamp
),
1494 new TmfEventField(ITmfEvent
.EVENT_FIELD_SOURCE
, source
),
1495 new TmfEventField(ITmfEvent
.EVENT_FIELD_TYPE
, type
),
1496 new TmfEventField(ITmfEvent
.EVENT_FIELD_REFERENCE
, reference
),
1497 new TmfEventField(ITmfEvent
.EVENT_FIELD_CONTENT
, content
)
1504 * Notify this table that is got the UI focus.
1506 public void setFocus() {
1511 * Assign a new trace to this event table.
1514 * The trace to assign to this event table
1515 * @param disposeOnClose
1516 * true if the trace should be disposed when the table is
1519 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
1520 if ((fTrace
!= null) && fDisposeOnClose
) {
1526 fDisposeOnClose
= disposeOnClose
;
1528 // Perform the updates on the UI thread
1529 fTable
.getDisplay().syncExec(new Runnable() {
1533 fCache
.setTrace(fTrace
); // Clear the cache
1534 if (fTrace
!= null) {
1535 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1536 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1537 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1540 fFilterMatchCount
= 0;
1541 fFilterCheckCount
= 0;
1542 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1543 startFilterThread();
1547 fRawViewer
.setTrace(fTrace
);
1552 // ------------------------------------------------------------------------
1554 // ------------------------------------------------------------------------
1557 * Notify that the event cache has been updated
1560 * Also notify if the populating of the cache is complete, or
1563 public void cacheUpdated(final boolean completed
) {
1564 synchronized (fCacheUpdateSyncObj
) {
1565 if (fCacheUpdateBusy
) {
1566 fCacheUpdatePending
= true;
1567 fCacheUpdateCompleted
= completed
;
1570 fCacheUpdateBusy
= true;
1572 // Event cache is now updated. Perform update on the UI thread
1573 if (!fTable
.isDisposed()) {
1574 fTable
.getDisplay().asyncExec(new Runnable() {
1577 if (!fTable
.isDisposed()) {
1582 populateCompleted();
1584 synchronized (fCacheUpdateSyncObj
) {
1585 fCacheUpdateBusy
= false;
1586 if (fCacheUpdatePending
) {
1587 fCacheUpdatePending
= false;
1588 cacheUpdated(fCacheUpdateCompleted
);
1596 protected void populateCompleted() {
1597 // Nothing by default;
1600 // ------------------------------------------------------------------------
1601 // ISelectionProvider
1602 // ------------------------------------------------------------------------
1605 * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
1611 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
1612 selectionChangedListeners
.add(listener
);
1616 * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
1622 public ISelection
getSelection() {
1623 if (fTable
== null || fTable
.isDisposed()) {
1624 return StructuredSelection
.EMPTY
;
1626 List
<Object
> list
= new ArrayList
<Object
>(fTable
.getSelection().length
);
1627 for (TableItem item
: fTable
.getSelection()) {
1628 if (item
.getData() != null) {
1629 list
.add(item
.getData());
1632 return new StructuredSelection(list
);
1636 * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
1642 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
1643 selectionChangedListeners
.remove(listener
);
1647 * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
1653 public void setSelection(ISelection selection
) {
1658 * Notifies any selection changed listeners that the viewer's selection has changed.
1659 * Only listeners registered at the time this method is called are notified.
1661 * @param event a selection changed event
1663 * @see ISelectionChangedListener#selectionChanged
1666 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
1667 Object
[] listeners
= selectionChangedListeners
.getListeners();
1668 for (int i
= 0; i
< listeners
.length
; ++i
) {
1669 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
1670 SafeRunnable
.run(new SafeRunnable() {
1673 l
.selectionChanged(event
);
1679 // ------------------------------------------------------------------------
1680 // Bookmark handling
1681 // ------------------------------------------------------------------------
1684 * Add a bookmark to this event table.
1686 * @param bookmarksFile
1687 * The file to use for the bookmarks
1689 public void addBookmark(final IFile bookmarksFile
) {
1690 fBookmarksFile
= bookmarksFile
;
1691 final TableItem
[] selection
= fTable
.getSelection();
1692 if (selection
.length
> 0) {
1693 final TableItem tableItem
= selection
[0];
1694 if (tableItem
.getData(Key
.RANK
) != null) {
1695 final StringBuffer defaultMessage
= new StringBuffer();
1696 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1699 defaultMessage
.append(", "); //$NON-NLS-1$
1701 defaultMessage
.append(tableItem
.getText(i
));
1703 final InputDialog dialog
= new MultiLineInputDialog(
1704 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1705 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
1706 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
1707 defaultMessage
.toString());
1708 if (dialog
.open() == Window
.OK
) {
1709 final String message
= dialog
.getValue();
1711 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
1712 if (bookmark
.exists()) {
1713 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
1714 final long rank
= (Long
) tableItem
.getData(Key
.RANK
);
1715 final int location
= (int) rank
;
1716 bookmark
.setAttribute(IMarker
.LOCATION
, (Integer
) location
);
1717 fBookmarksMap
.put(rank
, bookmark
.getId());
1720 } catch (final CoreException e
) {
1721 displayException(e
);
1730 * Remove a bookmark from this event table.
1733 * The bookmark to remove
1735 public void removeBookmark(final IMarker bookmark
) {
1736 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entrySet()) {
1737 if (entry
.getValue().equals(bookmark
.getId())) {
1738 fBookmarksMap
.remove(entry
.getKey());
1745 private void toggleBookmark(final long rank
) {
1746 if (fBookmarksFile
== null) {
1749 if (fBookmarksMap
.containsKey(rank
)) {
1750 final Long markerId
= fBookmarksMap
.remove(rank
);
1753 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
1754 if (bookmark
!= null) {
1757 } catch (final CoreException e
) {
1758 displayException(e
);
1761 addBookmark(fBookmarksFile
);
1766 * Refresh the bookmarks assigned to this trace, from the contents of a
1769 * @param bookmarksFile
1770 * The bookmark file to use
1772 public void refreshBookmarks(final IFile bookmarksFile
) {
1773 fBookmarksFile
= bookmarksFile
;
1774 if (bookmarksFile
== null) {
1775 fBookmarksMap
.clear();
1780 fBookmarksMap
.clear();
1781 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
1782 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
1783 if (location
!= -1) {
1784 final long rank
= location
;
1785 fBookmarksMap
.put(rank
, bookmark
.getId());
1789 } catch (final CoreException e
) {
1790 displayException(e
);
1795 public void gotoMarker(final IMarker marker
) {
1796 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
1799 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
1800 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
1801 } else if (rank
>= fTable
.getItemCount()) {
1802 fPendingGotoRank
= rank
;
1804 fTable
.setSelection(index
+ 1); // +1 for header row
1808 // ------------------------------------------------------------------------
1810 // ------------------------------------------------------------------------
1815 * @see org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener#colorSettingsChanged(org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting[])
1818 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
1822 // ------------------------------------------------------------------------
1824 // ------------------------------------------------------------------------
1827 * Handler for the trace updated signal
1830 * The incoming signal
1833 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
1834 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
1837 // Perform the refresh on the UI thread
1838 Display
.getDefault().asyncExec(new Runnable() {
1841 if (!fTable
.isDisposed() && (fTrace
!= null)) {
1842 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1843 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1844 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) { // +1 for header row
1845 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
1846 fPendingGotoRank
= -1;
1849 startFilterThread();
1852 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
1853 fRawViewer
.refreshEventCount();
1860 * Handler for the time synch signal.
1863 * The incoming signal
1866 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
1867 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
1869 // Create a request for one event that will be queued after other ongoing requests. When this request is completed
1870 // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents
1871 // the method fTrace.getRank() from interfering and delaying ongoing requests.
1872 final TmfDataRequest subRequest
= new TmfDataRequest(ITmfEvent
.class, 0, 1, ExecutionType
.FOREGROUND
) {
1874 TmfTimestamp ts
= new TmfTimestamp(signal
.getCurrentTime());
1877 public void handleData(final ITmfEvent event
) {
1878 super.handleData(event
);
1882 public void handleCompleted() {
1883 super.handleCompleted();
1884 if (fTrace
== null) {
1888 // Verify if the event is within the trace range and adjust if necessary
1889 ITmfTimestamp timestamp
= ts
;
1890 if (timestamp
.compareTo(fTrace
.getStartTime(), true) == -1) {
1891 timestamp
= fTrace
.getStartTime();
1893 if (timestamp
.compareTo(fTrace
.getEndTime(), true) == 1) {
1894 timestamp
= fTrace
.getEndTime();
1897 // Get the rank of the selected event in the table
1898 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
1899 final long rank
= context
.getRank();
1901 fSelectedRank
= rank
;
1903 fTable
.getDisplay().asyncExec(new Runnable() {
1906 // Return if table is disposed
1907 if (fTable
.isDisposed()) {
1911 int index
= (int) rank
;
1912 if (fTable
.isDisposed()) {
1915 if (fTable
.getData(Key
.FILTER_OBJ
) != null)
1917 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
1919 fTable
.setSelection(index
+ 1); // +1 for header row
1920 fRawViewer
.selectAndReveal(rank
);
1926 ((ITmfDataProvider
) fTrace
).sendRequest(subRequest
);
1930 // ------------------------------------------------------------------------
1932 // ------------------------------------------------------------------------
1935 * Display an exception in a message box
1937 * @param e the exception
1939 private static void displayException(final Exception e
) {
1940 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
1941 mb
.setText(e
.getClass().getName());
1942 mb
.setMessage(e
.getMessage());
1949 public void refresh() {