Commit | Line | Data |
---|---|---|
db4721fb | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2010, 2015 Ericsson |
db4721fb PT |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
baafe54c AM |
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) | |
ac44ef71 | 13 | * Ansgar Radermacher - Support navigation to model URIs (Bug 396956) |
f47ed727 | 14 | * Bernd Hufmann - Updated call site and model URI implementation |
baafe54c | 15 | * Alexandre Montplaisir - Update to new column API |
346ffed7 | 16 | * Matthew Khouzam - Add hide columns |
db4721fb PT |
17 | *******************************************************************************/ |
18 | ||
2bdf0193 | 19 | package org.eclipse.tracecompass.tmf.ui.viewers.events; |
db4721fb | 20 | |
5db5a3a4 AM |
21 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
22 | ||
60fb38b8 | 23 | import java.io.FileNotFoundException; |
db4721fb | 24 | import java.util.ArrayList; |
2db176a0 | 25 | import java.util.Collection; |
db4721fb | 26 | import java.util.HashMap; |
baafe54c | 27 | import java.util.LinkedList; |
db4721fb | 28 | import java.util.List; |
db4721fb | 29 | import java.util.Map.Entry; |
110d44a1 | 30 | import java.util.regex.Matcher; |
db4721fb PT |
31 | import java.util.regex.Pattern; |
32 | import java.util.regex.PatternSyntaxException; | |
33 | ||
d3de0920 XR |
34 | import org.eclipse.core.commands.Command; |
35 | import org.eclipse.core.commands.ExecutionException; | |
36 | import org.eclipse.core.commands.NotEnabledException; | |
37 | import org.eclipse.core.commands.NotHandledException; | |
38 | import org.eclipse.core.commands.ParameterizedCommand; | |
39 | import org.eclipse.core.commands.common.NotDefinedException; | |
40 | import org.eclipse.core.expressions.IEvaluationContext; | |
db4721fb PT |
41 | import org.eclipse.core.resources.IFile; |
42 | import org.eclipse.core.resources.IMarker; | |
43 | import org.eclipse.core.resources.IResource; | |
60fb38b8 | 44 | import org.eclipse.core.resources.IResourceVisitor; |
ac44ef71 | 45 | import org.eclipse.core.resources.ResourcesPlugin; |
db4721fb | 46 | import org.eclipse.core.runtime.CoreException; |
ac44ef71 | 47 | import org.eclipse.core.runtime.IPath; |
db4721fb PT |
48 | import org.eclipse.core.runtime.IProgressMonitor; |
49 | import org.eclipse.core.runtime.IStatus; | |
93bfd50a | 50 | import org.eclipse.core.runtime.ListenerList; |
ac44ef71 | 51 | import org.eclipse.core.runtime.Path; |
db4721fb PT |
52 | import org.eclipse.core.runtime.Status; |
53 | import org.eclipse.core.runtime.jobs.Job; | |
ac44ef71 AR |
54 | import org.eclipse.emf.common.util.URI; |
55 | import org.eclipse.emf.ecore.EValidator; | |
46671228 | 56 | import org.eclipse.jdt.annotation.NonNull; |
db4721fb PT |
57 | import org.eclipse.jface.action.Action; |
58 | import org.eclipse.jface.action.IAction; | |
59 | import org.eclipse.jface.action.IMenuListener; | |
60 | import org.eclipse.jface.action.IMenuManager; | |
3f43dc48 | 61 | import org.eclipse.jface.action.IStatusLineManager; |
db4721fb PT |
62 | import org.eclipse.jface.action.MenuManager; |
63 | import org.eclipse.jface.action.Separator; | |
64 | import org.eclipse.jface.dialogs.InputDialog; | |
65 | import org.eclipse.jface.dialogs.MessageDialog; | |
bb7c657f | 66 | import org.eclipse.jface.resource.ColorRegistry; |
812e7197 | 67 | import org.eclipse.jface.resource.FontRegistry; |
db4721fb PT |
68 | import org.eclipse.jface.resource.JFaceResources; |
69 | import org.eclipse.jface.resource.LocalResourceManager; | |
812e7197 | 70 | import org.eclipse.jface.util.IPropertyChangeListener; |
ac44ef71 | 71 | import org.eclipse.jface.util.OpenStrategy; |
812e7197 | 72 | import org.eclipse.jface.util.PropertyChangeEvent; |
93bfd50a | 73 | import org.eclipse.jface.util.SafeRunnable; |
60fb38b8 | 74 | import org.eclipse.jface.viewers.ArrayContentProvider; |
93bfd50a PT |
75 | import org.eclipse.jface.viewers.ISelection; |
76 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
77 | import org.eclipse.jface.viewers.ISelectionProvider; | |
60fb38b8 | 78 | import org.eclipse.jface.viewers.LabelProvider; |
93bfd50a PT |
79 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
80 | import org.eclipse.jface.viewers.StructuredSelection; | |
db4721fb | 81 | import org.eclipse.jface.window.Window; |
db4721fb PT |
82 | import org.eclipse.swt.SWT; |
83 | import org.eclipse.swt.custom.SashForm; | |
110d44a1 | 84 | import org.eclipse.swt.custom.StyleRange; |
db4721fb | 85 | import org.eclipse.swt.custom.TableEditor; |
6817308e PT |
86 | import org.eclipse.swt.events.ControlAdapter; |
87 | import org.eclipse.swt.events.ControlEvent; | |
db4721fb PT |
88 | import org.eclipse.swt.events.FocusAdapter; |
89 | import org.eclipse.swt.events.FocusEvent; | |
90 | import org.eclipse.swt.events.KeyAdapter; | |
91 | import org.eclipse.swt.events.KeyEvent; | |
92 | import org.eclipse.swt.events.MouseAdapter; | |
93 | import org.eclipse.swt.events.MouseEvent; | |
94 | import org.eclipse.swt.events.SelectionAdapter; | |
95 | import org.eclipse.swt.events.SelectionEvent; | |
96 | import org.eclipse.swt.graphics.Color; | |
97 | import org.eclipse.swt.graphics.Font; | |
110d44a1 | 98 | import org.eclipse.swt.graphics.GC; |
db4721fb PT |
99 | import org.eclipse.swt.graphics.Image; |
100 | import org.eclipse.swt.graphics.Point; | |
101 | import org.eclipse.swt.graphics.Rectangle; | |
102 | import org.eclipse.swt.layout.FillLayout; | |
103 | import org.eclipse.swt.layout.GridData; | |
104 | import org.eclipse.swt.layout.GridLayout; | |
105 | import org.eclipse.swt.widgets.Composite; | |
106 | import org.eclipse.swt.widgets.Display; | |
107 | import org.eclipse.swt.widgets.Event; | |
108 | import org.eclipse.swt.widgets.Label; | |
109 | import org.eclipse.swt.widgets.Listener; | |
110 | import org.eclipse.swt.widgets.Menu; | |
346ffed7 | 111 | import org.eclipse.swt.widgets.MenuItem; |
db4721fb PT |
112 | import org.eclipse.swt.widgets.MessageBox; |
113 | import org.eclipse.swt.widgets.Shell; | |
114 | import org.eclipse.swt.widgets.TableColumn; | |
115 | import org.eclipse.swt.widgets.TableItem; | |
116 | import org.eclipse.swt.widgets.Text; | |
6cfc180e | 117 | import org.eclipse.tracecompass.common.core.NonNullUtils; |
2bdf0193 AM |
118 | import org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter; |
119 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; | |
120 | import org.eclipse.tracecompass.internal.tmf.ui.Messages; | |
121 | import org.eclipse.tracecompass.internal.tmf.ui.commands.ExportToTextCommandHandler; | |
122 | import org.eclipse.tracecompass.internal.tmf.ui.dialogs.MultiLineInputDialog; | |
123 | import org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider; | |
124 | import org.eclipse.tracecompass.tmf.core.component.TmfComponent; | |
125 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
9447c7ee | 126 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
40dfafb3 | 127 | import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect; |
2bdf0193 AM |
128 | import org.eclipse.tracecompass.tmf.core.event.collapse.ITmfCollapsibleEvent; |
129 | import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite; | |
130 | import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup; | |
131 | import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup; | |
132 | import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter; | |
133 | import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode; | |
134 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode; | |
135 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode; | |
136 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode; | |
137 | import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType; | |
138 | import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest; | |
139 | import org.eclipse.tracecompass.tmf.core.signal.TmfEventFilterAppliedSignal; | |
140 | import org.eclipse.tracecompass.tmf.core.signal.TmfEventSearchAppliedSignal; | |
141 | import org.eclipse.tracecompass.tmf.core.signal.TmfEventSelectedSignal; | |
97c71024 | 142 | import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
bb7c657f | 143 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; |
2bdf0193 AM |
144 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceUpdatedSignal; |
145 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; | |
146 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; | |
147 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; | |
148 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
149 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
b04903a2 | 150 | import org.eclipse.tracecompass.tmf.core.trace.TmfTrace; |
2bdf0193 AM |
151 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; |
152 | import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation; | |
153 | import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsCache.CachedEvent; | |
154 | import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn; | |
2bdf0193 AM |
155 | import org.eclipse.tracecompass.tmf.ui.views.colors.ColorSetting; |
156 | import org.eclipse.tracecompass.tmf.ui.views.colors.ColorSettingsManager; | |
157 | import org.eclipse.tracecompass.tmf.ui.views.colors.IColorSettingsListener; | |
158 | import org.eclipse.tracecompass.tmf.ui.views.filter.FilterManager; | |
159 | import org.eclipse.tracecompass.tmf.ui.widgets.rawviewer.TmfRawEventViewer; | |
160 | import org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.TmfVirtualTable; | |
ac44ef71 | 161 | import org.eclipse.ui.IWorkbenchPage; |
db4721fb | 162 | import org.eclipse.ui.PlatformUI; |
d3de0920 | 163 | import org.eclipse.ui.commands.ICommandService; |
60fb38b8 | 164 | import org.eclipse.ui.dialogs.ListDialog; |
d3de0920 | 165 | import org.eclipse.ui.handlers.IHandlerService; |
ac44ef71 | 166 | import org.eclipse.ui.ide.IDE; |
db4721fb PT |
167 | import org.eclipse.ui.ide.IGotoMarker; |
168 | import org.eclipse.ui.themes.ColorUtil; | |
812e7197 | 169 | import org.eclipse.ui.themes.IThemeManager; |
db4721fb | 170 | |
2db176a0 PT |
171 | import com.google.common.base.Joiner; |
172 | import com.google.common.collect.HashMultimap; | |
baafe54c | 173 | import com.google.common.collect.ImmutableList; |
2db176a0 PT |
174 | import com.google.common.collect.Multimap; |
175 | ||
db4721fb PT |
176 | /** |
177 | * The generic TMF Events table | |
178 | * | |
179 | * This is a view that will list events that are read from a trace. | |
180 | * | |
db4721fb PT |
181 | * @author Francois Chouinard |
182 | * @author Patrick Tasse | |
183 | */ | |
812e7197 | 184 | public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorSettingsListener, ISelectionProvider, IPropertyChangeListener { |
db4721fb | 185 | |
cf37ad9f AM |
186 | /** |
187 | * Empty string array, used by {@link #getItemStrings}. | |
cf37ad9f | 188 | */ |
46671228 | 189 | protected static final @NonNull String[] EMPTY_STRING_ARRAY = new String[0]; |
cf37ad9f | 190 | |
baafe54c AM |
191 | /** |
192 | * Empty string | |
baafe54c AM |
193 | */ |
194 | protected static final @NonNull String EMPTY_STRING = ""; //$NON-NLS-1$ | |
195 | ||
03142470 BH |
196 | private static final boolean IS_LINUX = System.getProperty("os.name").contains("Linux") ? true : false; //$NON-NLS-1$ //$NON-NLS-2$ |
197 | ||
812e7197 | 198 | private static final String FONT_DEFINITION_ID = "org.eclipse.tracecompass.tmf.ui.font.eventtable"; //$NON-NLS-1$ |
bb7c657f | 199 | private static final String HIGHLIGHT_COLOR_DEFINITION_ID = "org.eclipse.tracecompass.tmf.ui.color.eventtable.highlight"; //$NON-NLS-1$ |
812e7197 | 200 | |
db4721fb PT |
201 | private static final Image BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath( |
202 | "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$ | |
203 | private static final Image SEARCH_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$ | |
204 | private static final Image SEARCH_MATCH_IMAGE = Activator.getDefault().getImageFromPath( | |
205 | "icons/elcl16/search_match.gif"); //$NON-NLS-1$ | |
206 | private static final Image SEARCH_MATCH_BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath( | |
207 | "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$ | |
8b7eb3cd | 208 | private static final Image FILTER_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$ |
db4721fb PT |
209 | private static final Image STOP_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$ |
210 | private static final String SEARCH_HINT = Messages.TmfEventsTable_SearchHint; | |
211 | private static final String FILTER_HINT = Messages.TmfEventsTable_FilterHint; | |
212 | private static final int MAX_CACHE_SIZE = 1000; | |
213 | ||
03142470 BH |
214 | private static final int MARGIN_COLUMN_INDEX = 0; |
215 | private static final int FILTER_SUMMARY_INDEX = 1; | |
216 | private static final int EVENT_COLUMNS_START_INDEX = MARGIN_COLUMN_INDEX + 1; | |
217 | ||
db4721fb | 218 | /** |
346ffed7 | 219 | * The events table search/filter/data keys |
db4721fb PT |
220 | * |
221 | * @version 1.0 | |
222 | * @author Patrick Tasse | |
223 | */ | |
224 | public interface Key { | |
225 | /** Search text */ | |
226 | String SEARCH_TXT = "$srch_txt"; //$NON-NLS-1$ | |
227 | ||
228 | /** Search object */ | |
229 | String SEARCH_OBJ = "$srch_obj"; //$NON-NLS-1$ | |
230 | ||
231 | /** Filter text */ | |
232 | String FILTER_TXT = "$fltr_txt"; //$NON-NLS-1$ | |
233 | ||
234 | /** Filter object */ | |
235 | String FILTER_OBJ = "$fltr_obj"; //$NON-NLS-1$ | |
236 | ||
dadf6e1a | 237 | /** Timestamp */ |
db4721fb PT |
238 | String TIMESTAMP = "$time"; //$NON-NLS-1$ |
239 | ||
240 | /** Rank */ | |
241 | String RANK = "$rank"; //$NON-NLS-1$ | |
242 | ||
db4721fb PT |
243 | /** Bookmark indicator */ |
244 | String BOOKMARK = "$bookmark"; //$NON-NLS-1$ | |
c409f16b AM |
245 | |
246 | /** Event aspect represented by this column */ | |
247 | String ASPECT = "$aspect"; //$NON-NLS-1$ | |
110d44a1 | 248 | |
8b7eb3cd MK |
249 | /** |
250 | * Table item list of style ranges | |
251 | * | |
252 | * @since 1.0 | |
253 | */ | |
110d44a1 | 254 | String STYLE_RANGES = "$style_ranges"; //$NON-NLS-1$ |
346ffed7 MK |
255 | |
256 | /** | |
257 | * The width of a table item | |
258 | * | |
259 | * @since 1.0 | |
260 | */ | |
261 | String WIDTH = "$width"; //$NON-NLS-1$ | |
db4721fb PT |
262 | } |
263 | ||
264 | /** | |
265 | * The events table search/filter state | |
266 | * | |
267 | * @version 1.0 | |
268 | * @author Patrick Tasse | |
269 | */ | |
270 | public static enum HeaderState { | |
271 | /** A search is being run */ | |
272 | SEARCH, | |
273 | ||
274 | /** A filter is applied */ | |
275 | FILTER | |
276 | } | |
277 | ||
278 | interface Direction { | |
279 | int FORWARD = +1; | |
280 | int BACKWARD = -1; | |
281 | } | |
282 | ||
283 | // ------------------------------------------------------------------------ | |
284 | // Table data | |
285 | // ------------------------------------------------------------------------ | |
286 | ||
a0a88f65 | 287 | /** The virtual event table */ |
db4721fb | 288 | protected TmfVirtualTable fTable; |
a0a88f65 AM |
289 | |
290 | private Composite fComposite; | |
291 | private SashForm fSashForm; | |
292 | private TmfRawEventViewer fRawViewer; | |
293 | private ITmfTrace fTrace; | |
574f43ad | 294 | private volatile boolean fPackDone = false; |
a0a88f65 AM |
295 | private HeaderState fHeaderState = HeaderState.SEARCH; |
296 | private long fSelectedRank = 0; | |
3f43dc48 PT |
297 | private ITmfTimestamp fSelectedBeginTimestamp = null; |
298 | private IStatusLineManager fStatusLineManager = null; | |
db4721fb PT |
299 | |
300 | // Filter data | |
a0a88f65 AM |
301 | private long fFilterMatchCount; |
302 | private long fFilterCheckCount; | |
303 | private FilterThread fFilterThread; | |
304 | private boolean fFilterThreadResume = false; | |
305 | private final Object fFilterSyncObj = new Object(); | |
306 | private SearchThread fSearchThread; | |
307 | private final Object fSearchSyncObj = new Object(); | |
db4721fb | 308 | |
93bfd50a | 309 | /** |
8b7eb3cd MK |
310 | * List of selection change listeners (element type: |
311 | * <code>ISelectionChangedListener</code>). | |
93bfd50a PT |
312 | * |
313 | * @see #fireSelectionChanged | |
314 | */ | |
315 | private ListenerList selectionChangedListeners = new ListenerList(); | |
316 | ||
db4721fb | 317 | // Bookmark map <Rank, MarkerId> |
2db176a0 | 318 | private Multimap<Long, Long> fBookmarksMap = HashMultimap.create(); |
a0a88f65 AM |
319 | private IFile fBookmarksFile; |
320 | private long fPendingGotoRank = -1; | |
db4721fb PT |
321 | |
322 | // SWT resources | |
a0a88f65 AM |
323 | private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources()); |
324 | private Color fGrayColor; | |
325 | private Color fGreenColor; | |
bb7c657f | 326 | private Color fHighlightColor; |
812e7197 | 327 | private Font fFont; |
a0a88f65 | 328 | private Font fBoldFont; |
db4721fb | 329 | |
baafe54c | 330 | private final List<TmfEventTableColumn> fColumns = new LinkedList<>(); |
db4721fb PT |
331 | |
332 | // Event cache | |
333 | private final TmfEventsCache fCache; | |
334 | private boolean fCacheUpdateBusy = false; | |
335 | private boolean fCacheUpdatePending = false; | |
336 | private boolean fCacheUpdateCompleted = false; | |
337 | private final Object fCacheUpdateSyncObj = new Object(); | |
338 | ||
14665360 PT |
339 | // Keep track of column order, it is needed after table is disposed |
340 | private int[] fColumnOrder; | |
341 | ||
db4721fb PT |
342 | private boolean fDisposeOnClose; |
343 | ||
346ffed7 MK |
344 | private Menu fHeaderMenu; |
345 | ||
346 | private Menu fTablePopup; | |
347 | ||
348 | private Menu fRawTablePopup; | |
349 | ||
db4721fb | 350 | // ------------------------------------------------------------------------ |
a0a88f65 | 351 | // Constructors |
db4721fb PT |
352 | // ------------------------------------------------------------------------ |
353 | ||
354 | /** | |
baafe54c | 355 | * Basic constructor, using the default set of columns |
db4721fb PT |
356 | * |
357 | * @param parent | |
358 | * The parent composite UI object | |
359 | * @param cacheSize | |
360 | * The size of the event table cache | |
361 | */ | |
362 | public TmfEventsTable(final Composite parent, final int cacheSize) { | |
b04903a2 | 363 | this(parent, cacheSize, TmfTrace.BASE_ASPECTS); |
db4721fb PT |
364 | } |
365 | ||
366 | /** | |
baafe54c | 367 | * Legacy constructor, using ColumnData to define columns |
db4721fb PT |
368 | * |
369 | * @param parent | |
370 | * The parent composite UI object | |
371 | * @param cacheSize | |
372 | * The size of the event table cache | |
373 | * @param columnData | |
40dfafb3 | 374 | * The column data array |
baafe54c AM |
375 | * @deprecated Deprecated constructor, use |
376 | * {@link #TmfEventsTable(Composite, int, Collection)} | |
377 | */ | |
378 | @Deprecated | |
379 | public TmfEventsTable(final Composite parent, int cacheSize, | |
2bdf0193 | 380 | final org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData[] columnData) { |
baafe54c AM |
381 | /* |
382 | * We'll do a "best-effort" to keep trace types still using this API to | |
8b7eb3cd MK |
383 | * keep working, by defining a TmfEventTableColumn for each ColumnData |
384 | * they passed. | |
baafe54c AM |
385 | */ |
386 | this(parent, cacheSize, convertFromColumnData(columnData)); | |
387 | } | |
388 | ||
389 | @Deprecated | |
8192209b | 390 | private static @NonNull Iterable<ITmfEventAspect> convertFromColumnData( |
2bdf0193 | 391 | org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData[] columnData) { |
baafe54c | 392 | |
b04903a2 | 393 | ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>(); |
2bdf0193 | 394 | for (org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData col : columnData) { |
9447c7ee AM |
395 | String fieldName = col.header; |
396 | if (fieldName != null) { | |
40dfafb3 | 397 | builder.add(new TmfContentFieldAspect(fieldName, fieldName)); |
baafe54c AM |
398 | } |
399 | } | |
5db5a3a4 | 400 | return checkNotNull(builder.build()); |
baafe54c AM |
401 | } |
402 | ||
403 | /** | |
404 | * Standard constructor, where we define which columns to use. | |
405 | * | |
406 | * @param parent | |
407 | * The parent composite UI object | |
408 | * @param cacheSize | |
409 | * The size of the event table cache | |
b04903a2 AM |
410 | * @param aspects |
411 | * The event aspects to display in this table. One column per | |
412 | * aspect will be created. | |
baafe54c AM |
413 | * <p> |
414 | * The iteration order of this collection will correspond to the | |
b04903a2 | 415 | * initial ordering of the columns in the table. |
baafe54c | 416 | * </p> |
db4721fb | 417 | */ |
baafe54c | 418 | public TmfEventsTable(final Composite parent, int cacheSize, |
8192209b | 419 | @NonNull Iterable<ITmfEventAspect> aspects) { |
db4721fb PT |
420 | super("TmfEventsTable"); //$NON-NLS-1$ |
421 | ||
422 | fComposite = new Composite(parent, SWT.NONE); | |
423 | final GridLayout gl = new GridLayout(1, false); | |
424 | gl.marginHeight = 0; | |
425 | gl.marginWidth = 0; | |
426 | gl.verticalSpacing = 0; | |
427 | fComposite.setLayout(gl); | |
428 | ||
429 | fSashForm = new SashForm(fComposite, SWT.HORIZONTAL); | |
430 | fSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
431 | ||
432 | // Create a virtual table | |
3f43dc48 | 433 | final int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION; |
db4721fb PT |
434 | fTable = new TmfVirtualTable(fSashForm, style); |
435 | ||
436 | // Set the table layout | |
437 | final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); | |
438 | fTable.setLayoutData(layoutData); | |
439 | ||
440 | // Some cosmetic enhancements | |
441 | fTable.setHeaderVisible(true); | |
442 | fTable.setLinesVisible(true); | |
443 | ||
baafe54c | 444 | // Setup the columns |
8192209b AM |
445 | for (ITmfEventAspect aspect : aspects) { |
446 | if (aspect != null) { | |
447 | fColumns.add(new TmfEventTableColumn(aspect)); | |
b04903a2 | 448 | } |
db4721fb PT |
449 | } |
450 | ||
03142470 BH |
451 | TmfMarginColumn collapseCol = new TmfMarginColumn(); |
452 | fColumns.add(MARGIN_COLUMN_INDEX, collapseCol); | |
453 | ||
346ffed7 | 454 | fHeaderMenu = new Menu(fTable); |
baafe54c | 455 | // Create the UI columns in the table |
2fcd5eea AM |
456 | for (TmfEventTableColumn col : fColumns) { |
457 | TableColumn column = fTable.newTableColumn(SWT.LEFT); | |
458 | column.setText(col.getHeaderName()); | |
459 | column.setToolTipText(col.getHeaderTooltip()); | |
c409f16b | 460 | column.setData(Key.ASPECT, col.getEventAspect()); |
2fcd5eea | 461 | column.pack(); |
03142470 BH |
462 | if (col instanceof TmfMarginColumn) { |
463 | column.setResizable(false); | |
6817308e PT |
464 | } else { |
465 | column.setMoveable(true); | |
346ffed7 | 466 | createHeaderMenuItem(fHeaderMenu, column); |
03142470 | 467 | } |
14665360 PT |
468 | column.addControlListener(new ControlAdapter() { |
469 | /* | |
8b7eb3cd MK |
470 | * Make sure that the margin column is always first and keep the |
471 | * column order variable up to date. | |
14665360 PT |
472 | */ |
473 | @Override | |
474 | public void controlMoved(ControlEvent e) { | |
475 | int[] order = fTable.getColumnOrder(); | |
476 | if (order[0] == MARGIN_COLUMN_INDEX) { | |
477 | fColumnOrder = order; | |
478 | return; | |
479 | } | |
480 | for (int i = order.length - 1; i > 0; i--) { | |
481 | if (order[i] == MARGIN_COLUMN_INDEX) { | |
482 | order[i] = order[i - 1]; | |
483 | order[i - 1] = MARGIN_COLUMN_INDEX; | |
484 | } | |
485 | } | |
486 | fTable.setColumnOrder(order); | |
487 | fColumnOrder = fTable.getColumnOrder(); | |
488 | } | |
489 | }); | |
2fcd5eea | 490 | } |
14665360 | 491 | fColumnOrder = fTable.getColumnOrder(); |
baafe54c | 492 | |
db4721fb PT |
493 | // Set the frozen row for header row |
494 | fTable.setFrozenRowCount(1); | |
495 | ||
496 | // Create the header row cell editor | |
497 | createHeaderEditor(); | |
498 | ||
499 | // Handle the table item selection | |
500 | fTable.addSelectionListener(new SelectionAdapter() { | |
501 | @Override | |
502 | public void widgetSelected(final SelectionEvent e) { | |
3f43dc48 PT |
503 | if (e.item == null) { |
504 | return; | |
505 | } | |
506 | updateStatusLine(null); | |
507 | if (fTable.getSelectionIndices().length > 0) { | |
508 | if (e.item.getData(Key.RANK) instanceof Long) { | |
509 | fSelectedRank = (Long) e.item.getData(Key.RANK); | |
510 | fRawViewer.selectAndReveal((Long) e.item.getData(Key.RANK)); | |
511 | } | |
512 | if (e.item.getData(Key.TIMESTAMP) instanceof ITmfTimestamp) { | |
6cfc180e | 513 | final ITmfTimestamp ts = NonNullUtils.checkNotNull((ITmfTimestamp) e.item.getData(Key.TIMESTAMP)); |
3f43dc48 PT |
514 | if (fTable.getSelectionIndices().length == 1) { |
515 | fSelectedBeginTimestamp = ts; | |
516 | } | |
6cfc180e GB |
517 | ITmfTimestamp selectedBeginTimestamp = fSelectedBeginTimestamp; |
518 | if (selectedBeginTimestamp != null) { | |
85203d74 PT |
519 | broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, selectedBeginTimestamp, ts)); |
520 | if (fTable.getSelectionIndices().length == 2) { | |
521 | updateStatusLine(ts.getDelta(selectedBeginTimestamp)); | |
3f43dc48 | 522 | } |
db4721fb | 523 | } |
3f43dc48 PT |
524 | } else { |
525 | if (fTable.getSelectionIndices().length == 1) { | |
526 | fSelectedBeginTimestamp = null; | |
db4721fb PT |
527 | } |
528 | } | |
529 | } | |
6b44794a MK |
530 | if (e.item.getData() instanceof ITmfEvent) { |
531 | broadcast(new TmfEventSelectedSignal(TmfEventsTable.this, (ITmfEvent) e.item.getData())); | |
3f43dc48 PT |
532 | fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, new StructuredSelection(e.item.getData()))); |
533 | } else { | |
534 | fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, StructuredSelection.EMPTY)); | |
535 | } | |
db4721fb PT |
536 | } |
537 | }); | |
538 | ||
41b5c37f AM |
539 | int realCacheSize = Math.max(cacheSize, Display.getDefault().getBounds().height / fTable.getItemHeight()); |
540 | realCacheSize = Math.min(realCacheSize, MAX_CACHE_SIZE); | |
541 | fCache = new TmfEventsCache(realCacheSize, this); | |
db4721fb PT |
542 | |
543 | // Handle the table item requests | |
544 | fTable.addListener(SWT.SetData, new Listener() { | |
545 | ||
546 | @Override | |
547 | public void handleEvent(final Event event) { | |
548 | ||
549 | final TableItem item = (TableItem) event.item; | |
550 | int index = event.index - 1; // -1 for the header row | |
551 | ||
552 | if (event.index == 0) { | |
553 | setHeaderRowItemData(item); | |
554 | return; | |
555 | } | |
556 | ||
557 | if (fTable.getData(Key.FILTER_OBJ) != null) { | |
558 | if ((event.index == 1) || (event.index == (fTable.getItemCount() - 1))) { | |
559 | setFilterStatusRowItemData(item); | |
560 | return; | |
561 | } | |
8b7eb3cd MK |
562 | /* -1 for top filter status row */ |
563 | index = index - 1; | |
db4721fb PT |
564 | } |
565 | ||
566 | final CachedEvent cachedEvent = fCache.getEvent(index); | |
567 | if (cachedEvent != null) { | |
03142470 | 568 | setItemData(item, cachedEvent, cachedEvent.rank); |
db4721fb PT |
569 | return; |
570 | } | |
571 | ||
572 | // Else, fill the cache asynchronously (and off the UI thread) | |
573 | event.doit = false; | |
574 | } | |
575 | }); | |
576 | ||
346ffed7 MK |
577 | fTable.addListener(SWT.MenuDetect, new Listener() { |
578 | @Override | |
579 | public void handleEvent(Event event) { | |
580 | Point pt = fTable.getDisplay().map(null, fTable, new Point(event.x, event.y)); | |
581 | Rectangle clientArea = fTable.getClientArea(); | |
582 | boolean header = clientArea.y <= pt.y && pt.y < (clientArea.y + fTable.getHeaderHeight()); | |
583 | fTable.setMenu(header ? fHeaderMenu : fTablePopup); | |
584 | } | |
585 | }); | |
586 | ||
db4721fb PT |
587 | fTable.addMouseListener(new MouseAdapter() { |
588 | @Override | |
589 | public void mouseDoubleClick(final MouseEvent event) { | |
590 | if (event.button != 1) { | |
591 | return; | |
592 | } | |
593 | // Identify the selected row | |
594 | final Point point = new Point(event.x, event.y); | |
595 | final TableItem item = fTable.getItem(point); | |
596 | if (item != null) { | |
597 | final Rectangle imageBounds = item.getImageBounds(0); | |
598 | imageBounds.width = BOOKMARK_IMAGE.getBounds().width; | |
599 | if (imageBounds.contains(point)) { | |
600 | final Long rank = (Long) item.getData(Key.RANK); | |
601 | if (rank != null) { | |
602 | toggleBookmark(rank); | |
603 | } | |
604 | } | |
605 | } | |
606 | } | |
607 | }); | |
608 | ||
8b7eb3cd | 609 | final Listener tooltipListener = new Listener() { |
db4721fb | 610 | Shell tooltipShell = null; |
8b7eb3cd | 611 | |
db4721fb PT |
612 | @Override |
613 | public void handleEvent(final Event event) { | |
614 | switch (event.type) { | |
8b7eb3cd MK |
615 | case SWT.MouseHover: |
616 | final TableItem item = fTable.getItem(new Point(event.x, event.y)); | |
617 | if (item == null) { | |
618 | return; | |
619 | } | |
620 | final Long rank = (Long) item.getData(Key.RANK); | |
621 | if (rank == null) { | |
622 | return; | |
623 | } | |
624 | final String tooltipText = (String) item.getData(Key.BOOKMARK); | |
625 | final Rectangle bounds = item.getImageBounds(0); | |
626 | bounds.width = BOOKMARK_IMAGE.getBounds().width; | |
627 | if (!bounds.contains(event.x, event.y)) { | |
628 | return; | |
629 | } | |
630 | if ((tooltipShell != null) && !tooltipShell.isDisposed()) { | |
631 | tooltipShell.dispose(); | |
632 | } | |
633 | tooltipShell = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); | |
634 | tooltipShell.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); | |
635 | final FillLayout layout = new FillLayout(); | |
636 | layout.marginWidth = 2; | |
637 | tooltipShell.setLayout(layout); | |
638 | final Label label = new Label(tooltipShell, SWT.WRAP); | |
639 | String text = rank.toString() + (tooltipText != null ? ": " + tooltipText : EMPTY_STRING); //$NON-NLS-1$ | |
640 | label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); | |
641 | label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); | |
642 | label.setText(text); | |
643 | label.addListener(SWT.MouseExit, this); | |
644 | label.addListener(SWT.MouseDown, this); | |
645 | label.addListener(SWT.MouseWheel, this); | |
646 | final Point size = tooltipShell.computeSize(SWT.DEFAULT, SWT.DEFAULT); | |
647 | /* | |
648 | * Bug in Linux. The coordinates of the event have an origin | |
649 | * that excludes the table header but the method toDisplay() | |
650 | * expects coordinates relative to an origin that includes | |
651 | * the table header. | |
652 | */ | |
653 | int y = event.y; | |
654 | if (IS_LINUX) { | |
655 | y += fTable.getHeaderHeight(); | |
656 | } | |
657 | Point pt = fTable.toDisplay(event.x, y); | |
658 | pt.x += BOOKMARK_IMAGE.getBounds().width; | |
659 | pt.y += item.getBounds().height; | |
660 | tooltipShell.setBounds(pt.x, pt.y, size.x, size.y); | |
661 | tooltipShell.setVisible(true); | |
662 | break; | |
663 | case SWT.Dispose: | |
664 | case SWT.KeyDown: | |
665 | case SWT.MouseMove: | |
666 | case SWT.MouseExit: | |
667 | case SWT.MouseDown: | |
668 | case SWT.MouseWheel: | |
669 | if (tooltipShell != null) { | |
670 | tooltipShell.dispose(); | |
671 | tooltipShell = null; | |
672 | } | |
673 | break; | |
674 | default: | |
675 | break; | |
db4721fb PT |
676 | } |
677 | } | |
678 | }; | |
679 | ||
680 | fTable.addListener(SWT.MouseHover, tooltipListener); | |
681 | fTable.addListener(SWT.Dispose, tooltipListener); | |
682 | fTable.addListener(SWT.KeyDown, tooltipListener); | |
683 | fTable.addListener(SWT.MouseMove, tooltipListener); | |
684 | fTable.addListener(SWT.MouseExit, tooltipListener); | |
685 | fTable.addListener(SWT.MouseDown, tooltipListener); | |
686 | fTable.addListener(SWT.MouseWheel, tooltipListener); | |
687 | ||
110d44a1 PT |
688 | fTable.addListener(SWT.EraseItem, new Listener() { |
689 | @Override | |
690 | public void handleEvent(Event event) { | |
691 | TableItem item = (TableItem) event.item; | |
692 | List<?> styleRanges = (List<?>) item.getData(Key.STYLE_RANGES); | |
693 | ||
694 | GC gc = event.gc; | |
695 | Color background = item.getBackground(event.index); | |
696 | /* | |
697 | * Paint the background if it is not the default system color. | |
698 | * In Windows, if you let the widget draw the background, it | |
699 | * will not show the item's background color if the item is | |
700 | * selected or hot. If there are no style ranges and the item | |
701 | * background is the default system color, we do not want to | |
702 | * paint it or otherwise we would override the platform theme | |
703 | * (e.g. alternating colors). | |
704 | */ | |
4c27e423 | 705 | if (styleRanges != null || !background.equals(item.getParent().getBackground())) { |
110d44a1 PT |
706 | // we will paint the table item's background |
707 | event.detail &= ~SWT.BACKGROUND; | |
708 | ||
709 | // paint the item's default background | |
710 | gc.setBackground(background); | |
711 | gc.fillRectangle(event.x, event.y, event.width, event.height); | |
712 | } | |
713 | ||
714 | /* | |
8b7eb3cd MK |
715 | * We will paint the table item's foreground. In Windows, if you |
716 | * paint the background but let the widget draw the foreground, | |
717 | * it will override your background, unless the item is selected | |
718 | * or hot. | |
110d44a1 PT |
719 | */ |
720 | event.detail &= ~SWT.FOREGROUND; | |
721 | ||
722 | // paint the highlighted background for all style ranges | |
723 | if (styleRanges != null) { | |
724 | Rectangle textBounds = item.getTextBounds(event.index); | |
725 | String text = item.getText(event.index); | |
726 | for (Object o : styleRanges) { | |
727 | if (o instanceof StyleRange) { | |
728 | StyleRange styleRange = (StyleRange) o; | |
729 | if (styleRange.data.equals(event.index)) { | |
730 | int startIndex = styleRange.start; | |
731 | int endIndex = startIndex + styleRange.length; | |
732 | int startX = gc.stringExtent(text.substring(0, startIndex)).x; | |
733 | int endX = gc.stringExtent(text.substring(0, endIndex)).x; | |
734 | gc.setBackground(styleRange.background); | |
735 | gc.fillRectangle(textBounds.x + startX, textBounds.y, (endX - startX), textBounds.height); | |
736 | } | |
737 | } | |
738 | } | |
739 | } | |
740 | } | |
741 | }); | |
742 | ||
743 | fTable.addListener(SWT.PaintItem, new Listener() { | |
744 | @Override | |
745 | public void handleEvent(Event event) { | |
746 | TableItem item = (TableItem) event.item; | |
747 | ||
748 | // we promised to paint the table item's foreground | |
749 | GC gc = event.gc; | |
750 | Image image = item.getImage(event.index); | |
751 | if (image != null) { | |
752 | Rectangle imageBounds = item.getImageBounds(event.index); | |
753 | /* | |
754 | * The image bounds don't match the default image position. | |
755 | */ | |
4c27e423 PT |
756 | if (IS_LINUX) { |
757 | gc.drawImage(image, imageBounds.x + 1, imageBounds.y + 3); | |
758 | } else { | |
759 | gc.drawImage(image, imageBounds.x, imageBounds.y + 1); | |
760 | } | |
110d44a1 PT |
761 | } |
762 | gc.setForeground(item.getForeground(event.index)); | |
763 | gc.setFont(item.getFont(event.index)); | |
764 | String text = item.getText(event.index); | |
765 | Rectangle textBounds = item.getTextBounds(event.index); | |
766 | /* | |
767 | * The text bounds don't match the default text position. | |
768 | */ | |
4c27e423 PT |
769 | if (IS_LINUX) { |
770 | gc.drawText(text, textBounds.x + 1, textBounds.y + 3, true); | |
771 | } else { | |
772 | gc.drawText(text, textBounds.x - 1, textBounds.y + 2, true); | |
773 | } | |
110d44a1 PT |
774 | } |
775 | }); | |
776 | ||
db4721fb PT |
777 | // Create resources |
778 | createResources(); | |
779 | ||
812e7197 | 780 | initializeFonts(); |
bb7c657f | 781 | initializeColors(); |
812e7197 PT |
782 | PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(this); |
783 | ||
db4721fb PT |
784 | ColorSettingsManager.addColorSettingsListener(this); |
785 | ||
786 | fTable.setItemCount(1); // +1 for header row | |
787 | ||
788 | fRawViewer = new TmfRawEventViewer(fSashForm, SWT.H_SCROLL | SWT.V_SCROLL); | |
789 | ||
790 | fRawViewer.addSelectionListener(new Listener() { | |
791 | @Override | |
792 | public void handleEvent(final Event e) { | |
793 | if (e.data instanceof Long) { | |
794 | final long rank = (Long) e.data; | |
795 | int index = (int) rank; | |
796 | if (fTable.getData(Key.FILTER_OBJ) != null) { | |
8b7eb3cd MK |
797 | // +1 for top filter status row |
798 | index = fCache.getFilteredEventIndex(rank) + 1; | |
db4721fb | 799 | } |
8b7eb3cd MK |
800 | // +1 for header row |
801 | fTable.setSelection(index + 1); | |
db4721fb | 802 | fSelectedRank = rank; |
3f43dc48 | 803 | updateStatusLine(null); |
1e1bef82 | 804 | } else if (e.data instanceof ITmfLocation) { |
8b7eb3cd MK |
805 | /** |
806 | * DOES NOT WORK: rank undefined in context from | |
807 | * seekLocation() <code> | |
808 | * ITmfLocation<?> location = (ITmfLocation<?>) e.data; | |
809 | * TmfContext context = fTrace.seekLocation(location); | |
810 | * fTable.setSelection((int) context.getRank()); | |
811 | * </code> | |
812 | */ | |
db4721fb PT |
813 | return; |
814 | } else { | |
815 | return; | |
816 | } | |
817 | final TableItem[] selection = fTable.getSelection(); | |
818 | if ((selection != null) && (selection.length > 0)) { | |
476a18ba PT |
819 | TableItem item = fTable.getSelection()[0]; |
820 | final TmfTimestamp ts = (TmfTimestamp) item.getData(Key.TIMESTAMP); | |
db4721fb | 821 | if (ts != null) { |
97c71024 | 822 | broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, ts)); |
db4721fb | 823 | } |
476a18ba PT |
824 | if (item.getData() instanceof ITmfEvent) { |
825 | broadcast(new TmfEventSelectedSignal(TmfEventsTable.this, (ITmfEvent) item.getData())); | |
826 | fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, new StructuredSelection(item.getData()))); | |
827 | } else { | |
828 | fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, StructuredSelection.EMPTY)); | |
829 | } | |
db4721fb PT |
830 | } |
831 | } | |
832 | }); | |
833 | ||
834 | fSashForm.setWeights(new int[] { 1, 1 }); | |
835 | fRawViewer.setVisible(false); | |
836 | ||
837 | createPopupMenu(); | |
838 | } | |
839 | ||
346ffed7 MK |
840 | /** |
841 | * Checked menu creator to make columns visible or not. | |
842 | * | |
843 | * @param parent | |
844 | * the parent menu | |
845 | * @param column | |
846 | * the column | |
847 | */ | |
848 | private static void createHeaderMenuItem(Menu parent, final TableColumn column) { | |
849 | final MenuItem columnMenuItem = new MenuItem(parent, SWT.CHECK); | |
850 | columnMenuItem.setText(column.getText()); | |
851 | columnMenuItem.setSelection(column.getResizable()); | |
852 | columnMenuItem.addSelectionListener(new SelectionAdapter() { | |
853 | @Override | |
854 | public void widgetSelected(SelectionEvent e) { | |
855 | if (columnMenuItem.getSelection()) { | |
856 | column.setWidth((int) column.getData(Key.WIDTH)); | |
857 | column.setResizable(true); | |
858 | } else { | |
859 | column.setData(Key.WIDTH, column.getWidth()); | |
860 | column.setWidth(0); | |
861 | column.setResizable(false); | |
862 | } | |
863 | } | |
864 | }); | |
865 | } | |
866 | ||
867 | private void createResetHeaderMenuItem() { | |
868 | final MenuItem resetMenu = new MenuItem(fHeaderMenu, SWT.PUSH); | |
869 | resetMenu.setText(Messages.TmfEventsTable_showAll); | |
870 | resetMenu.addSelectionListener(new SelectionAdapter() { | |
871 | @Override | |
872 | public void widgetSelected(SelectionEvent e) { | |
873 | for (TableColumn column : fTable.getColumns()) { | |
874 | final Object widthVal = column.getData(Key.WIDTH); | |
875 | if (widthVal instanceof Integer) { | |
876 | Integer width = (Integer) widthVal; | |
877 | if (!column.getResizable()) { | |
878 | column.setWidth(width); | |
879 | column.setResizable(true); | |
880 | /* | |
881 | * This is because Linux always resizes the last | |
882 | * column to fill in the void, this means that | |
883 | * hiding a column resizes others and we can have 10 | |
884 | * columns that are 1000 pixels wide by hiding the | |
885 | * last one progressively. | |
886 | */ | |
887 | if (IS_LINUX) { | |
888 | column.pack(); | |
889 | } | |
890 | } | |
891 | } | |
892 | } | |
893 | for (MenuItem menuItem : fHeaderMenu.getItems()) { | |
894 | menuItem.setSelection(true); | |
895 | } | |
896 | ||
897 | } | |
898 | }); | |
899 | } | |
900 | ||
baafe54c AM |
901 | // ------------------------------------------------------------------------ |
902 | // Operations | |
903 | // ------------------------------------------------------------------------ | |
904 | ||
a0a88f65 AM |
905 | /** |
906 | * Create a pop-up menu. | |
907 | */ | |
a890f499 | 908 | private void createPopupMenu() { |
346ffed7 | 909 | createResetHeaderMenuItem(); |
db4721fb PT |
910 | final IAction showTableAction = new Action(Messages.TmfEventsTable_ShowTableActionText) { |
911 | @Override | |
912 | public void run() { | |
913 | fTable.setVisible(true); | |
914 | fSashForm.layout(); | |
915 | } | |
916 | }; | |
917 | ||
918 | final IAction hideTableAction = new Action(Messages.TmfEventsTable_HideTableActionText) { | |
919 | @Override | |
920 | public void run() { | |
921 | fTable.setVisible(false); | |
922 | fSashForm.layout(); | |
923 | } | |
924 | }; | |
925 | ||
926 | final IAction showRawAction = new Action(Messages.TmfEventsTable_ShowRawActionText) { | |
927 | @Override | |
928 | public void run() { | |
929 | fRawViewer.setVisible(true); | |
930 | fSashForm.layout(); | |
931 | final int index = fTable.getSelectionIndex(); | |
dadf6e1a | 932 | if (index >= 1) { |
db4721fb PT |
933 | fRawViewer.selectAndReveal(index - 1); |
934 | } | |
935 | } | |
936 | }; | |
937 | ||
938 | final IAction hideRawAction = new Action(Messages.TmfEventsTable_HideRawActionText) { | |
939 | @Override | |
940 | public void run() { | |
941 | fRawViewer.setVisible(false); | |
942 | fSashForm.layout(); | |
943 | } | |
944 | }; | |
945 | ||
029df6e3 | 946 | final IAction openCallsiteAction = new Action(Messages.TmfEventsTable_OpenSourceCodeActionText) { |
60fb38b8 PT |
947 | @Override |
948 | public void run() { | |
949 | final TableItem items[] = fTable.getSelection(); | |
950 | if (items.length != 1) { | |
951 | return; | |
952 | } | |
953 | final TableItem item = items[0]; | |
954 | ||
955 | final Object data = item.getData(); | |
f47ed727 BH |
956 | if (data instanceof ITmfSourceLookup) { |
957 | ITmfSourceLookup event = (ITmfSourceLookup) data; | |
958 | ITmfCallsite cs = event.getCallsite(); | |
60fb38b8 PT |
959 | if (cs == null || cs.getFileName() == null) { |
960 | return; | |
961 | } | |
962 | IMarker marker = null; | |
963 | try { | |
964 | String fileName = cs.getFileName(); | |
03142470 | 965 | final String trimmedPath = fileName.replaceAll("\\.\\./", EMPTY_STRING); //$NON-NLS-1$ |
507b1336 | 966 | final ArrayList<IFile> files = new ArrayList<>(); |
60fb38b8 PT |
967 | ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() { |
968 | @Override | |
969 | public boolean visit(IResource resource) throws CoreException { | |
970 | if (resource instanceof IFile && resource.getFullPath().toString().endsWith(trimmedPath)) { | |
971 | files.add((IFile) resource); | |
972 | } | |
973 | return true; | |
974 | } | |
975 | }); | |
976 | IFile file = null; | |
977 | if (files.size() > 1) { | |
978 | ListDialog dialog = new ListDialog(getTable().getShell()); | |
979 | dialog.setContentProvider(ArrayContentProvider.getInstance()); | |
980 | dialog.setLabelProvider(new LabelProvider() { | |
981 | @Override | |
982 | public String getText(Object element) { | |
983 | return ((IFile) element).getFullPath().toString(); | |
984 | } | |
985 | }); | |
986 | dialog.setInput(files); | |
029df6e3 JCK |
987 | dialog.setTitle(Messages.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle); |
988 | dialog.setMessage(Messages.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle + '\n' + cs.toString()); | |
60fb38b8 PT |
989 | dialog.open(); |
990 | Object[] result = dialog.getResult(); | |
991 | if (result != null && result.length > 0) { | |
992 | file = (IFile) result[0]; | |
993 | } | |
994 | } else if (files.size() == 1) { | |
995 | file = files.get(0); | |
996 | } | |
997 | if (file != null) { | |
998 | marker = file.createMarker(IMarker.MARKER); | |
999 | marker.setAttribute(IMarker.LINE_NUMBER, Long.valueOf(cs.getLineNumber()).intValue()); | |
1000 | IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker); | |
1001 | marker.delete(); | |
8b7eb3cd | 1002 | } else if (files.size() == 0) { |
029df6e3 | 1003 | displayException(new FileNotFoundException('\'' + cs.toString() + '\'' + '\n' + Messages.TmfEventsTable_OpenSourceCodeNotFound)); |
60fb38b8 | 1004 | } |
60fb38b8 | 1005 | } catch (CoreException e) { |
8e95e814 | 1006 | displayException(e); |
60fb38b8 PT |
1007 | } |
1008 | } | |
1009 | } | |
1010 | }; | |
1011 | ||
1012 | final IAction openModelAction = new Action(Messages.TmfEventsTable_OpenModelActionText) { | |
ac44ef71 AR |
1013 | @Override |
1014 | public void run() { | |
1015 | ||
1016 | final TableItem items[] = fTable.getSelection(); | |
1017 | if (items.length != 1) { | |
1018 | return; | |
1019 | } | |
1020 | final TableItem item = items[0]; | |
1021 | ||
1022 | final Object eventData = item.getData(); | |
f47ed727 BH |
1023 | if (eventData instanceof ITmfModelLookup) { |
1024 | String modelURI = ((ITmfModelLookup) eventData).getModelUri(); | |
ac44ef71 AR |
1025 | |
1026 | if (modelURI != null) { | |
1027 | IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
1028 | ||
1029 | IFile file = null; | |
1030 | final URI uri = URI.createURI(modelURI); | |
1031 | if (uri.isPlatformResource()) { | |
1032 | IPath path = new Path(uri.toPlatformString(true)); | |
1033 | file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); | |
1034 | } else if (uri.isFile() && !uri.isRelative()) { | |
1035 | file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( | |
1036 | new Path(uri.toFileString())); | |
1037 | } | |
1038 | ||
1039 | if (file != null) { | |
1040 | try { | |
1041 | /* | |
1042 | * create a temporary validation marker on the | |
1043 | * model file, remove it afterwards thus, | |
1044 | * navigation works with all model editors | |
1045 | * supporting the navigation to a marker | |
1046 | */ | |
1047 | IMarker marker = file.createMarker(EValidator.MARKER); | |
1048 | marker.setAttribute(EValidator.URI_ATTRIBUTE, modelURI); | |
1049 | marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); | |
1050 | ||
1051 | IDE.openEditor(activePage, marker, OpenStrategy.activateOnOpen()); | |
1052 | marker.delete(); | |
8b7eb3cd | 1053 | } catch (CoreException e) { |
ac44ef71 AR |
1054 | displayException(e); |
1055 | } | |
60fb38b8 PT |
1056 | } else { |
1057 | displayException(new FileNotFoundException('\'' + modelURI + '\'' + '\n' + Messages.TmfEventsTable_OpenModelUnsupportedURI)); | |
ac44ef71 AR |
1058 | } |
1059 | } | |
1060 | } | |
1061 | } | |
1062 | }; | |
60fb38b8 | 1063 | |
d3de0920 XR |
1064 | final IAction exportToTextAction = new Action(Messages.TmfEventsTable_Export_to_text) { |
1065 | @Override | |
1066 | public void run() { | |
1067 | IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
346fa221 MAL |
1068 | Object handlerServiceObject = activePage.getActiveEditor().getSite().getService(IHandlerService.class); |
1069 | IHandlerService handlerService = (IHandlerService) handlerServiceObject; | |
1070 | Object cmdServiceObject = activePage.getActiveEditor().getSite().getService(ICommandService.class); | |
1071 | ICommandService cmdService = (ICommandService) cmdServiceObject; | |
d3de0920 | 1072 | try { |
507b1336 | 1073 | HashMap<String, Object> parameters = new HashMap<>(); |
d3de0920 | 1074 | Command command = cmdService.getCommand(ExportToTextCommandHandler.COMMAND_ID); |
03142470 BH |
1075 | ParameterizedCommand cmd = ParameterizedCommand.generateCommand(command, parameters); |
1076 | ||
d3de0920 | 1077 | IEvaluationContext context = handlerService.getCurrentState(); |
6817308e PT |
1078 | List<TmfEventTableColumn> exportColumns = new ArrayList<>(); |
1079 | for (int i : fTable.getColumnOrder()) { | |
1080 | // Omit the margin column | |
1081 | if (i >= EVENT_COLUMNS_START_INDEX) { | |
1082 | exportColumns.add(fColumns.get(i)); | |
1083 | } | |
1084 | } | |
03142470 BH |
1085 | context.addVariable(ExportToTextCommandHandler.TMF_EVENT_TABLE_COLUMNS_ID, exportColumns); |
1086 | ||
d3de0920 | 1087 | handlerService.executeCommandInContext(cmd, null, context); |
23c625f1 | 1088 | } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { |
d3de0920 XR |
1089 | displayException(e); |
1090 | } | |
1091 | } | |
1092 | }; | |
1093 | ||
db4721fb PT |
1094 | final IAction showSearchBarAction = new Action(Messages.TmfEventsTable_ShowSearchBarActionText) { |
1095 | @Override | |
1096 | public void run() { | |
1097 | fHeaderState = HeaderState.SEARCH; | |
1098 | fTable.refresh(); | |
110d44a1 | 1099 | fTable.redraw(); |
db4721fb PT |
1100 | } |
1101 | }; | |
1102 | ||
1103 | final IAction showFilterBarAction = new Action(Messages.TmfEventsTable_ShowFilterBarActionText) { | |
1104 | @Override | |
1105 | public void run() { | |
1106 | fHeaderState = HeaderState.FILTER; | |
1107 | fTable.refresh(); | |
110d44a1 | 1108 | fTable.redraw(); |
db4721fb PT |
1109 | } |
1110 | }; | |
1111 | ||
1112 | final IAction clearFiltersAction = new Action(Messages.TmfEventsTable_ClearFiltersActionText) { | |
1113 | @Override | |
1114 | public void run() { | |
1115 | clearFilters(); | |
1116 | } | |
1117 | }; | |
1118 | ||
03142470 BH |
1119 | final IAction collapseAction = new Action(Messages.TmfEventsTable_CollapseFilterMenuName) { |
1120 | @Override | |
1121 | public void run() { | |
1122 | applyFilter(new TmfCollapseFilter()); | |
1123 | } | |
1124 | }; | |
1125 | ||
db4721fb | 1126 | class ToggleBookmarkAction extends Action { |
0126a8ca | 1127 | Long fRank; |
db4721fb | 1128 | |
0126a8ca | 1129 | public ToggleBookmarkAction(final String text, final Long rank) { |
db4721fb PT |
1130 | super(text); |
1131 | fRank = rank; | |
1132 | } | |
1133 | ||
1134 | @Override | |
1135 | public void run() { | |
1136 | toggleBookmark(fRank); | |
1137 | } | |
1138 | } | |
1139 | ||
1140 | final MenuManager tablePopupMenu = new MenuManager(); | |
1141 | tablePopupMenu.setRemoveAllWhenShown(true); | |
1142 | tablePopupMenu.addMenuListener(new IMenuListener() { | |
1143 | @Override | |
1144 | public void menuAboutToShow(final IMenuManager manager) { | |
1145 | if (fTable.getSelectionIndex() == 0) { | |
1146 | // Right-click on header row | |
1147 | if (fHeaderState == HeaderState.FILTER) { | |
1148 | tablePopupMenu.add(showSearchBarAction); | |
1149 | } else { | |
1150 | tablePopupMenu.add(showFilterBarAction); | |
1151 | } | |
1152 | return; | |
1153 | } | |
1154 | final Point point = fTable.toControl(Display.getDefault().getCursorLocation()); | |
1155 | final TableItem item = fTable.getSelection().length > 0 ? fTable.getSelection()[0] : null; | |
1156 | if (item != null) { | |
1157 | final Rectangle imageBounds = item.getImageBounds(0); | |
1158 | imageBounds.width = BOOKMARK_IMAGE.getBounds().width; | |
1159 | if (point.x <= (imageBounds.x + imageBounds.width)) { | |
1160 | // Right-click on left margin | |
1161 | final Long rank = (Long) item.getData(Key.RANK); | |
1162 | if ((rank != null) && (fBookmarksFile != null)) { | |
1163 | if (fBookmarksMap.containsKey(rank)) { | |
1164 | tablePopupMenu.add(new ToggleBookmarkAction( | |
1165 | Messages.TmfEventsTable_RemoveBookmarkActionText, rank)); | |
1166 | } else { | |
1167 | tablePopupMenu.add(new ToggleBookmarkAction( | |
1168 | Messages.TmfEventsTable_AddBookmarkActionText, rank)); | |
1169 | } | |
1170 | } | |
1171 | return; | |
1172 | } | |
1173 | } | |
60fb38b8 | 1174 | |
db4721fb PT |
1175 | // Right-click on table |
1176 | if (fTable.isVisible() && fRawViewer.isVisible()) { | |
1177 | tablePopupMenu.add(hideTableAction); | |
1178 | tablePopupMenu.add(hideRawAction); | |
1179 | } else if (!fTable.isVisible()) { | |
1180 | tablePopupMenu.add(showTableAction); | |
1181 | } else if (!fRawViewer.isVisible()) { | |
1182 | tablePopupMenu.add(showRawAction); | |
1183 | } | |
d3de0920 | 1184 | tablePopupMenu.add(exportToTextAction); |
db4721fb | 1185 | tablePopupMenu.add(new Separator()); |
60fb38b8 | 1186 | |
ac44ef71 | 1187 | if (item != null) { |
60fb38b8 | 1188 | final Object data = item.getData(); |
f47ed727 BH |
1189 | Separator separator = null; |
1190 | if (data instanceof ITmfSourceLookup) { | |
1191 | ITmfSourceLookup event = (ITmfSourceLookup) data; | |
60fb38b8 PT |
1192 | if (event.getCallsite() != null) { |
1193 | tablePopupMenu.add(openCallsiteAction); | |
1194 | separator = new Separator(); | |
1195 | } | |
f47ed727 BH |
1196 | } |
1197 | ||
1198 | if (data instanceof ITmfModelLookup) { | |
1199 | ITmfModelLookup event = (ITmfModelLookup) data; | |
1200 | if (event.getModelUri() != null) { | |
60fb38b8 PT |
1201 | tablePopupMenu.add(openModelAction); |
1202 | separator = new Separator(); | |
1203 | } | |
f47ed727 | 1204 | |
60fb38b8 PT |
1205 | if (separator != null) { |
1206 | tablePopupMenu.add(separator); | |
ac44ef71 AR |
1207 | } |
1208 | } | |
1209 | } | |
60fb38b8 | 1210 | |
8b7eb3cd MK |
1211 | /* |
1212 | * Only show collapse filter if at least one trace can be | |
1213 | * collapsed. | |
1214 | */ | |
03142470 BH |
1215 | boolean isCollapsible = false; |
1216 | if (fTrace != null) { | |
c14c0757 | 1217 | for (ITmfTrace trace : TmfTraceManager.getTraceSet(fTrace)) { |
8b7eb3cd | 1218 | Class<? extends ITmfEvent> eventClass = trace.getEventType(); |
03142470 BH |
1219 | isCollapsible = ITmfCollapsibleEvent.class.isAssignableFrom(eventClass); |
1220 | if (isCollapsible) { | |
1221 | break; | |
1222 | } | |
1223 | } | |
1224 | } | |
1225 | ||
1226 | if (isCollapsible && !(fTable.getData(Key.FILTER_OBJ) instanceof TmfCollapseFilter)) { | |
1227 | tablePopupMenu.add(collapseAction); | |
1228 | tablePopupMenu.add(new Separator()); | |
1229 | } | |
1230 | ||
db4721fb PT |
1231 | tablePopupMenu.add(clearFiltersAction); |
1232 | final ITmfFilterTreeNode[] savedFilters = FilterManager.getSavedFilters(); | |
1233 | if (savedFilters.length > 0) { | |
1234 | final MenuManager subMenu = new MenuManager(Messages.TmfEventsTable_ApplyPresetFilterMenuName); | |
1235 | for (final ITmfFilterTreeNode node : savedFilters) { | |
1236 | if (node instanceof TmfFilterNode) { | |
1237 | final TmfFilterNode filter = (TmfFilterNode) node; | |
1238 | subMenu.add(new Action(filter.getFilterName()) { | |
1239 | @Override | |
1240 | public void run() { | |
1241 | applyFilter(filter); | |
1242 | } | |
1243 | }); | |
1244 | } | |
1245 | } | |
1246 | tablePopupMenu.add(subMenu); | |
1247 | } | |
1248 | appendToTablePopupMenu(tablePopupMenu, item); | |
1249 | } | |
1250 | }); | |
1251 | ||
1252 | final MenuManager rawViewerPopupMenu = new MenuManager(); | |
1253 | rawViewerPopupMenu.setRemoveAllWhenShown(true); | |
1254 | rawViewerPopupMenu.addMenuListener(new IMenuListener() { | |
1255 | @Override | |
1256 | public void menuAboutToShow(final IMenuManager manager) { | |
1257 | if (fTable.isVisible() && fRawViewer.isVisible()) { | |
1258 | rawViewerPopupMenu.add(hideTableAction); | |
1259 | rawViewerPopupMenu.add(hideRawAction); | |
1260 | } else if (!fTable.isVisible()) { | |
1261 | rawViewerPopupMenu.add(showTableAction); | |
1262 | } else if (!fRawViewer.isVisible()) { | |
1263 | rawViewerPopupMenu.add(showRawAction); | |
1264 | } | |
1265 | appendToRawPopupMenu(tablePopupMenu); | |
1266 | } | |
1267 | }); | |
1268 | ||
346ffed7 MK |
1269 | fTablePopup = tablePopupMenu.createContextMenu(fTable); |
1270 | fTable.setMenu(fTablePopup); | |
db4721fb | 1271 | |
346ffed7 MK |
1272 | fRawTablePopup = rawViewerPopupMenu.createContextMenu(fRawViewer); |
1273 | fRawViewer.setMenu(fRawTablePopup); | |
db4721fb PT |
1274 | } |
1275 | ||
a0a88f65 AM |
1276 | /** |
1277 | * Append an item to the event table's pop-up menu. | |
1278 | * | |
1279 | * @param tablePopupMenu | |
1280 | * The menu manager | |
1281 | * @param selectedItem | |
1282 | * The item to append | |
1283 | */ | |
db4721fb PT |
1284 | protected void appendToTablePopupMenu(final MenuManager tablePopupMenu, final TableItem selectedItem) { |
1285 | // override to append more actions | |
1286 | } | |
1287 | ||
a0a88f65 AM |
1288 | /** |
1289 | * Append an item to the raw viewer's pop-up menu. | |
1290 | * | |
1291 | * @param rawViewerPopupMenu | |
1292 | * The menu manager | |
1293 | */ | |
db4721fb PT |
1294 | protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu) { |
1295 | // override to append more actions | |
1296 | } | |
1297 | ||
1298 | @Override | |
1299 | public void dispose() { | |
1300 | stopSearchThread(); | |
1301 | stopFilterThread(); | |
812e7197 | 1302 | PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(this); |
db4721fb PT |
1303 | ColorSettingsManager.removeColorSettingsListener(this); |
1304 | fComposite.dispose(); | |
1305 | if ((fTrace != null) && fDisposeOnClose) { | |
1306 | fTrace.dispose(); | |
1307 | } | |
1308 | fResourceManager.dispose(); | |
3a97628a | 1309 | fRawViewer.dispose(); |
db4721fb PT |
1310 | super.dispose(); |
1311 | } | |
1312 | ||
1313 | /** | |
1314 | * Assign a layout data object to this view. | |
1315 | * | |
1316 | * @param layoutData | |
1317 | * The layout data to assign | |
1318 | */ | |
1319 | public void setLayoutData(final Object layoutData) { | |
1320 | fComposite.setLayoutData(layoutData); | |
1321 | } | |
1322 | ||
1323 | /** | |
1324 | * Get the virtual table contained in this event table. | |
1325 | * | |
1326 | * @return The TMF virtual table | |
1327 | */ | |
1328 | public TmfVirtualTable getTable() { | |
1329 | return fTable; | |
1330 | } | |
1331 | ||
1332 | /** | |
1333 | * @param columnData | |
baafe54c AM |
1334 | * columnData |
1335 | * @deprecated The column headers are now set at the constructor, this | |
1336 | * shouldn't be called anymore. | |
db4721fb | 1337 | */ |
baafe54c | 1338 | @Deprecated |
8b7eb3cd | 1339 | protected void setColumnHeaders(final org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData[] columnData) { |
baafe54c | 1340 | /* No-op */ |
db4721fb PT |
1341 | } |
1342 | ||
a0a88f65 AM |
1343 | /** |
1344 | * Set a table item's data. | |
1345 | * | |
1346 | * @param item | |
1347 | * The item to set | |
1348 | * @param event | |
1349 | * Which trace event to link with this entry | |
1350 | * @param rank | |
1351 | * Which rank this event has in the trace/experiment | |
1352 | */ | |
db4721fb | 1353 | protected void setItemData(final TableItem item, final ITmfEvent event, final long rank) { |
03142470 | 1354 | String[] itemStrings = getItemStrings(fColumns, event); |
32528869 BH |
1355 | |
1356 | // Get the actual ITmfEvent from the CachedEvent | |
1357 | ITmfEvent tmfEvent = event; | |
1358 | if (event instanceof CachedEvent) { | |
1359 | tmfEvent = ((CachedEvent) event).event; | |
1360 | } | |
03142470 | 1361 | item.setText(itemStrings); |
32528869 BH |
1362 | item.setData(tmfEvent); |
1363 | item.setData(Key.TIMESTAMP, new TmfTimestamp(tmfEvent.getTimestamp())); | |
db4721fb PT |
1364 | item.setData(Key.RANK, rank); |
1365 | ||
2db176a0 PT |
1366 | final Collection<Long> markerIds = fBookmarksMap.get(rank); |
1367 | if (!markerIds.isEmpty()) { | |
1368 | Joiner joiner = Joiner.on("\n -").skipNulls(); //$NON-NLS-1$ | |
1369 | List<Object> parts = new ArrayList<>(); | |
1370 | if (markerIds.size() > 1) { | |
1371 | parts.add(Messages.TmfEventsTable_MultipleBookmarksToolTip); | |
1372 | } | |
db4721fb | 1373 | try { |
2db176a0 PT |
1374 | for (long markerId : markerIds) { |
1375 | final IMarker marker = fBookmarksFile.findMarker(markerId); | |
1376 | parts.add(marker.getAttribute(IMarker.MESSAGE)); | |
1377 | } | |
1378 | } catch (CoreException e) { | |
db4721fb PT |
1379 | displayException(e); |
1380 | } | |
2db176a0 | 1381 | item.setData(Key.BOOKMARK, joiner.join(parts)); |
db4721fb PT |
1382 | } else { |
1383 | item.setData(Key.BOOKMARK, null); | |
1384 | } | |
1385 | ||
1386 | boolean searchMatch = false; | |
1387 | boolean searchNoMatch = false; | |
1388 | final ITmfFilter searchFilter = (ITmfFilter) fTable.getData(Key.SEARCH_OBJ); | |
1389 | if (searchFilter != null) { | |
32528869 | 1390 | if (searchFilter.matches(tmfEvent)) { |
db4721fb PT |
1391 | searchMatch = true; |
1392 | } else { | |
1393 | searchNoMatch = true; | |
1394 | } | |
1395 | } | |
1396 | ||
32528869 | 1397 | final ColorSetting colorSetting = ColorSettingsManager.getColorSetting(tmfEvent); |
db4721fb PT |
1398 | if (searchNoMatch) { |
1399 | item.setForeground(colorSetting.getDimmedForegroundColor()); | |
1400 | item.setBackground(colorSetting.getDimmedBackgroundColor()); | |
1401 | } else { | |
1402 | item.setForeground(colorSetting.getForegroundColor()); | |
1403 | item.setBackground(colorSetting.getBackgroundColor()); | |
1404 | } | |
812e7197 | 1405 | item.setFont(fFont); |
db4721fb PT |
1406 | |
1407 | if (searchMatch) { | |
2db176a0 | 1408 | if (!markerIds.isEmpty()) { |
db4721fb PT |
1409 | item.setImage(SEARCH_MATCH_BOOKMARK_IMAGE); |
1410 | } else { | |
1411 | item.setImage(SEARCH_MATCH_IMAGE); | |
1412 | } | |
2db176a0 | 1413 | } else if (!markerIds.isEmpty()) { |
db4721fb PT |
1414 | item.setImage(BOOKMARK_IMAGE); |
1415 | } else { | |
1416 | item.setImage((Image) null); | |
1417 | } | |
03142470 | 1418 | |
110d44a1 PT |
1419 | List<StyleRange> styleRanges = new ArrayList<>(); |
1420 | for (int index = 0; index < fTable.getColumns().length; index++) { | |
1421 | TableColumn column = fTable.getColumns()[index]; | |
1422 | String regex = null; | |
1423 | if (fHeaderState == HeaderState.FILTER) { | |
1424 | regex = (String) column.getData(Key.FILTER_TXT); | |
1425 | } else if (searchMatch) { | |
1426 | regex = (String) column.getData(Key.SEARCH_TXT); | |
1427 | } | |
1428 | if (regex != null) { | |
110d44a1 PT |
1429 | String text = item.getText(index); |
1430 | try { | |
1431 | Pattern pattern = Pattern.compile(regex); | |
1432 | Matcher matcher = pattern.matcher(text); | |
1433 | while (matcher.find()) { | |
1434 | int start = matcher.start(); | |
1435 | int length = matcher.end() - start; | |
1436 | Color foreground = colorSetting.getForegroundColor(); | |
bb7c657f | 1437 | Color background = fHighlightColor; |
110d44a1 PT |
1438 | StyleRange styleRange = new StyleRange(start, length, foreground, background); |
1439 | styleRange.data = index; | |
1440 | styleRanges.add(styleRange); | |
1441 | } | |
1442 | } catch (PatternSyntaxException e) { | |
1443 | /* ignored */ | |
1444 | } | |
1445 | } | |
1446 | } | |
1447 | if (styleRanges.isEmpty()) { | |
1448 | item.setData(Key.STYLE_RANGES, null); | |
1449 | } else { | |
1450 | item.setData(Key.STYLE_RANGES, styleRanges); | |
1451 | } | |
1452 | item.getParent().redraw(); | |
1453 | ||
03142470 BH |
1454 | if ((itemStrings[MARGIN_COLUMN_INDEX] != null) && !itemStrings[MARGIN_COLUMN_INDEX].isEmpty()) { |
1455 | packMarginColumn(); | |
1456 | } | |
db4721fb PT |
1457 | } |
1458 | ||
a0a88f65 AM |
1459 | /** |
1460 | * Set the item data of the header row. | |
1461 | * | |
1462 | * @param item | |
1463 | * The item to use as table header | |
1464 | */ | |
db4721fb PT |
1465 | protected void setHeaderRowItemData(final TableItem item) { |
1466 | String txtKey = null; | |
1467 | if (fHeaderState == HeaderState.SEARCH) { | |
1468 | item.setImage(SEARCH_IMAGE); | |
1469 | txtKey = Key.SEARCH_TXT; | |
1470 | } else if (fHeaderState == HeaderState.FILTER) { | |
1471 | item.setImage(FILTER_IMAGE); | |
1472 | txtKey = Key.FILTER_TXT; | |
1473 | } | |
1474 | item.setForeground(fGrayColor); | |
03142470 BH |
1475 | // Ignore collapse and image column |
1476 | for (int i = EVENT_COLUMNS_START_INDEX; i < fTable.getColumns().length; i++) { | |
db4721fb PT |
1477 | final TableColumn column = fTable.getColumns()[i]; |
1478 | final String filter = (String) column.getData(txtKey); | |
1479 | if (filter == null) { | |
1480 | if (fHeaderState == HeaderState.SEARCH) { | |
1481 | item.setText(i, SEARCH_HINT); | |
1482 | } else if (fHeaderState == HeaderState.FILTER) { | |
1483 | item.setText(i, FILTER_HINT); | |
1484 | } | |
1485 | item.setForeground(i, fGrayColor); | |
812e7197 | 1486 | item.setFont(i, fFont); |
db4721fb PT |
1487 | } else { |
1488 | item.setText(i, filter); | |
1489 | item.setForeground(i, fGreenColor); | |
1490 | item.setFont(i, fBoldFont); | |
1491 | } | |
1492 | } | |
1493 | } | |
1494 | ||
a0a88f65 AM |
1495 | /** |
1496 | * Set the item data of the "filter status" row. | |
1497 | * | |
1498 | * @param item | |
1499 | * The item to use as filter status row | |
1500 | */ | |
db4721fb PT |
1501 | protected void setFilterStatusRowItemData(final TableItem item) { |
1502 | for (int i = 0; i < fTable.getColumns().length; i++) { | |
03142470 | 1503 | if (i == MARGIN_COLUMN_INDEX) { |
db4721fb PT |
1504 | if ((fTrace == null) || (fFilterCheckCount == fTrace.getNbEvents())) { |
1505 | item.setImage(FILTER_IMAGE); | |
1506 | } else { | |
1507 | item.setImage(STOP_IMAGE); | |
1508 | } | |
03142470 BH |
1509 | } |
1510 | ||
1511 | if (i == FILTER_SUMMARY_INDEX) { | |
1512 | item.setText(FILTER_SUMMARY_INDEX, fFilterMatchCount + "/" + fFilterCheckCount); //$NON-NLS-1$ | |
db4721fb | 1513 | } else { |
03142470 | 1514 | item.setText(i, EMPTY_STRING); |
db4721fb PT |
1515 | } |
1516 | } | |
93bfd50a | 1517 | item.setData(null); |
db4721fb PT |
1518 | item.setData(Key.TIMESTAMP, null); |
1519 | item.setData(Key.RANK, null); | |
110d44a1 | 1520 | item.setData(Key.STYLE_RANGES, null); |
db4721fb PT |
1521 | item.setForeground(null); |
1522 | item.setBackground(null); | |
812e7197 | 1523 | item.setFont(fFont); |
db4721fb PT |
1524 | } |
1525 | ||
a0a88f65 AM |
1526 | /** |
1527 | * Create an editor for the header. | |
1528 | */ | |
a890f499 | 1529 | private void createHeaderEditor() { |
db4721fb PT |
1530 | final TableEditor tableEditor = fTable.createTableEditor(); |
1531 | tableEditor.horizontalAlignment = SWT.LEFT; | |
1532 | tableEditor.verticalAlignment = SWT.CENTER; | |
1533 | tableEditor.grabHorizontal = true; | |
1534 | tableEditor.minimumWidth = 50; | |
1535 | ||
1536 | // Handle the header row selection | |
1537 | fTable.addMouseListener(new MouseAdapter() { | |
1538 | int columnIndex; | |
1539 | TableColumn column; | |
1540 | TableItem item; | |
1541 | ||
1542 | @Override | |
1543 | public void mouseDown(final MouseEvent event) { | |
1544 | if (event.button != 1) { | |
1545 | return; | |
1546 | } | |
1547 | // Identify the selected row | |
1548 | final Point point = new Point(event.x, event.y); | |
1549 | item = fTable.getItem(point); | |
1550 | ||
1551 | // Header row selected | |
1552 | if ((item != null) && (fTable.indexOf(item) == 0)) { | |
1553 | ||
8ec1247f BH |
1554 | // Margin column selected |
1555 | if (item.getBounds(0).contains(point)) { | |
db4721fb PT |
1556 | if (fHeaderState == HeaderState.SEARCH) { |
1557 | fHeaderState = HeaderState.FILTER; | |
1558 | } else if (fHeaderState == HeaderState.FILTER) { | |
1559 | fHeaderState = HeaderState.SEARCH; | |
1560 | } | |
3f43dc48 | 1561 | fTable.setSelection(0); |
db4721fb | 1562 | fTable.refresh(); |
110d44a1 | 1563 | fTable.redraw(); |
db4721fb PT |
1564 | return; |
1565 | } | |
1566 | ||
1567 | // Identify the selected column | |
1568 | columnIndex = -1; | |
1569 | for (int i = 0; i < fTable.getColumns().length; i++) { | |
1570 | final Rectangle rect = item.getBounds(i); | |
1571 | if (rect.contains(point)) { | |
1572 | columnIndex = i; | |
1573 | break; | |
1574 | } | |
1575 | } | |
1576 | ||
1577 | if (columnIndex == -1) { | |
1578 | return; | |
1579 | } | |
1580 | ||
1581 | column = fTable.getColumns()[columnIndex]; | |
1582 | ||
1583 | String txtKey = null; | |
1584 | if (fHeaderState == HeaderState.SEARCH) { | |
1585 | txtKey = Key.SEARCH_TXT; | |
1586 | } else if (fHeaderState == HeaderState.FILTER) { | |
1587 | txtKey = Key.FILTER_TXT; | |
1588 | } | |
1589 | ||
8b7eb3cd MK |
1590 | /* |
1591 | * The control that will be the editor must be a child of | |
1592 | * the Table | |
1593 | */ | |
db4721fb PT |
1594 | final Text newEditor = (Text) fTable.createTableEditorControl(Text.class); |
1595 | final String headerString = (String) column.getData(txtKey); | |
1596 | if (headerString != null) { | |
1597 | newEditor.setText(headerString); | |
1598 | } | |
1599 | newEditor.addFocusListener(new FocusAdapter() { | |
1600 | @Override | |
1601 | public void focusLost(final FocusEvent e) { | |
1602 | final boolean changed = updateHeader(newEditor.getText()); | |
1603 | if (changed) { | |
1604 | applyHeader(); | |
1605 | } | |
1606 | } | |
1607 | }); | |
1608 | newEditor.addKeyListener(new KeyAdapter() { | |
1609 | @Override | |
1610 | public void keyPressed(final KeyEvent e) { | |
1611 | if (e.character == SWT.CR) { | |
1612 | updateHeader(newEditor.getText()); | |
1613 | applyHeader(); | |
d81b17ea | 1614 | |
8b7eb3cd MK |
1615 | /* |
1616 | * Set focus on the table so that the next | |
1617 | * carriage return goes to the next result | |
1618 | */ | |
d81b17ea | 1619 | TmfEventsTable.this.getTable().setFocus(); |
db4721fb PT |
1620 | } else if (e.character == SWT.ESC) { |
1621 | tableEditor.getEditor().dispose(); | |
1622 | } | |
1623 | } | |
1624 | }); | |
1625 | newEditor.selectAll(); | |
1626 | newEditor.setFocus(); | |
1627 | tableEditor.setEditor(newEditor, item, columnIndex); | |
1628 | } | |
1629 | } | |
1630 | ||
1631 | /* | |
1632 | * returns true is value was changed | |
1633 | */ | |
17dd85d7 | 1634 | private boolean updateHeader(final String regex) { |
db4721fb PT |
1635 | String objKey = null; |
1636 | String txtKey = null; | |
1637 | if (fHeaderState == HeaderState.SEARCH) { | |
1638 | objKey = Key.SEARCH_OBJ; | |
1639 | txtKey = Key.SEARCH_TXT; | |
1640 | } else if (fHeaderState == HeaderState.FILTER) { | |
1641 | objKey = Key.FILTER_OBJ; | |
1642 | txtKey = Key.FILTER_TXT; | |
1643 | } | |
17dd85d7 | 1644 | if (regex.length() > 0) { |
db4721fb | 1645 | try { |
db4721fb PT |
1646 | Pattern.compile(regex); |
1647 | if (regex.equals(column.getData(txtKey))) { | |
1648 | tableEditor.getEditor().dispose(); | |
1649 | return false; | |
1650 | } | |
ec34bf48 | 1651 | final TmfFilterMatchesNode filter = new TmfFilterMatchesNode(null); |
c409f16b AM |
1652 | ITmfEventAspect aspect = (ITmfEventAspect) column.getData(Key.ASPECT); |
1653 | filter.setEventAspect(aspect); | |
db4721fb PT |
1654 | filter.setRegex(regex); |
1655 | column.setData(objKey, filter); | |
1656 | column.setData(txtKey, regex); | |
1657 | } catch (final PatternSyntaxException ex) { | |
1658 | tableEditor.getEditor().dispose(); | |
1659 | MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), | |
1660 | ex.getDescription(), ex.getMessage()); | |
1661 | return false; | |
1662 | } | |
1663 | } else { | |
1664 | if (column.getData(txtKey) == null) { | |
1665 | tableEditor.getEditor().dispose(); | |
1666 | return false; | |
1667 | } | |
1668 | column.setData(objKey, null); | |
1669 | column.setData(txtKey, null); | |
1670 | } | |
1671 | return true; | |
1672 | } | |
1673 | ||
1674 | private void applyHeader() { | |
1675 | if (fHeaderState == HeaderState.SEARCH) { | |
1676 | stopSearchThread(); | |
1677 | final TmfFilterAndNode filter = new TmfFilterAndNode(null); | |
3dca7aa5 AM |
1678 | for (final TableColumn col : fTable.getColumns()) { |
1679 | final Object filterObj = col.getData(Key.SEARCH_OBJ); | |
db4721fb PT |
1680 | if (filterObj instanceof ITmfFilterTreeNode) { |
1681 | filter.addChild((ITmfFilterTreeNode) filterObj); | |
1682 | } | |
1683 | } | |
1684 | if (filter.getChildrenCount() > 0) { | |
1685 | fTable.setData(Key.SEARCH_OBJ, filter); | |
1686 | fTable.refresh(); | |
1687 | searchNext(); | |
1688 | fireSearchApplied(filter); | |
1689 | } else { | |
1690 | fTable.setData(Key.SEARCH_OBJ, null); | |
1691 | fTable.refresh(); | |
1692 | fireSearchApplied(null); | |
1693 | } | |
1694 | } else if (fHeaderState == HeaderState.FILTER) { | |
1695 | final TmfFilterAndNode filter = new TmfFilterAndNode(null); | |
3dca7aa5 AM |
1696 | for (final TableColumn col : fTable.getColumns()) { |
1697 | final Object filterObj = col.getData(Key.FILTER_OBJ); | |
db4721fb PT |
1698 | if (filterObj instanceof ITmfFilterTreeNode) { |
1699 | filter.addChild((ITmfFilterTreeNode) filterObj); | |
1700 | } | |
1701 | } | |
1702 | if (filter.getChildrenCount() > 0) { | |
1703 | applyFilter(filter); | |
1704 | } else { | |
1705 | clearFilters(); | |
1706 | } | |
1707 | } | |
1708 | ||
1709 | tableEditor.getEditor().dispose(); | |
1710 | } | |
1711 | }); | |
1712 | ||
1713 | fTable.addKeyListener(new KeyAdapter() { | |
1714 | @Override | |
1715 | public void keyPressed(final KeyEvent e) { | |
1716 | e.doit = false; | |
1717 | if (e.character == SWT.ESC) { | |
1718 | stopFilterThread(); | |
1719 | stopSearchThread(); | |
1720 | fTable.refresh(); | |
1721 | } else if (e.character == SWT.DEL) { | |
1722 | if (fHeaderState == HeaderState.SEARCH) { | |
1723 | stopSearchThread(); | |
1724 | for (final TableColumn column : fTable.getColumns()) { | |
1725 | column.setData(Key.SEARCH_OBJ, null); | |
1726 | column.setData(Key.SEARCH_TXT, null); | |
1727 | } | |
1728 | fTable.setData(Key.SEARCH_OBJ, null); | |
1729 | fTable.refresh(); | |
1730 | fireSearchApplied(null); | |
1731 | } else if (fHeaderState == HeaderState.FILTER) { | |
1732 | clearFilters(); | |
1733 | } | |
1734 | } else if (e.character == SWT.CR) { | |
1735 | if ((e.stateMask & SWT.SHIFT) == 0) { | |
1736 | searchNext(); | |
1737 | } else { | |
1738 | searchPrevious(); | |
1739 | } | |
1740 | } | |
1741 | } | |
1742 | }); | |
1743 | } | |
1744 | ||
a0a88f65 AM |
1745 | /** |
1746 | * Send an event indicating a filter has been applied. | |
1747 | * | |
1748 | * @param filter | |
1749 | * The filter that was just applied | |
1750 | */ | |
db4721fb | 1751 | protected void fireFilterApplied(final ITmfFilter filter) { |
faa38350 | 1752 | broadcast(new TmfEventFilterAppliedSignal(this, fTrace, filter)); |
db4721fb PT |
1753 | } |
1754 | ||
a0a88f65 AM |
1755 | /** |
1756 | * Send an event indicating that a search has been applied. | |
1757 | * | |
1758 | * @param filter | |
1759 | * The search filter that was just applied | |
1760 | */ | |
db4721fb | 1761 | protected void fireSearchApplied(final ITmfFilter filter) { |
faa38350 | 1762 | broadcast(new TmfEventSearchAppliedSignal(this, fTrace, filter)); |
db4721fb PT |
1763 | } |
1764 | ||
a0a88f65 AM |
1765 | /** |
1766 | * Start the filtering thread. | |
1767 | */ | |
db4721fb PT |
1768 | protected void startFilterThread() { |
1769 | synchronized (fFilterSyncObj) { | |
1770 | final ITmfFilterTreeNode filter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ); | |
1771 | if (fFilterThread == null || fFilterThread.filter != filter) { | |
1772 | if (fFilterThread != null) { | |
1773 | fFilterThread.cancel(); | |
1774 | fFilterThreadResume = false; | |
1775 | } | |
1776 | fFilterThread = new FilterThread(filter); | |
1777 | fFilterThread.start(); | |
1778 | } else { | |
1779 | fFilterThreadResume = true; | |
1780 | } | |
1781 | } | |
1782 | } | |
1783 | ||
a0a88f65 AM |
1784 | /** |
1785 | * Stop the filtering thread. | |
1786 | */ | |
db4721fb PT |
1787 | protected void stopFilterThread() { |
1788 | synchronized (fFilterSyncObj) { | |
1789 | if (fFilterThread != null) { | |
1790 | fFilterThread.cancel(); | |
1791 | fFilterThread = null; | |
1792 | fFilterThreadResume = false; | |
1793 | } | |
1794 | } | |
1795 | } | |
1796 | ||
1797 | /** | |
a0a88f65 AM |
1798 | * Apply a filter. |
1799 | * | |
1800 | * @param filter | |
1801 | * The filter to apply | |
db4721fb PT |
1802 | */ |
1803 | protected void applyFilter(ITmfFilter filter) { | |
f29f8868 BH |
1804 | stopFilterThread(); |
1805 | stopSearchThread(); | |
db4721fb PT |
1806 | fFilterMatchCount = 0; |
1807 | fFilterCheckCount = 0; | |
1808 | fCache.applyFilter(filter); | |
1809 | fTable.clearAll(); | |
1810 | fTable.setData(Key.FILTER_OBJ, filter); | |
8b7eb3cd MK |
1811 | /* +1 for header row, +2 for top and bottom filter status rows */ |
1812 | fTable.setItemCount(3); | |
db4721fb PT |
1813 | startFilterThread(); |
1814 | fireFilterApplied(filter); | |
1815 | } | |
1816 | ||
a0a88f65 AM |
1817 | /** |
1818 | * Clear all currently active filters. | |
1819 | */ | |
db4721fb PT |
1820 | protected void clearFilters() { |
1821 | if (fTable.getData(Key.FILTER_OBJ) == null) { | |
1822 | return; | |
1823 | } | |
1824 | stopFilterThread(); | |
1825 | stopSearchThread(); | |
1826 | fCache.clearFilter(); | |
1827 | fTable.clearAll(); | |
1828 | for (final TableColumn column : fTable.getColumns()) { | |
1829 | column.setData(Key.FILTER_OBJ, null); | |
1830 | column.setData(Key.FILTER_TXT, null); | |
1831 | } | |
1832 | fTable.setData(Key.FILTER_OBJ, null); | |
1833 | if (fTrace != null) { | |
8b7eb3cd MK |
1834 | /* +1 for header row */ |
1835 | fTable.setItemCount((int) fTrace.getNbEvents() + 1); | |
db4721fb | 1836 | } else { |
8b7eb3cd MK |
1837 | /* +1 for header row */ |
1838 | fTable.setItemCount(1); | |
db4721fb PT |
1839 | } |
1840 | fFilterMatchCount = 0; | |
1841 | fFilterCheckCount = 0; | |
1842 | if (fSelectedRank >= 0) { | |
8b7eb3cd MK |
1843 | /* +1 for header row */ |
1844 | fTable.setSelection((int) fSelectedRank + 1); | |
db4721fb PT |
1845 | } else { |
1846 | fTable.setSelection(0); | |
1847 | } | |
1848 | fireFilterApplied(null); | |
3f43dc48 | 1849 | updateStatusLine(null); |
03142470 BH |
1850 | |
1851 | // Set original width | |
1852 | fTable.getColumns()[MARGIN_COLUMN_INDEX].setWidth(0); | |
1853 | packMarginColumn(); | |
db4721fb PT |
1854 | } |
1855 | ||
a0a88f65 AM |
1856 | /** |
1857 | * Wrapper Thread object for the filtering thread. | |
1858 | */ | |
db4721fb PT |
1859 | protected class FilterThread extends Thread { |
1860 | private final ITmfFilterTreeNode filter; | |
fd3f1eff | 1861 | private TmfEventRequest request; |
db4721fb PT |
1862 | private boolean refreshBusy = false; |
1863 | private boolean refreshPending = false; | |
1864 | private final Object syncObj = new Object(); | |
1865 | ||
a0a88f65 AM |
1866 | /** |
1867 | * Constructor. | |
1868 | * | |
1869 | * @param filter | |
1870 | * The filter this thread will be processing | |
1871 | */ | |
db4721fb PT |
1872 | public FilterThread(final ITmfFilterTreeNode filter) { |
1873 | super("Filter Thread"); //$NON-NLS-1$ | |
1874 | this.filter = filter; | |
1875 | } | |
1876 | ||
1877 | @Override | |
1878 | public void run() { | |
1879 | if (fTrace == null) { | |
1880 | return; | |
1881 | } | |
1882 | final int nbRequested = (int) (fTrace.getNbEvents() - fFilterCheckCount); | |
1883 | if (nbRequested <= 0) { | |
1884 | return; | |
1885 | } | |
fd3f1eff AM |
1886 | request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, |
1887 | (int) fFilterCheckCount, nbRequested, ExecutionType.BACKGROUND) { | |
db4721fb PT |
1888 | @Override |
1889 | public void handleData(final ITmfEvent event) { | |
1890 | super.handleData(event); | |
1891 | if (request.isCancelled()) { | |
1892 | return; | |
1893 | } | |
03142470 | 1894 | boolean refresh = false; |
db4721fb PT |
1895 | if (filter.matches(event)) { |
1896 | final long rank = fFilterCheckCount; | |
1897 | final int index = (int) fFilterMatchCount; | |
1898 | fFilterMatchCount++; | |
bd54d363 | 1899 | fCache.storeEvent(event, rank, index); |
03142470 BH |
1900 | refresh = true; |
1901 | } else { | |
1902 | if (filter instanceof TmfCollapseFilter) { | |
1903 | fCache.updateCollapsedEvent((int) fFilterMatchCount - 1); | |
1904 | } | |
1905 | } | |
1906 | ||
1907 | if (refresh || (fFilterCheckCount % 100) == 0) { | |
db4721fb PT |
1908 | refreshTable(); |
1909 | } | |
1910 | fFilterCheckCount++; | |
1911 | } | |
1912 | }; | |
fd3f1eff | 1913 | ((ITmfEventProvider) fTrace).sendRequest(request); |
db4721fb PT |
1914 | try { |
1915 | request.waitForCompletion(); | |
1916 | } catch (final InterruptedException e) { | |
1917 | } | |
1918 | refreshTable(); | |
1919 | synchronized (fFilterSyncObj) { | |
1920 | fFilterThread = null; | |
1921 | if (fFilterThreadResume) { | |
1922 | fFilterThreadResume = false; | |
1923 | fFilterThread = new FilterThread(filter); | |
1924 | fFilterThread.start(); | |
1925 | } | |
1926 | } | |
1927 | } | |
1928 | ||
a0a88f65 AM |
1929 | /** |
1930 | * Refresh the filter. | |
1931 | */ | |
db4721fb PT |
1932 | public void refreshTable() { |
1933 | synchronized (syncObj) { | |
1934 | if (refreshBusy) { | |
1935 | refreshPending = true; | |
1936 | return; | |
1937 | } | |
1938 | refreshBusy = true; | |
1939 | } | |
1940 | Display.getDefault().asyncExec(new Runnable() { | |
1941 | @Override | |
1942 | public void run() { | |
1943 | if (request.isCancelled()) { | |
1944 | return; | |
1945 | } | |
1946 | if (fTable.isDisposed()) { | |
1947 | return; | |
1948 | } | |
8b7eb3cd MK |
1949 | /* |
1950 | * +1 for header row, +2 for top and bottom filter status | |
1951 | * rows | |
1952 | */ | |
1953 | fTable.setItemCount((int) fFilterMatchCount + 3); | |
db4721fb PT |
1954 | fTable.refresh(); |
1955 | synchronized (syncObj) { | |
1956 | refreshBusy = false; | |
1957 | if (refreshPending) { | |
1958 | refreshPending = false; | |
1959 | refreshTable(); | |
1960 | } | |
1961 | } | |
1962 | } | |
1963 | }); | |
1964 | } | |
1965 | ||
a0a88f65 AM |
1966 | /** |
1967 | * Cancel this filtering thread. | |
1968 | */ | |
db4721fb PT |
1969 | public void cancel() { |
1970 | if (request != null) { | |
1971 | request.cancel(); | |
1972 | } | |
1973 | } | |
1974 | } | |
1975 | ||
a0a88f65 AM |
1976 | /** |
1977 | * Go to the next item of a search. | |
1978 | */ | |
db4721fb PT |
1979 | protected void searchNext() { |
1980 | synchronized (fSearchSyncObj) { | |
1981 | if (fSearchThread != null) { | |
1982 | return; | |
1983 | } | |
1984 | final ITmfFilterTreeNode searchFilter = (ITmfFilterTreeNode) fTable.getData(Key.SEARCH_OBJ); | |
1985 | if (searchFilter == null) { | |
1986 | return; | |
1987 | } | |
1988 | final int selectionIndex = fTable.getSelectionIndex(); | |
1989 | int startIndex; | |
1990 | if (selectionIndex > 0) { | |
8b7eb3cd MK |
1991 | /* -1 for header row, +1 for next event */ |
1992 | startIndex = selectionIndex; | |
db4721fb | 1993 | } else { |
8b7eb3cd MK |
1994 | /* |
1995 | * header row is selected, start at top event | |
1996 | */ | |
1997 | /* -1 for header row */ | |
1998 | startIndex = Math.max(0, fTable.getTopIndex() - 1); | |
db4721fb PT |
1999 | } |
2000 | final ITmfFilterTreeNode eventFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ); | |
60fb38b8 | 2001 | if (eventFilter != null) { |
8b7eb3cd MK |
2002 | // -1 for top filter status row |
2003 | startIndex = Math.max(0, startIndex - 1); | |
db4721fb PT |
2004 | } |
2005 | fSearchThread = new SearchThread(searchFilter, eventFilter, startIndex, fSelectedRank, Direction.FORWARD); | |
2006 | fSearchThread.schedule(); | |
2007 | } | |
2008 | } | |
2009 | ||
a0a88f65 AM |
2010 | /** |
2011 | * Go to the previous item of a search. | |
2012 | */ | |
db4721fb PT |
2013 | protected void searchPrevious() { |
2014 | synchronized (fSearchSyncObj) { | |
2015 | if (fSearchThread != null) { | |
2016 | return; | |
2017 | } | |
2018 | final ITmfFilterTreeNode searchFilter = (ITmfFilterTreeNode) fTable.getData(Key.SEARCH_OBJ); | |
2019 | if (searchFilter == null) { | |
2020 | return; | |
2021 | } | |
2022 | final int selectionIndex = fTable.getSelectionIndex(); | |
2023 | int startIndex; | |
2024 | if (selectionIndex > 0) { | |
8b7eb3cd MK |
2025 | /* -1 for header row, -1 for previous event */ |
2026 | startIndex = selectionIndex - 2; | |
db4721fb | 2027 | } else { |
8b7eb3cd MK |
2028 | /* |
2029 | * Header row is selected, start at precedent of top event | |
2030 | */ | |
2031 | /* -1 for header row, -1 for previous event */ | |
2032 | startIndex = fTable.getTopIndex() - 2; | |
db4721fb PT |
2033 | } |
2034 | final ITmfFilterTreeNode eventFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ); | |
60fb38b8 | 2035 | if (eventFilter != null) { |
8b7eb3cd MK |
2036 | /* -1 for top filter status row */ |
2037 | startIndex = startIndex - 1; | |
db4721fb PT |
2038 | } |
2039 | fSearchThread = new SearchThread(searchFilter, eventFilter, startIndex, fSelectedRank, Direction.BACKWARD); | |
2040 | fSearchThread.schedule(); | |
2041 | } | |
2042 | } | |
2043 | ||
a0a88f65 AM |
2044 | /** |
2045 | * Stop the search thread. | |
2046 | */ | |
db4721fb PT |
2047 | protected void stopSearchThread() { |
2048 | fPendingGotoRank = -1; | |
2049 | synchronized (fSearchSyncObj) { | |
2050 | if (fSearchThread != null) { | |
2051 | fSearchThread.cancel(); | |
2052 | fSearchThread = null; | |
2053 | } | |
2054 | } | |
2055 | } | |
2056 | ||
a0a88f65 AM |
2057 | /** |
2058 | * Wrapper for the search thread. | |
2059 | */ | |
db4721fb | 2060 | protected class SearchThread extends Job { |
a0a88f65 AM |
2061 | |
2062 | private ITmfFilterTreeNode searchFilter; | |
2063 | private ITmfFilterTreeNode eventFilter; | |
2064 | private int startIndex; | |
2065 | private int direction; | |
2066 | private long rank; | |
2067 | private long foundRank = -1; | |
fd3f1eff | 2068 | private TmfEventRequest request; |
ae3ffd37 | 2069 | private ITmfTimestamp foundTimestamp = null; |
db4721fb | 2070 | |
a0a88f65 AM |
2071 | /** |
2072 | * Constructor. | |
2073 | * | |
2074 | * @param searchFilter | |
2075 | * The search filter | |
2076 | * @param eventFilter | |
2077 | * The event filter | |
2078 | * @param startIndex | |
2079 | * The index at which we should start searching | |
2080 | * @param currentRank | |
2081 | * The current rank | |
2082 | * @param direction | |
2083 | * In which direction should we search, forward or backwards | |
2084 | */ | |
2085 | public SearchThread(final ITmfFilterTreeNode searchFilter, | |
2086 | final ITmfFilterTreeNode eventFilter, final int startIndex, | |
db4721fb PT |
2087 | final long currentRank, final int direction) { |
2088 | super(Messages.TmfEventsTable_SearchingJobName); | |
2089 | this.searchFilter = searchFilter; | |
2090 | this.eventFilter = eventFilter; | |
2091 | this.startIndex = startIndex; | |
2092 | this.rank = currentRank; | |
2093 | this.direction = direction; | |
2094 | } | |
2095 | ||
2096 | @Override | |
2097 | protected IStatus run(final IProgressMonitor monitor) { | |
f4e06774 FLN |
2098 | final ITmfTrace trace = fTrace; |
2099 | if (trace == null) { | |
db4721fb PT |
2100 | return Status.OK_STATUS; |
2101 | } | |
2102 | final Display display = Display.getDefault(); | |
2103 | if (startIndex < 0) { | |
f4e06774 | 2104 | rank = (int) trace.getNbEvents() - 1; |
8b7eb3cd MK |
2105 | /* |
2106 | * -1 for header row, -3 for header and top and bottom filter | |
2107 | * status rows | |
2108 | */ | |
2109 | } else if (startIndex >= (fTable.getItemCount() - (eventFilter == null ? 1 : 3))) { | |
db4721fb PT |
2110 | rank = 0; |
2111 | } else { | |
2112 | int idx = startIndex; | |
2113 | while (foundRank == -1) { | |
2114 | final CachedEvent event = fCache.peekEvent(idx); | |
2115 | if (event == null) { | |
2116 | break; | |
2117 | } | |
2118 | rank = event.rank; | |
2119 | if (searchFilter.matches(event.event) && ((eventFilter == null) || eventFilter.matches(event.event))) { | |
2120 | foundRank = event.rank; | |
ae3ffd37 | 2121 | foundTimestamp = event.event.getTimestamp(); |
db4721fb PT |
2122 | break; |
2123 | } | |
2124 | if (direction == Direction.FORWARD) { | |
2125 | idx++; | |
2126 | } else { | |
2127 | idx--; | |
2128 | } | |
2129 | } | |
2130 | if (foundRank == -1) { | |
2131 | if (direction == Direction.FORWARD) { | |
2132 | rank++; | |
f4e06774 | 2133 | if (rank > (trace.getNbEvents() - 1)) { |
db4721fb PT |
2134 | rank = 0; |
2135 | } | |
2136 | } else { | |
2137 | rank--; | |
2138 | if (rank < 0) { | |
f4e06774 | 2139 | rank = (int) trace.getNbEvents() - 1; |
db4721fb PT |
2140 | } |
2141 | } | |
2142 | } | |
2143 | } | |
2144 | final int startRank = (int) rank; | |
2145 | boolean wrapped = false; | |
f4e06774 FLN |
2146 | while (!monitor.isCanceled() && (foundRank == -1)) { |
2147 | int nbRequested = (direction == Direction.FORWARD ? Integer.MAX_VALUE : Math.min((int) rank + 1, trace.getCacheSize())); | |
db4721fb | 2148 | if (direction == Direction.BACKWARD) { |
f4e06774 | 2149 | rank = Math.max(0, rank - trace.getCacheSize() + 1); |
db4721fb | 2150 | } |
fd3f1eff AM |
2151 | request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, |
2152 | (int) rank, nbRequested, ExecutionType.BACKGROUND) { | |
db4721fb PT |
2153 | long currentRank = rank; |
2154 | ||
2155 | @Override | |
2156 | public void handleData(final ITmfEvent event) { | |
2157 | super.handleData(event); | |
2158 | if (searchFilter.matches(event) && ((eventFilter == null) || eventFilter.matches(event))) { | |
2159 | foundRank = currentRank; | |
ae3ffd37 | 2160 | foundTimestamp = event.getTimestamp(); |
db4721fb PT |
2161 | if (direction == Direction.FORWARD) { |
2162 | done(); | |
2163 | return; | |
2164 | } | |
2165 | } | |
2166 | currentRank++; | |
2167 | } | |
2168 | }; | |
f4e06774 | 2169 | ((ITmfEventProvider) trace).sendRequest(request); |
db4721fb PT |
2170 | try { |
2171 | request.waitForCompletion(); | |
2172 | if (request.isCancelled()) { | |
2173 | return Status.OK_STATUS; | |
2174 | } | |
2175 | } catch (final InterruptedException e) { | |
2176 | synchronized (fSearchSyncObj) { | |
2177 | fSearchThread = null; | |
2178 | } | |
2179 | return Status.OK_STATUS; | |
2180 | } | |
2181 | if (foundRank == -1) { | |
2182 | if (direction == Direction.FORWARD) { | |
2183 | if (rank == 0) { | |
2184 | synchronized (fSearchSyncObj) { | |
2185 | fSearchThread = null; | |
2186 | } | |
2187 | return Status.OK_STATUS; | |
2188 | } | |
2189 | nbRequested = (int) rank; | |
2190 | rank = 0; | |
2191 | wrapped = true; | |
2192 | } else { | |
2193 | rank--; | |
2194 | if (rank < 0) { | |
f4e06774 | 2195 | rank = (int) trace.getNbEvents() - 1; |
db4721fb PT |
2196 | wrapped = true; |
2197 | } | |
2198 | if ((rank <= startRank) && wrapped) { | |
2199 | synchronized (fSearchSyncObj) { | |
2200 | fSearchThread = null; | |
2201 | } | |
2202 | return Status.OK_STATUS; | |
2203 | } | |
2204 | } | |
2205 | } | |
2206 | } | |
2207 | int index = (int) foundRank; | |
2208 | if (eventFilter != null) { | |
2209 | index = fCache.getFilteredEventIndex(foundRank); | |
2210 | } | |
8b7eb3cd MK |
2211 | /* +1 for header row, +1 for top filter status row */ |
2212 | final int selection = index + 1 + (eventFilter != null ? +1 : 0); | |
db4721fb PT |
2213 | |
2214 | display.asyncExec(new Runnable() { | |
2215 | @Override | |
2216 | public void run() { | |
2217 | if (monitor.isCanceled()) { | |
2218 | return; | |
2219 | } | |
2220 | if (fTable.isDisposed()) { | |
2221 | return; | |
2222 | } | |
2223 | fTable.setSelection(selection); | |
2224 | fSelectedRank = foundRank; | |
ae3ffd37 PT |
2225 | fRawViewer.selectAndReveal(fSelectedRank); |
2226 | if (foundTimestamp != null) { | |
97c71024 | 2227 | broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, foundTimestamp)); |
ae3ffd37 | 2228 | } |
a56ec2b8 | 2229 | fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, getSelection())); |
db4721fb PT |
2230 | synchronized (fSearchSyncObj) { |
2231 | fSearchThread = null; | |
2232 | } | |
3f43dc48 | 2233 | updateStatusLine(null); |
db4721fb PT |
2234 | } |
2235 | }); | |
2236 | return Status.OK_STATUS; | |
2237 | } | |
2238 | ||
2239 | @Override | |
2240 | protected void canceling() { | |
2241 | request.cancel(); | |
2242 | synchronized (fSearchSyncObj) { | |
2243 | fSearchThread = null; | |
2244 | } | |
2245 | } | |
2246 | } | |
2247 | ||
a0a88f65 AM |
2248 | /** |
2249 | * Create the resources. | |
2250 | */ | |
a890f499 | 2251 | private void createResources() { |
8b7eb3cd | 2252 | fGrayColor = fResourceManager.createColor(ColorUtil.blend(fTable.getBackground().getRGB(), fTable.getForeground().getRGB())); |
db4721fb | 2253 | fGreenColor = fTable.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN); |
812e7197 PT |
2254 | } |
2255 | ||
2256 | /** | |
2257 | * Initialize the fonts. | |
812e7197 | 2258 | */ |
a890f499 | 2259 | private void initializeFonts() { |
812e7197 PT |
2260 | FontRegistry fontRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry(); |
2261 | fFont = fontRegistry.get(FONT_DEFINITION_ID); | |
2262 | fBoldFont = fontRegistry.getBold(FONT_DEFINITION_ID); | |
2263 | fTable.setFont(fFont); | |
2264 | /* Column header font cannot be set. See Bug 63038 */ | |
2265 | } | |
2266 | ||
bb7c657f PT |
2267 | /** |
2268 | * Initialize the colors. | |
bb7c657f | 2269 | */ |
a890f499 | 2270 | private void initializeColors() { |
bb7c657f PT |
2271 | ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); |
2272 | fHighlightColor = colorRegistry.get(HIGHLIGHT_COLOR_DEFINITION_ID); | |
2273 | } | |
2274 | ||
812e7197 PT |
2275 | /** |
2276 | * @since 1.0 | |
2277 | */ | |
2278 | @Override | |
2279 | public void propertyChange(PropertyChangeEvent event) { | |
2280 | if ((IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) || | |
2281 | (FONT_DEFINITION_ID.equals(event.getProperty()))) { | |
2282 | initializeFonts(); | |
2283 | fTable.refresh(); | |
2284 | } | |
bb7c657f PT |
2285 | if ((IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) || |
2286 | (HIGHLIGHT_COLOR_DEFINITION_ID.equals(event.getProperty()))) { | |
2287 | initializeColors(); | |
2288 | fTable.refresh(); | |
2289 | } | |
db4721fb PT |
2290 | } |
2291 | ||
a0a88f65 AM |
2292 | /** |
2293 | * Pack the columns. | |
2294 | */ | |
db4721fb PT |
2295 | protected void packColumns() { |
2296 | if (fPackDone) { | |
2297 | return; | |
2298 | } | |
d3bc98ee | 2299 | fTable.setRedraw(false); |
03142470 BH |
2300 | try { |
2301 | TableColumn tableColumns[] = fTable.getColumns(); | |
2302 | for (int i = 0; i < tableColumns.length; i++) { | |
2303 | final TableColumn column = tableColumns[i]; | |
2304 | packSingleColumn(i, column); | |
346ffed7 | 2305 | column.setData(Key.WIDTH, column.getWidth()); |
03142470 | 2306 | } |
346ffed7 | 2307 | |
03142470 BH |
2308 | } finally { |
2309 | // Make sure that redraw is always enabled. | |
2310 | fTable.setRedraw(true); | |
2311 | } | |
2312 | fPackDone = true; | |
2313 | } | |
d3bc98ee | 2314 | |
03142470 BH |
2315 | private void packMarginColumn() { |
2316 | TableColumn[] columns = fTable.getColumns(); | |
2317 | if (columns.length > 0) { | |
2318 | packSingleColumn(0, columns[0]); | |
2319 | } | |
2320 | } | |
f29f8868 | 2321 | |
03142470 BH |
2322 | private void packSingleColumn(int i, final TableColumn column) { |
2323 | final int headerWidth = column.getWidth(); | |
2324 | column.pack(); | |
8b7eb3cd MK |
2325 | /* |
2326 | * Workaround for Linux which doesn't consider the image width of | |
2327 | * search/filter row in TableColumn.pack() after having executed | |
2328 | * TableItem.setImage(null) for other rows than search/filter row. | |
2329 | */ | |
03142470 BH |
2330 | boolean isCollapseFilter = fTable.getData(Key.FILTER_OBJ) instanceof TmfCollapseFilter; |
2331 | if (IS_LINUX && (i == 0) && isCollapseFilter) { | |
2332 | column.setWidth(column.getWidth() + SEARCH_IMAGE.getBounds().width); | |
db4721fb | 2333 | } |
d3bc98ee | 2334 | |
03142470 BH |
2335 | if (column.getWidth() < headerWidth) { |
2336 | column.setWidth(headerWidth); | |
2337 | } | |
db4721fb PT |
2338 | } |
2339 | ||
d3de0920 | 2340 | /** |
baafe54c AM |
2341 | * Get the array of item strings (e.g., what to display in each cell of the |
2342 | * table row) corresponding to the columns and trace event passed in | |
2343 | * parameter. The order of the Strings in the returned array will correspond | |
2344 | * to the iteration order of 'columns'. | |
d3de0920 | 2345 | * |
baafe54c AM |
2346 | * <p> |
2347 | * To ensure consistent results, make sure only call this within a scope | |
2348 | * synchronized on 'columns'! If the order of 'columns' changes right after | |
2349 | * this method is called, the returned value won't be ordered correctly | |
2350 | * anymore. | |
2351 | */ | |
2352 | private static String[] getItemStrings(List<TmfEventTableColumn> columns, ITmfEvent event) { | |
2353 | if (event == null) { | |
2354 | return EMPTY_STRING_ARRAY; | |
2355 | } | |
2356 | synchronized (columns) { | |
2357 | List<String> itemStrings = new ArrayList<>(columns.size()); | |
2358 | for (TmfEventTableColumn column : columns) { | |
03142470 BH |
2359 | ITmfEvent passedEvent = event; |
2360 | if (!(column instanceof TmfMarginColumn) && (event instanceof CachedEvent)) { | |
8b7eb3cd MK |
2361 | /* |
2362 | * Make sure that the event object from the trace is passed | |
2363 | * to all columns but the TmfMarginColumn | |
2364 | */ | |
03142470 BH |
2365 | passedEvent = ((CachedEvent) event).event; |
2366 | } | |
2367 | if (passedEvent == null) { | |
2368 | itemStrings.add(EMPTY_STRING); | |
2369 | } else { | |
2370 | itemStrings.add(column.getItemString(passedEvent)); | |
2371 | } | |
2372 | ||
baafe54c AM |
2373 | } |
2374 | return itemStrings.toArray(new String[0]); | |
2375 | } | |
2376 | } | |
2377 | ||
2378 | /** | |
2379 | * Get the contents of the row in the events table corresponding to an | |
2380 | * event. The order of the elements corresponds to the current order of the | |
2381 | * columns. | |
a0a88f65 | 2382 | * |
db4721fb | 2383 | * @param event |
cf37ad9f AM |
2384 | * The event printed in this row |
2385 | * @return The event row entries | |
db4721fb | 2386 | */ |
cf37ad9f | 2387 | public String[] getItemStrings(ITmfEvent event) { |
6817308e PT |
2388 | List<TmfEventTableColumn> columns = new ArrayList<>(); |
2389 | for (int i : fTable.getColumnOrder()) { | |
2390 | columns.add(fColumns.get(i)); | |
2391 | } | |
2392 | return getItemStrings(columns, event); | |
db4721fb PT |
2393 | } |
2394 | ||
14665360 | 2395 | /** |
8b7eb3cd MK |
2396 | * Returns an array of zero-relative integers that map the creation order of |
2397 | * the receiver's columns to the order in which they are currently being | |
2398 | * displayed. | |
14665360 | 2399 | * <p> |
8b7eb3cd MK |
2400 | * Specifically, the indices of the returned array represent the current |
2401 | * visual order of the columns, and the contents of the array represent the | |
2402 | * creation order of the columns. | |
14665360 PT |
2403 | * |
2404 | * @return the current visual order of the receiver's columns | |
2405 | * @since 1.0 | |
2406 | */ | |
2407 | public int[] getColumnOrder() { | |
2408 | return fColumnOrder; | |
2409 | } | |
2410 | ||
2411 | /** | |
8b7eb3cd MK |
2412 | * Sets the order that the columns in the receiver should be displayed in to |
2413 | * the given argument which is described in terms of the zero-relative | |
2414 | * ordering of when the columns were added. | |
14665360 | 2415 | * <p> |
8b7eb3cd MK |
2416 | * Specifically, the contents of the array represent the original position |
2417 | * of each column at the time its creation. | |
14665360 | 2418 | * |
8b7eb3cd MK |
2419 | * @param order |
2420 | * the new order to display the columns | |
14665360 PT |
2421 | * @since 1.0 |
2422 | */ | |
2423 | public void setColumnOrder(int[] order) { | |
2424 | if (order == null || order.length != fTable.getColumns().length) { | |
2425 | return; | |
2426 | } | |
2427 | fTable.setColumnOrder(order); | |
2428 | fColumnOrder = fTable.getColumnOrder(); | |
2429 | } | |
2430 | ||
db4721fb PT |
2431 | /** |
2432 | * Notify this table that is got the UI focus. | |
2433 | */ | |
2434 | public void setFocus() { | |
2435 | fTable.setFocus(); | |
2436 | } | |
2437 | ||
2438 | /** | |
2439 | * Assign a new trace to this event table. | |
2440 | * | |
2441 | * @param trace | |
2442 | * The trace to assign to this event table | |
2443 | * @param disposeOnClose | |
2444 | * true if the trace should be disposed when the table is | |
2445 | * disposed | |
2446 | */ | |
2447 | public void setTrace(final ITmfTrace trace, final boolean disposeOnClose) { | |
2448 | if ((fTrace != null) && fDisposeOnClose) { | |
2449 | fTrace.dispose(); | |
2450 | } | |
2451 | fTrace = trace; | |
2452 | fPackDone = false; | |
2453 | fSelectedRank = 0; | |
2454 | fDisposeOnClose = disposeOnClose; | |
2455 | ||
2456 | // Perform the updates on the UI thread | |
2457 | fTable.getDisplay().syncExec(new Runnable() { | |
2458 | @Override | |
2459 | public void run() { | |
2460 | fTable.removeAll(); | |
f4e06774 FLN |
2461 | fCache.setTrace(trace); // Clear the cache |
2462 | if (trace != null) { | |
2463 | if (!fTable.isDisposed()) { | |
db4721fb | 2464 | if (fTable.getData(Key.FILTER_OBJ) == null) { |
8b7eb3cd | 2465 | // +1 for header row |
f4e06774 | 2466 | fTable.setItemCount((int) trace.getNbEvents() + 1); |
db4721fb PT |
2467 | } else { |
2468 | stopFilterThread(); | |
2469 | fFilterMatchCount = 0; | |
2470 | fFilterCheckCount = 0; | |
8b7eb3cd MK |
2471 | /* |
2472 | * +1 for header row, +2 for top and bottom filter | |
2473 | * status rows | |
2474 | */ | |
2475 | fTable.setItemCount(3); | |
db4721fb PT |
2476 | startFilterThread(); |
2477 | } | |
2478 | } | |
db4721fb | 2479 | } |
f4e06774 | 2480 | fRawViewer.setTrace(trace); |
db4721fb PT |
2481 | } |
2482 | }); | |
2483 | } | |
2484 | ||
3f43dc48 PT |
2485 | /** |
2486 | * Assign the status line manager | |
2487 | * | |
2488 | * @param statusLineManager | |
8b7eb3cd MK |
2489 | * The status line manager, or null to disable status line |
2490 | * messages | |
3f43dc48 PT |
2491 | */ |
2492 | public void setStatusLineManager(IStatusLineManager statusLineManager) { | |
2493 | if (fStatusLineManager != null && statusLineManager == null) { | |
03142470 | 2494 | fStatusLineManager.setMessage(EMPTY_STRING); |
3f43dc48 PT |
2495 | } |
2496 | fStatusLineManager = statusLineManager; | |
2497 | } | |
2498 | ||
2499 | private void updateStatusLine(ITmfTimestamp delta) { | |
2500 | if (fStatusLineManager != null) { | |
2501 | if (delta != null) { | |
2502 | fStatusLineManager.setMessage("\u0394: " + delta); //$NON-NLS-1$ | |
2503 | } else { | |
2504 | fStatusLineManager.setMessage(null); | |
2505 | } | |
2506 | } | |
2507 | } | |
2508 | ||
db4721fb PT |
2509 | // ------------------------------------------------------------------------ |
2510 | // Event cache | |
2511 | // ------------------------------------------------------------------------ | |
2512 | ||
2513 | /** | |
2514 | * Notify that the event cache has been updated | |
2515 | * | |
2516 | * @param completed | |
2517 | * Also notify if the populating of the cache is complete, or | |
2518 | * not. | |
2519 | */ | |
2520 | public void cacheUpdated(final boolean completed) { | |
2521 | synchronized (fCacheUpdateSyncObj) { | |
2522 | if (fCacheUpdateBusy) { | |
2523 | fCacheUpdatePending = true; | |
2524 | fCacheUpdateCompleted = completed; | |
2525 | return; | |
2526 | } | |
2527 | fCacheUpdateBusy = true; | |
2528 | } | |
2529 | // Event cache is now updated. Perform update on the UI thread | |
2530 | if (!fTable.isDisposed()) { | |
2531 | fTable.getDisplay().asyncExec(new Runnable() { | |
2532 | @Override | |
2533 | public void run() { | |
2534 | if (!fTable.isDisposed()) { | |
2535 | fTable.refresh(); | |
2536 | packColumns(); | |
2537 | } | |
2538 | if (completed) { | |
2539 | populateCompleted(); | |
2540 | } | |
2541 | synchronized (fCacheUpdateSyncObj) { | |
2542 | fCacheUpdateBusy = false; | |
2543 | if (fCacheUpdatePending) { | |
2544 | fCacheUpdatePending = false; | |
2545 | cacheUpdated(fCacheUpdateCompleted); | |
2546 | } | |
2547 | } | |
2548 | } | |
2549 | }); | |
2550 | } | |
2551 | } | |
2552 | ||
a0a88f65 AM |
2553 | /** |
2554 | * Callback for when populating the table is complete. | |
2555 | */ | |
db4721fb PT |
2556 | protected void populateCompleted() { |
2557 | // Nothing by default; | |
2558 | } | |
2559 | ||
93bfd50a PT |
2560 | // ------------------------------------------------------------------------ |
2561 | // ISelectionProvider | |
2562 | // ------------------------------------------------------------------------ | |
2563 | ||
93bfd50a PT |
2564 | @Override |
2565 | public void addSelectionChangedListener(ISelectionChangedListener listener) { | |
2566 | selectionChangedListeners.add(listener); | |
2567 | } | |
2568 | ||
93bfd50a PT |
2569 | @Override |
2570 | public ISelection getSelection() { | |
2571 | if (fTable == null || fTable.isDisposed()) { | |
2572 | return StructuredSelection.EMPTY; | |
2573 | } | |
507b1336 | 2574 | List<Object> list = new ArrayList<>(fTable.getSelection().length); |
93bfd50a PT |
2575 | for (TableItem item : fTable.getSelection()) { |
2576 | if (item.getData() != null) { | |
2577 | list.add(item.getData()); | |
2578 | } | |
2579 | } | |
2580 | return new StructuredSelection(list); | |
2581 | } | |
2582 | ||
93bfd50a PT |
2583 | @Override |
2584 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { | |
2585 | selectionChangedListeners.remove(listener); | |
2586 | } | |
2587 | ||
93bfd50a PT |
2588 | @Override |
2589 | public void setSelection(ISelection selection) { | |
2590 | // not implemented | |
2591 | } | |
2592 | ||
2593 | /** | |
8b7eb3cd MK |
2594 | * Notifies any selection changed listeners that the viewer's selection has |
2595 | * changed. Only listeners registered at the time this method is called are | |
2596 | * notified. | |
93bfd50a | 2597 | * |
8b7eb3cd MK |
2598 | * @param event |
2599 | * a selection changed event | |
93bfd50a PT |
2600 | * |
2601 | * @see ISelectionChangedListener#selectionChanged | |
93bfd50a PT |
2602 | */ |
2603 | protected void fireSelectionChanged(final SelectionChangedEvent event) { | |
2604 | Object[] listeners = selectionChangedListeners.getListeners(); | |
2605 | for (int i = 0; i < listeners.length; ++i) { | |
2606 | final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i]; | |
2607 | SafeRunnable.run(new SafeRunnable() { | |
faa38350 | 2608 | @Override |
93bfd50a PT |
2609 | public void run() { |
2610 | l.selectionChanged(event); | |
2611 | } | |
2612 | }); | |
2613 | } | |
2614 | } | |
2615 | ||
db4721fb PT |
2616 | // ------------------------------------------------------------------------ |
2617 | // Bookmark handling | |
2618 | // ------------------------------------------------------------------------ | |
2619 | ||
2620 | /** | |
2621 | * Add a bookmark to this event table. | |
2622 | * | |
2623 | * @param bookmarksFile | |
2624 | * The file to use for the bookmarks | |
2625 | */ | |
2626 | public void addBookmark(final IFile bookmarksFile) { | |
2627 | fBookmarksFile = bookmarksFile; | |
2628 | final TableItem[] selection = fTable.getSelection(); | |
2629 | if (selection.length > 0) { | |
2630 | final TableItem tableItem = selection[0]; | |
2631 | if (tableItem.getData(Key.RANK) != null) { | |
2632 | final StringBuffer defaultMessage = new StringBuffer(); | |
2633 | for (int i = 0; i < fTable.getColumns().length; i++) { | |
60fb38b8 | 2634 | if (i > 0) { |
db4721fb PT |
2635 | defaultMessage.append(", "); //$NON-NLS-1$ |
2636 | } | |
2637 | defaultMessage.append(tableItem.getText(i)); | |
2638 | } | |
3be2946f PT |
2639 | final InputDialog dialog = new MultiLineInputDialog( |
2640 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), | |
2641 | Messages.TmfEventsTable_AddBookmarkDialogTitle, | |
2642 | Messages.TmfEventsTable_AddBookmarkDialogMessage, | |
2643 | defaultMessage.toString()); | |
db4721fb PT |
2644 | if (dialog.open() == Window.OK) { |
2645 | final String message = dialog.getValue(); | |
2646 | try { | |
2647 | final IMarker bookmark = bookmarksFile.createMarker(IMarker.BOOKMARK); | |
2648 | if (bookmark.exists()) { | |
2649 | bookmark.setAttribute(IMarker.MESSAGE, message.toString()); | |
0126a8ca AM |
2650 | final Long rank = (Long) tableItem.getData(Key.RANK); |
2651 | final int location = rank.intValue(); | |
2652 | bookmark.setAttribute(IMarker.LOCATION, Integer.valueOf(location)); | |
db4721fb PT |
2653 | fBookmarksMap.put(rank, bookmark.getId()); |
2654 | fTable.refresh(); | |
2655 | } | |
2656 | } catch (final CoreException e) { | |
2657 | displayException(e); | |
2658 | } | |
2659 | } | |
2660 | } | |
2661 | } | |
2662 | ||
2663 | } | |
2664 | ||
2665 | /** | |
2666 | * Remove a bookmark from this event table. | |
2667 | * | |
2668 | * @param bookmark | |
2669 | * The bookmark to remove | |
2670 | */ | |
2671 | public void removeBookmark(final IMarker bookmark) { | |
2db176a0 | 2672 | for (final Entry<Long, Long> entry : fBookmarksMap.entries()) { |
db4721fb | 2673 | if (entry.getValue().equals(bookmark.getId())) { |
2db176a0 | 2674 | fBookmarksMap.remove(entry.getKey(), entry.getValue()); |
db4721fb PT |
2675 | fTable.refresh(); |
2676 | return; | |
2677 | } | |
2678 | } | |
2679 | } | |
2680 | ||
0126a8ca | 2681 | private void toggleBookmark(final Long rank) { |
db4721fb PT |
2682 | if (fBookmarksFile == null) { |
2683 | return; | |
2684 | } | |
2685 | if (fBookmarksMap.containsKey(rank)) { | |
2db176a0 | 2686 | final Collection<Long> markerIds = fBookmarksMap.removeAll(rank); |
db4721fb PT |
2687 | fTable.refresh(); |
2688 | try { | |
2db176a0 PT |
2689 | for (long markerId : markerIds) { |
2690 | final IMarker bookmark = fBookmarksFile.findMarker(markerId); | |
2691 | if (bookmark != null) { | |
2692 | bookmark.delete(); | |
2693 | } | |
db4721fb PT |
2694 | } |
2695 | } catch (final CoreException e) { | |
2696 | displayException(e); | |
2697 | } | |
2698 | } else { | |
2699 | addBookmark(fBookmarksFile); | |
2700 | } | |
2701 | } | |
2702 | ||
2703 | /** | |
2704 | * Refresh the bookmarks assigned to this trace, from the contents of a | |
2705 | * bookmark file. | |
2706 | * | |
2707 | * @param bookmarksFile | |
2708 | * The bookmark file to use | |
2709 | */ | |
2710 | public void refreshBookmarks(final IFile bookmarksFile) { | |
2711 | fBookmarksFile = bookmarksFile; | |
2712 | if (bookmarksFile == null) { | |
2713 | fBookmarksMap.clear(); | |
2714 | fTable.refresh(); | |
2715 | return; | |
2716 | } | |
2717 | try { | |
2718 | fBookmarksMap.clear(); | |
2719 | for (final IMarker bookmark : bookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) { | |
2720 | final int location = bookmark.getAttribute(IMarker.LOCATION, -1); | |
2721 | if (location != -1) { | |
2722 | final long rank = location; | |
2723 | fBookmarksMap.put(rank, bookmark.getId()); | |
2724 | } | |
2725 | } | |
2726 | fTable.refresh(); | |
2727 | } catch (final CoreException e) { | |
2728 | displayException(e); | |
2729 | } | |
2730 | } | |
2731 | ||
2732 | @Override | |
2733 | public void gotoMarker(final IMarker marker) { | |
2734 | final int rank = marker.getAttribute(IMarker.LOCATION, -1); | |
2735 | if (rank != -1) { | |
2736 | int index = rank; | |
2737 | if (fTable.getData(Key.FILTER_OBJ) != null) { | |
8b7eb3cd MK |
2738 | // +1 for top filter status row |
2739 | index = fCache.getFilteredEventIndex(rank) + 1; | |
db4721fb PT |
2740 | } else if (rank >= fTable.getItemCount()) { |
2741 | fPendingGotoRank = rank; | |
2742 | } | |
a56ec2b8 | 2743 | fSelectedRank = rank; |
db4721fb | 2744 | fTable.setSelection(index + 1); // +1 for header row |
3f43dc48 | 2745 | updateStatusLine(null); |
db4721fb PT |
2746 | } |
2747 | } | |
2748 | ||
2749 | // ------------------------------------------------------------------------ | |
2750 | // Listeners | |
2751 | // ------------------------------------------------------------------------ | |
2752 | ||
db4721fb PT |
2753 | @Override |
2754 | public void colorSettingsChanged(final ColorSetting[] colorSettings) { | |
2755 | fTable.refresh(); | |
2756 | } | |
2757 | ||
db4721fb PT |
2758 | // ------------------------------------------------------------------------ |
2759 | // Signal handlers | |
2760 | // ------------------------------------------------------------------------ | |
2761 | ||
db4721fb PT |
2762 | /** |
2763 | * Handler for the trace updated signal | |
2764 | * | |
2765 | * @param signal | |
2766 | * The incoming signal | |
2767 | */ | |
2768 | @TmfSignalHandler | |
2769 | public void traceUpdated(final TmfTraceUpdatedSignal signal) { | |
2770 | if ((signal.getTrace() != fTrace) || fTable.isDisposed()) { | |
2771 | return; | |
2772 | } | |
2773 | // Perform the refresh on the UI thread | |
2774 | Display.getDefault().asyncExec(new Runnable() { | |
2775 | @Override | |
2776 | public void run() { | |
2777 | if (!fTable.isDisposed() && (fTrace != null)) { | |
2778 | if (fTable.getData(Key.FILTER_OBJ) == null) { | |
8b7eb3cd MK |
2779 | /* +1 for header row */ |
2780 | fTable.setItemCount((int) fTrace.getNbEvents() + 1); | |
2781 | /* +1 for header row */ | |
2782 | if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) { | |
2783 | /* +1 for header row */ | |
2784 | fTable.setSelection((int) fPendingGotoRank + 1); | |
db4721fb | 2785 | fPendingGotoRank = -1; |
3f43dc48 | 2786 | updateStatusLine(null); |
db4721fb PT |
2787 | } |
2788 | } else { | |
2789 | startFilterThread(); | |
2790 | } | |
2791 | } | |
2792 | if (!fRawViewer.isDisposed() && (fTrace != null)) { | |
2793 | fRawViewer.refreshEventCount(); | |
2794 | } | |
2795 | } | |
2796 | }); | |
2797 | } | |
2798 | ||
2799 | /** | |
97c71024 | 2800 | * Handler for the selection range signal. |
db4721fb PT |
2801 | * |
2802 | * @param signal | |
2803 | * The incoming signal | |
97c71024 | 2804 | * @since 1.0 |
db4721fb PT |
2805 | */ |
2806 | @TmfSignalHandler | |
97c71024 | 2807 | public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) { |
db4721fb PT |
2808 | if ((signal.getSource() != this) && (fTrace != null) && (!fTable.isDisposed())) { |
2809 | ||
8b7eb3cd MK |
2810 | /* |
2811 | * Create a request for one event that will be queued after other | |
2812 | * ongoing requests. When this request is completed do the work to | |
2813 | * select the actual event with the timestamp specified in the | |
2814 | * signal. This procedure prevents the method fTrace.getRank() from | |
2815 | * interfering and delaying ongoing requests. | |
2816 | */ | |
fd3f1eff AM |
2817 | final TmfEventRequest subRequest = new TmfEventRequest(ITmfEvent.class, |
2818 | TmfTimeRange.ETERNITY, 0, 1, ExecutionType.FOREGROUND) { | |
db4721fb | 2819 | |
0fcf3b09 | 2820 | TmfTimestamp ts = new TmfTimestamp(signal.getBeginTime()); |
db4721fb PT |
2821 | |
2822 | @Override | |
2823 | public void handleData(final ITmfEvent event) { | |
2824 | super.handleData(event); | |
2825 | } | |
2826 | ||
2827 | @Override | |
73fce654 AM |
2828 | public void handleSuccess() { |
2829 | super.handleSuccess(); | |
db4721fb PT |
2830 | if (fTrace == null) { |
2831 | return; | |
2832 | } | |
2833 | ||
8b7eb3cd MK |
2834 | /* |
2835 | * Verify if the event is within the trace range and adjust | |
2836 | * if necessary | |
2837 | */ | |
db4721fb | 2838 | ITmfTimestamp timestamp = ts; |
065cc19b | 2839 | if (timestamp.compareTo(fTrace.getStartTime()) == -1) { |
db4721fb PT |
2840 | timestamp = fTrace.getStartTime(); |
2841 | } | |
065cc19b | 2842 | if (timestamp.compareTo(fTrace.getEndTime()) == 1) { |
db4721fb PT |
2843 | timestamp = fTrace.getEndTime(); |
2844 | } | |
2845 | ||
2846 | // Get the rank of the selected event in the table | |
2847 | final ITmfContext context = fTrace.seekEvent(timestamp); | |
2848 | final long rank = context.getRank(); | |
4c9f2944 | 2849 | context.dispose(); |
db4721fb PT |
2850 | fSelectedRank = rank; |
2851 | ||
2852 | fTable.getDisplay().asyncExec(new Runnable() { | |
2853 | @Override | |
2854 | public void run() { | |
2855 | // Return if table is disposed | |
2856 | if (fTable.isDisposed()) { | |
2857 | return; | |
2858 | } | |
2859 | ||
2860 | int index = (int) rank; | |
2861 | if (fTable.isDisposed()) { | |
2862 | return; | |
2863 | } | |
60fb38b8 | 2864 | if (fTable.getData(Key.FILTER_OBJ) != null) { |
8b7eb3cd MK |
2865 | /* +1 for top filter status row */ |
2866 | index = fCache.getFilteredEventIndex(rank) + 1; | |
db4721fb | 2867 | } |
8b7eb3cd MK |
2868 | /* +1 for header row */ |
2869 | fTable.setSelection(index + 1); | |
db4721fb | 2870 | fRawViewer.selectAndReveal(rank); |
3f43dc48 | 2871 | updateStatusLine(null); |
db4721fb PT |
2872 | } |
2873 | }); | |
2874 | } | |
2875 | }; | |
2876 | ||
fd3f1eff | 2877 | ((ITmfEventProvider) fTrace).sendRequest(subRequest); |
db4721fb PT |
2878 | } |
2879 | } | |
2880 | ||
2881 | // ------------------------------------------------------------------------ | |
2882 | // Error handling | |
2883 | // ------------------------------------------------------------------------ | |
2884 | ||
2885 | /** | |
2886 | * Display an exception in a message box | |
2887 | * | |
8b7eb3cd MK |
2888 | * @param e |
2889 | * the exception | |
db4721fb PT |
2890 | */ |
2891 | private static void displayException(final Exception e) { | |
2892 | final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); | |
60fb38b8 | 2893 | mb.setText(e.getClass().getSimpleName()); |
db4721fb PT |
2894 | mb.setMessage(e.getMessage()); |
2895 | mb.open(); | |
2896 | } | |
2897 | ||
f8177ba2 | 2898 | /** |
ae09c4ad | 2899 | * Refresh the table |
f8177ba2 FC |
2900 | */ |
2901 | public void refresh() { | |
2902 | fCache.clear(); | |
2903 | fTable.refresh(); | |
2904 | fTable.redraw(); | |
2905 | } | |
03142470 BH |
2906 | |
2907 | /** | |
9447c7ee AM |
2908 | * Margin column for images and special text (e.g. collapse count) |
2909 | */ | |
2910 | private static final class TmfMarginColumn extends TmfEventTableColumn { | |
2911 | ||
2912 | private static final @NonNull ITmfEventAspect MARGIN_ASPECT = new ITmfEventAspect() { | |
2913 | ||
2914 | @Override | |
2915 | public String getName() { | |
2916 | return EMPTY_STRING; | |
2917 | } | |
2918 | ||
2919 | @Override | |
2920 | public String resolve(ITmfEvent event) { | |
2921 | if (!(event instanceof CachedEvent) || ((CachedEvent) event).repeatCount == 0) { | |
2922 | return EMPTY_STRING; | |
2923 | } | |
2924 | return "+" + ((CachedEvent) event).repeatCount; //$NON-NLS-1$ | |
2925 | } | |
2926 | ||
2927 | @Override | |
2928 | public String getHelpText() { | |
2929 | return EMPTY_STRING; | |
2930 | } | |
9447c7ee AM |
2931 | }; |
2932 | ||
2933 | /** | |
2934 | * Constructor | |
2935 | */ | |
2936 | public TmfMarginColumn() { | |
2937 | super(MARGIN_ASPECT); | |
2938 | } | |
2939 | } | |
03142470 | 2940 | |
db4721fb | 2941 | } |