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