1 /*******************************************************************************
2 * Copyright (c) 2010 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
;
22 import java
.util
.Map
.Entry
;
23 import java
.util
.regex
.Pattern
;
24 import java
.util
.regex
.PatternSyntaxException
;
26 import org
.eclipse
.core
.resources
.IFile
;
27 import org
.eclipse
.core
.resources
.IMarker
;
28 import org
.eclipse
.core
.resources
.IResource
;
29 import org
.eclipse
.core
.runtime
.CoreException
;
30 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
31 import org
.eclipse
.core
.runtime
.IStatus
;
32 import org
.eclipse
.core
.runtime
.Status
;
33 import org
.eclipse
.core
.runtime
.jobs
.Job
;
34 import org
.eclipse
.jface
.action
.Action
;
35 import org
.eclipse
.jface
.action
.IAction
;
36 import org
.eclipse
.jface
.action
.IMenuListener
;
37 import org
.eclipse
.jface
.action
.IMenuManager
;
38 import org
.eclipse
.jface
.action
.MenuManager
;
39 import org
.eclipse
.jface
.action
.Separator
;
40 import org
.eclipse
.jface
.dialogs
.Dialog
;
41 import org
.eclipse
.jface
.dialogs
.InputDialog
;
42 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
43 import org
.eclipse
.jface
.resource
.FontDescriptor
;
44 import org
.eclipse
.jface
.resource
.JFaceResources
;
45 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
50 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
51 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
52 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
53 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
54 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
55 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
56 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
57 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
58 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
59 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
60 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
.ExecutionType
;
61 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
62 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
63 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentUpdatedSignal
;
64 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
65 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
66 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
67 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
68 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
69 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
70 import org
.eclipse
.linuxtools
.tmf
.ui
.internal
.Messages
;
71 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
72 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSetting
;
73 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
74 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
75 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
.FilterManager
;
76 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.ColumnData
;
77 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.TmfRawEventViewer
;
78 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.TmfVirtualTable
;
79 import org
.eclipse
.swt
.SWT
;
80 import org
.eclipse
.swt
.custom
.SashForm
;
81 import org
.eclipse
.swt
.custom
.TableEditor
;
82 import org
.eclipse
.swt
.events
.FocusAdapter
;
83 import org
.eclipse
.swt
.events
.FocusEvent
;
84 import org
.eclipse
.swt
.events
.KeyAdapter
;
85 import org
.eclipse
.swt
.events
.KeyEvent
;
86 import org
.eclipse
.swt
.events
.MouseAdapter
;
87 import org
.eclipse
.swt
.events
.MouseEvent
;
88 import org
.eclipse
.swt
.events
.SelectionAdapter
;
89 import org
.eclipse
.swt
.events
.SelectionEvent
;
90 import org
.eclipse
.swt
.graphics
.Color
;
91 import org
.eclipse
.swt
.graphics
.Font
;
92 import org
.eclipse
.swt
.graphics
.Image
;
93 import org
.eclipse
.swt
.graphics
.Point
;
94 import org
.eclipse
.swt
.graphics
.Rectangle
;
95 import org
.eclipse
.swt
.layout
.FillLayout
;
96 import org
.eclipse
.swt
.layout
.GridData
;
97 import org
.eclipse
.swt
.layout
.GridLayout
;
98 import org
.eclipse
.swt
.widgets
.Composite
;
99 import org
.eclipse
.swt
.widgets
.Display
;
100 import org
.eclipse
.swt
.widgets
.Event
;
101 import org
.eclipse
.swt
.widgets
.Label
;
102 import org
.eclipse
.swt
.widgets
.Listener
;
103 import org
.eclipse
.swt
.widgets
.Menu
;
104 import org
.eclipse
.swt
.widgets
.MessageBox
;
105 import org
.eclipse
.swt
.widgets
.Shell
;
106 import org
.eclipse
.swt
.widgets
.TableColumn
;
107 import org
.eclipse
.swt
.widgets
.TableItem
;
108 import org
.eclipse
.swt
.widgets
.Text
;
109 import org
.eclipse
.ui
.PlatformUI
;
110 import org
.eclipse
.ui
.ide
.IGotoMarker
;
111 import org
.eclipse
.ui
.themes
.ColorUtil
;
114 * <b><u>TmfEventsTable</u></b>
116 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
,
117 ITmfEventsFilterProvider
{
119 private static final Image BOOKMARK_IMAGE
= TmfUiPlugin
.getDefault().getImageFromPath(
120 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
121 private static final Image SEARCH_IMAGE
= TmfUiPlugin
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
122 private static final Image SEARCH_MATCH_IMAGE
= TmfUiPlugin
.getDefault().getImageFromPath(
123 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
124 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= TmfUiPlugin
.getDefault().getImageFromPath(
125 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
126 private static final Image FILTER_IMAGE
= TmfUiPlugin
.getDefault()
127 .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
128 private static final Image STOP_IMAGE
= TmfUiPlugin
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
129 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
130 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
131 private static final int MAX_CACHE_SIZE
= 1000;
133 public interface Key
{
134 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
135 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
136 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
137 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
138 String TIMESTAMP
= "$time"; //$NON-NLS-1$
139 String RANK
= "$rank"; //$NON-NLS-1$
140 String FIELD_ID
= "$field_id"; //$NON-NLS-1$
141 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
144 public static enum HeaderState
{
148 interface Direction
{
153 // ------------------------------------------------------------------------
155 // ------------------------------------------------------------------------
157 protected Composite fComposite
;
158 protected SashForm fSashForm
;
159 protected TmfVirtualTable fTable
;
160 protected TmfRawEventViewer fRawViewer
;
161 protected ITmfTrace
<?
> fTrace
;
162 protected boolean fPackDone
= false;
163 protected HeaderState fHeaderState
= HeaderState
.SEARCH
;
164 protected long fSelectedRank
= 0;
167 protected long fFilterMatchCount
;
168 protected long fFilterCheckCount
;
169 protected FilterThread fFilterThread
;
170 protected final Object fFilterSyncObj
= new Object();
171 protected SearchThread fSearchThread
;
172 protected final Object fSearchSyncObj
= new Object();
173 protected ArrayList
<ITmfEventsFilterListener
> fEventsFilterListeners
= new ArrayList
<ITmfEventsFilterListener
>();
175 // Bookmark map <Rank, MarkerId>
176 protected Map
<Long
, Long
> fBookmarksMap
= new HashMap
<Long
, Long
>();
177 protected IFile fBookmarksFile
;
178 protected long fPendingGotoRank
= -1;
181 protected LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
182 protected Color fGrayColor
;
183 protected Color fGreenColor
;
184 protected Font fBoldFont
;
186 // Table column names
187 static private final String
[] COLUMN_NAMES
= new String
[] { Messages
.TmfEventsTable_TimestampColumnHeader
,
188 Messages
.TmfEventsTable_SourceColumnHeader
, Messages
.TmfEventsTable_TypeColumnHeader
,
189 Messages
.TmfEventsTable_ReferenceColumnHeader
, Messages
.TmfEventsTable_ContentColumnHeader
};
191 static private ColumnData
[] COLUMN_DATA
= new ColumnData
[] { new ColumnData(COLUMN_NAMES
[0], 100, SWT
.LEFT
),
192 new ColumnData(COLUMN_NAMES
[1], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[2], 100, SWT
.LEFT
),
193 new ColumnData(COLUMN_NAMES
[3], 100, SWT
.LEFT
), new ColumnData(COLUMN_NAMES
[4], 100, SWT
.LEFT
) };
196 private final TmfEventsCache fCache
;
197 private boolean fCacheUpdateBusy
= false;
198 private boolean fCacheUpdatePending
= false;
199 private boolean fCacheUpdateCompleted
= false;
200 private Object fCacheUpdateSyncObj
= new Object();
202 private boolean fDisposeOnClose
;
204 // ------------------------------------------------------------------------
206 // ------------------------------------------------------------------------
208 public TmfEventsTable(Composite parent
, int cacheSize
) {
209 this(parent
, cacheSize
, COLUMN_DATA
);
212 public TmfEventsTable(Composite parent
, int cacheSize
, ColumnData
[] columnData
) {
213 super("TmfEventsTable"); //$NON-NLS-1$
215 fComposite
= new Composite(parent
, SWT
.NONE
);
216 GridLayout gl
= new GridLayout(1, false);
219 gl
.verticalSpacing
= 0;
220 fComposite
.setLayout(gl
);
222 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
223 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
225 // Create a virtual table
226 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.SINGLE
| SWT
.FULL_SELECTION
;
227 fTable
= new TmfVirtualTable(fSashForm
, style
);
229 // Set the table layout
230 GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
231 fTable
.setLayoutData(layoutData
);
233 // Some cosmetic enhancements
234 fTable
.setHeaderVisible(true);
235 fTable
.setLinesVisible(true);
238 setColumnHeaders(columnData
);
240 // Set the default column field ids if this is not a subclass
241 if (Arrays
.equals(columnData
, COLUMN_DATA
)) {
242 fTable
.getColumns()[0].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
243 fTable
.getColumns()[1].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_SOURCE
);
244 fTable
.getColumns()[2].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_TYPE
);
245 fTable
.getColumns()[3].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_REFERENCE
);
246 fTable
.getColumns()[4].setData(Key
.FIELD_ID
, ITmfEvent
.EVENT_FIELD_CONTENT
);
249 // Set the frozen row for header row
250 fTable
.setFrozenRowCount(1);
252 // Create the header row cell editor
253 createHeaderEditor();
255 // Handle the table item selection
256 fTable
.addSelectionListener(new SelectionAdapter() {
258 public void widgetSelected(SelectionEvent e
) {
259 TableItem
[] selection
= fTable
.getSelection();
260 if (selection
.length
> 0) {
261 TableItem selectedTableItem
= selection
[0];
262 if (selectedTableItem
!= null) {
263 if (selectedTableItem
.getData(Key
.RANK
) instanceof Long
) {
264 fSelectedRank
= (Long
) selectedTableItem
.getData(Key
.RANK
);
265 fRawViewer
.selectAndReveal((Long
) selectedTableItem
.getData(Key
.RANK
));
267 if (selectedTableItem
.getData(Key
.TIMESTAMP
) instanceof TmfTimestamp
) {
268 TmfTimestamp ts
= (TmfTimestamp
) selectedTableItem
.getData(Key
.TIMESTAMP
);
269 broadcast(new TmfTimeSynchSignal(fTable
, ts
));
276 cacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
277 cacheSize
= Math
.min(cacheSize
, MAX_CACHE_SIZE
);
278 fCache
= new TmfEventsCache(cacheSize
, this);
280 // Handle the table item requests
281 fTable
.addListener(SWT
.SetData
, new Listener() {
284 public void handleEvent(Event event
) {
286 final TableItem item
= (TableItem
) event
.item
;
287 int index
= event
.index
- 1; // -1 for the header row
289 if (event
.index
== 0) {
290 setHeaderRowItemData(item
);
294 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
295 if (event
.index
== 1 || event
.index
== fTable
.getItemCount() - 1) {
296 setFilterStatusRowItemData(item
);
299 index
= index
- 1; // -1 for top filter status row
302 CachedEvent cachedEvent
= fCache
.getEvent(index
);
303 if (cachedEvent
!= null) {
304 setItemData(item
, cachedEvent
.event
, cachedEvent
.rank
);
308 // Else, fill the cache asynchronously (and off the UI thread)
313 fTable
.addMouseListener(new MouseAdapter() {
315 public void mouseDoubleClick(MouseEvent event
) {
316 if (event
.button
!= 1) {
319 // Identify the selected row
320 Point point
= new Point(event
.x
, event
.y
);
321 TableItem item
= fTable
.getItem(point
);
323 Rectangle imageBounds
= item
.getImageBounds(0);
324 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
325 if (imageBounds
.contains(point
)) {
326 Long rank
= (Long
) item
.getData(Key
.RANK
);
328 toggleBookmark(rank
);
335 final Listener bookmarkListener
= new Listener () {
336 Shell tooltipShell
= null;
338 public void handleEvent(Event event
) {
339 switch (event
.type
) {
341 TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
345 String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
346 if (tooltipText
== null) {
349 Rectangle bounds
= item
.getImageBounds(0);
350 if (!bounds
.contains(event
.x
,event
.y
)) {
353 if (tooltipShell
!= null && !tooltipShell
.isDisposed()) {
354 tooltipShell
.dispose();
356 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
357 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
358 FillLayout layout
= new FillLayout();
359 layout
.marginWidth
= 2;
360 tooltipShell
.setLayout(layout
);
361 Label label
= new Label(tooltipShell
, SWT
.WRAP
);
362 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
363 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
364 label
.setText(tooltipText
);
365 label
.addListener(SWT
.MouseExit
, this);
366 label
.addListener(SWT
.MouseDown
, this);
367 label
.addListener(SWT
.MouseWheel
, this);
368 Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
369 Point pt
= fTable
.toDisplay(event
.x
, event
.y
);
370 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
371 tooltipShell
.setVisible(true);
379 if (tooltipShell
!= null) {
380 tooltipShell
.dispose();
388 fTable
.addListener(SWT
.MouseHover
, bookmarkListener
);
389 fTable
.addListener(SWT
.Dispose
, bookmarkListener
);
390 fTable
.addListener(SWT
.KeyDown
, bookmarkListener
);
391 fTable
.addListener(SWT
.MouseMove
, bookmarkListener
);
392 fTable
.addListener(SWT
.MouseExit
, bookmarkListener
);
393 fTable
.addListener(SWT
.MouseDown
, bookmarkListener
);
394 fTable
.addListener(SWT
.MouseWheel
, bookmarkListener
);
399 ColorSettingsManager
.addColorSettingsListener(this);
401 fTable
.setItemCount(1); // +1 for header row
403 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
405 fRawViewer
.addSelectionListener(new Listener() {
407 public void handleEvent(Event e
) {
408 if (e
.data
instanceof Long
) {
409 long rank
= (Long
) e
.data
;
410 int index
= (int) rank
;
411 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
412 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
414 fTable
.setSelection(index
+ 1); // +1 for header row
415 fSelectedRank
= rank
;
416 } else if (e
.data
instanceof ITmfLocation
<?
>) {
417 // DOES NOT WORK: rank undefined in context from seekLocation()
418 // ITmfLocation<?> location = (ITmfLocation<?>) e.data;
419 // TmfContext context = fTrace.seekLocation(location);
420 // fTable.setSelection((int) context.getRank());
425 TableItem
[] selection
= fTable
.getSelection();
426 if (selection
!= null && selection
.length
> 0) {
427 TmfTimestamp ts
= (TmfTimestamp
) fTable
.getSelection()[0].getData(Key
.TIMESTAMP
);
429 broadcast(new TmfTimeSynchSignal(fTable
, ts
));
435 fSashForm
.setWeights(new int[] { 1, 1 });
436 fRawViewer
.setVisible(false);
441 protected void createPopupMenu() {
442 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
445 fTable
.setVisible(true);
450 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
453 fTable
.setVisible(false);
458 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
461 fRawViewer
.setVisible(true);
463 int index
= fTable
.getSelectionIndex();
464 if (index
>= +1) { // +1 for header row
465 fRawViewer
.selectAndReveal(index
- 1);
470 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
473 fRawViewer
.setVisible(false);
478 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
481 fHeaderState
= HeaderState
.SEARCH
;
486 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
489 fHeaderState
= HeaderState
.FILTER
;
494 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
503 class ToggleBookmarkAction
extends Action
{
506 public ToggleBookmarkAction(String text
, long rank
) {
513 toggleBookmark(fRank
);
517 final MenuManager tablePopupMenu
= new MenuManager();
518 tablePopupMenu
.setRemoveAllWhenShown(true);
519 tablePopupMenu
.addMenuListener(new IMenuListener() {
521 public void menuAboutToShow(IMenuManager manager
) {
522 if (fTable
.getSelectionIndex() == 0) {
523 // Right-click on header row
524 if (fHeaderState
== HeaderState
.FILTER
) {
525 tablePopupMenu
.add(showSearchBarAction
);
527 tablePopupMenu
.add(showFilterBarAction
);
531 Point point
= fTable
.toControl(Display
.getDefault().getCursorLocation());
532 TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
534 Rectangle imageBounds
= item
.getImageBounds(0);
535 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
536 if (point
.x
<= imageBounds
.x
+ imageBounds
.width
) {
537 // Right-click on left margin
538 Long rank
= (Long
) item
.getData(Key
.RANK
);
539 if (rank
!= null && fBookmarksFile
!= null) {
540 if (fBookmarksMap
.containsKey(rank
)) {
541 tablePopupMenu
.add(new ToggleBookmarkAction(
542 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
544 tablePopupMenu
.add(new ToggleBookmarkAction(
545 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
551 // Right-click on table
552 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
553 tablePopupMenu
.add(hideTableAction
);
554 tablePopupMenu
.add(hideRawAction
);
555 } else if (!fTable
.isVisible()) {
556 tablePopupMenu
.add(showTableAction
);
557 } else if (!fRawViewer
.isVisible()) {
558 tablePopupMenu
.add(showRawAction
);
560 tablePopupMenu
.add(new Separator());
561 tablePopupMenu
.add(clearFiltersAction
);
562 ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
563 if (savedFilters
.length
> 0) {
564 MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
565 for (ITmfFilterTreeNode node
: savedFilters
) {
566 if (node
instanceof TmfFilterNode
) {
567 final TmfFilterNode filter
= (TmfFilterNode
) node
;
568 subMenu
.add(new Action(filter
.getFilterName()) {
572 fFilterMatchCount
= 0;
573 fFilterCheckCount
= 0;
574 fCache
.applyFilter(filter
);
576 fTable
.setData(Key
.FILTER_OBJ
, filter
);
577 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status
580 fireFilterApplied(filter
);
585 tablePopupMenu
.add(subMenu
);
587 appendToTablePopupMenu(tablePopupMenu
, item
);
591 final MenuManager rawViewerPopupMenu
= new MenuManager();
592 rawViewerPopupMenu
.setRemoveAllWhenShown(true);
593 rawViewerPopupMenu
.addMenuListener(new IMenuListener() {
595 public void menuAboutToShow(IMenuManager manager
) {
596 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
597 rawViewerPopupMenu
.add(hideTableAction
);
598 rawViewerPopupMenu
.add(hideRawAction
);
599 } else if (!fTable
.isVisible()) {
600 rawViewerPopupMenu
.add(showTableAction
);
601 } else if (!fRawViewer
.isVisible()) {
602 rawViewerPopupMenu
.add(showRawAction
);
604 appendToRawPopupMenu(tablePopupMenu
);
608 Menu menu
= tablePopupMenu
.createContextMenu(fTable
);
609 fTable
.setMenu(menu
);
611 menu
= rawViewerPopupMenu
.createContextMenu(fRawViewer
);
612 fRawViewer
.setMenu(menu
);
615 protected void appendToTablePopupMenu(MenuManager tablePopupMenu
, TableItem selectedItem
) {
616 // override to append more actions
619 protected void appendToRawPopupMenu(MenuManager rawViewerPopupMenu
) {
620 // override to append more actions
624 public void dispose() {
627 ColorSettingsManager
.removeColorSettingsListener(this);
628 fComposite
.dispose();
629 if (fTrace
!= null && fDisposeOnClose
) {
632 fResourceManager
.dispose();
636 public void setLayoutData(Object layoutData
) {
637 fComposite
.setLayoutData(layoutData
);
640 public TmfVirtualTable
getTable() {
647 * FIXME: Add support for column selection
649 protected void setColumnHeaders(ColumnData
[] columnData
) {
650 fTable
.setColumnHeaders(columnData
);
653 protected void setItemData(TableItem item
, TmfEvent event
, long rank
) {
654 ITmfEventField
[] fields
= extractItemFields(event
);
655 String
[] content
= new String
[fields
.length
];
656 for (int i
= 0; i
< fields
.length
; i
++) {
657 content
[i
] = fields
[i
].getValue() != null ? fields
[i
].getValue().toString() : ""; //$NON-NLS-1$
659 item
.setText(content
);
660 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(event
.getTimestamp()));
661 item
.setData(Key
.RANK
, rank
);
663 boolean bookmark
= false;
664 Long markerId
= fBookmarksMap
.get(rank
);
665 if (markerId
!= null) {
668 IMarker marker
= fBookmarksFile
.findMarker(markerId
);
669 item
.setData(Key
.BOOKMARK
, marker
.getAttribute(IMarker
.MESSAGE
));
670 } catch (CoreException e
) {
674 item
.setData(Key
.BOOKMARK
, null);
677 boolean searchMatch
= false;
678 boolean searchNoMatch
= false;
679 ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
680 if (searchFilter
!= null) {
681 if (searchFilter
.matches(event
)) {
684 searchNoMatch
= true;
688 ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(event
);
690 item
.setForeground(colorSetting
.getDimmedForegroundColor());
691 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
693 item
.setForeground(colorSetting
.getForegroundColor());
694 item
.setBackground(colorSetting
.getBackgroundColor());
699 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
701 item
.setImage(SEARCH_MATCH_IMAGE
);
703 } else if (bookmark
) {
704 item
.setImage(BOOKMARK_IMAGE
);
706 item
.setImage((Image
) null);
710 protected void setHeaderRowItemData(TableItem item
) {
711 String txtKey
= null;
712 if (fHeaderState
== HeaderState
.SEARCH
) {
713 item
.setImage(SEARCH_IMAGE
);
714 txtKey
= Key
.SEARCH_TXT
;
715 } else if (fHeaderState
== HeaderState
.FILTER
) {
716 item
.setImage(FILTER_IMAGE
);
717 txtKey
= Key
.FILTER_TXT
;
719 item
.setForeground(fGrayColor
);
720 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
721 TableColumn column
= fTable
.getColumns()[i
];
722 String filter
= (String
) column
.getData(txtKey
);
723 if (filter
== null) {
724 if (fHeaderState
== HeaderState
.SEARCH
) {
725 item
.setText(i
, SEARCH_HINT
);
726 } else if (fHeaderState
== HeaderState
.FILTER
) {
727 item
.setText(i
, FILTER_HINT
);
729 item
.setForeground(i
, fGrayColor
);
730 item
.setFont(i
, fTable
.getFont());
732 item
.setText(i
, filter
);
733 item
.setForeground(i
, fGreenColor
);
734 item
.setFont(i
, fBoldFont
);
739 protected void setFilterStatusRowItemData(TableItem item
) {
740 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
742 if (fTrace
== null || fFilterCheckCount
== fTrace
.getNbEvents()) {
743 item
.setImage(FILTER_IMAGE
);
745 item
.setImage(STOP_IMAGE
);
747 item
.setText(0, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
749 item
.setText(i
, ""); //$NON-NLS-1$
752 item
.setData(Key
.TIMESTAMP
, null);
753 item
.setData(Key
.RANK
, null);
754 item
.setForeground(null);
755 item
.setBackground(null);
758 protected void createHeaderEditor() {
759 final TableEditor tableEditor
= fTable
.createTableEditor();
760 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
761 tableEditor
.verticalAlignment
= SWT
.CENTER
;
762 tableEditor
.grabHorizontal
= true;
763 tableEditor
.minimumWidth
= 50;
765 // Handle the header row selection
766 fTable
.addMouseListener(new MouseAdapter() {
772 public void mouseDown(MouseEvent event
) {
773 if (event
.button
!= 1) {
776 // Identify the selected row
777 Point point
= new Point(event
.x
, event
.y
);
778 item
= fTable
.getItem(point
);
780 // Header row selected
781 if (item
!= null && fTable
.indexOf(item
) == 0) {
784 if (item
.getImageBounds(0).contains(point
)) {
785 if (fHeaderState
== HeaderState
.SEARCH
) {
786 fHeaderState
= HeaderState
.FILTER
;
787 } else if (fHeaderState
== HeaderState
.FILTER
) {
788 fHeaderState
= HeaderState
.SEARCH
;
794 // Identify the selected column
796 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
797 Rectangle rect
= item
.getBounds(i
);
798 if (rect
.contains(point
)) {
804 if (columnIndex
== -1) {
808 column
= fTable
.getColumns()[columnIndex
];
810 String txtKey
= null;
811 if (fHeaderState
== HeaderState
.SEARCH
) {
812 txtKey
= Key
.SEARCH_TXT
;
813 } else if (fHeaderState
== HeaderState
.FILTER
) {
814 txtKey
= Key
.FILTER_TXT
;
817 // The control that will be the editor must be a child of the Table
818 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
819 String headerString
= (String
) column
.getData(txtKey
);
820 if (headerString
!= null) {
821 newEditor
.setText(headerString
);
823 newEditor
.addFocusListener(new FocusAdapter() {
825 public void focusLost(FocusEvent e
) {
826 boolean changed
= updateHeader(newEditor
.getText());
832 newEditor
.addKeyListener(new KeyAdapter() {
834 public void keyPressed(KeyEvent e
) {
835 if (e
.character
== SWT
.CR
) {
836 updateHeader(newEditor
.getText());
838 } else if (e
.character
== SWT
.ESC
) {
839 tableEditor
.getEditor().dispose();
843 newEditor
.selectAll();
844 newEditor
.setFocus();
845 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
850 * returns true is value was changed
852 private boolean updateHeader(String text
) {
853 String objKey
= null;
854 String txtKey
= null;
855 if (fHeaderState
== HeaderState
.SEARCH
) {
856 objKey
= Key
.SEARCH_OBJ
;
857 txtKey
= Key
.SEARCH_TXT
;
858 } else if (fHeaderState
== HeaderState
.FILTER
) {
859 objKey
= Key
.FILTER_OBJ
;
860 txtKey
= Key
.FILTER_TXT
;
862 if (text
.trim().length() > 0) {
864 String regex
= TmfFilterMatchesNode
.regexFix(text
);
865 Pattern
.compile(regex
);
866 if (regex
.equals(column
.getData(txtKey
))) {
867 tableEditor
.getEditor().dispose();
870 TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
871 String fieldId
= (String
) column
.getData(Key
.FIELD_ID
);
872 if (fieldId
== null) {
873 fieldId
= column
.getText();
875 filter
.setField(fieldId
);
876 filter
.setRegex(regex
);
877 column
.setData(objKey
, filter
);
878 column
.setData(txtKey
, regex
);
879 } catch (PatternSyntaxException ex
) {
880 tableEditor
.getEditor().dispose();
881 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
882 ex
.getDescription(), ex
.getMessage());
886 if (column
.getData(txtKey
) == null) {
887 tableEditor
.getEditor().dispose();
890 column
.setData(objKey
, null);
891 column
.setData(txtKey
, null);
896 private void applyHeader() {
898 if (fHeaderState
== HeaderState
.SEARCH
) {
899 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
900 for (TableColumn column
: fTable
.getColumns()) {
901 Object filterObj
= column
.getData(Key
.SEARCH_OBJ
);
902 if (filterObj
instanceof ITmfFilterTreeNode
) {
903 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
906 if (filter
.getChildrenCount() > 0) {
907 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
910 fireSearchApplied(filter
);
912 fTable
.setData(Key
.SEARCH_OBJ
, null);
914 fireSearchApplied(null);
916 } else if (fHeaderState
== HeaderState
.FILTER
) {
918 fFilterMatchCount
= 0;
919 fFilterCheckCount
= 0;
920 TmfFilterAndNode filter
= new TmfFilterAndNode(null);
921 for (TableColumn column
: fTable
.getColumns()) {
922 Object filterObj
= column
.getData(Key
.FILTER_OBJ
);
923 if (filterObj
instanceof ITmfFilterTreeNode
) {
924 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
927 if (filter
.getChildrenCount() > 0) {
928 fCache
.applyFilter(filter
);
930 fTable
.setData(Key
.FILTER_OBJ
, filter
);
931 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
933 fireFilterApplied(filter
);
935 fCache
.clearFilter();
938 fTable
.setData(Key
.FILTER_OBJ
, null);
939 if (fTrace
!= null) {
940 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
942 fTable
.setItemCount(1); // +1 for header row
944 fireFilterApplied(null);
948 tableEditor
.getEditor().dispose();
952 fTable
.addKeyListener(new KeyAdapter() {
954 public void keyPressed(KeyEvent e
) {
956 if (e
.character
== SWT
.ESC
) {
960 } else if (e
.character
== SWT
.DEL
) {
963 if (fHeaderState
== HeaderState
.SEARCH
) {
964 for (TableColumn column
: fTable
.getColumns()) {
965 column
.setData(Key
.SEARCH_OBJ
, null);
966 column
.setData(Key
.SEARCH_TXT
, null);
968 fTable
.setData(Key
.SEARCH_OBJ
, null);
970 fireSearchApplied(null);
971 } else if (fHeaderState
== HeaderState
.FILTER
) {
974 } else if (e
.character
== SWT
.CR
) {
975 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
985 protected void fireFilterApplied(ITmfFilter filter
) {
986 for (ITmfEventsFilterListener listener
: fEventsFilterListeners
) {
987 listener
.filterApplied(filter
, fTrace
);
991 protected void fireSearchApplied(ITmfFilter filter
) {
992 for (ITmfEventsFilterListener listener
: fEventsFilterListeners
) {
993 listener
.searchApplied(filter
, fTrace
);
997 protected void startFilterThread() {
998 synchronized (fFilterSyncObj
) {
999 if (fFilterThread
!= null) {
1000 fFilterThread
.cancel();
1002 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1003 fFilterThread
= new FilterThread(filter
);
1004 fFilterThread
.start();
1008 protected void stopFilterThread() {
1009 synchronized (fFilterSyncObj
) {
1010 if (fFilterThread
!= null) {
1011 fFilterThread
.cancel();
1016 protected void clearFilters() {
1017 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1020 fCache
.clearFilter();
1022 for (TableColumn column
: fTable
.getColumns()) {
1023 column
.setData(Key
.FILTER_OBJ
, null);
1024 column
.setData(Key
.FILTER_TXT
, null);
1026 fTable
.setData(Key
.FILTER_OBJ
, null);
1027 if (fTrace
!= null) {
1028 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1030 fTable
.setItemCount(1); // +1 for header row
1032 fFilterMatchCount
= 0;
1033 fFilterCheckCount
= 0;
1034 if (fSelectedRank
>= 0) {
1035 fTable
.setSelection((int) fSelectedRank
+ 1); // +1 for header row
1037 fTable
.setSelection(0);
1039 fireFilterApplied(null);
1042 protected class FilterThread
extends Thread
{
1043 private final ITmfFilterTreeNode filter
;
1044 private TmfEventRequest
<TmfEvent
> request
;
1045 private boolean refreshBusy
= false;
1046 private boolean refreshPending
= false;
1047 private Object syncObj
= new Object();
1049 public FilterThread(ITmfFilterTreeNode filter
) {
1050 super("Filter Thread"); //$NON-NLS-1$
1051 this.filter
= filter
;
1054 @SuppressWarnings("unchecked")
1057 if (fTrace
== null) {
1060 int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1061 if (nbRequested
<= 0) {
1064 request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, TmfTimeRange
.ETERNITY
, (int) fFilterCheckCount
,
1065 nbRequested
, fTrace
.getCacheSize(), ExecutionType
.BACKGROUND
) {
1067 public void handleData(TmfEvent event
) {
1068 super.handleData(event
);
1069 if (request
.isCancelled())
1071 if (filter
.matches(event
)) {
1072 long rank
= fFilterCheckCount
;
1073 int index
= (int) fFilterMatchCount
;
1074 fFilterMatchCount
++;
1075 fCache
.storeEvent(event
.clone(), rank
, index
);
1077 } else if (fFilterCheckCount
% 100 == 0) {
1080 fFilterCheckCount
++;
1083 ((ITmfDataProvider
<TmfEvent
>) fTrace
).sendRequest(request
);
1085 request
.waitForCompletion();
1086 } catch (InterruptedException e
) {
1091 public void refreshTable() {
1092 synchronized (syncObj
) {
1094 refreshPending
= true;
1100 Display
.getDefault().asyncExec(new Runnable() {
1103 if (request
.isCancelled())
1105 if (fTable
.isDisposed())
1107 fTable
.setItemCount((int) fFilterMatchCount
+ 3); // +1 for header row, +2 for top and bottom filter
1110 synchronized (syncObj
) {
1111 refreshBusy
= false;
1112 if (refreshPending
) {
1113 refreshPending
= false;
1121 public void cancel() {
1122 if (request
!= null) {
1128 protected void searchNext() {
1129 synchronized (fSearchSyncObj
) {
1130 if (fSearchThread
!= null) {
1133 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1134 if (searchFilter
== null) {
1137 int selectionIndex
= fTable
.getSelectionIndex();
1139 if (selectionIndex
> 0) {
1140 startIndex
= selectionIndex
; // -1 for header row, +1 for next event
1142 // header row is selected, start at top event
1143 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1); // -1 for header row
1145 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1146 if (eventFilter
!= null) {
1147 startIndex
= Math
.max(0, startIndex
- 1); // -1 for top filter status row
1149 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
1150 fSearchThread
.schedule();
1154 protected void searchPrevious() {
1155 synchronized (fSearchSyncObj
) {
1156 if (fSearchThread
!= null) {
1159 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
1160 if (searchFilter
== null) {
1163 int selectionIndex
= fTable
.getSelectionIndex();
1165 if (selectionIndex
> 0) {
1166 startIndex
= selectionIndex
- 2; // -1 for header row, -1 for previous event
1168 // header row is selected, start at precedent of top event
1169 startIndex
= fTable
.getTopIndex() - 2; // -1 for header row, -1 for previous event
1171 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1172 if (eventFilter
!= null) {
1173 startIndex
= startIndex
- 1; // -1 for top filter status row
1175 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
1176 fSearchThread
.schedule();
1180 protected void stopSearchThread() {
1181 fPendingGotoRank
= -1;
1182 synchronized (fSearchSyncObj
) {
1183 if (fSearchThread
!= null) {
1184 fSearchThread
.cancel();
1185 fSearchThread
= null;
1190 protected class SearchThread
extends Job
{
1191 protected ITmfFilterTreeNode searchFilter
;
1192 protected ITmfFilterTreeNode eventFilter
;
1193 protected int startIndex
;
1194 protected int direction
;
1195 protected long rank
;
1196 protected long foundRank
= -1;
1197 protected TmfDataRequest
<TmfEvent
> request
;
1199 public SearchThread(ITmfFilterTreeNode searchFilter
, ITmfFilterTreeNode eventFilter
, int startIndex
,
1200 long currentRank
, int direction
) {
1201 super(Messages
.TmfEventsTable_SearchingJobName
);
1202 this.searchFilter
= searchFilter
;
1203 this.eventFilter
= eventFilter
;
1204 this.startIndex
= startIndex
;
1205 this.rank
= currentRank
;
1206 this.direction
= direction
;
1209 @SuppressWarnings("unchecked")
1211 protected IStatus
run(final IProgressMonitor monitor
) {
1212 if (fTrace
== null) {
1213 return Status
.OK_STATUS
;
1215 final Display display
= Display
.getDefault();
1216 if (startIndex
< 0) {
1217 rank
= (int) fTrace
.getNbEvents() - 1;
1218 } else if (startIndex
>= fTable
.getItemCount() - (eventFilter
== null ?
1 : 3)) { // -1 for header row, -2
1219 // for top and bottom
1220 // filter status rows
1223 int idx
= startIndex
;
1224 while (foundRank
== -1) {
1225 CachedEvent event
= fCache
.peekEvent(idx
);
1226 if (event
== null) {
1230 if (searchFilter
.matches(event
.event
) && (eventFilter
== null || eventFilter
.matches(event
.event
))) {
1231 foundRank
= event
.rank
;
1234 if (direction
== Direction
.FORWARD
) {
1240 if (foundRank
== -1) {
1241 if (direction
== Direction
.FORWARD
) {
1243 if (rank
> fTrace
.getNbEvents() - 1) {
1249 rank
= (int) fTrace
.getNbEvents() - 1;
1254 int startRank
= (int) rank
;
1255 boolean wrapped
= false;
1256 while (!monitor
.isCanceled() && foundRank
== -1 && fTrace
!= null) {
1257 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1,
1258 fTrace
.getCacheSize()));
1259 if (direction
== Direction
.BACKWARD
) {
1260 rank
= Math
.max(0, rank
- fTrace
.getCacheSize() + 1);
1262 request
= new TmfDataRequest
<TmfEvent
>(TmfEvent
.class, (int) rank
, nbRequested
) {
1263 long currentRank
= rank
;
1266 public void handleData(TmfEvent event
) {
1267 super.handleData(event
);
1268 if (searchFilter
.matches(event
) && (eventFilter
== null || eventFilter
.matches(event
))) {
1269 foundRank
= currentRank
;
1270 if (direction
== Direction
.FORWARD
) {
1278 ((ITmfDataProvider
<TmfEvent
>) fTrace
).sendRequest(request
);
1280 request
.waitForCompletion();
1281 if (request
.isCancelled()) {
1282 return Status
.OK_STATUS
;
1284 } catch (InterruptedException e
) {
1285 synchronized (fSearchSyncObj
) {
1286 fSearchThread
= null;
1288 return Status
.OK_STATUS
;
1290 if (foundRank
== -1) {
1291 if (direction
== Direction
.FORWARD
) {
1293 synchronized (fSearchSyncObj
) {
1294 fSearchThread
= null;
1296 return Status
.OK_STATUS
;
1298 nbRequested
= (int) rank
;
1305 rank
= (int) fTrace
.getNbEvents() - 1;
1308 if (rank
<= startRank
&& wrapped
) {
1309 synchronized (fSearchSyncObj
) {
1310 fSearchThread
= null;
1312 return Status
.OK_STATUS
;
1317 int index
= (int) foundRank
;
1318 if (eventFilter
!= null) {
1319 index
= fCache
.getFilteredEventIndex(foundRank
);
1321 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0); // +1 for header row, +1 for top filter
1324 display
.asyncExec(new Runnable() {
1327 if (monitor
.isCanceled())
1329 if (fTable
.isDisposed())
1331 fTable
.setSelection(selection
);
1332 fSelectedRank
= foundRank
;
1333 synchronized (fSearchSyncObj
) {
1334 fSearchThread
= null;
1338 return Status
.OK_STATUS
;
1342 protected void canceling() {
1344 synchronized (fSearchSyncObj
) {
1345 fSearchThread
= null;
1350 protected void createResources() {
1351 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
1352 .getForeground().getRGB()));
1353 fGreenColor
= fTable
.getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
1354 fBoldFont
= fResourceManager
.createFont(FontDescriptor
.createFrom(fTable
.getFont()).setStyle(SWT
.BOLD
));
1357 protected void packColumns() {
1360 for (TableColumn column
: fTable
.getColumns()) {
1361 int headerWidth
= column
.getWidth();
1363 if (column
.getWidth() < headerWidth
) {
1364 column
.setWidth(headerWidth
);
1374 * FIXME: Add support for column selection
1376 protected ITmfEventField
[] extractItemFields(TmfEvent event
) {
1377 ITmfEventField
[] fields
= new TmfEventField
[0];
1378 if (event
!= null) {
1379 String timestamp
= ((Long
) event
.getTimestamp().getValue()).toString();
1380 String source
= event
.getSource();
1381 String type
= event
.getType().getName();
1382 String reference
= event
.getReference();
1383 ITmfEventField content
= event
.getContent();
1384 String value
= (content
.getValue() != null) ? content
.getValue().toString() : content
.toString();
1385 fields
= new TmfEventField
[] {
1386 new TmfEventField(ITmfEvent
.EVENT_FIELD_TIMESTAMP
, timestamp
),
1387 new TmfEventField(ITmfEvent
.EVENT_FIELD_SOURCE
, source
),
1388 new TmfEventField(ITmfEvent
.EVENT_FIELD_TYPE
, type
),
1389 new TmfEventField(ITmfEvent
.EVENT_FIELD_REFERENCE
, reference
),
1390 new TmfEventField(ITmfEvent
.EVENT_FIELD_CONTENT
, value
)
1396 public void setFocus() {
1402 * @param disposeOnClose
1403 * true if the trace should be disposed when the table is disposed
1405 public void setTrace(ITmfTrace
<?
> trace
, boolean disposeOnClose
) {
1406 if (fTrace
!= null && fDisposeOnClose
) {
1412 fDisposeOnClose
= disposeOnClose
;
1414 // Perform the updates on the UI thread
1415 fTable
.getDisplay().syncExec(new Runnable() {
1419 fCache
.setTrace(fTrace
); // Clear the cache
1420 if (fTrace
!= null) {
1421 if (!fTable
.isDisposed() && fTrace
!= null) {
1422 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1423 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1426 fFilterMatchCount
= 0;
1427 fFilterCheckCount
= 0;
1428 fTable
.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows
1429 startFilterThread();
1432 fRawViewer
.setTrace(fTrace
);
1438 // ------------------------------------------------------------------------
1440 // ------------------------------------------------------------------------
1442 public void cacheUpdated(final boolean completed
) {
1443 synchronized (fCacheUpdateSyncObj
) {
1444 if (fCacheUpdateBusy
) {
1445 fCacheUpdatePending
= true;
1446 fCacheUpdateCompleted
= completed
;
1449 fCacheUpdateBusy
= true;
1452 // Event cache is now updated. Perform update on the UI thread
1453 if (!fTable
.isDisposed()) {
1454 fTable
.getDisplay().asyncExec(new Runnable() {
1457 if (!fTable
.isDisposed()) {
1462 populateCompleted();
1464 synchronized (fCacheUpdateSyncObj
) {
1465 fCacheUpdateBusy
= false;
1466 if (fCacheUpdatePending
) {
1467 fCacheUpdatePending
= false;
1468 cacheUpdated(fCacheUpdateCompleted
);
1476 protected void populateCompleted() {
1477 // Nothing by default;
1480 // ------------------------------------------------------------------------
1481 // Bookmark handling
1482 // ------------------------------------------------------------------------
1484 public void addBookmark(IFile bookmarksFile
) {
1485 fBookmarksFile
= bookmarksFile
;
1486 TableItem
[] selection
= fTable
.getSelection();
1487 if (selection
.length
> 0) {
1488 TableItem tableItem
= selection
[0];
1489 if (tableItem
.getData(Key
.RANK
) != null) {
1490 StringBuffer defaultMessage
= new StringBuffer();
1491 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1493 defaultMessage
.append(", "); //$NON-NLS-1$
1495 defaultMessage
.append(tableItem
.getText(i
));
1497 InputDialog dialog
= new InputDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1498 Messages
.TmfEventsTable_AddBookmarkDialogTitle
, Messages
.TmfEventsTable_AddBookmarkDialogText
,
1499 defaultMessage
.toString(), null);
1500 if (dialog
.open() == Dialog
.OK
) {
1501 String message
= dialog
.getValue();
1503 IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
1504 if (bookmark
.exists()) {
1505 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
1506 long rank
= (Long
) tableItem
.getData(Key
.RANK
);
1507 int location
= (int) rank
;
1508 bookmark
.setAttribute(IMarker
.LOCATION
, (Integer
) location
);
1509 fBookmarksMap
.put(rank
, bookmark
.getId());
1512 } catch (CoreException e
) {
1513 displayException(e
);
1521 public void removeBookmark(IMarker bookmark
) {
1522 for (Entry
<Long
, Long
> entry
: fBookmarksMap
.entrySet()) {
1523 if (entry
.getValue().equals(bookmark
.getId())) {
1524 fBookmarksMap
.remove(entry
.getKey());
1531 private void toggleBookmark(long rank
) {
1532 if (fBookmarksFile
== null) {
1535 if (fBookmarksMap
.containsKey(rank
)) {
1536 Long markerId
= fBookmarksMap
.remove(rank
);
1539 IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
1540 if (bookmark
!= null) {
1543 } catch (CoreException e
) {
1544 displayException(e
);
1547 addBookmark(fBookmarksFile
);
1551 public void refreshBookmarks(IFile bookmarksFile
) {
1552 fBookmarksFile
= bookmarksFile
;
1554 fBookmarksMap
.clear();
1555 for (IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
1556 int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
1557 if (location
!= -1) {
1558 long rank
= location
;
1559 fBookmarksMap
.put(rank
, bookmark
.getId());
1563 } catch (CoreException e
) {
1564 displayException(e
);
1569 public void gotoMarker(IMarker marker
) {
1570 int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
1573 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
1574 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
1575 } else if (rank
>= fTable
.getItemCount()) {
1576 fPendingGotoRank
= rank
;
1578 fTable
.setSelection(index
+ 1); // +1 for header row
1582 // ------------------------------------------------------------------------
1584 // ------------------------------------------------------------------------
1590 * org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener#colorSettingsChanged(org.eclipse.linuxtools
1591 * .tmf.ui.views.colors.ColorSetting[])
1594 public void colorSettingsChanged(ColorSetting
[] colorSettings
) {
1599 public void addEventsFilterListener(ITmfEventsFilterListener listener
) {
1600 if (!fEventsFilterListeners
.contains(listener
)) {
1601 fEventsFilterListeners
.add(listener
);
1606 public void removeEventsFilterListener(ITmfEventsFilterListener listener
) {
1607 fEventsFilterListeners
.remove(listener
);
1610 // ------------------------------------------------------------------------
1612 // ------------------------------------------------------------------------
1615 public void experimentUpdated(TmfExperimentUpdatedSignal signal
) {
1616 if ((signal
.getExperiment() != fTrace
) || fTable
.isDisposed())
1618 // Perform the refresh on the UI thread
1619 Display
.getDefault().asyncExec(new Runnable() {
1622 if (!fTable
.isDisposed() && fTrace
!= null) {
1623 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1624 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1625 if (fPendingGotoRank
!= -1 && fPendingGotoRank
+ 1 < fTable
.getItemCount()) { // +1 for header row
1626 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
1627 fPendingGotoRank
= -1;
1630 startFilterThread();
1633 if (!fRawViewer
.isDisposed() && fTrace
!= null) {
1634 fRawViewer
.refreshEventCount();
1641 public void traceUpdated(TmfTraceUpdatedSignal signal
) {
1642 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed())
1644 // Perform the refresh on the UI thread
1645 Display
.getDefault().asyncExec(new Runnable() {
1648 if (!fTable
.isDisposed() && fTrace
!= null) {
1649 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1650 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1); // +1 for header row
1651 if (fPendingGotoRank
!= -1 && fPendingGotoRank
+ 1 < fTable
.getItemCount()) { // +1 for header row
1652 fTable
.setSelection((int) fPendingGotoRank
+ 1); // +1 for header row
1653 fPendingGotoRank
= -1;
1656 startFilterThread();
1659 if (!fRawViewer
.isDisposed() && fTrace
!= null) {
1660 fRawViewer
.refreshEventCount();
1666 @SuppressWarnings("unchecked")
1668 public void currentTimeUpdated(final TmfTimeSynchSignal signal
) {
1669 if ((signal
.getSource() != fTable
) && (fTrace
!= null) && (!fTable
.isDisposed())) {
1671 // Create a request for one event that will be queued after other ongoing requests. When this request is
1673 // do the work to select the actual event with the timestamp specified in the signal. This procedure
1675 // the method fTrace.getRank() from interfering and delaying ongoing requests.
1676 final TmfDataRequest
<TmfEvent
> subRequest
= new TmfDataRequest
<TmfEvent
>(TmfEvent
.class, 0, 1,
1677 ExecutionType
.FOREGROUND
) {
1679 TmfTimestamp ts
= new TmfTimestamp(signal
.getCurrentTime());
1682 public void handleData(TmfEvent event
) {
1683 super.handleData(event
);
1687 public void handleCompleted() {
1688 super.handleCompleted();
1689 if (fTrace
== null) {
1692 // Verify if event is within the trace range
1693 final ITmfTimestamp timestamp
[] = new TmfTimestamp
[1];
1694 timestamp
[0] = ts
; // signal.getCurrentTime();
1695 if (timestamp
[0].compareTo(fTrace
.getStartTime(), true) == -1) {
1696 timestamp
[0] = fTrace
.getStartTime();
1698 if (timestamp
[0].compareTo(fTrace
.getEndTime(), true) == 1) {
1699 timestamp
[0] = fTrace
.getEndTime();
1702 // Get the rank for the event selection in the table
1703 final long rank
= fTrace
.getRank(timestamp
[0]);
1704 fSelectedRank
= rank
;
1706 fTable
.getDisplay().asyncExec(new Runnable() {
1709 // Return if table is disposed
1710 if (fTable
.isDisposed())
1713 int index
= (int) rank
;
1714 if (fTable
.isDisposed())
1716 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
1717 index
= fCache
.getFilteredEventIndex(rank
) + 1; // +1 for top filter status row
1719 fTable
.setSelection(index
+ 1); // +1 for header row
1720 fRawViewer
.selectAndReveal(rank
);
1726 ((ITmfDataProvider
<TmfEvent
>) fTrace
).sendRequest(subRequest
);
1730 // ------------------------------------------------------------------------
1732 // ------------------------------------------------------------------------
1735 * Display an exception in a message box
1737 * @param e the exception
1739 private void displayException(Exception e
) {
1740 MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
1741 mb
.setText(e
.getClass().getName());
1742 mb
.setMessage(e
.getMessage());