1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 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, replaced Table by TmfVirtualTable
11 * Patrick Tasse - Factored out from events view,
12 * Filter implementation (inspired by www.eclipse.org/mat)
13 * Ansgar Radermacher - Support navigation to model URIs (Bug 396956)
14 * Bernd Hufmann - Updated call site and model URI implementation
15 * Alexandre Montplaisir - Update to new column API
16 * Matthew Khouzam - Add hide columns
17 *******************************************************************************/
19 package org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
;
21 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
23 import java
.io
.FileNotFoundException
;
24 import java
.lang
.reflect
.InvocationTargetException
;
25 import java
.util
.ArrayList
;
26 import java
.util
.Collection
;
27 import java
.util
.HashMap
;
28 import java
.util
.LinkedList
;
29 import java
.util
.List
;
30 import java
.util
.Map
.Entry
;
31 import java
.util
.regex
.Matcher
;
32 import java
.util
.regex
.Pattern
;
33 import java
.util
.regex
.PatternSyntaxException
;
35 import org
.eclipse
.core
.commands
.Command
;
36 import org
.eclipse
.core
.commands
.ExecutionException
;
37 import org
.eclipse
.core
.commands
.NotEnabledException
;
38 import org
.eclipse
.core
.commands
.NotHandledException
;
39 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
40 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
41 import org
.eclipse
.core
.expressions
.IEvaluationContext
;
42 import org
.eclipse
.core
.resources
.IFile
;
43 import org
.eclipse
.core
.resources
.IMarker
;
44 import org
.eclipse
.core
.resources
.IResource
;
45 import org
.eclipse
.core
.resources
.IResourceVisitor
;
46 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
47 import org
.eclipse
.core
.runtime
.CoreException
;
48 import org
.eclipse
.core
.runtime
.IPath
;
49 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
50 import org
.eclipse
.core
.runtime
.IStatus
;
51 import org
.eclipse
.core
.runtime
.ListenerList
;
52 import org
.eclipse
.core
.runtime
.Path
;
53 import org
.eclipse
.core
.runtime
.Status
;
54 import org
.eclipse
.core
.runtime
.jobs
.Job
;
55 import org
.eclipse
.emf
.common
.util
.URI
;
56 import org
.eclipse
.emf
.ecore
.EValidator
;
57 import org
.eclipse
.jdt
.annotation
.NonNull
;
58 import org
.eclipse
.jface
.action
.Action
;
59 import org
.eclipse
.jface
.action
.IAction
;
60 import org
.eclipse
.jface
.action
.IMenuListener
;
61 import org
.eclipse
.jface
.action
.IMenuManager
;
62 import org
.eclipse
.jface
.action
.IStatusLineManager
;
63 import org
.eclipse
.jface
.action
.MenuManager
;
64 import org
.eclipse
.jface
.action
.Separator
;
65 import org
.eclipse
.jface
.dialogs
.InputDialog
;
66 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
67 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
68 import org
.eclipse
.jface
.resource
.ColorRegistry
;
69 import org
.eclipse
.jface
.resource
.FontRegistry
;
70 import org
.eclipse
.jface
.resource
.JFaceResources
;
71 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
72 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
73 import org
.eclipse
.jface
.util
.OpenStrategy
;
74 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
75 import org
.eclipse
.jface
.util
.SafeRunnable
;
76 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
77 import org
.eclipse
.jface
.viewers
.ISelection
;
78 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
79 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
80 import org
.eclipse
.jface
.viewers
.LabelProvider
;
81 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
82 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
83 import org
.eclipse
.jface
.window
.Window
;
84 import org
.eclipse
.swt
.SWT
;
85 import org
.eclipse
.swt
.custom
.SashForm
;
86 import org
.eclipse
.swt
.custom
.StyleRange
;
87 import org
.eclipse
.swt
.custom
.TableEditor
;
88 import org
.eclipse
.swt
.events
.ControlAdapter
;
89 import org
.eclipse
.swt
.events
.ControlEvent
;
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
.GC
;
101 import org
.eclipse
.swt
.graphics
.Image
;
102 import org
.eclipse
.swt
.graphics
.Point
;
103 import org
.eclipse
.swt
.graphics
.Rectangle
;
104 import org
.eclipse
.swt
.layout
.FillLayout
;
105 import org
.eclipse
.swt
.layout
.GridData
;
106 import org
.eclipse
.swt
.layout
.GridLayout
;
107 import org
.eclipse
.swt
.widgets
.Composite
;
108 import org
.eclipse
.swt
.widgets
.Display
;
109 import org
.eclipse
.swt
.widgets
.Event
;
110 import org
.eclipse
.swt
.widgets
.Label
;
111 import org
.eclipse
.swt
.widgets
.Listener
;
112 import org
.eclipse
.swt
.widgets
.Menu
;
113 import org
.eclipse
.swt
.widgets
.MessageBox
;
114 import org
.eclipse
.swt
.widgets
.Shell
;
115 import org
.eclipse
.swt
.widgets
.TableColumn
;
116 import org
.eclipse
.swt
.widgets
.TableItem
;
117 import org
.eclipse
.swt
.widgets
.Text
;
118 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
119 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
120 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
121 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
122 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.CopyToClipboardOperation
;
123 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
.ExportToTextCommandHandler
;
124 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.MultiLineInputDialog
;
125 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
126 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
127 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
128 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
129 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfContentFieldAspect
;
130 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
131 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
132 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
133 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
134 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
135 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
136 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
137 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
138 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
139 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
140 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
141 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventFilterAppliedSignal
;
142 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSearchAppliedSignal
;
143 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEventSelectedSignal
;
144 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
145 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
146 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
147 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
148 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
149 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
150 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
151 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
152 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
153 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
154 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
155 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventsCache
.CachedEvent
;
156 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
157 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSetting
;
158 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
159 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
.IColorSettingsListener
;
160 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
.FilterManager
;
161 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.rawviewer
.TmfRawEventViewer
;
162 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.TmfVirtualTable
;
163 import org
.eclipse
.ui
.IEditorSite
;
164 import org
.eclipse
.ui
.IWorkbenchPage
;
165 import org
.eclipse
.ui
.IWorkbenchPartSite
;
166 import org
.eclipse
.ui
.PlatformUI
;
167 import org
.eclipse
.ui
.commands
.ICommandService
;
168 import org
.eclipse
.ui
.dialogs
.ListDialog
;
169 import org
.eclipse
.ui
.handlers
.IHandlerService
;
170 import org
.eclipse
.ui
.ide
.IDE
;
171 import org
.eclipse
.ui
.ide
.IGotoMarker
;
172 import org
.eclipse
.ui
.themes
.ColorUtil
;
173 import org
.eclipse
.ui
.themes
.IThemeManager
;
175 import com
.google
.common
.base
.Joiner
;
176 import com
.google
.common
.collect
.HashMultimap
;
177 import com
.google
.common
.collect
.ImmutableList
;
178 import com
.google
.common
.collect
.Multimap
;
181 * The generic TMF Events table
183 * This is a view that will list events that are read from a trace.
185 * @author Francois Chouinard
186 * @author Patrick Tasse
188 public class TmfEventsTable
extends TmfComponent
implements IGotoMarker
, IColorSettingsListener
, ISelectionProvider
, IPropertyChangeListener
{
191 * Empty string array, used by {@link #getItemStrings}.
193 protected static final @NonNull String
[] EMPTY_STRING_ARRAY
= new String
[0];
198 protected static final @NonNull String EMPTY_STRING
= ""; //$NON-NLS-1$
200 private static final boolean IS_LINUX
= System
.getProperty("os.name").contains("Linux") ?
true : false; //$NON-NLS-1$ //$NON-NLS-2$
202 private static final String FONT_DEFINITION_ID
= "org.eclipse.tracecompass.tmf.ui.font.eventtable"; //$NON-NLS-1$
203 private static final String HIGHLIGHT_COLOR_DEFINITION_ID
= "org.eclipse.tracecompass.tmf.ui.color.eventtable.highlight"; //$NON-NLS-1$
205 private static final Image BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
206 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
207 private static final Image SEARCH_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
208 private static final Image SEARCH_MATCH_IMAGE
= Activator
.getDefault().getImageFromPath(
209 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
210 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE
= Activator
.getDefault().getImageFromPath(
211 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
212 private static final Image FILTER_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
213 private static final Image STOP_IMAGE
= Activator
.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
214 private static final String SEARCH_HINT
= Messages
.TmfEventsTable_SearchHint
;
215 private static final String FILTER_HINT
= Messages
.TmfEventsTable_FilterHint
;
216 private static final int MAX_CACHE_SIZE
= 1000;
218 private static final int MARGIN_COLUMN_INDEX
= 0;
219 private static final int FILTER_SUMMARY_INDEX
= 1;
220 private static final int EVENT_COLUMNS_START_INDEX
= MARGIN_COLUMN_INDEX
+ 1;
222 private final class ColumnMovedListener
extends ControlAdapter
{
224 * Make sure that the margin column is always first and keep the
225 * column order variable up to date.
228 public void controlMoved(ControlEvent e
) {
229 int[] order
= fTable
.getColumnOrder();
230 if (order
[0] == MARGIN_COLUMN_INDEX
) {
231 fColumnOrder
= order
;
234 for (int i
= order
.length
- 1; i
> 0; i
--) {
235 if (order
[i
] == MARGIN_COLUMN_INDEX
) {
236 order
[i
] = order
[i
- 1];
237 order
[i
- 1] = MARGIN_COLUMN_INDEX
;
240 fTable
.setColumnOrder(order
);
241 fColumnOrder
= fTable
.getColumnOrder();
245 private final class TableSelectionListener
extends SelectionAdapter
{
247 public void widgetSelected(final SelectionEvent e
) {
248 if (e
.item
== null) {
251 updateStatusLine(null);
252 if (fTable
.getSelectionIndices().length
> 0) {
253 if (e
.item
.getData(Key
.RANK
) instanceof Long
) {
254 fSelectedRank
= (Long
) e
.item
.getData(Key
.RANK
);
255 fRawViewer
.selectAndReveal((Long
) e
.item
.getData(Key
.RANK
));
259 if (fTable
.getSelectionIndices().length
== 1) {
260 fSelectedBeginRank
= fSelectedRank
;
262 if (e
.item
.getData(Key
.TIMESTAMP
) instanceof ITmfTimestamp
) {
263 final ITmfTimestamp ts
= NonNullUtils
.checkNotNull((ITmfTimestamp
) e
.item
.getData(Key
.TIMESTAMP
));
264 if (fTable
.getSelectionIndices().length
== 1) {
265 fSelectedBeginTimestamp
= ts
;
267 ITmfTimestamp selectedBeginTimestamp
= fSelectedBeginTimestamp
;
268 if (selectedBeginTimestamp
!= null) {
269 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, selectedBeginTimestamp
, ts
));
270 if (fTable
.getSelectionIndices().length
== 2) {
271 updateStatusLine(ts
.getDelta(selectedBeginTimestamp
));
275 if (fTable
.getSelectionIndices().length
== 1) {
276 fSelectedBeginTimestamp
= null;
280 if (e
.item
.getData() instanceof ITmfEvent
) {
281 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) e
.item
.getData()));
282 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(e
.item
.getData())));
284 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
289 private final class MouseDoubleClickListener
extends MouseAdapter
{
291 public void mouseDoubleClick(final MouseEvent event
) {
292 if (event
.button
!= 1) {
295 // Identify the selected row
296 final Point point
= new Point(event
.x
, event
.y
);
297 final TableItem item
= fTable
.getItem(point
);
299 final Rectangle imageBounds
= item
.getImageBounds(0);
300 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
301 if (imageBounds
.contains(point
)) {
302 final Long rank
= (Long
) item
.getData(Key
.RANK
);
304 toggleBookmark(rank
);
311 private final class RawSelectionListener
implements Listener
{
313 public void handleEvent(final Event e
) {
314 if (fTrace
== null) {
318 if (e
.data
instanceof Long
) {
319 rank
= (Long
) e
.data
;
320 } else if (e
.data
instanceof ITmfLocation
) {
321 rank
= findRank((ITmfLocation
) e
.data
);
325 int index
= (int) rank
;
326 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
327 // +1 for top filter status row
328 index
= fCache
.getFilteredEventIndex(rank
) + 1;
331 fTable
.setSelection(index
+ 1);
332 fSelectedRank
= rank
;
333 fSelectedBeginRank
= fSelectedRank
;
334 updateStatusLine(null);
335 final TableItem
[] selection
= fTable
.getSelection();
336 if ((selection
!= null) && (selection
.length
> 0)) {
337 TableItem item
= fTable
.getSelection()[0];
338 final TmfTimestamp ts
= (TmfTimestamp
) item
.getData(Key
.TIMESTAMP
);
340 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, ts
));
342 if (item
.getData() instanceof ITmfEvent
) {
343 broadcast(new TmfEventSelectedSignal(TmfEventsTable
.this, (ITmfEvent
) item
.getData()));
344 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, new StructuredSelection(item
.getData())));
346 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, StructuredSelection
.EMPTY
));
351 private long findRank(final ITmfLocation selectedLocation
) {
352 final double selectedRatio
= fTrace
.getLocationRatio(selectedLocation
);
354 long high
= fTrace
.getNbEvents();
355 long rank
= high
/ 2;
357 while (ratio
!= selectedRatio
) {
358 ITmfContext context
= fTrace
.seekEvent(rank
);
359 ratio
= fTrace
.getLocationRatio(context
.getLocation());
361 if (ratio
< selectedRatio
) {
363 rank
= (rank
+ high
) / 2;
364 } else if (ratio
> selectedRatio
) {
366 rank
= (rank
+ low
) / 2;
368 if ((high
- low
) < 2) {
376 private final class SetDataListener
implements Listener
{
378 public void handleEvent(final Event event
) {
380 final TableItem item
= (TableItem
) event
.item
;
381 int index
= event
.index
- 1; // -1 for the header row
383 if (event
.index
== 0) {
384 setHeaderRowItemData(item
);
388 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
389 if ((event
.index
== 1) || (event
.index
== (fTable
.getItemCount() - 1))) {
390 setFilterStatusRowItemData(item
);
393 /* -1 for top filter status row */
397 final CachedEvent cachedEvent
= fCache
.getEvent(index
);
398 if (cachedEvent
!= null) {
399 setItemData(item
, cachedEvent
, cachedEvent
.rank
);
403 // Else, fill the cache asynchronously (and off the UI thread)
408 private final class PainItemListener
implements Listener
{
410 public void handleEvent(Event event
) {
411 TableItem item
= (TableItem
) event
.item
;
413 // we promised to paint the table item's foreground
415 Image image
= item
.getImage(event
.index
);
417 Rectangle imageBounds
= item
.getImageBounds(event
.index
);
419 * The image bounds don't match the default image position.
422 gc
.drawImage(image
, imageBounds
.x
+ 1, imageBounds
.y
+ 3);
424 gc
.drawImage(image
, imageBounds
.x
, imageBounds
.y
+ 1);
427 gc
.setForeground(item
.getForeground(event
.index
));
428 gc
.setFont(item
.getFont(event
.index
));
429 String text
= item
.getText(event
.index
);
430 Rectangle textBounds
= item
.getTextBounds(event
.index
);
432 * The text bounds don't match the default text position.
435 gc
.drawText(text
, textBounds
.x
+ 1, textBounds
.y
+ 3, true);
437 gc
.drawText(text
, textBounds
.x
- 1, textBounds
.y
+ 2, true);
442 private final class EraseItemListener
implements Listener
{
444 public void handleEvent(Event event
) {
445 TableItem item
= (TableItem
) event
.item
;
446 List
<?
> styleRanges
= (List
<?
>) item
.getData(Key
.STYLE_RANGES
);
449 Color background
= item
.getBackground(event
.index
);
451 * Paint the background if it is not the default system color.
452 * In Windows, if you let the widget draw the background, it
453 * will not show the item's background color if the item is
454 * selected or hot. If there are no style ranges and the item
455 * background is the default system color, we do not want to
456 * paint it or otherwise we would override the platform theme
457 * (e.g. alternating colors).
459 if (styleRanges
!= null || !background
.equals(item
.getParent().getBackground())) {
460 // we will paint the table item's background
461 event
.detail
&= ~SWT
.BACKGROUND
;
463 // paint the item's default background
464 gc
.setBackground(background
);
465 gc
.fillRectangle(event
.x
, event
.y
, event
.width
, event
.height
);
469 * We will paint the table item's foreground. In Windows, if you
470 * paint the background but let the widget draw the foreground,
471 * it will override your background, unless the item is selected
474 event
.detail
&= ~SWT
.FOREGROUND
;
476 // paint the highlighted background for all style ranges
477 if (styleRanges
!= null) {
478 Rectangle textBounds
= item
.getTextBounds(event
.index
);
479 String text
= item
.getText(event
.index
);
480 for (Object o
: styleRanges
) {
481 if (o
instanceof StyleRange
) {
482 StyleRange styleRange
= (StyleRange
) o
;
483 if (styleRange
.data
.equals(event
.index
)) {
484 int startIndex
= styleRange
.start
;
485 int endIndex
= startIndex
+ styleRange
.length
;
486 int startX
= gc
.textExtent(text
.substring(0, startIndex
)).x
;
487 int endX
= gc
.textExtent(text
.substring(0, endIndex
)).x
;
488 gc
.setBackground(styleRange
.background
);
489 gc
.fillRectangle(textBounds
.x
+ startX
, textBounds
.y
, (endX
- startX
), textBounds
.height
);
497 private final class TooltipListener
implements Listener
{
498 Shell tooltipShell
= null;
501 public void handleEvent(final Event event
) {
502 switch (event
.type
) {
504 final TableItem item
= fTable
.getItem(new Point(event
.x
, event
.y
));
508 final Long rank
= (Long
) item
.getData(Key
.RANK
);
512 final String tooltipText
= (String
) item
.getData(Key
.BOOKMARK
);
513 final Rectangle bounds
= item
.getImageBounds(0);
514 bounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
515 if (!bounds
.contains(event
.x
, event
.y
)) {
518 if ((tooltipShell
!= null) && !tooltipShell
.isDisposed()) {
519 tooltipShell
.dispose();
521 tooltipShell
= new Shell(fTable
.getShell(), SWT
.ON_TOP
| SWT
.NO_FOCUS
| SWT
.TOOL
);
522 tooltipShell
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
523 final FillLayout layout
= new FillLayout();
524 layout
.marginWidth
= 2;
525 tooltipShell
.setLayout(layout
);
526 final Label label
= new Label(tooltipShell
, SWT
.WRAP
);
527 String text
= rank
.toString() + (tooltipText
!= null ?
": " + tooltipText
: EMPTY_STRING
); //$NON-NLS-1$
528 label
.setForeground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_FOREGROUND
));
529 label
.setBackground(PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
531 label
.addListener(SWT
.MouseExit
, this);
532 label
.addListener(SWT
.MouseDown
, this);
533 label
.addListener(SWT
.MouseWheel
, this);
534 final Point size
= tooltipShell
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
536 * Bug in Linux. The coordinates of the event have an origin
537 * that excludes the table header but the method toDisplay()
538 * expects coordinates relative to an origin that includes
543 y
+= fTable
.getHeaderHeight();
545 Point pt
= fTable
.toDisplay(event
.x
, y
);
546 pt
.x
+= BOOKMARK_IMAGE
.getBounds().width
;
547 pt
.y
+= item
.getBounds().height
;
548 tooltipShell
.setBounds(pt
.x
, pt
.y
, size
.x
, size
.y
);
549 tooltipShell
.setVisible(true);
557 if (tooltipShell
!= null) {
558 tooltipShell
.dispose();
569 * The events table search/filter/data keys
571 * @author Patrick Tasse
572 * @noimplement This interface only contains Event Table specific
573 * static definitions.
575 public interface Key
{
578 String SEARCH_TXT
= "$srch_txt"; //$NON-NLS-1$
581 String SEARCH_OBJ
= "$srch_obj"; //$NON-NLS-1$
584 String FILTER_TXT
= "$fltr_txt"; //$NON-NLS-1$
587 String FILTER_OBJ
= "$fltr_obj"; //$NON-NLS-1$
590 String TIMESTAMP
= "$time"; //$NON-NLS-1$
593 String RANK
= "$rank"; //$NON-NLS-1$
595 /** Bookmark indicator */
596 String BOOKMARK
= "$bookmark"; //$NON-NLS-1$
598 /** Event aspect represented by this column */
599 String ASPECT
= "$aspect"; //$NON-NLS-1$
602 * Table item list of style ranges
606 String STYLE_RANGES
= "$style_ranges"; //$NON-NLS-1$
609 * The width of a table item
613 String WIDTH
= "$width"; //$NON-NLS-1$
617 * The events table search/filter state
620 * @author Patrick Tasse
622 public static enum HeaderState
{
623 /** A search is being run */
626 /** A filter is applied */
630 interface Direction
{
635 // ------------------------------------------------------------------------
637 // ------------------------------------------------------------------------
639 /** The virtual event table */
640 protected TmfVirtualTable fTable
;
642 private Composite fComposite
;
643 private SashForm fSashForm
;
644 private TmfRawEventViewer fRawViewer
;
645 private ITmfTrace fTrace
;
646 private volatile boolean fPackDone
= false;
647 private HeaderState fHeaderState
= HeaderState
.SEARCH
;
648 private long fSelectedRank
= -1;
649 private long fSelectedBeginRank
= -1;
650 private ITmfTimestamp fSelectedBeginTimestamp
= null;
651 private IStatusLineManager fStatusLineManager
= null;
654 private long fFilterMatchCount
;
655 private long fFilterCheckCount
;
656 private FilterThread fFilterThread
;
657 private boolean fFilterThreadResume
= false;
658 private final Object fFilterSyncObj
= new Object();
659 private SearchThread fSearchThread
;
660 private final Object fSearchSyncObj
= new Object();
663 * List of selection change listeners (element type:
664 * <code>ISelectionChangedListener</code>).
666 * @see #fireSelectionChanged
668 private ListenerList selectionChangedListeners
= new ListenerList();
670 // Bookmark map <Rank, MarkerId>
671 private Multimap
<Long
, Long
> fBookmarksMap
= HashMultimap
.create();
672 private IFile fBookmarksFile
;
673 private long fPendingGotoRank
= -1;
676 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
677 private Color fGrayColor
;
678 private Color fGreenColor
;
679 private Color fHighlightColor
;
681 private Font fBoldFont
;
683 private final List
<TmfEventTableColumn
> fColumns
= new LinkedList
<>();
686 private final TmfEventsCache fCache
;
687 private boolean fCacheUpdateBusy
= false;
688 private boolean fCacheUpdatePending
= false;
689 private boolean fCacheUpdateCompleted
= false;
690 private final Object fCacheUpdateSyncObj
= new Object();
692 // Keep track of column order, it is needed after table is disposed
693 private int[] fColumnOrder
;
695 private boolean fDisposeOnClose
;
697 private Menu fHeaderMenu
;
699 private Menu fTablePopup
;
701 private Menu fRawTablePopup
;
703 private Point fLastMenuCursorLocation
;
704 private MenuManager fRawViewerPopupMenuManager
;
705 private MenuManager fTablePopupMenuManager
;
706 private MenuManager fHeaderPopupMenuManager
;
708 // ------------------------------------------------------------------------
710 // ------------------------------------------------------------------------
713 * Basic constructor, using the default set of columns
716 * The parent composite UI object
718 * The size of the event table cache
720 public TmfEventsTable(final Composite parent
, final int cacheSize
) {
721 this(parent
, cacheSize
, TmfTrace
.BASE_ASPECTS
);
725 * Legacy constructor, using ColumnData to define columns
728 * The parent composite UI object
730 * The size of the event table cache
732 * The column data array
733 * @deprecated Deprecated constructor, use
734 * {@link #TmfEventsTable(Composite, int, Collection)}
737 public TmfEventsTable(final Composite parent
, int cacheSize
,
738 final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
740 * We'll do a "best-effort" to keep trace types still using this API to
741 * keep working, by defining a TmfEventTableColumn for each ColumnData
744 this(parent
, cacheSize
, convertFromColumnData(columnData
));
748 private static @NonNull Iterable
<ITmfEventAspect
> convertFromColumnData(
749 org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
751 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
752 for (org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData col
: columnData
) {
753 String fieldName
= col
.header
;
754 if (fieldName
!= null) {
755 builder
.add(new TmfContentFieldAspect(fieldName
, fieldName
));
758 return checkNotNull(builder
.build());
762 * Standard constructor, where we define which columns to use.
765 * The parent composite UI object
767 * The size of the event table cache
769 * The event aspects to display in this table. One column per
770 * aspect will be created.
772 * The iteration order of this collection will correspond to the
773 * initial ordering of the columns in the table.
776 public TmfEventsTable(final Composite parent
, int cacheSize
,
777 @NonNull Iterable
<ITmfEventAspect
> aspects
) {
778 super("TmfEventsTable"); //$NON-NLS-1$
780 fComposite
= new Composite(parent
, SWT
.NONE
);
781 final GridLayout gl
= new GridLayout(1, false);
784 gl
.verticalSpacing
= 0;
785 fComposite
.setLayout(gl
);
787 fSashForm
= new SashForm(fComposite
, SWT
.HORIZONTAL
);
788 fSashForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
790 // Create a virtual table
791 final int style
= SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
| SWT
.FULL_SELECTION
;
792 fTable
= new TmfVirtualTable(fSashForm
, style
);
794 // Set the table layout
795 final GridData layoutData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
796 fTable
.setLayoutData(layoutData
);
798 // Some cosmetic enhancements
799 fTable
.setHeaderVisible(true);
800 fTable
.setLinesVisible(true);
803 for (ITmfEventAspect aspect
: aspects
) {
804 if (aspect
!= null) {
805 fColumns
.add(new TmfEventTableColumn(aspect
));
809 TmfMarginColumn collapseCol
= new TmfMarginColumn();
810 fColumns
.add(MARGIN_COLUMN_INDEX
, collapseCol
);
812 fHeaderMenu
= new Menu(fTable
);
813 // Create the UI columns in the table
814 for (TmfEventTableColumn col
: fColumns
) {
815 TableColumn column
= fTable
.newTableColumn(SWT
.LEFT
);
816 column
.setText(col
.getHeaderName());
817 column
.setToolTipText(col
.getHeaderTooltip());
818 column
.setData(Key
.ASPECT
, col
.getEventAspect());
820 if (col
instanceof TmfMarginColumn
) {
821 column
.setResizable(false);
823 column
.setMoveable(true);
824 column
.setData(Key
.WIDTH
, -1);
826 column
.addControlListener(new ColumnMovedListener());
828 fColumnOrder
= fTable
.getColumnOrder();
830 // Set the frozen row for header row
831 fTable
.setFrozenRowCount(1);
833 // Create the header row cell editor
834 createHeaderEditor();
836 // Handle the table item selection
837 fTable
.addSelectionListener(new TableSelectionListener());
839 int realCacheSize
= Math
.max(cacheSize
, Display
.getDefault().getBounds().height
/ fTable
.getItemHeight());
840 realCacheSize
= Math
.min(realCacheSize
, MAX_CACHE_SIZE
);
841 fCache
= new TmfEventsCache(realCacheSize
, this);
843 // Handle the table item requests
844 fTable
.addListener(SWT
.SetData
, new SetDataListener());
846 fTable
.addListener(SWT
.MenuDetect
, new Listener() {
848 public void handleEvent(Event event
) {
849 fLastMenuCursorLocation
= new Point(event
.x
, event
.y
);
850 Point pt
= fTable
.getDisplay().map(null, fTable
, fLastMenuCursorLocation
);
851 Rectangle clientArea
= fTable
.getClientArea();
852 boolean header
= clientArea
.y
<= pt
.y
&& pt
.y
< (clientArea
.y
+ fTable
.getHeaderHeight());
853 fTable
.setMenu(header ? fHeaderMenu
: fTablePopup
);
857 fTable
.addMouseListener(new MouseDoubleClickListener());
859 final Listener tooltipListener
= new TooltipListener();
861 fTable
.addListener(SWT
.MouseHover
, tooltipListener
);
862 fTable
.addListener(SWT
.Dispose
, tooltipListener
);
863 fTable
.addListener(SWT
.KeyDown
, tooltipListener
);
864 fTable
.addListener(SWT
.MouseMove
, tooltipListener
);
865 fTable
.addListener(SWT
.MouseExit
, tooltipListener
);
866 fTable
.addListener(SWT
.MouseDown
, tooltipListener
);
867 fTable
.addListener(SWT
.MouseWheel
, tooltipListener
);
869 fTable
.addListener(SWT
.EraseItem
, new EraseItemListener());
871 fTable
.addListener(SWT
.PaintItem
, new PainItemListener());
878 PlatformUI
.getWorkbench().getThemeManager().addPropertyChangeListener(this);
880 ColorSettingsManager
.addColorSettingsListener(this);
882 fTable
.setItemCount(1); // +1 for header row
884 fRawViewer
= new TmfRawEventViewer(fSashForm
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
886 fRawViewer
.addSelectionListener(new RawSelectionListener());
888 fSashForm
.setWeights(new int[] { 1, 1 });
889 fRawViewer
.setVisible(false);
895 * Checked menu creator to make columns visible or not.
902 private static IAction
createHeaderAction(final TableColumn column
) {
903 final IAction columnMenuAction
= new Action(column
.getText(), IAction
.AS_CHECK_BOX
) {
907 column
.setWidth((int) column
.getData(Key
.WIDTH
));
908 column
.setResizable(true);
910 column
.setData(Key
.WIDTH
, column
.getWidth());
912 column
.setResizable(false);
916 columnMenuAction
.setChecked(column
.getResizable());
917 return columnMenuAction
;
920 private IAction
createResetHeaderAction() {
921 return new Action(Messages
.TmfEventsTable_ShowAll
) {
924 for (TableColumn column
: fTable
.getColumns()) {
925 final Object widthVal
= column
.getData(Key
.WIDTH
);
926 if (widthVal
instanceof Integer
) {
927 Integer width
= (Integer
) widthVal
;
928 if (!column
.getResizable()) {
929 column
.setWidth(width
);
930 column
.setResizable(true);
932 * This is because Linux always resizes the last
933 * column to fill in the void, this means that
934 * hiding a column resizes others and we can have 10
935 * columns that are 1000 pixels wide by hiding the
936 * last one progressively.
948 // ------------------------------------------------------------------------
950 // ------------------------------------------------------------------------
953 * Create a pop-up menu.
955 private void createPopupMenu() {
956 final IAction copyAction
= new Action(Messages
.TmfEventsTable_CopyToClipboardActionText
) {
959 ITmfTrace trace
= fTrace
;
960 if (trace
== null || (fSelectedRank
== -1 && fSelectedBeginRank
== -1)) {
964 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
965 for (int i
: fTable
.getColumnOrder()) {
966 TableColumn column
= fTable
.getColumns()[i
];
967 // Omit the margin column and hidden columns
968 if (i
>= EVENT_COLUMNS_START_INDEX
&& (column
.getResizable() || column
.getWidth() > 0)) {
969 columns
.add(fColumns
.get(i
));
973 long start
= Math
.min(fSelectedBeginRank
, fSelectedRank
);
974 long end
= Math
.max(fSelectedBeginRank
, fSelectedRank
);
975 final ITmfFilter filter
= (ITmfFilter
) fTable
.getData(Key
.FILTER_OBJ
);
976 IRunnableWithProgress operation
= new CopyToClipboardOperation(trace
, filter
, columns
, start
, end
);
978 PlatformUI
.getWorkbench().getProgressService().busyCursorWhile(operation
);
979 } catch (InvocationTargetException e
) {
980 Activator
.getDefault().logError("Invocation target exception copying to clipboard ", e
); //$NON-NLS-1$
981 } catch (InterruptedException e
) {
987 final IAction showTableAction
= new Action(Messages
.TmfEventsTable_ShowTableActionText
) {
990 fTable
.setVisible(true);
995 final IAction hideTableAction
= new Action(Messages
.TmfEventsTable_HideTableActionText
) {
998 fTable
.setVisible(false);
1003 final IAction showRawAction
= new Action(Messages
.TmfEventsTable_ShowRawActionText
) {
1006 fRawViewer
.setVisible(true);
1008 final int index
= fTable
.getSelectionIndex();
1010 fRawViewer
.selectAndReveal(index
- 1);
1015 final IAction hideRawAction
= new Action(Messages
.TmfEventsTable_HideRawActionText
) {
1018 fRawViewer
.setVisible(false);
1023 final IAction openCallsiteAction
= new Action(Messages
.TmfEventsTable_OpenSourceCodeActionText
) {
1026 final TableItem items
[] = fTable
.getSelection();
1027 if (items
.length
!= 1) {
1030 final TableItem item
= items
[0];
1032 final Object data
= item
.getData();
1033 if (data
instanceof ITmfSourceLookup
) {
1034 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
1035 ITmfCallsite cs
= event
.getCallsite();
1039 IMarker marker
= null;
1041 String fileName
= cs
.getFileName();
1042 final String trimmedPath
= fileName
.replaceAll("\\.\\./", EMPTY_STRING
); //$NON-NLS-1$
1043 if (trimmedPath
.isEmpty()) {
1046 final ArrayList
<IFile
> files
= new ArrayList
<>();
1047 ResourcesPlugin
.getWorkspace().getRoot().accept(new IResourceVisitor() {
1049 public boolean visit(IResource resource
) throws CoreException
{
1050 if (resource
instanceof IFile
&& resource
.getFullPath().toString().endsWith(trimmedPath
)) {
1051 files
.add((IFile
) resource
);
1057 if (files
.size() > 1) {
1058 ListDialog dialog
= new ListDialog(getTable().getShell());
1059 dialog
.setContentProvider(ArrayContentProvider
.getInstance());
1060 dialog
.setLabelProvider(new LabelProvider() {
1062 public String
getText(Object element
) {
1063 return ((IFile
) element
).getFullPath().toString();
1066 dialog
.setInput(files
);
1067 dialog
.setTitle(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
);
1068 dialog
.setMessage(Messages
.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle
+ '\n' + cs
.toString());
1070 Object
[] result
= dialog
.getResult();
1071 if (result
!= null && result
.length
> 0) {
1072 file
= (IFile
) result
[0];
1074 } else if (files
.size() == 1) {
1075 file
= files
.get(0);
1078 marker
= file
.createMarker(IMarker
.MARKER
);
1079 marker
.setAttribute(IMarker
.LINE_NUMBER
, Long
.valueOf(cs
.getLineNumber()).intValue());
1080 IDE
.openEditor(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker
);
1082 } else if (files
.size() == 0) {
1083 displayException(new FileNotFoundException('\'' + cs
.toString() + '\'' + '\n' + Messages
.TmfEventsTable_OpenSourceCodeNotFound
));
1085 } catch (CoreException e
) {
1086 displayException(e
);
1092 final IAction openModelAction
= new Action(Messages
.TmfEventsTable_OpenModelActionText
) {
1096 final TableItem items
[] = fTable
.getSelection();
1097 if (items
.length
!= 1) {
1100 final TableItem item
= items
[0];
1102 final Object eventData
= item
.getData();
1103 if (eventData
instanceof ITmfModelLookup
) {
1104 String modelURI
= ((ITmfModelLookup
) eventData
).getModelUri();
1106 if (modelURI
!= null) {
1107 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1110 final URI uri
= URI
.createURI(modelURI
);
1111 if (uri
.isPlatformResource()) {
1112 IPath path
= new Path(uri
.toPlatformString(true));
1113 file
= ResourcesPlugin
.getWorkspace().getRoot().getFile(path
);
1114 } else if (uri
.isFile() && !uri
.isRelative()) {
1115 file
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(
1116 new Path(uri
.toFileString()));
1122 * create a temporary validation marker on the
1123 * model file, remove it afterwards thus,
1124 * navigation works with all model editors
1125 * supporting the navigation to a marker
1127 IMarker marker
= file
.createMarker(EValidator
.MARKER
);
1128 marker
.setAttribute(EValidator
.URI_ATTRIBUTE
, modelURI
);
1129 marker
.setAttribute(IMarker
.SEVERITY
, IMarker
.SEVERITY_INFO
);
1131 IDE
.openEditor(activePage
, marker
, OpenStrategy
.activateOnOpen());
1133 } catch (CoreException e
) {
1134 displayException(e
);
1137 displayException(new FileNotFoundException('\'' + modelURI
+ '\'' + '\n' + Messages
.TmfEventsTable_OpenModelUnsupportedURI
));
1144 final IAction exportToTextAction
= new Action(Messages
.TmfEventsTable_Export_to_text
) {
1147 IWorkbenchPage activePage
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1148 Object handlerServiceObject
= activePage
.getActiveEditor().getSite().getService(IHandlerService
.class);
1149 IHandlerService handlerService
= (IHandlerService
) handlerServiceObject
;
1150 Object cmdServiceObject
= activePage
.getActiveEditor().getSite().getService(ICommandService
.class);
1151 ICommandService cmdService
= (ICommandService
) cmdServiceObject
;
1153 HashMap
<String
, Object
> parameters
= new HashMap
<>();
1154 Command command
= cmdService
.getCommand(ExportToTextCommandHandler
.COMMAND_ID
);
1155 ParameterizedCommand cmd
= ParameterizedCommand
.generateCommand(command
, parameters
);
1157 IEvaluationContext context
= handlerService
.getCurrentState();
1158 List
<TmfEventTableColumn
> exportColumns
= new ArrayList
<>();
1159 for (int i
: fTable
.getColumnOrder()) {
1160 TableColumn column
= fTable
.getColumns()[i
];
1161 // Omit the margin column and hidden columns
1162 if (i
>= EVENT_COLUMNS_START_INDEX
&& (column
.getResizable() || column
.getWidth() > 0)) {
1163 exportColumns
.add(fColumns
.get(i
));
1166 context
.addVariable(ExportToTextCommandHandler
.TMF_EVENT_TABLE_COLUMNS_ID
, exportColumns
);
1168 handlerService
.executeCommandInContext(cmd
, null, context
);
1169 } catch (ExecutionException
| NotDefinedException
| NotEnabledException
| NotHandledException e
) {
1170 displayException(e
);
1175 final IAction showSearchBarAction
= new Action(Messages
.TmfEventsTable_ShowSearchBarActionText
) {
1178 fHeaderState
= HeaderState
.SEARCH
;
1184 final IAction showFilterBarAction
= new Action(Messages
.TmfEventsTable_ShowFilterBarActionText
) {
1187 fHeaderState
= HeaderState
.FILTER
;
1193 final IAction clearFiltersAction
= new Action(Messages
.TmfEventsTable_ClearFiltersActionText
) {
1200 final IAction collapseAction
= new Action(Messages
.TmfEventsTable_CollapseFilterMenuName
) {
1203 applyFilter(new TmfCollapseFilter());
1207 class ToggleBookmarkAction
extends Action
{
1210 public ToggleBookmarkAction(final String text
, final Long rank
) {
1217 toggleBookmark(fRank
);
1221 fHeaderPopupMenuManager
= new MenuManager();
1222 fHeaderPopupMenuManager
.setRemoveAllWhenShown(true);
1223 fHeaderPopupMenuManager
.addMenuListener(new IMenuListener() {
1225 public void menuAboutToShow(IMenuManager manager
) {
1226 for (int index
: fTable
.getColumnOrder()) {
1227 if (fTable
.getColumns()[index
].getData(Key
.WIDTH
) != null) {
1228 fHeaderPopupMenuManager
.add(createHeaderAction(fTable
.getColumns()[index
]));
1231 fHeaderPopupMenuManager
.add(new Separator());
1232 fHeaderPopupMenuManager
.add(createResetHeaderAction());
1236 fTablePopupMenuManager
= new MenuManager();
1237 fTablePopupMenuManager
.setRemoveAllWhenShown(true);
1238 fTablePopupMenuManager
.addMenuListener(new IMenuListener() {
1240 public void menuAboutToShow(final IMenuManager manager
) {
1241 if (fTable
.getSelectionIndices().length
== 1 && fTable
.getSelectionIndices()[0] == 0) {
1242 // Right-click on header row
1243 if (fHeaderState
== HeaderState
.FILTER
) {
1244 fTablePopupMenuManager
.add(showSearchBarAction
);
1246 fTablePopupMenuManager
.add(showFilterBarAction
);
1250 final Point point
= fTable
.toControl(fLastMenuCursorLocation
);
1251 final TableItem item
= fTable
.getSelection().length
> 0 ? fTable
.getSelection()[0] : null;
1253 final Rectangle imageBounds
= item
.getImageBounds(0);
1254 imageBounds
.width
= BOOKMARK_IMAGE
.getBounds().width
;
1255 if (point
.x
<= (imageBounds
.x
+ imageBounds
.width
)) {
1256 // Right-click on left margin
1257 final Long rank
= (Long
) item
.getData(Key
.RANK
);
1258 if ((rank
!= null) && (fBookmarksFile
!= null)) {
1259 if (fBookmarksMap
.containsKey(rank
)) {
1260 fTablePopupMenuManager
.add(new ToggleBookmarkAction(
1261 Messages
.TmfEventsTable_RemoveBookmarkActionText
, rank
));
1263 fTablePopupMenuManager
.add(new ToggleBookmarkAction(
1264 Messages
.TmfEventsTable_AddBookmarkActionText
, rank
));
1271 // Right-click on table
1272 if (fSelectedRank
!= -1 && fSelectedBeginRank
!= -1) {
1273 fTablePopupMenuManager
.add(copyAction
);
1274 fTablePopupMenuManager
.add(new Separator());
1276 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1277 fTablePopupMenuManager
.add(hideTableAction
);
1278 fTablePopupMenuManager
.add(hideRawAction
);
1279 } else if (!fTable
.isVisible()) {
1280 fTablePopupMenuManager
.add(showTableAction
);
1281 } else if (!fRawViewer
.isVisible()) {
1282 fTablePopupMenuManager
.add(showRawAction
);
1284 fTablePopupMenuManager
.add(exportToTextAction
);
1285 fTablePopupMenuManager
.add(new Separator());
1288 final Object data
= item
.getData();
1289 Separator separator
= null;
1290 if (data
instanceof ITmfSourceLookup
) {
1291 ITmfSourceLookup event
= (ITmfSourceLookup
) data
;
1292 if (event
.getCallsite() != null) {
1293 fTablePopupMenuManager
.add(openCallsiteAction
);
1294 separator
= new Separator();
1298 if (data
instanceof ITmfModelLookup
) {
1299 ITmfModelLookup event
= (ITmfModelLookup
) data
;
1300 if (event
.getModelUri() != null) {
1301 fTablePopupMenuManager
.add(openModelAction
);
1302 separator
= new Separator();
1305 if (separator
!= null) {
1306 fTablePopupMenuManager
.add(separator
);
1312 * Only show collapse filter if at least one trace can be
1315 boolean isCollapsible
= false;
1316 if (fTrace
!= null) {
1317 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
1318 Class
<?
extends ITmfEvent
> eventClass
= trace
.getEventType();
1319 isCollapsible
= ITmfCollapsibleEvent
.class.isAssignableFrom(eventClass
);
1320 if (isCollapsible
) {
1326 if (isCollapsible
&& !(fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
)) {
1327 fTablePopupMenuManager
.add(collapseAction
);
1328 fTablePopupMenuManager
.add(new Separator());
1331 fTablePopupMenuManager
.add(clearFiltersAction
);
1332 final ITmfFilterTreeNode
[] savedFilters
= FilterManager
.getSavedFilters();
1333 if (savedFilters
.length
> 0) {
1334 final MenuManager subMenu
= new MenuManager(Messages
.TmfEventsTable_ApplyPresetFilterMenuName
);
1335 for (final ITmfFilterTreeNode node
: savedFilters
) {
1336 if (node
instanceof TmfFilterNode
) {
1337 final TmfFilterNode filter
= (TmfFilterNode
) node
;
1338 subMenu
.add(new Action(filter
.getFilterName()) {
1341 applyFilter(filter
);
1346 fTablePopupMenuManager
.add(subMenu
);
1348 appendToTablePopupMenu(fTablePopupMenuManager
, item
);
1352 fRawViewerPopupMenuManager
= new MenuManager();
1353 fRawViewerPopupMenuManager
.setRemoveAllWhenShown(true);
1354 fRawViewerPopupMenuManager
.addMenuListener(new IMenuListener() {
1356 public void menuAboutToShow(final IMenuManager manager
) {
1357 if (fTable
.isVisible() && fRawViewer
.isVisible()) {
1358 fRawViewerPopupMenuManager
.add(hideTableAction
);
1359 fRawViewerPopupMenuManager
.add(hideRawAction
);
1360 } else if (!fTable
.isVisible()) {
1361 fRawViewerPopupMenuManager
.add(showTableAction
);
1362 } else if (!fRawViewer
.isVisible()) {
1363 fRawViewerPopupMenuManager
.add(showRawAction
);
1365 appendToRawPopupMenu(fRawViewerPopupMenuManager
);
1369 fHeaderMenu
= fHeaderPopupMenuManager
.createContextMenu(fTable
);
1371 fTablePopup
= fTablePopupMenuManager
.createContextMenu(fTable
);
1372 fTable
.setMenu(fTablePopup
);
1374 fRawTablePopup
= fRawViewerPopupMenuManager
.createContextMenu(fRawViewer
);
1375 fRawViewer
.setMenu(fRawTablePopup
);
1379 * Append an item to the event table's pop-up menu.
1381 * @param tablePopupMenu
1383 * @param selectedItem
1384 * The item to append
1386 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu
, final TableItem selectedItem
) {
1387 // override to append more actions
1391 * Append an item to the raw viewer's pop-up menu.
1393 * @param rawViewerPopupMenu
1396 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu
) {
1397 // override to append more actions
1401 public void dispose() {
1404 PlatformUI
.getWorkbench().getThemeManager().removePropertyChangeListener(this);
1405 ColorSettingsManager
.removeColorSettingsListener(this);
1406 fComposite
.dispose();
1407 if ((fTrace
!= null) && fDisposeOnClose
) {
1410 fResourceManager
.dispose();
1411 fRawViewer
.dispose();
1412 if (fRawViewerPopupMenuManager
!= null) {
1413 fRawViewerPopupMenuManager
.dispose();
1415 if (fHeaderPopupMenuManager
!= null) {
1416 fHeaderPopupMenuManager
.dispose();
1418 if (fTablePopupMenuManager
!= null) {
1419 fTablePopupMenuManager
.dispose();
1426 * Assign a layout data object to this view.
1429 * The layout data to assign
1431 public void setLayoutData(final Object layoutData
) {
1432 fComposite
.setLayoutData(layoutData
);
1436 * Get the virtual table contained in this event table.
1438 * @return The TMF virtual table
1440 public TmfVirtualTable
getTable() {
1447 * @deprecated The column headers are now set at the constructor, this
1448 * shouldn't be called anymore.
1451 protected void setColumnHeaders(final org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.virtualtable
.ColumnData
[] columnData
) {
1456 * Set a table item's data.
1461 * Which trace event to link with this entry
1463 * Which rank this event has in the trace/experiment
1465 protected void setItemData(final TableItem item
, final ITmfEvent event
, final long rank
) {
1466 String
[] itemStrings
= getItemStrings(fColumns
, event
);
1468 // Get the actual ITmfEvent from the CachedEvent
1469 ITmfEvent tmfEvent
= event
;
1470 if (event
instanceof CachedEvent
) {
1471 tmfEvent
= ((CachedEvent
) event
).event
;
1473 item
.setText(itemStrings
);
1474 item
.setData(tmfEvent
);
1475 item
.setData(Key
.TIMESTAMP
, new TmfTimestamp(tmfEvent
.getTimestamp()));
1476 item
.setData(Key
.RANK
, rank
);
1478 final Collection
<Long
> markerIds
= fBookmarksMap
.get(rank
);
1479 if (!markerIds
.isEmpty()) {
1480 Joiner joiner
= Joiner
.on("\n -").skipNulls(); //$NON-NLS-1$
1481 List
<Object
> parts
= new ArrayList
<>();
1482 if (markerIds
.size() > 1) {
1483 parts
.add(Messages
.TmfEventsTable_MultipleBookmarksToolTip
);
1486 for (long markerId
: markerIds
) {
1487 final IMarker marker
= fBookmarksFile
.findMarker(markerId
);
1488 parts
.add(marker
.getAttribute(IMarker
.MESSAGE
));
1490 } catch (CoreException e
) {
1491 displayException(e
);
1493 item
.setData(Key
.BOOKMARK
, joiner
.join(parts
));
1495 item
.setData(Key
.BOOKMARK
, null);
1498 boolean searchMatch
= false;
1499 boolean searchNoMatch
= false;
1500 final ITmfFilter searchFilter
= (ITmfFilter
) fTable
.getData(Key
.SEARCH_OBJ
);
1501 if (searchFilter
!= null) {
1502 if (searchFilter
.matches(tmfEvent
)) {
1505 searchNoMatch
= true;
1509 final ColorSetting colorSetting
= ColorSettingsManager
.getColorSetting(tmfEvent
);
1510 if (searchNoMatch
) {
1511 item
.setForeground(colorSetting
.getDimmedForegroundColor());
1512 item
.setBackground(colorSetting
.getDimmedBackgroundColor());
1514 item
.setForeground(colorSetting
.getForegroundColor());
1515 item
.setBackground(colorSetting
.getBackgroundColor());
1517 item
.setFont(fFont
);
1520 if (!markerIds
.isEmpty()) {
1521 item
.setImage(SEARCH_MATCH_BOOKMARK_IMAGE
);
1523 item
.setImage(SEARCH_MATCH_IMAGE
);
1525 } else if (!markerIds
.isEmpty()) {
1526 item
.setImage(BOOKMARK_IMAGE
);
1528 item
.setImage((Image
) null);
1531 List
<StyleRange
> styleRanges
= new ArrayList
<>();
1532 for (int index
= 0; index
< fTable
.getColumns().length
; index
++) {
1533 TableColumn column
= fTable
.getColumns()[index
];
1534 String regex
= null;
1535 if (fHeaderState
== HeaderState
.FILTER
) {
1536 regex
= (String
) column
.getData(Key
.FILTER_TXT
);
1537 } else if (searchMatch
) {
1538 regex
= (String
) column
.getData(Key
.SEARCH_TXT
);
1540 if (regex
!= null) {
1541 String text
= item
.getText(index
);
1543 Pattern pattern
= Pattern
.compile(regex
);
1544 Matcher matcher
= pattern
.matcher(text
);
1545 while (matcher
.find()) {
1546 int start
= matcher
.start();
1547 int length
= matcher
.end() - start
;
1548 Color foreground
= colorSetting
.getForegroundColor();
1549 Color background
= fHighlightColor
;
1550 StyleRange styleRange
= new StyleRange(start
, length
, foreground
, background
);
1551 styleRange
.data
= index
;
1552 styleRanges
.add(styleRange
);
1554 } catch (PatternSyntaxException e
) {
1559 if (styleRanges
.isEmpty()) {
1560 item
.setData(Key
.STYLE_RANGES
, null);
1562 item
.setData(Key
.STYLE_RANGES
, styleRanges
);
1564 item
.getParent().redraw();
1566 if ((itemStrings
[MARGIN_COLUMN_INDEX
] != null) && !itemStrings
[MARGIN_COLUMN_INDEX
].isEmpty()) {
1572 * Set the item data of the header row.
1575 * The item to use as table header
1577 protected void setHeaderRowItemData(final TableItem item
) {
1578 String txtKey
= null;
1579 if (fHeaderState
== HeaderState
.SEARCH
) {
1580 item
.setImage(SEARCH_IMAGE
);
1581 txtKey
= Key
.SEARCH_TXT
;
1582 } else if (fHeaderState
== HeaderState
.FILTER
) {
1583 item
.setImage(FILTER_IMAGE
);
1584 txtKey
= Key
.FILTER_TXT
;
1586 item
.setForeground(fGrayColor
);
1587 // Ignore collapse and image column
1588 for (int i
= EVENT_COLUMNS_START_INDEX
; i
< fTable
.getColumns().length
; i
++) {
1589 final TableColumn column
= fTable
.getColumns()[i
];
1590 final String filter
= (String
) column
.getData(txtKey
);
1591 if (filter
== null) {
1592 if (fHeaderState
== HeaderState
.SEARCH
) {
1593 item
.setText(i
, SEARCH_HINT
);
1594 } else if (fHeaderState
== HeaderState
.FILTER
) {
1595 item
.setText(i
, FILTER_HINT
);
1597 item
.setForeground(i
, fGrayColor
);
1598 item
.setFont(i
, fFont
);
1600 item
.setText(i
, filter
);
1601 item
.setForeground(i
, fGreenColor
);
1602 item
.setFont(i
, fBoldFont
);
1608 * Set the item data of the "filter status" row.
1611 * The item to use as filter status row
1613 protected void setFilterStatusRowItemData(final TableItem item
) {
1614 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1615 if (i
== MARGIN_COLUMN_INDEX
) {
1616 if ((fTrace
== null) || (fFilterCheckCount
== fTrace
.getNbEvents())) {
1617 item
.setImage(FILTER_IMAGE
);
1619 item
.setImage(STOP_IMAGE
);
1623 if (i
== FILTER_SUMMARY_INDEX
) {
1624 item
.setText(FILTER_SUMMARY_INDEX
, fFilterMatchCount
+ "/" + fFilterCheckCount
); //$NON-NLS-1$
1626 item
.setText(i
, EMPTY_STRING
);
1630 item
.setData(Key
.TIMESTAMP
, null);
1631 item
.setData(Key
.RANK
, null);
1632 item
.setData(Key
.STYLE_RANGES
, null);
1633 item
.setForeground(null);
1634 item
.setBackground(null);
1635 item
.setFont(fFont
);
1639 * Create an editor for the header.
1641 private void createHeaderEditor() {
1642 final TableEditor tableEditor
= fTable
.createTableEditor();
1643 tableEditor
.horizontalAlignment
= SWT
.LEFT
;
1644 tableEditor
.verticalAlignment
= SWT
.CENTER
;
1645 tableEditor
.grabHorizontal
= true;
1646 tableEditor
.minimumWidth
= 50;
1648 // Handle the header row selection
1649 fTable
.addMouseListener(new MouseAdapter() {
1655 public void mouseDown(final MouseEvent event
) {
1656 if (event
.button
!= 1) {
1659 // Identify the selected row
1660 final Point point
= new Point(event
.x
, event
.y
);
1661 item
= fTable
.getItem(point
);
1663 // Header row selected
1664 if ((item
!= null) && (fTable
.indexOf(item
) == 0)) {
1666 // Margin column selected
1667 if (item
.getBounds(0).contains(point
)) {
1668 if (fHeaderState
== HeaderState
.SEARCH
) {
1669 fHeaderState
= HeaderState
.FILTER
;
1670 } else if (fHeaderState
== HeaderState
.FILTER
) {
1671 fHeaderState
= HeaderState
.SEARCH
;
1673 fTable
.setSelection(0);
1679 // Identify the selected column
1681 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
1682 final Rectangle rect
= item
.getBounds(i
);
1683 if (rect
.contains(point
)) {
1689 if (columnIndex
== -1) {
1693 column
= fTable
.getColumns()[columnIndex
];
1695 String txtKey
= null;
1696 if (fHeaderState
== HeaderState
.SEARCH
) {
1697 txtKey
= Key
.SEARCH_TXT
;
1698 } else if (fHeaderState
== HeaderState
.FILTER
) {
1699 txtKey
= Key
.FILTER_TXT
;
1703 * The control that will be the editor must be a child of
1706 final Text newEditor
= (Text
) fTable
.createTableEditorControl(Text
.class);
1707 final String headerString
= (String
) column
.getData(txtKey
);
1708 if (headerString
!= null) {
1709 newEditor
.setText(headerString
);
1711 newEditor
.addFocusListener(new FocusAdapter() {
1713 public void focusLost(final FocusEvent e
) {
1714 final boolean changed
= updateHeader(newEditor
.getText());
1720 newEditor
.addKeyListener(new KeyAdapter() {
1722 public void keyPressed(final KeyEvent e
) {
1723 if (e
.character
== SWT
.CR
) {
1724 updateHeader(newEditor
.getText());
1728 * Set focus on the table so that the next
1729 * carriage return goes to the next result
1731 TmfEventsTable
.this.getTable().setFocus();
1732 } else if (e
.character
== SWT
.ESC
) {
1733 tableEditor
.getEditor().dispose();
1737 newEditor
.selectAll();
1738 newEditor
.setFocus();
1739 tableEditor
.setEditor(newEditor
, item
, columnIndex
);
1744 * returns true is value was changed
1746 private boolean updateHeader(final String regex
) {
1747 String objKey
= null;
1748 String txtKey
= null;
1749 if (fHeaderState
== HeaderState
.SEARCH
) {
1750 objKey
= Key
.SEARCH_OBJ
;
1751 txtKey
= Key
.SEARCH_TXT
;
1752 } else if (fHeaderState
== HeaderState
.FILTER
) {
1753 objKey
= Key
.FILTER_OBJ
;
1754 txtKey
= Key
.FILTER_TXT
;
1756 if (regex
.length() > 0) {
1758 Pattern
.compile(regex
);
1759 if (regex
.equals(column
.getData(txtKey
))) {
1760 tableEditor
.getEditor().dispose();
1763 final TmfFilterMatchesNode filter
= new TmfFilterMatchesNode(null);
1764 ITmfEventAspect aspect
= (ITmfEventAspect
) column
.getData(Key
.ASPECT
);
1765 filter
.setEventAspect(aspect
);
1766 filter
.setRegex(regex
);
1767 column
.setData(objKey
, filter
);
1768 column
.setData(txtKey
, regex
);
1769 } catch (final PatternSyntaxException ex
) {
1770 tableEditor
.getEditor().dispose();
1771 MessageDialog
.openError(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
1772 ex
.getDescription(), ex
.getMessage());
1776 if (column
.getData(txtKey
) == null) {
1777 tableEditor
.getEditor().dispose();
1780 column
.setData(objKey
, null);
1781 column
.setData(txtKey
, null);
1786 private void applyHeader() {
1787 if (fHeaderState
== HeaderState
.SEARCH
) {
1789 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1790 for (final TableColumn col
: fTable
.getColumns()) {
1791 final Object filterObj
= col
.getData(Key
.SEARCH_OBJ
);
1792 if (filterObj
instanceof ITmfFilterTreeNode
) {
1793 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1796 if (filter
.getChildrenCount() > 0) {
1797 fTable
.setData(Key
.SEARCH_OBJ
, filter
);
1800 fireSearchApplied(filter
);
1802 fTable
.setData(Key
.SEARCH_OBJ
, null);
1804 fireSearchApplied(null);
1806 } else if (fHeaderState
== HeaderState
.FILTER
) {
1807 final TmfFilterAndNode filter
= new TmfFilterAndNode(null);
1808 for (final TableColumn col
: fTable
.getColumns()) {
1809 final Object filterObj
= col
.getData(Key
.FILTER_OBJ
);
1810 if (filterObj
instanceof ITmfFilterTreeNode
) {
1811 filter
.addChild((ITmfFilterTreeNode
) filterObj
);
1814 if (filter
.getChildrenCount() > 0) {
1815 applyFilter(filter
);
1821 tableEditor
.getEditor().dispose();
1825 fTable
.addKeyListener(new KeyAdapter() {
1827 public void keyPressed(final KeyEvent e
) {
1829 if (e
.character
== SWT
.ESC
) {
1833 } else if (e
.character
== SWT
.DEL
) {
1834 if (fHeaderState
== HeaderState
.SEARCH
) {
1836 for (final TableColumn column
: fTable
.getColumns()) {
1837 column
.setData(Key
.SEARCH_OBJ
, null);
1838 column
.setData(Key
.SEARCH_TXT
, null);
1840 fTable
.setData(Key
.SEARCH_OBJ
, null);
1842 fireSearchApplied(null);
1843 } else if (fHeaderState
== HeaderState
.FILTER
) {
1846 } else if (e
.character
== SWT
.CR
) {
1847 if ((e
.stateMask
& SWT
.SHIFT
) == 0) {
1858 * Send an event indicating a filter has been applied.
1861 * The filter that was just applied
1863 protected void fireFilterApplied(final ITmfFilter filter
) {
1864 broadcast(new TmfEventFilterAppliedSignal(this, fTrace
, filter
));
1868 * Send an event indicating that a search has been applied.
1871 * The search filter that was just applied
1873 protected void fireSearchApplied(final ITmfFilter filter
) {
1874 broadcast(new TmfEventSearchAppliedSignal(this, fTrace
, filter
));
1878 * Start the filtering thread.
1880 protected void startFilterThread() {
1881 synchronized (fFilterSyncObj
) {
1882 final ITmfFilterTreeNode filter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
1883 if (fFilterThread
== null || fFilterThread
.filter
!= filter
) {
1884 if (fFilterThread
!= null) {
1885 fFilterThread
.cancel();
1886 fFilterThreadResume
= false;
1888 fFilterThread
= new FilterThread(filter
);
1889 fFilterThread
.start();
1891 fFilterThreadResume
= true;
1897 * Stop the filtering thread.
1899 protected void stopFilterThread() {
1900 synchronized (fFilterSyncObj
) {
1901 if (fFilterThread
!= null) {
1902 fFilterThread
.cancel();
1903 fFilterThread
= null;
1904 fFilterThreadResume
= false;
1913 * The filter to apply
1915 protected void applyFilter(ITmfFilter filter
) {
1918 fFilterMatchCount
= 0;
1919 fFilterCheckCount
= 0;
1920 fCache
.applyFilter(filter
);
1922 fTable
.setData(Key
.FILTER_OBJ
, filter
);
1923 /* +1 for header row, +2 for top and bottom filter status rows */
1924 fTable
.setItemCount(3);
1925 startFilterThread();
1926 fireFilterApplied(filter
);
1930 * Clear all currently active filters.
1932 protected void clearFilters() {
1933 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
1938 fCache
.clearFilter();
1940 for (final TableColumn column
: fTable
.getColumns()) {
1941 column
.setData(Key
.FILTER_OBJ
, null);
1942 column
.setData(Key
.FILTER_TXT
, null);
1944 fTable
.setData(Key
.FILTER_OBJ
, null);
1945 if (fTrace
!= null) {
1946 /* +1 for header row */
1947 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1);
1949 /* +1 for header row */
1950 fTable
.setItemCount(1);
1952 fFilterMatchCount
= 0;
1953 fFilterCheckCount
= 0;
1954 if (fSelectedRank
>= 0) {
1955 /* +1 for header row */
1956 fTable
.setSelection((int) fSelectedRank
+ 1);
1958 fTable
.setSelection(0);
1960 fireFilterApplied(null);
1961 updateStatusLine(null);
1963 // Set original width
1964 fTable
.getColumns()[MARGIN_COLUMN_INDEX
].setWidth(0);
1969 * Wrapper Thread object for the filtering thread.
1971 protected class FilterThread
extends Thread
{
1972 private final ITmfFilterTreeNode filter
;
1973 private TmfEventRequest request
;
1974 private boolean refreshBusy
= false;
1975 private boolean refreshPending
= false;
1976 private final Object syncObj
= new Object();
1982 * The filter this thread will be processing
1984 public FilterThread(final ITmfFilterTreeNode filter
) {
1985 super("Filter Thread"); //$NON-NLS-1$
1986 this.filter
= filter
;
1991 if (fTrace
== null) {
1994 final int nbRequested
= (int) (fTrace
.getNbEvents() - fFilterCheckCount
);
1995 if (nbRequested
<= 0) {
1998 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
1999 (int) fFilterCheckCount
, nbRequested
, ExecutionType
.BACKGROUND
) {
2001 public void handleData(final ITmfEvent event
) {
2002 super.handleData(event
);
2003 if (request
.isCancelled()) {
2006 boolean refresh
= false;
2007 if (filter
.matches(event
)) {
2008 final long rank
= fFilterCheckCount
;
2009 final int index
= (int) fFilterMatchCount
;
2010 fFilterMatchCount
++;
2011 fCache
.storeEvent(event
, rank
, index
);
2014 if (filter
instanceof TmfCollapseFilter
) {
2015 fCache
.updateCollapsedEvent((int) fFilterMatchCount
- 1);
2019 if (refresh
|| (fFilterCheckCount
% 100) == 0) {
2022 fFilterCheckCount
++;
2025 ((ITmfEventProvider
) fTrace
).sendRequest(request
);
2027 request
.waitForCompletion();
2028 } catch (final InterruptedException e
) {
2031 synchronized (fFilterSyncObj
) {
2032 fFilterThread
= null;
2033 if (fFilterThreadResume
) {
2034 fFilterThreadResume
= false;
2035 fFilterThread
= new FilterThread(filter
);
2036 fFilterThread
.start();
2042 * Refresh the filter.
2044 public void refreshTable() {
2045 synchronized (syncObj
) {
2047 refreshPending
= true;
2052 Display
.getDefault().asyncExec(new Runnable() {
2055 if (request
.isCancelled()) {
2058 if (fTable
.isDisposed()) {
2062 * +1 for header row, +2 for top and bottom filter status
2065 fTable
.setItemCount((int) fFilterMatchCount
+ 3);
2067 synchronized (syncObj
) {
2068 refreshBusy
= false;
2069 if (refreshPending
) {
2070 refreshPending
= false;
2079 * Cancel this filtering thread.
2081 public void cancel() {
2082 if (request
!= null) {
2089 * Go to the next item of a search.
2091 protected void searchNext() {
2092 synchronized (fSearchSyncObj
) {
2093 if (fSearchThread
!= null) {
2096 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
2097 if (searchFilter
== null) {
2100 final int selectionIndex
= fTable
.getSelectionIndex();
2102 if (selectionIndex
> 0) {
2103 /* -1 for header row, +1 for next event */
2104 startIndex
= selectionIndex
;
2107 * header row is selected, start at top event
2109 /* -1 for header row */
2110 startIndex
= Math
.max(0, fTable
.getTopIndex() - 1);
2112 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
2113 if (eventFilter
!= null) {
2114 // -1 for top filter status row
2115 startIndex
= Math
.max(0, startIndex
- 1);
2117 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.FORWARD
);
2118 fSearchThread
.schedule();
2123 * Go to the previous item of a search.
2125 protected void searchPrevious() {
2126 synchronized (fSearchSyncObj
) {
2127 if (fSearchThread
!= null) {
2130 final ITmfFilterTreeNode searchFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.SEARCH_OBJ
);
2131 if (searchFilter
== null) {
2134 final int selectionIndex
= fTable
.getSelectionIndex();
2136 if (selectionIndex
> 0) {
2137 /* -1 for header row, -1 for previous event */
2138 startIndex
= selectionIndex
- 2;
2141 * Header row is selected, start at precedent of top event
2143 /* -1 for header row, -1 for previous event */
2144 startIndex
= fTable
.getTopIndex() - 2;
2146 final ITmfFilterTreeNode eventFilter
= (ITmfFilterTreeNode
) fTable
.getData(Key
.FILTER_OBJ
);
2147 if (eventFilter
!= null) {
2148 /* -1 for top filter status row */
2149 startIndex
= startIndex
- 1;
2151 fSearchThread
= new SearchThread(searchFilter
, eventFilter
, startIndex
, fSelectedRank
, Direction
.BACKWARD
);
2152 fSearchThread
.schedule();
2157 * Stop the search thread.
2159 protected void stopSearchThread() {
2160 fPendingGotoRank
= -1;
2161 synchronized (fSearchSyncObj
) {
2162 if (fSearchThread
!= null) {
2163 fSearchThread
.cancel();
2164 fSearchThread
= null;
2170 * Wrapper for the search thread.
2172 protected class SearchThread
extends Job
{
2174 private ITmfFilterTreeNode searchFilter
;
2175 private ITmfFilterTreeNode eventFilter
;
2176 private int startIndex
;
2177 private int direction
;
2179 private long foundRank
= -1;
2180 private TmfEventRequest request
;
2181 private ITmfTimestamp foundTimestamp
= null;
2186 * @param searchFilter
2188 * @param eventFilter
2191 * The index at which we should start searching
2192 * @param currentRank
2195 * In which direction should we search, forward or backwards
2197 public SearchThread(final ITmfFilterTreeNode searchFilter
,
2198 final ITmfFilterTreeNode eventFilter
, final int startIndex
,
2199 final long currentRank
, final int direction
) {
2200 super(Messages
.TmfEventsTable_SearchingJobName
);
2201 this.searchFilter
= searchFilter
;
2202 this.eventFilter
= eventFilter
;
2203 this.startIndex
= startIndex
;
2204 this.rank
= currentRank
;
2205 this.direction
= direction
;
2209 protected IStatus
run(final IProgressMonitor monitor
) {
2210 final ITmfTrace trace
= fTrace
;
2211 if (trace
== null) {
2212 return Status
.OK_STATUS
;
2214 final Display display
= Display
.getDefault();
2215 if (startIndex
< 0) {
2216 rank
= (int) trace
.getNbEvents() - 1;
2218 * -1 for header row, -3 for header and top and bottom filter
2221 } else if (startIndex
>= (fTable
.getItemCount() - (eventFilter
== null ?
1 : 3))) {
2224 int idx
= startIndex
;
2225 while (foundRank
== -1) {
2226 final CachedEvent event
= fCache
.peekEvent(idx
);
2227 if (event
== null) {
2231 if (searchFilter
.matches(event
.event
) && ((eventFilter
== null) || eventFilter
.matches(event
.event
))) {
2232 foundRank
= event
.rank
;
2233 foundTimestamp
= event
.event
.getTimestamp();
2236 if (direction
== Direction
.FORWARD
) {
2242 if (foundRank
== -1) {
2243 if (direction
== Direction
.FORWARD
) {
2245 if (rank
> (trace
.getNbEvents() - 1)) {
2251 rank
= (int) trace
.getNbEvents() - 1;
2256 final int startRank
= (int) rank
;
2257 boolean wrapped
= false;
2258 while (!monitor
.isCanceled() && (foundRank
== -1)) {
2259 int nbRequested
= (direction
== Direction
.FORWARD ? Integer
.MAX_VALUE
: Math
.min((int) rank
+ 1, trace
.getCacheSize()));
2260 if (direction
== Direction
.BACKWARD
) {
2261 rank
= Math
.max(0, rank
- trace
.getCacheSize() + 1);
2263 request
= new TmfEventRequest(ITmfEvent
.class, TmfTimeRange
.ETERNITY
,
2264 (int) rank
, nbRequested
, ExecutionType
.BACKGROUND
) {
2265 long currentRank
= rank
;
2268 public void handleData(final ITmfEvent event
) {
2269 super.handleData(event
);
2270 if (searchFilter
.matches(event
) && ((eventFilter
== null) || eventFilter
.matches(event
))) {
2271 foundRank
= currentRank
;
2272 foundTimestamp
= event
.getTimestamp();
2273 if (direction
== Direction
.FORWARD
) {
2281 ((ITmfEventProvider
) trace
).sendRequest(request
);
2283 request
.waitForCompletion();
2284 if (request
.isCancelled()) {
2285 return Status
.OK_STATUS
;
2287 } catch (final InterruptedException e
) {
2288 synchronized (fSearchSyncObj
) {
2289 fSearchThread
= null;
2291 return Status
.OK_STATUS
;
2293 if (foundRank
== -1) {
2294 if (direction
== Direction
.FORWARD
) {
2296 synchronized (fSearchSyncObj
) {
2297 fSearchThread
= null;
2299 return Status
.OK_STATUS
;
2301 nbRequested
= (int) rank
;
2307 rank
= (int) trace
.getNbEvents() - 1;
2310 if ((rank
<= startRank
) && wrapped
) {
2311 synchronized (fSearchSyncObj
) {
2312 fSearchThread
= null;
2314 return Status
.OK_STATUS
;
2319 int index
= (int) foundRank
;
2320 if (eventFilter
!= null) {
2321 index
= fCache
.getFilteredEventIndex(foundRank
);
2323 /* +1 for header row, +1 for top filter status row */
2324 final int selection
= index
+ 1 + (eventFilter
!= null ?
+1 : 0);
2326 display
.asyncExec(new Runnable() {
2329 if (monitor
.isCanceled()) {
2332 if (fTable
.isDisposed()) {
2335 fTable
.setSelection(selection
);
2336 fSelectedRank
= foundRank
;
2337 fSelectedBeginRank
= fSelectedRank
;
2338 fRawViewer
.selectAndReveal(fSelectedRank
);
2339 if (foundTimestamp
!= null) {
2340 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable
.this, foundTimestamp
));
2342 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable
.this, getSelection()));
2343 synchronized (fSearchSyncObj
) {
2344 fSearchThread
= null;
2346 updateStatusLine(null);
2349 return Status
.OK_STATUS
;
2353 protected void canceling() {
2355 synchronized (fSearchSyncObj
) {
2356 fSearchThread
= null;
2362 * Create the resources.
2364 private void createResources() {
2365 fGrayColor
= fResourceManager
.createColor(ColorUtil
.blend(fTable
.getBackground().getRGB(), fTable
.getForeground().getRGB()));
2366 fGreenColor
= PlatformUI
.getWorkbench().getDisplay().getSystemColor(SWT
.COLOR_DARK_GREEN
);
2370 * Initialize the fonts.
2372 private void initializeFonts() {
2373 FontRegistry fontRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
2374 fFont
= fontRegistry
.get(FONT_DEFINITION_ID
);
2375 fBoldFont
= fontRegistry
.getBold(FONT_DEFINITION_ID
);
2376 fTable
.setFont(fFont
);
2377 /* Column header font cannot be set. See Bug 63038 */
2381 * Initialize the colors.
2383 private void initializeColors() {
2384 ColorRegistry colorRegistry
= PlatformUI
.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
2385 fHighlightColor
= colorRegistry
.get(HIGHLIGHT_COLOR_DEFINITION_ID
);
2392 public void propertyChange(PropertyChangeEvent event
) {
2393 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2394 (FONT_DEFINITION_ID
.equals(event
.getProperty()))) {
2398 if ((IThemeManager
.CHANGE_CURRENT_THEME
.equals(event
.getProperty())) ||
2399 (HIGHLIGHT_COLOR_DEFINITION_ID
.equals(event
.getProperty()))) {
2408 protected void packColumns() {
2412 fTable
.setRedraw(false);
2414 TableColumn tableColumns
[] = fTable
.getColumns();
2415 for (int i
= 0; i
< tableColumns
.length
; i
++) {
2416 final TableColumn column
= tableColumns
[i
];
2417 packSingleColumn(i
, column
);
2421 // Make sure that redraw is always enabled.
2422 fTable
.setRedraw(true);
2427 private void packMarginColumn() {
2428 TableColumn
[] columns
= fTable
.getColumns();
2429 if (columns
.length
> 0) {
2430 packSingleColumn(0, columns
[0]);
2434 private void packSingleColumn(int i
, final TableColumn column
) {
2435 final int headerWidth
= column
.getWidth();
2438 * Workaround for Linux which doesn't consider the image width of
2439 * search/filter row in TableColumn.pack() after having executed
2440 * TableItem.setImage(null) for other rows than search/filter row.
2442 boolean isCollapseFilter
= fTable
.getData(Key
.FILTER_OBJ
) instanceof TmfCollapseFilter
;
2443 if (IS_LINUX
&& (i
== 0) && isCollapseFilter
) {
2444 column
.setWidth(column
.getWidth() + SEARCH_IMAGE
.getBounds().width
);
2447 if (column
.getWidth() < headerWidth
) {
2448 column
.setWidth(headerWidth
);
2453 * Get the array of item strings (e.g., what to display in each cell of the
2454 * table row) corresponding to the columns and trace event passed in
2455 * parameter. The order of the Strings in the returned array will correspond
2456 * to the iteration order of 'columns'.
2459 * To ensure consistent results, make sure only call this within a scope
2460 * synchronized on 'columns'! If the order of 'columns' changes right after
2461 * this method is called, the returned value won't be ordered correctly
2464 private static String
[] getItemStrings(List
<TmfEventTableColumn
> columns
, ITmfEvent event
) {
2465 if (event
== null) {
2466 return EMPTY_STRING_ARRAY
;
2468 synchronized (columns
) {
2469 List
<String
> itemStrings
= new ArrayList
<>(columns
.size());
2470 for (TmfEventTableColumn column
: columns
) {
2471 ITmfEvent passedEvent
= event
;
2472 if (!(column
instanceof TmfMarginColumn
) && (event
instanceof CachedEvent
)) {
2474 * Make sure that the event object from the trace is passed
2475 * to all columns but the TmfMarginColumn
2477 passedEvent
= ((CachedEvent
) event
).event
;
2479 if (passedEvent
== null) {
2480 itemStrings
.add(EMPTY_STRING
);
2482 itemStrings
.add(column
.getItemString(passedEvent
));
2486 return itemStrings
.toArray(new String
[0]);
2491 * Get the contents of the row in the events table corresponding to an
2492 * event. The order of the elements corresponds to the current order of the
2496 * The event printed in this row
2497 * @return The event row entries
2499 public String
[] getItemStrings(ITmfEvent event
) {
2500 List
<TmfEventTableColumn
> columns
= new ArrayList
<>();
2501 for (int i
: fTable
.getColumnOrder()) {
2502 columns
.add(fColumns
.get(i
));
2504 return getItemStrings(columns
, event
);
2508 * Returns an array of zero-relative integers that map the creation order of
2509 * the receiver's columns to the order in which they are currently being
2512 * Specifically, the indices of the returned array represent the current
2513 * visual order of the columns, and the contents of the array represent the
2514 * creation order of the columns.
2516 * @return the current visual order of the receiver's columns
2519 public int[] getColumnOrder() {
2520 return fColumnOrder
;
2524 * Sets the order that the columns in the receiver should be displayed in to
2525 * the given argument which is described in terms of the zero-relative
2526 * ordering of when the columns were added.
2528 * Specifically, the contents of the array represent the original position
2529 * of each column at the time its creation.
2532 * the new order to display the columns
2535 public void setColumnOrder(int[] order
) {
2536 if (order
== null || order
.length
!= fTable
.getColumns().length
) {
2539 fTable
.setColumnOrder(order
);
2540 fColumnOrder
= fTable
.getColumnOrder();
2544 * Notify this table that is got the UI focus.
2546 public void setFocus() {
2551 * Registers context menus with a site for extension. This method can be
2552 * called for part sites so that context menu contributions can be added.
2555 * the site that the context menus will be registered for
2559 public void registerContextMenus(IWorkbenchPartSite site
) {
2560 if (site
instanceof IEditorSite
) {
2561 IEditorSite editorSite
= (IEditorSite
) site
;
2562 // Don't use the editor input when adding contributions, otherwise
2563 // we get too many unwanted things.
2564 editorSite
.registerContextMenu(fTablePopupMenuManager
, this, false);
2569 * Assign a new trace to this event table.
2572 * The trace to assign to this event table
2573 * @param disposeOnClose
2574 * true if the trace should be disposed when the table is
2577 public void setTrace(final ITmfTrace trace
, final boolean disposeOnClose
) {
2578 if ((fTrace
!= null) && fDisposeOnClose
) {
2583 fDisposeOnClose
= disposeOnClose
;
2585 // Perform the updates on the UI thread
2586 PlatformUI
.getWorkbench().getDisplay().syncExec(new Runnable() {
2590 fSelectedBeginRank
= -1;
2592 fCache
.setTrace(trace
); // Clear the cache
2593 if (trace
!= null) {
2594 if (!fTable
.isDisposed()) {
2595 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2596 // +1 for header row
2597 fTable
.setItemCount((int) trace
.getNbEvents() + 1);
2600 fFilterMatchCount
= 0;
2601 fFilterCheckCount
= 0;
2603 * +1 for header row, +2 for top and bottom filter
2606 fTable
.setItemCount(3);
2607 startFilterThread();
2611 fRawViewer
.setTrace(trace
);
2617 * Assign the status line manager
2619 * @param statusLineManager
2620 * The status line manager, or null to disable status line
2623 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
2624 if (fStatusLineManager
!= null && statusLineManager
== null) {
2625 fStatusLineManager
.setMessage(EMPTY_STRING
);
2627 fStatusLineManager
= statusLineManager
;
2630 private void updateStatusLine(ITmfTimestamp delta
) {
2631 if (fStatusLineManager
!= null) {
2632 if (delta
!= null) {
2633 fStatusLineManager
.setMessage("\u0394: " + delta
); //$NON-NLS-1$
2635 fStatusLineManager
.setMessage(null);
2640 // ------------------------------------------------------------------------
2642 // ------------------------------------------------------------------------
2645 * Notify that the event cache has been updated
2648 * Also notify if the populating of the cache is complete, or
2651 public void cacheUpdated(final boolean completed
) {
2652 synchronized (fCacheUpdateSyncObj
) {
2653 if (fCacheUpdateBusy
) {
2654 fCacheUpdatePending
= true;
2655 fCacheUpdateCompleted
= completed
;
2658 fCacheUpdateBusy
= true;
2660 // Event cache is now updated. Perform update on the UI thread
2661 PlatformUI
.getWorkbench().getDisplay().asyncExec(new Runnable() {
2664 if (!fTable
.isDisposed()) {
2669 populateCompleted();
2671 synchronized (fCacheUpdateSyncObj
) {
2672 fCacheUpdateBusy
= false;
2673 if (fCacheUpdatePending
) {
2674 fCacheUpdatePending
= false;
2675 cacheUpdated(fCacheUpdateCompleted
);
2683 * Callback for when populating the table is complete.
2685 protected void populateCompleted() {
2686 // Nothing by default;
2689 // ------------------------------------------------------------------------
2690 // ISelectionProvider
2691 // ------------------------------------------------------------------------
2694 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2695 selectionChangedListeners
.add(listener
);
2699 public ISelection
getSelection() {
2700 if (fTable
== null || fTable
.isDisposed()) {
2701 return StructuredSelection
.EMPTY
;
2703 List
<Object
> list
= new ArrayList
<>(fTable
.getSelection().length
);
2704 for (TableItem item
: fTable
.getSelection()) {
2705 if (item
.getData() != null) {
2706 list
.add(item
.getData());
2709 return new StructuredSelection(list
);
2713 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2714 selectionChangedListeners
.remove(listener
);
2718 public void setSelection(ISelection selection
) {
2723 * Notifies any selection changed listeners that the viewer's selection has
2724 * changed. Only listeners registered at the time this method is called are
2728 * a selection changed event
2730 * @see ISelectionChangedListener#selectionChanged
2732 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
2733 Object
[] listeners
= selectionChangedListeners
.getListeners();
2734 for (int i
= 0; i
< listeners
.length
; ++i
) {
2735 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
2736 SafeRunnable
.run(new SafeRunnable() {
2739 l
.selectionChanged(event
);
2745 // ------------------------------------------------------------------------
2746 // Bookmark handling
2747 // ------------------------------------------------------------------------
2750 * Add a bookmark to this event table.
2752 * @param bookmarksFile
2753 * The file to use for the bookmarks
2755 public void addBookmark(final IFile bookmarksFile
) {
2756 fBookmarksFile
= bookmarksFile
;
2757 final TableItem
[] selection
= fTable
.getSelection();
2758 if (selection
.length
> 0) {
2759 final TableItem tableItem
= selection
[0];
2760 if (tableItem
.getData(Key
.RANK
) != null) {
2761 final StringBuffer defaultMessage
= new StringBuffer();
2762 for (int i
= 0; i
< fTable
.getColumns().length
; i
++) {
2764 defaultMessage
.append(", "); //$NON-NLS-1$
2766 defaultMessage
.append(tableItem
.getText(i
));
2768 final InputDialog dialog
= new MultiLineInputDialog(
2769 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
2770 Messages
.TmfEventsTable_AddBookmarkDialogTitle
,
2771 Messages
.TmfEventsTable_AddBookmarkDialogMessage
,
2772 defaultMessage
.toString());
2773 if (dialog
.open() == Window
.OK
) {
2774 final String message
= dialog
.getValue();
2776 final IMarker bookmark
= bookmarksFile
.createMarker(IMarker
.BOOKMARK
);
2777 if (bookmark
.exists()) {
2778 bookmark
.setAttribute(IMarker
.MESSAGE
, message
.toString());
2779 final Long rank
= (Long
) tableItem
.getData(Key
.RANK
);
2780 final int location
= rank
.intValue();
2781 bookmark
.setAttribute(IMarker
.LOCATION
, Integer
.valueOf(location
));
2782 fBookmarksMap
.put(rank
, bookmark
.getId());
2785 } catch (final CoreException e
) {
2786 displayException(e
);
2795 * Remove a bookmark from this event table.
2798 * The bookmark to remove
2800 public void removeBookmark(final IMarker bookmark
) {
2801 for (final Entry
<Long
, Long
> entry
: fBookmarksMap
.entries()) {
2802 if (entry
.getValue().equals(bookmark
.getId())) {
2803 fBookmarksMap
.remove(entry
.getKey(), entry
.getValue());
2810 private void toggleBookmark(final Long rank
) {
2811 if (fBookmarksFile
== null) {
2814 if (fBookmarksMap
.containsKey(rank
)) {
2815 final Collection
<Long
> markerIds
= fBookmarksMap
.removeAll(rank
);
2818 for (long markerId
: markerIds
) {
2819 final IMarker bookmark
= fBookmarksFile
.findMarker(markerId
);
2820 if (bookmark
!= null) {
2824 } catch (final CoreException e
) {
2825 displayException(e
);
2828 addBookmark(fBookmarksFile
);
2833 * Refresh the bookmarks assigned to this trace, from the contents of a
2836 * @param bookmarksFile
2837 * The bookmark file to use
2839 public void refreshBookmarks(final IFile bookmarksFile
) {
2840 fBookmarksFile
= bookmarksFile
;
2841 if (bookmarksFile
== null) {
2842 fBookmarksMap
.clear();
2847 fBookmarksMap
.clear();
2848 for (final IMarker bookmark
: bookmarksFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
2849 final int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
2850 if (location
!= -1) {
2851 final long rank
= location
;
2852 fBookmarksMap
.put(rank
, bookmark
.getId());
2856 } catch (final CoreException e
) {
2857 displayException(e
);
2862 public void gotoMarker(final IMarker marker
) {
2863 final int rank
= marker
.getAttribute(IMarker
.LOCATION
, -1);
2866 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2867 // +1 for top filter status row
2868 index
= fCache
.getFilteredEventIndex(rank
) + 1;
2869 } else if (rank
>= fTable
.getItemCount()) {
2870 fPendingGotoRank
= rank
;
2872 fSelectedRank
= rank
;
2873 fSelectedBeginRank
= fSelectedRank
;
2874 fTable
.setSelection(index
+ 1); // +1 for header row
2875 updateStatusLine(null);
2879 // ------------------------------------------------------------------------
2881 // ------------------------------------------------------------------------
2884 public void colorSettingsChanged(final ColorSetting
[] colorSettings
) {
2888 // ------------------------------------------------------------------------
2890 // ------------------------------------------------------------------------
2893 * Handler for the trace updated signal
2896 * The incoming signal
2899 public void traceUpdated(final TmfTraceUpdatedSignal signal
) {
2900 if ((signal
.getTrace() != fTrace
) || fTable
.isDisposed()) {
2903 // Perform the refresh on the UI thread
2904 Display
.getDefault().asyncExec(new Runnable() {
2907 if (!fTable
.isDisposed() && (fTrace
!= null)) {
2908 if (fTable
.getData(Key
.FILTER_OBJ
) == null) {
2909 /* +1 for header row */
2910 fTable
.setItemCount((int) fTrace
.getNbEvents() + 1);
2911 /* +1 for header row */
2912 if ((fPendingGotoRank
!= -1) && ((fPendingGotoRank
+ 1) < fTable
.getItemCount())) {
2913 /* +1 for header row */
2914 fTable
.setSelection((int) fPendingGotoRank
+ 1);
2915 fPendingGotoRank
= -1;
2916 updateStatusLine(null);
2919 startFilterThread();
2922 if (!fRawViewer
.isDisposed() && (fTrace
!= null)) {
2923 fRawViewer
.refreshEventCount();
2930 * Handler for the selection range signal.
2933 * The incoming signal
2937 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
2938 if ((signal
.getSource() != this) && (fTrace
!= null) && (!fTable
.isDisposed())) {
2941 * Create a request for one event that will be queued after other
2942 * ongoing requests. When this request is completed do the work to
2943 * select the actual event with the timestamp specified in the
2944 * signal. This procedure prevents the method fTrace.getRank() from
2945 * interfering and delaying ongoing requests.
2947 final TmfEventRequest subRequest
= new TmfEventRequest(ITmfEvent
.class,
2948 TmfTimeRange
.ETERNITY
, 0, 1, ExecutionType
.FOREGROUND
) {
2950 TmfTimestamp ts
= new TmfTimestamp(signal
.getBeginTime());
2953 public void handleData(final ITmfEvent event
) {
2954 super.handleData(event
);
2958 public void handleSuccess() {
2959 super.handleSuccess();
2960 if (fTrace
== null) {
2965 * Verify if the event is within the trace range and adjust
2968 ITmfTimestamp timestamp
= ts
;
2969 if (timestamp
.compareTo(fTrace
.getStartTime()) == -1) {
2970 timestamp
= fTrace
.getStartTime();
2972 if (timestamp
.compareTo(fTrace
.getEndTime()) == 1) {
2973 timestamp
= fTrace
.getEndTime();
2976 // Get the rank of the selected event in the table
2977 final ITmfContext context
= fTrace
.seekEvent(timestamp
);
2978 final long rank
= context
.getRank();
2981 PlatformUI
.getWorkbench().getDisplay().asyncExec(new Runnable() {
2984 // Return if table is disposed
2985 if (fTable
.isDisposed()) {
2989 fSelectedRank
= rank
;
2990 fSelectedBeginRank
= fSelectedRank
;
2991 int index
= (int) rank
;
2992 if (fTable
.getData(Key
.FILTER_OBJ
) != null) {
2993 /* +1 for top filter status row */
2994 index
= fCache
.getFilteredEventIndex(rank
) + 1;
2996 /* +1 for header row */
2997 fTable
.setSelection(index
+ 1);
2998 fRawViewer
.selectAndReveal(rank
);
2999 updateStatusLine(null);
3005 ((ITmfEventProvider
) fTrace
).sendRequest(subRequest
);
3009 // ------------------------------------------------------------------------
3011 // ------------------------------------------------------------------------
3014 * Display an exception in a message box
3019 private static void displayException(final Exception e
) {
3020 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
3021 mb
.setText(e
.getClass().getSimpleName());
3022 mb
.setMessage(e
.getMessage());
3029 public void refresh() {
3036 * Margin column for images and special text (e.g. collapse count)
3038 private static final class TmfMarginColumn
extends TmfEventTableColumn
{
3040 private static final @NonNull ITmfEventAspect MARGIN_ASPECT
= new ITmfEventAspect() {
3043 public String
getName() {
3044 return EMPTY_STRING
;
3048 public String
resolve(ITmfEvent event
) {
3049 if (!(event
instanceof CachedEvent
) || ((CachedEvent
) event
).repeatCount
== 0) {
3050 return EMPTY_STRING
;
3052 return "+" + ((CachedEvent
) event
).repeatCount
; //$NON-NLS-1$
3056 public String
getHelpText() {
3057 return EMPTY_STRING
;
3064 public TmfMarginColumn() {
3065 super(MARGIN_ASPECT
);