| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal |
| 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: |
| 10 | * Patrick Tasse - Initial API and implementation |
| 11 | * Bernd Hufmann - Updated signal handling |
| 12 | * Geneviève Bastien - Move code to provide base classes for time graph view |
| 13 | * Marc-Andre Laperle - Add time zone preference |
| 14 | * Geneviève Bastien - Add event links between entries |
| 15 | *******************************************************************************/ |
| 16 | |
| 17 | package org.eclipse.tracecompass.tmf.ui.views.timegraph; |
| 18 | |
| 19 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
| 20 | |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.Collections; |
| 23 | import java.util.Comparator; |
| 24 | import java.util.HashMap; |
| 25 | import java.util.HashSet; |
| 26 | import java.util.List; |
| 27 | import java.util.Map; |
| 28 | import java.util.Set; |
| 29 | import java.util.concurrent.CopyOnWriteArrayList; |
| 30 | import java.util.concurrent.atomic.AtomicInteger; |
| 31 | import java.util.regex.Matcher; |
| 32 | import java.util.regex.Pattern; |
| 33 | |
| 34 | import org.eclipse.core.resources.IFile; |
| 35 | import org.eclipse.core.resources.IMarker; |
| 36 | import org.eclipse.core.resources.IMarkerDelta; |
| 37 | import org.eclipse.core.resources.IResource; |
| 38 | import org.eclipse.core.resources.IResourceChangeEvent; |
| 39 | import org.eclipse.core.resources.IResourceChangeListener; |
| 40 | import org.eclipse.core.resources.IWorkspaceRunnable; |
| 41 | import org.eclipse.core.resources.ResourcesPlugin; |
| 42 | import org.eclipse.core.runtime.CoreException; |
| 43 | import org.eclipse.core.runtime.IProgressMonitor; |
| 44 | import org.eclipse.core.runtime.NullProgressMonitor; |
| 45 | import org.eclipse.jdt.annotation.NonNull; |
| 46 | import org.eclipse.jdt.annotation.Nullable; |
| 47 | import org.eclipse.jface.action.Action; |
| 48 | import org.eclipse.jface.action.IAction; |
| 49 | import org.eclipse.jface.action.IMenuManager; |
| 50 | import org.eclipse.jface.action.IStatusLineManager; |
| 51 | import org.eclipse.jface.action.IToolBarManager; |
| 52 | import org.eclipse.jface.action.Separator; |
| 53 | import org.eclipse.jface.viewers.AbstractTreeViewer; |
| 54 | import org.eclipse.jface.viewers.ILabelProvider; |
| 55 | import org.eclipse.jface.viewers.ILabelProviderListener; |
| 56 | import org.eclipse.jface.viewers.ISelectionProvider; |
| 57 | import org.eclipse.jface.viewers.ITableLabelProvider; |
| 58 | import org.eclipse.jface.viewers.ITreeContentProvider; |
| 59 | import org.eclipse.jface.viewers.TreeViewer; |
| 60 | import org.eclipse.jface.viewers.ViewerFilter; |
| 61 | import org.eclipse.osgi.util.NLS; |
| 62 | import org.eclipse.swt.SWT; |
| 63 | import org.eclipse.swt.events.SelectionAdapter; |
| 64 | import org.eclipse.swt.events.SelectionEvent; |
| 65 | import org.eclipse.swt.graphics.Color; |
| 66 | import org.eclipse.swt.graphics.Image; |
| 67 | import org.eclipse.swt.widgets.Composite; |
| 68 | import org.eclipse.swt.widgets.Display; |
| 69 | import org.eclipse.swt.widgets.Tree; |
| 70 | import org.eclipse.swt.widgets.TreeColumn; |
| 71 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
| 72 | import org.eclipse.tracecompass.tmf.core.resources.ITmfMarker; |
| 73 | import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
| 74 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; |
| 75 | import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal; |
| 76 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; |
| 77 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; |
| 78 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal; |
| 79 | import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal; |
| 80 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
| 81 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp; |
| 82 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; |
| 83 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
| 84 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceAdapterManager; |
| 85 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext; |
| 86 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; |
| 87 | import org.eclipse.tracecompass.tmf.ui.TmfUiRefreshHandler; |
| 88 | import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo; |
| 89 | import org.eclipse.tracecompass.tmf.ui.views.ITmfTimeAligned; |
| 90 | import org.eclipse.tracecompass.tmf.ui.views.TmfView; |
| 91 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphBookmarkListener; |
| 92 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphContentProvider; |
| 93 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2; |
| 94 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphRangeListener; |
| 95 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener; |
| 96 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphTimeListener; |
| 97 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphBookmarkEvent; |
| 98 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphCombo; |
| 99 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphContentProvider; |
| 100 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; |
| 101 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent; |
| 102 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphTimeEvent; |
| 103 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer; |
| 104 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent; |
| 105 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent; |
| 106 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEventSource; |
| 107 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; |
| 108 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; |
| 109 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent; |
| 110 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry; |
| 111 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; |
| 112 | import org.eclipse.ui.IActionBars; |
| 113 | |
| 114 | /** |
| 115 | * An abstract view all time graph views can inherit |
| 116 | * |
| 117 | * This view contains either a time graph viewer, or a time graph combo which is |
| 118 | * divided between a tree viewer on the left and a time graph viewer on the right. |
| 119 | */ |
| 120 | public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeAligned, IResourceChangeListener { |
| 121 | |
| 122 | /** Constant indicating that all levels of the time graph should be expanded */ |
| 123 | protected static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS; |
| 124 | |
| 125 | private static final Pattern RGBA_PATTERN = Pattern.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$ |
| 126 | |
| 127 | /** |
| 128 | * Redraw state enum |
| 129 | */ |
| 130 | private enum State { |
| 131 | IDLE, BUSY, PENDING |
| 132 | } |
| 133 | |
| 134 | // ------------------------------------------------------------------------ |
| 135 | // Fields |
| 136 | // ------------------------------------------------------------------------ |
| 137 | |
| 138 | /** The timegraph wrapper */ |
| 139 | private ITimeGraphWrapper fTimeGraphWrapper; |
| 140 | |
| 141 | private AtomicInteger fDirty = new AtomicInteger(); |
| 142 | |
| 143 | /** The selected trace */ |
| 144 | private ITmfTrace fTrace; |
| 145 | |
| 146 | /** The selected trace editor file*/ |
| 147 | private IFile fEditorFile; |
| 148 | |
| 149 | /** The timegraph entry list */ |
| 150 | private List<TimeGraphEntry> fEntryList; |
| 151 | |
| 152 | /** The trace to entry list hash map */ |
| 153 | private final Map<ITmfTrace, List<TimeGraphEntry>> fEntryListMap = new HashMap<>(); |
| 154 | |
| 155 | /** The trace to filters hash map */ |
| 156 | private final Map<ITmfTrace, @NonNull ViewerFilter[]> fFiltersMap = new HashMap<>(); |
| 157 | |
| 158 | /** The trace to marker event sources hash map */ |
| 159 | private final Map<ITmfTrace, List<IMarkerEventSource>> fMarkerEventSourcesMap = new HashMap<>(); |
| 160 | |
| 161 | /** The trace to build thread hash map */ |
| 162 | private final Map<ITmfTrace, BuildThread> fBuildThreadMap = new HashMap<>(); |
| 163 | |
| 164 | /** The start time */ |
| 165 | private long fStartTime = SWT.DEFAULT; |
| 166 | |
| 167 | /** The end time */ |
| 168 | private long fEndTime = SWT.DEFAULT; |
| 169 | |
| 170 | /** The display width */ |
| 171 | private final int fDisplayWidth; |
| 172 | |
| 173 | /** The zoom thread */ |
| 174 | private ZoomThread fZoomThread; |
| 175 | |
| 176 | /** The next resource action */ |
| 177 | private Action fNextResourceAction; |
| 178 | |
| 179 | /** The previous resource action */ |
| 180 | private Action fPreviousResourceAction; |
| 181 | |
| 182 | /** A comparator class */ |
| 183 | private Comparator<ITimeGraphEntry> fEntryComparator = null; |
| 184 | |
| 185 | /** The redraw state used to prevent unnecessary queuing of display runnables */ |
| 186 | private State fRedrawState = State.IDLE; |
| 187 | |
| 188 | /** The redraw synchronization object */ |
| 189 | private final Object fSyncObj = new Object(); |
| 190 | |
| 191 | /** The presentation provider for this view */ |
| 192 | private final TimeGraphPresentationProvider fPresentation; |
| 193 | |
| 194 | /** The tree column label array, or null if combo is not used */ |
| 195 | private String[] fColumns; |
| 196 | |
| 197 | private Comparator<ITimeGraphEntry>[] fColumnComparators; |
| 198 | |
| 199 | /** The sort direction */ |
| 200 | private int fDirection = SWT.DOWN; |
| 201 | |
| 202 | /** The tree label provider, or null if combo is not used */ |
| 203 | private TreeLabelProvider fLabelProvider = null; |
| 204 | |
| 205 | /** The time graph content provider */ |
| 206 | private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider = new TimeGraphContentProvider(); |
| 207 | |
| 208 | /** The relative weight of the sash, ignored if combo is not used */ |
| 209 | private int[] fWeight = { 1, 3 }; |
| 210 | |
| 211 | /** The filter column label array, or null if filter is not used */ |
| 212 | private String[] fFilterColumns; |
| 213 | |
| 214 | /** The pack done flag */ |
| 215 | private boolean fPackDone = false; |
| 216 | |
| 217 | /** The filter content provider, or null if filter is not used */ |
| 218 | private ITreeContentProvider fFilterContentProvider; |
| 219 | |
| 220 | /** The filter label provider, or null if filter is not used */ |
| 221 | private TreeLabelProvider fFilterLabelProvider; |
| 222 | |
| 223 | private int fAutoExpandLevel = ALL_LEVELS; |
| 224 | |
| 225 | /** The list of color resources created by this view */ |
| 226 | private final List<Color> fColors = new ArrayList<>(); |
| 227 | |
| 228 | /** The default column index for sorting */ |
| 229 | private int fInitialSortColumn = 0; |
| 230 | |
| 231 | /** Flag to indicate to reveal selection */ |
| 232 | private volatile boolean fIsRevealSelection = false; |
| 233 | |
| 234 | // ------------------------------------------------------------------------ |
| 235 | // Classes |
| 236 | // ------------------------------------------------------------------------ |
| 237 | |
| 238 | private interface ITimeGraphWrapper { |
| 239 | |
| 240 | void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider); |
| 241 | |
| 242 | void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider); |
| 243 | |
| 244 | TimeGraphViewer getTimeGraphViewer(); |
| 245 | |
| 246 | void addSelectionListener(ITimeGraphSelectionListener listener); |
| 247 | |
| 248 | ISelectionProvider getSelectionProvider(); |
| 249 | |
| 250 | void setFocus(); |
| 251 | |
| 252 | boolean isDisposed(); |
| 253 | |
| 254 | void refresh(); |
| 255 | |
| 256 | void setInput(Object input); |
| 257 | |
| 258 | Object getInput(); |
| 259 | |
| 260 | void setFilters(@NonNull ViewerFilter[] filters); |
| 261 | |
| 262 | @NonNull ViewerFilter[] getFilters(); |
| 263 | |
| 264 | void redraw(); |
| 265 | |
| 266 | void update(); |
| 267 | |
| 268 | void setAutoExpandLevel(int level); |
| 269 | |
| 270 | void setFilterColumns(String[] columnNames); |
| 271 | |
| 272 | void setFilterContentProvider(ITreeContentProvider contentProvider); |
| 273 | |
| 274 | void setFilterLabelProvider(ITableLabelProvider labelProvider); |
| 275 | |
| 276 | IAction getShowFilterDialogAction(); |
| 277 | |
| 278 | void performAlign(int offset, int width); |
| 279 | |
| 280 | TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo(); |
| 281 | |
| 282 | int getAvailableWidth(int requestedOffset); |
| 283 | } |
| 284 | |
| 285 | private class TimeGraphViewerWrapper implements ITimeGraphWrapper { |
| 286 | private TimeGraphViewer viewer; |
| 287 | |
| 288 | private TimeGraphViewerWrapper(Composite parent, int style) { |
| 289 | viewer = new TimeGraphViewer(parent, style); |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) { |
| 294 | viewer.setTimeGraphContentProvider(timeGraphContentProvider); |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider) { |
| 299 | viewer.setTimeGraphProvider(timeGraphPresentationProvider); |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public TimeGraphViewer getTimeGraphViewer() { |
| 304 | return viewer; |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public void addSelectionListener(ITimeGraphSelectionListener listener) { |
| 309 | viewer.addSelectionListener(listener); |
| 310 | } |
| 311 | |
| 312 | @Override |
| 313 | public ISelectionProvider getSelectionProvider() { |
| 314 | return viewer.getSelectionProvider(); |
| 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public void setFocus() { |
| 319 | viewer.setFocus(); |
| 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public boolean isDisposed() { |
| 324 | return viewer.getControl().isDisposed(); |
| 325 | } |
| 326 | |
| 327 | @Override |
| 328 | public void setInput(Object input) { |
| 329 | viewer.setInput(input); |
| 330 | } |
| 331 | |
| 332 | @Override |
| 333 | public Object getInput() { |
| 334 | return viewer.getInput(); |
| 335 | } |
| 336 | |
| 337 | @Override |
| 338 | public void setFilterColumns(String[] columnNames) { |
| 339 | viewer.setFilterColumns(columnNames); |
| 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public void setFilterContentProvider(ITreeContentProvider contentProvider) { |
| 344 | viewer.setFilterContentProvider(contentProvider); |
| 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public void setFilterLabelProvider(ITableLabelProvider labelProvider) { |
| 349 | viewer.setFilterLabelProvider(labelProvider); |
| 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public void setFilters(@NonNull ViewerFilter[] filters) { |
| 354 | viewer.setFilters(filters); |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public @NonNull ViewerFilter[] getFilters() { |
| 359 | return viewer.getFilters(); |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public IAction getShowFilterDialogAction() { |
| 364 | return viewer.getShowFilterDialogAction(); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public void refresh() { |
| 369 | viewer.refresh(); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public void redraw() { |
| 374 | viewer.getControl().redraw(); |
| 375 | } |
| 376 | |
| 377 | @Override |
| 378 | public void update() { |
| 379 | viewer.getControl().update(); |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public void setAutoExpandLevel(int level) { |
| 384 | viewer.setAutoExpandLevel(level); |
| 385 | } |
| 386 | |
| 387 | @Override |
| 388 | public void performAlign(int offset, int width) { |
| 389 | viewer.performAlign(offset, width); |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() { |
| 394 | return viewer.getTimeViewAlignmentInfo(); |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public int getAvailableWidth(int requestedOffset) { |
| 399 | return viewer.getAvailableWidth(requestedOffset); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | private class TimeGraphComboWrapper implements ITimeGraphWrapper { |
| 404 | private TimeGraphCombo combo; |
| 405 | |
| 406 | private TimeGraphComboWrapper(Composite parent, int style) { |
| 407 | combo = new TimeGraphCombo(parent, style, fWeight); |
| 408 | } |
| 409 | |
| 410 | @Override |
| 411 | public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) { |
| 412 | combo.setTimeGraphContentProvider(timeGraphContentProvider); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider) { |
| 417 | combo.setTimeGraphProvider(timeGraphPresentationProvider); |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public TimeGraphViewer getTimeGraphViewer() { |
| 422 | return combo.getTimeGraphViewer(); |
| 423 | } |
| 424 | |
| 425 | @Override |
| 426 | public void addSelectionListener(ITimeGraphSelectionListener listener) { |
| 427 | combo.addSelectionListener(listener); |
| 428 | } |
| 429 | |
| 430 | @Override |
| 431 | public ISelectionProvider getSelectionProvider() { |
| 432 | return combo.getTreeViewer(); |
| 433 | } |
| 434 | |
| 435 | @Override |
| 436 | public void setFocus() { |
| 437 | combo.setFocus(); |
| 438 | } |
| 439 | |
| 440 | @Override |
| 441 | public boolean isDisposed() { |
| 442 | return combo.isDisposed(); |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | public void setInput(Object input) { |
| 447 | combo.setInput(input); |
| 448 | } |
| 449 | |
| 450 | @Override |
| 451 | public Object getInput() { |
| 452 | return combo.getInput(); |
| 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public void setFilterColumns(String[] columnNames) { |
| 457 | combo.setFilterColumns(columnNames); |
| 458 | } |
| 459 | |
| 460 | @Override |
| 461 | public void setFilterContentProvider(ITreeContentProvider contentProvider) { |
| 462 | combo.setFilterContentProvider(contentProvider); |
| 463 | } |
| 464 | |
| 465 | @Override |
| 466 | public void setFilterLabelProvider(ITableLabelProvider labelProvider) { |
| 467 | combo.setFilterLabelProvider(labelProvider); |
| 468 | } |
| 469 | |
| 470 | @Override |
| 471 | public void setFilters(@NonNull ViewerFilter[] filters) { |
| 472 | combo.setFilters(filters); |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public @NonNull ViewerFilter[] getFilters() { |
| 477 | return combo.getFilters(); |
| 478 | } |
| 479 | |
| 480 | @Override |
| 481 | public IAction getShowFilterDialogAction() { |
| 482 | return combo.getShowFilterDialogAction(); |
| 483 | } |
| 484 | |
| 485 | @Override |
| 486 | public void refresh() { |
| 487 | combo.refresh(); |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public void redraw() { |
| 492 | combo.redraw(); |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public void update() { |
| 497 | combo.update(); |
| 498 | } |
| 499 | |
| 500 | @Override |
| 501 | public void setAutoExpandLevel(int level) { |
| 502 | combo.setAutoExpandLevel(level); |
| 503 | } |
| 504 | |
| 505 | TimeGraphCombo getTimeGraphCombo() { |
| 506 | return combo; |
| 507 | } |
| 508 | |
| 509 | TreeViewer getTreeViewer() { |
| 510 | return combo.getTreeViewer(); |
| 511 | } |
| 512 | |
| 513 | @Override |
| 514 | public void performAlign(int offset, int width) { |
| 515 | combo.performAlign(offset, width); |
| 516 | } |
| 517 | |
| 518 | @Override |
| 519 | public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() { |
| 520 | return combo.getTimeViewAlignmentInfo(); |
| 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public int getAvailableWidth(int requestedOffset) { |
| 525 | return combo.getAvailableWidth(requestedOffset); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Base class to provide the labels for the tree viewer. Views extending |
| 531 | * this class typically need to override the getColumnText method if they |
| 532 | * have more than one column to display |
| 533 | */ |
| 534 | protected static class TreeLabelProvider implements ITableLabelProvider, ILabelProvider { |
| 535 | |
| 536 | @Override |
| 537 | public void addListener(ILabelProviderListener listener) { |
| 538 | } |
| 539 | |
| 540 | @Override |
| 541 | public void dispose() { |
| 542 | } |
| 543 | |
| 544 | @Override |
| 545 | public boolean isLabelProperty(Object element, String property) { |
| 546 | return false; |
| 547 | } |
| 548 | |
| 549 | @Override |
| 550 | public void removeListener(ILabelProviderListener listener) { |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public Image getColumnImage(Object element, int columnIndex) { |
| 555 | return null; |
| 556 | } |
| 557 | |
| 558 | @Override |
| 559 | public String getColumnText(Object element, int columnIndex) { |
| 560 | TimeGraphEntry entry = (TimeGraphEntry) element; |
| 561 | if (columnIndex == 0) { |
| 562 | return entry.getName(); |
| 563 | } |
| 564 | return new String(); |
| 565 | } |
| 566 | |
| 567 | @Override |
| 568 | public Image getImage(Object element) { |
| 569 | return null; |
| 570 | } |
| 571 | |
| 572 | @Override |
| 573 | public String getText(Object element) { |
| 574 | TimeGraphEntry entry = (TimeGraphEntry) element; |
| 575 | return entry.getName(); |
| 576 | } |
| 577 | |
| 578 | } |
| 579 | |
| 580 | private class BuildThread extends Thread { |
| 581 | private final @NonNull ITmfTrace fBuildTrace; |
| 582 | private final @NonNull ITmfTrace fParentTrace; |
| 583 | private final @NonNull IProgressMonitor fMonitor; |
| 584 | |
| 585 | public BuildThread(final @NonNull ITmfTrace trace, final @NonNull ITmfTrace parentTrace, final String name) { |
| 586 | super(name + " build"); //$NON-NLS-1$ |
| 587 | fBuildTrace = trace; |
| 588 | fParentTrace = parentTrace; |
| 589 | fMonitor = new NullProgressMonitor(); |
| 590 | } |
| 591 | |
| 592 | @Override |
| 593 | public void run() { |
| 594 | buildEventList(fBuildTrace, fParentTrace, fMonitor); |
| 595 | synchronized (fBuildThreadMap) { |
| 596 | fBuildThreadMap.remove(fBuildTrace); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | public void cancel() { |
| 601 | fMonitor.setCanceled(true); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Zoom thread |
| 607 | * @since 1.1 |
| 608 | */ |
| 609 | protected abstract class ZoomThread extends Thread { |
| 610 | private final long fZoomStartTime; |
| 611 | private final long fZoomEndTime; |
| 612 | private final long fResolution; |
| 613 | private final @NonNull IProgressMonitor fMonitor; |
| 614 | |
| 615 | /** |
| 616 | * Constructor |
| 617 | * |
| 618 | * @param startTime |
| 619 | * the start time |
| 620 | * @param endTime |
| 621 | * the end time |
| 622 | * @param resolution |
| 623 | * the resolution |
| 624 | */ |
| 625 | public ZoomThread(long startTime, long endTime, long resolution) { |
| 626 | super(AbstractTimeGraphView.this.getName() + " zoom"); //$NON-NLS-1$ |
| 627 | fZoomStartTime = startTime; |
| 628 | fZoomEndTime = endTime; |
| 629 | fResolution = resolution; |
| 630 | fMonitor = new NullProgressMonitor(); |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * @return the zoom start time |
| 635 | */ |
| 636 | public long getZoomStartTime() { |
| 637 | return fZoomStartTime; |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * @return the zoom end time |
| 642 | */ |
| 643 | public long getZoomEndTime() { |
| 644 | return fZoomEndTime; |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * @return the resolution |
| 649 | */ |
| 650 | public long getResolution() { |
| 651 | return fResolution; |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * @return the monitor |
| 656 | */ |
| 657 | public @NonNull IProgressMonitor getMonitor() { |
| 658 | return fMonitor; |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Cancel the zoom thread |
| 663 | */ |
| 664 | public void cancel() { |
| 665 | fMonitor.setCanceled(true); |
| 666 | } |
| 667 | |
| 668 | @Override |
| 669 | public final void run() { |
| 670 | doRun(); |
| 671 | fDirty.decrementAndGet(); |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * Run the zoom operation. |
| 676 | * @since 2.0 |
| 677 | */ |
| 678 | public abstract void doRun(); |
| 679 | } |
| 680 | |
| 681 | private class ZoomThreadByEntry extends ZoomThread { |
| 682 | private final @NonNull List<TimeGraphEntry> fZoomEntryList; |
| 683 | |
| 684 | public ZoomThreadByEntry(@NonNull List<TimeGraphEntry> entryList, long startTime, long endTime, long resolution) { |
| 685 | super(startTime, endTime, resolution); |
| 686 | fZoomEntryList = entryList; |
| 687 | } |
| 688 | |
| 689 | @Override |
| 690 | public void doRun() { |
| 691 | for (TimeGraphEntry entry : fZoomEntryList) { |
| 692 | if (getMonitor().isCanceled()) { |
| 693 | return; |
| 694 | } |
| 695 | if (entry == null) { |
| 696 | break; |
| 697 | } |
| 698 | zoom(entry, getMonitor()); |
| 699 | } |
| 700 | /* Refresh the arrows when zooming */ |
| 701 | List<ILinkEvent> events = getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()); |
| 702 | if (events != null) { |
| 703 | fTimeGraphWrapper.getTimeGraphViewer().setLinks(events); |
| 704 | redraw(); |
| 705 | } |
| 706 | /* Refresh the view-specific markers when zooming */ |
| 707 | List<IMarkerEvent> markers = new ArrayList<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor())); |
| 708 | /* Refresh the trace-specific markers when zooming */ |
| 709 | markers.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor())); |
| 710 | fTimeGraphWrapper.getTimeGraphViewer().setMarkers(markers); |
| 711 | redraw(); |
| 712 | } |
| 713 | |
| 714 | private void zoom(@NonNull TimeGraphEntry entry, @NonNull IProgressMonitor monitor) { |
| 715 | if (getZoomStartTime() <= fStartTime && getZoomEndTime() >= fEndTime) { |
| 716 | entry.setZoomedEventList(null); |
| 717 | } else { |
| 718 | List<ITimeEvent> zoomedEventList = getEventList(entry, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor); |
| 719 | if (zoomedEventList != null) { |
| 720 | entry.setZoomedEventList(zoomedEventList); |
| 721 | } |
| 722 | } |
| 723 | redraw(); |
| 724 | for (ITimeGraphEntry child : entry.getChildren()) { |
| 725 | if (monitor.isCanceled()) { |
| 726 | return; |
| 727 | } |
| 728 | if (child instanceof TimeGraphEntry) { |
| 729 | zoom((TimeGraphEntry) child, monitor); |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | } |
| 735 | |
| 736 | // ------------------------------------------------------------------------ |
| 737 | // Constructors |
| 738 | // ------------------------------------------------------------------------ |
| 739 | |
| 740 | /** |
| 741 | * Constructs a time graph view that contains either a time graph viewer or |
| 742 | * a time graph combo. |
| 743 | * |
| 744 | * By default, the view uses a time graph viewer. To use a time graph combo, |
| 745 | * the subclass constructor must call {@link #setTreeColumns(String[])} and |
| 746 | * {@link #setTreeLabelProvider(TreeLabelProvider)}. |
| 747 | * |
| 748 | * @param id |
| 749 | * The id of the view |
| 750 | * @param pres |
| 751 | * The presentation provider |
| 752 | */ |
| 753 | public AbstractTimeGraphView(String id, TimeGraphPresentationProvider pres) { |
| 754 | super(id); |
| 755 | fPresentation = pres; |
| 756 | fDisplayWidth = Display.getDefault().getBounds().width; |
| 757 | } |
| 758 | |
| 759 | // ------------------------------------------------------------------------ |
| 760 | // Getters and setters |
| 761 | // ------------------------------------------------------------------------ |
| 762 | |
| 763 | /** |
| 764 | * Getter for the time graph combo |
| 765 | * |
| 766 | * @return The time graph combo, or null if combo is not used |
| 767 | */ |
| 768 | protected TimeGraphCombo getTimeGraphCombo() { |
| 769 | if (fTimeGraphWrapper instanceof TimeGraphComboWrapper) { |
| 770 | return ((TimeGraphComboWrapper) fTimeGraphWrapper).getTimeGraphCombo(); |
| 771 | } |
| 772 | return null; |
| 773 | } |
| 774 | |
| 775 | /** |
| 776 | * Getter for the time graph viewer |
| 777 | * |
| 778 | * @return The time graph viewer |
| 779 | */ |
| 780 | protected TimeGraphViewer getTimeGraphViewer() { |
| 781 | return fTimeGraphWrapper.getTimeGraphViewer(); |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * Getter for the presentation provider |
| 786 | * |
| 787 | * @return The time graph presentation provider |
| 788 | */ |
| 789 | protected ITimeGraphPresentationProvider2 getPresentationProvider() { |
| 790 | return fPresentation; |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Sets the tree column labels. |
| 795 | * <p> |
| 796 | * This should be called from the constructor. |
| 797 | * |
| 798 | * @param columns |
| 799 | * The array of tree column labels |
| 800 | */ |
| 801 | protected void setTreeColumns(final String[] columns) { |
| 802 | setTreeColumns(columns, null, 0); |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * Sets the tree column labels. |
| 807 | * <p> |
| 808 | * This should be called from the constructor. |
| 809 | * |
| 810 | * @param columns |
| 811 | * The array of tree column labels |
| 812 | * @param comparators |
| 813 | * An array of column comparators for sorting of columns when |
| 814 | * clicking on column header |
| 815 | * @param initialSortColumn |
| 816 | * Index of column to sort initially |
| 817 | * @since 2.0 |
| 818 | */ |
| 819 | protected void setTreeColumns(final String[] columns, final Comparator<ITimeGraphEntry>[] comparators, int initialSortColumn) { |
| 820 | checkPartNotCreated(); |
| 821 | fColumns = columns; |
| 822 | fColumnComparators = comparators; |
| 823 | fInitialSortColumn = initialSortColumn; |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * Sets the tree label provider. |
| 828 | * <p> |
| 829 | * This should be called from the constructor. |
| 830 | * |
| 831 | * @param tlp |
| 832 | * The tree label provider |
| 833 | */ |
| 834 | protected void setTreeLabelProvider(final TreeLabelProvider tlp) { |
| 835 | checkPartNotCreated(); |
| 836 | fLabelProvider = tlp; |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * Sets the time graph content provider. |
| 841 | * <p> |
| 842 | * This should be called from the constructor. |
| 843 | * |
| 844 | * @param tgcp |
| 845 | * The time graph content provider |
| 846 | * @since 1.0 |
| 847 | */ |
| 848 | protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp) { |
| 849 | checkPartNotCreated(); |
| 850 | fTimeGraphContentProvider = tgcp; |
| 851 | } |
| 852 | |
| 853 | /** |
| 854 | * Sets the relative weight of each part of the time graph combo. |
| 855 | * <p> |
| 856 | * This should be called from the constructor. |
| 857 | * |
| 858 | * @param weights |
| 859 | * The array (length 2) of relative weights of each part of the combo |
| 860 | */ |
| 861 | protected void setWeight(final int[] weights) { |
| 862 | checkPartNotCreated(); |
| 863 | fWeight = weights; |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Sets the filter column labels. |
| 868 | * <p> |
| 869 | * This should be called from the constructor. |
| 870 | * |
| 871 | * @param filterColumns |
| 872 | * The array of filter column labels |
| 873 | */ |
| 874 | protected void setFilterColumns(final String[] filterColumns) { |
| 875 | checkPartNotCreated(); |
| 876 | fFilterColumns = filterColumns; |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Sets the filter content provider. |
| 881 | * <p> |
| 882 | * This should be called from the constructor. |
| 883 | * |
| 884 | * @param contentProvider |
| 885 | * The filter content provider |
| 886 | * @since 2.0 |
| 887 | */ |
| 888 | protected void setFilterContentProvider(final ITreeContentProvider contentProvider) { |
| 889 | checkPartNotCreated(); |
| 890 | fFilterContentProvider = contentProvider; |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * Sets the filter label provider. |
| 895 | * <p> |
| 896 | * This should be called from the constructor. |
| 897 | * |
| 898 | * @param labelProvider |
| 899 | * The filter label provider |
| 900 | */ |
| 901 | protected void setFilterLabelProvider(final TreeLabelProvider labelProvider) { |
| 902 | checkPartNotCreated(); |
| 903 | fFilterLabelProvider = labelProvider; |
| 904 | } |
| 905 | |
| 906 | private void checkPartNotCreated() { |
| 907 | if (getParentComposite() != null) { |
| 908 | throw new IllegalStateException("This method must be called before createPartControl."); //$NON-NLS-1$ |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Gets the display width |
| 914 | * |
| 915 | * @return the display width |
| 916 | */ |
| 917 | protected int getDisplayWidth() { |
| 918 | return fDisplayWidth; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * Gets the comparator for the entries |
| 923 | * |
| 924 | * @return The entry comparator |
| 925 | */ |
| 926 | protected Comparator<ITimeGraphEntry> getEntryComparator() { |
| 927 | return fEntryComparator; |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * Sets the comparator class for the entries. |
| 932 | * <p> |
| 933 | * This comparator will apply recursively to entries that implement |
| 934 | * {@link TimeGraphEntry#sortChildren(Comparator)}. |
| 935 | * |
| 936 | * @param comparator |
| 937 | * A comparator object |
| 938 | */ |
| 939 | protected void setEntryComparator(final Comparator<ITimeGraphEntry> comparator) { |
| 940 | fEntryComparator = comparator; |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * Gets the trace displayed in the view |
| 945 | * |
| 946 | * @return The trace |
| 947 | */ |
| 948 | protected ITmfTrace getTrace() { |
| 949 | return fTrace; |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * Gets the start time |
| 954 | * |
| 955 | * @return The start time |
| 956 | */ |
| 957 | protected long getStartTime() { |
| 958 | return fStartTime; |
| 959 | } |
| 960 | |
| 961 | /** |
| 962 | * Sets the start time |
| 963 | * |
| 964 | * @param time |
| 965 | * The start time |
| 966 | */ |
| 967 | protected void setStartTime(long time) { |
| 968 | fStartTime = time; |
| 969 | } |
| 970 | |
| 971 | /** |
| 972 | * Gets the end time |
| 973 | * |
| 974 | * @return The end time |
| 975 | */ |
| 976 | protected long getEndTime() { |
| 977 | return fEndTime; |
| 978 | } |
| 979 | |
| 980 | /** |
| 981 | * Sets the end time |
| 982 | * |
| 983 | * @param time |
| 984 | * The end time |
| 985 | */ |
| 986 | protected void setEndTime(long time) { |
| 987 | fEndTime = time; |
| 988 | } |
| 989 | |
| 990 | /** |
| 991 | * Sets the auto-expand level to be used for the input of the view. The |
| 992 | * value 0 means that there is no auto-expand; 1 means that top-level |
| 993 | * elements are expanded, but not their children; 2 means that top-level |
| 994 | * elements are expanded, and their children, but not grand-children; and so |
| 995 | * on. |
| 996 | * <p> |
| 997 | * The value {@link #ALL_LEVELS} means that all subtrees should be expanded. |
| 998 | * </p> |
| 999 | * |
| 1000 | * @param level |
| 1001 | * non-negative level, or <code>ALL_LEVELS</code> to expand all |
| 1002 | * levels of the tree |
| 1003 | */ |
| 1004 | protected void setAutoExpandLevel(int level) { |
| 1005 | fAutoExpandLevel = level; |
| 1006 | ITimeGraphWrapper tgWrapper = fTimeGraphWrapper; |
| 1007 | if (tgWrapper != null) { |
| 1008 | tgWrapper.setAutoExpandLevel(level); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * Gets the entry list for a trace |
| 1014 | * |
| 1015 | * @param trace |
| 1016 | * the trace |
| 1017 | * |
| 1018 | * @return the entry list map |
| 1019 | */ |
| 1020 | protected List<TimeGraphEntry> getEntryList(ITmfTrace trace) { |
| 1021 | synchronized (fEntryListMap) { |
| 1022 | return fEntryListMap.get(trace); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | /** |
| 1027 | * Adds a trace entry list to the entry list map |
| 1028 | * |
| 1029 | * @param trace |
| 1030 | * the trace to add |
| 1031 | * @param list |
| 1032 | * the list of time graph entries |
| 1033 | */ |
| 1034 | protected void putEntryList(ITmfTrace trace, List<TimeGraphEntry> list) { |
| 1035 | synchronized (fEntryListMap) { |
| 1036 | fEntryListMap.put(trace, new CopyOnWriteArrayList<>(list)); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | /** |
| 1041 | * Adds a list of entries to a trace's entry list |
| 1042 | * |
| 1043 | * @param trace |
| 1044 | * the trace |
| 1045 | * @param list |
| 1046 | * the list of time graph entries to add |
| 1047 | */ |
| 1048 | protected void addToEntryList(ITmfTrace trace, List<TimeGraphEntry> list) { |
| 1049 | synchronized (fEntryListMap) { |
| 1050 | List<TimeGraphEntry> entryList = fEntryListMap.get(trace); |
| 1051 | if (entryList == null) { |
| 1052 | fEntryListMap.put(trace, new CopyOnWriteArrayList<>(list)); |
| 1053 | } else { |
| 1054 | entryList.addAll(list); |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | /** |
| 1060 | * Removes a list of entries from a trace's entry list |
| 1061 | * |
| 1062 | * @param trace |
| 1063 | * the trace |
| 1064 | * @param list |
| 1065 | * the list of time graph entries to remove |
| 1066 | */ |
| 1067 | protected void removeFromEntryList(ITmfTrace trace, List<TimeGraphEntry> list) { |
| 1068 | synchronized (fEntryListMap) { |
| 1069 | List<TimeGraphEntry> entryList = fEntryListMap.get(trace); |
| 1070 | if (entryList != null) { |
| 1071 | entryList.removeAll(list); |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | /** |
| 1077 | * Text for the "next" button |
| 1078 | * |
| 1079 | * @return The "next" button text |
| 1080 | */ |
| 1081 | protected String getNextText() { |
| 1082 | return Messages.AbstractTimeGraphtView_NextText; |
| 1083 | } |
| 1084 | |
| 1085 | /** |
| 1086 | * Tooltip for the "next" button |
| 1087 | * |
| 1088 | * @return Tooltip for the "next" button |
| 1089 | */ |
| 1090 | protected String getNextTooltip() { |
| 1091 | return Messages.AbstractTimeGraphView_NextTooltip; |
| 1092 | } |
| 1093 | |
| 1094 | /** |
| 1095 | * Text for the "Previous" button |
| 1096 | * |
| 1097 | * @return The "Previous" button text |
| 1098 | */ |
| 1099 | protected String getPrevText() { |
| 1100 | return Messages.AbstractTimeGraphView_PreviousText; |
| 1101 | } |
| 1102 | |
| 1103 | /** |
| 1104 | * Tooltip for the "previous" button |
| 1105 | * |
| 1106 | * @return Tooltip for the "previous" button |
| 1107 | */ |
| 1108 | protected String getPrevTooltip() { |
| 1109 | return Messages.AbstractTimeGraphView_PreviousTooltip; |
| 1110 | } |
| 1111 | |
| 1112 | // ------------------------------------------------------------------------ |
| 1113 | // ViewPart |
| 1114 | // ------------------------------------------------------------------------ |
| 1115 | |
| 1116 | @Override |
| 1117 | public void createPartControl(Composite parent) { |
| 1118 | super.createPartControl(parent); |
| 1119 | if (fColumns == null || fLabelProvider == null) { |
| 1120 | fTimeGraphWrapper = new TimeGraphViewerWrapper(parent, SWT.NONE); |
| 1121 | } else { |
| 1122 | TimeGraphComboWrapper wrapper = new TimeGraphComboWrapper(parent, SWT.NONE); |
| 1123 | fTimeGraphWrapper = wrapper; |
| 1124 | TimeGraphCombo combo = wrapper.getTimeGraphCombo(); |
| 1125 | combo.setTreeContentProvider(fTimeGraphContentProvider); |
| 1126 | combo.setTreeLabelProvider(fLabelProvider); |
| 1127 | combo.setTreeColumns(fColumns); |
| 1128 | if (fColumnComparators != null) { |
| 1129 | createColumnSelectionListener(combo.getTreeViewer()); |
| 1130 | } |
| 1131 | } |
| 1132 | fTimeGraphWrapper.setTimeGraphContentProvider(fTimeGraphContentProvider); |
| 1133 | fTimeGraphWrapper.setFilterContentProvider(fFilterContentProvider != null ? fFilterContentProvider : fTimeGraphContentProvider); |
| 1134 | fTimeGraphWrapper.setFilterLabelProvider(fFilterLabelProvider); |
| 1135 | fTimeGraphWrapper.setFilterColumns(fFilterColumns); |
| 1136 | |
| 1137 | fTimeGraphWrapper.setTimeGraphPresentationProvider(fPresentation); |
| 1138 | fTimeGraphWrapper.setAutoExpandLevel(fAutoExpandLevel); |
| 1139 | |
| 1140 | fTimeGraphWrapper.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() { |
| 1141 | @Override |
| 1142 | public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) { |
| 1143 | final long startTime = event.getStartTime(); |
| 1144 | final long endTime = event.getEndTime(); |
| 1145 | TmfTimeRange range = new TmfTimeRange(new TmfNanoTimestamp(startTime), new TmfNanoTimestamp(endTime)); |
| 1146 | broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView.this, range)); |
| 1147 | startZoomThread(startTime, endTime); |
| 1148 | } |
| 1149 | }); |
| 1150 | |
| 1151 | fTimeGraphWrapper.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() { |
| 1152 | @Override |
| 1153 | public void timeSelected(TimeGraphTimeEvent event) { |
| 1154 | TmfNanoTimestamp startTime = new TmfNanoTimestamp(event.getBeginTime()); |
| 1155 | TmfNanoTimestamp endTime = new TmfNanoTimestamp(event.getEndTime()); |
| 1156 | broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView.this, startTime, endTime)); |
| 1157 | } |
| 1158 | }); |
| 1159 | |
| 1160 | fTimeGraphWrapper.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() { |
| 1161 | @Override |
| 1162 | public void bookmarkAdded(final TimeGraphBookmarkEvent event) { |
| 1163 | try { |
| 1164 | ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { |
| 1165 | @Override |
| 1166 | public void run(IProgressMonitor monitor) throws CoreException { |
| 1167 | IMarkerEvent bookmark = event.getBookmark(); |
| 1168 | IMarker marker = fEditorFile.createMarker(IMarker.BOOKMARK); |
| 1169 | marker.setAttribute(IMarker.MESSAGE, bookmark.getLabel()); |
| 1170 | marker.setAttribute(ITmfMarker.MARKER_TIME, Long.toString(bookmark.getTime())); |
| 1171 | if (bookmark.getDuration() > 0) { |
| 1172 | marker.setAttribute(ITmfMarker.MARKER_DURATION, Long.toString(bookmark.getDuration())); |
| 1173 | marker.setAttribute(IMarker.LOCATION, |
| 1174 | NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTimeRange, |
| 1175 | new TmfNanoTimestamp(bookmark.getTime()), |
| 1176 | new TmfNanoTimestamp(bookmark.getTime() + bookmark.getDuration()))); |
| 1177 | } else { |
| 1178 | marker.setAttribute(IMarker.LOCATION, |
| 1179 | NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTime, |
| 1180 | new TmfNanoTimestamp(bookmark.getTime()))); |
| 1181 | } |
| 1182 | marker.setAttribute(ITmfMarker.MARKER_COLOR, bookmark.getColor().getRGBA().toString()); |
| 1183 | } |
| 1184 | }, null); |
| 1185 | } catch (CoreException e) { |
| 1186 | Activator.getDefault().logError(e.getMessage()); |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | @Override |
| 1191 | public void bookmarkRemoved(TimeGraphBookmarkEvent event) { |
| 1192 | try { |
| 1193 | IMarkerEvent bookmark = event.getBookmark(); |
| 1194 | IMarker[] markers = fEditorFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO); |
| 1195 | for (IMarker marker : markers) { |
| 1196 | if (bookmark.getLabel().equals(marker.getAttribute(IMarker.MESSAGE)) && |
| 1197 | Long.toString(bookmark.getTime()).equals(marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null)) && |
| 1198 | Long.toString(bookmark.getDuration()).equals(marker.getAttribute(ITmfMarker.MARKER_DURATION, Long.toString(0))) && |
| 1199 | bookmark.getColor().getRGBA().toString().equals(marker.getAttribute(ITmfMarker.MARKER_COLOR))) { |
| 1200 | marker.delete(); |
| 1201 | break; |
| 1202 | } |
| 1203 | } |
| 1204 | } catch (CoreException e) { |
| 1205 | Activator.getDefault().logError(e.getMessage()); |
| 1206 | } |
| 1207 | } |
| 1208 | }); |
| 1209 | |
| 1210 | fTimeGraphWrapper.getTimeGraphViewer().setTimeFormat(TimeFormat.CALENDAR); |
| 1211 | |
| 1212 | IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager(); |
| 1213 | fTimeGraphWrapper.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager); |
| 1214 | |
| 1215 | // View Action Handling |
| 1216 | makeActions(); |
| 1217 | contributeToActionBars(); |
| 1218 | |
| 1219 | ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace(); |
| 1220 | if (trace != null) { |
| 1221 | traceSelected(new TmfTraceSelectedSignal(this, trace)); |
| 1222 | } |
| 1223 | |
| 1224 | // make selection available to other views |
| 1225 | getSite().setSelectionProvider(fTimeGraphWrapper.getSelectionProvider()); |
| 1226 | |
| 1227 | ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); |
| 1228 | } |
| 1229 | |
| 1230 | @Override |
| 1231 | public void setFocus() { |
| 1232 | fTimeGraphWrapper.setFocus(); |
| 1233 | } |
| 1234 | |
| 1235 | @Override |
| 1236 | public void dispose() { |
| 1237 | super.dispose(); |
| 1238 | ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * @since 2.0 |
| 1243 | */ |
| 1244 | @Override |
| 1245 | public void resourceChanged(final IResourceChangeEvent event) { |
| 1246 | for (final IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) { |
| 1247 | if (delta.getResource().equals(fEditorFile)) { |
| 1248 | fTimeGraphWrapper.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile)); |
| 1249 | redraw(); |
| 1250 | return; |
| 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | private List<IMarkerEvent> refreshBookmarks(final IFile editorFile) { |
| 1256 | List<IMarkerEvent> bookmarks = new ArrayList<>(); |
| 1257 | for (Color color : fColors) { |
| 1258 | color.dispose(); |
| 1259 | } |
| 1260 | fColors.clear(); |
| 1261 | if (editorFile == null || !editorFile.exists()) { |
| 1262 | return bookmarks; |
| 1263 | } |
| 1264 | try { |
| 1265 | IMarker[] markers = editorFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO); |
| 1266 | for (IMarker marker : markers) { |
| 1267 | String label = marker.getAttribute(IMarker.MESSAGE, (String) null); |
| 1268 | String time = marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null); |
| 1269 | String duration = marker.getAttribute(ITmfMarker.MARKER_DURATION, Long.toString(0)); |
| 1270 | String rgba = marker.getAttribute(ITmfMarker.MARKER_COLOR, (String) null); |
| 1271 | if (label != null && time != null && rgba != null) { |
| 1272 | Matcher matcher = RGBA_PATTERN.matcher(rgba); |
| 1273 | if (matcher.matches()) { |
| 1274 | try { |
| 1275 | int red = Integer.valueOf(matcher.group(1)); |
| 1276 | int green = Integer.valueOf(matcher.group(2)); |
| 1277 | int blue = Integer.valueOf(matcher.group(3)); |
| 1278 | int alpha = Integer.valueOf(matcher.group(4)); |
| 1279 | Color color = new Color(Display.getDefault(), red, green, blue, alpha); |
| 1280 | fColors.add(color); |
| 1281 | bookmarks.add(new MarkerEvent(null, Long.valueOf(time), Long.valueOf(duration), IMarkerEvent.BOOKMARKS, color, label, true)); |
| 1282 | } catch (NumberFormatException e) { |
| 1283 | Activator.getDefault().logError(e.getMessage()); |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | } catch (CoreException e) { |
| 1289 | Activator.getDefault().logError(e.getMessage()); |
| 1290 | } |
| 1291 | return bookmarks; |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | |
| 1296 | // ------------------------------------------------------------------------ |
| 1297 | // Signal handlers |
| 1298 | // ------------------------------------------------------------------------ |
| 1299 | |
| 1300 | /** |
| 1301 | * Handler for the trace opened signal. |
| 1302 | * |
| 1303 | * @param signal |
| 1304 | * The incoming signal |
| 1305 | */ |
| 1306 | @TmfSignalHandler |
| 1307 | public void traceOpened(TmfTraceOpenedSignal signal) { |
| 1308 | loadTrace(signal.getTrace()); |
| 1309 | } |
| 1310 | |
| 1311 | /** |
| 1312 | * Handler for the trace selected signal |
| 1313 | * |
| 1314 | * @param signal |
| 1315 | * The incoming signal |
| 1316 | */ |
| 1317 | @TmfSignalHandler |
| 1318 | public void traceSelected(final TmfTraceSelectedSignal signal) { |
| 1319 | if (signal.getTrace() == fTrace) { |
| 1320 | return; |
| 1321 | } |
| 1322 | loadTrace(signal.getTrace()); |
| 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * Trace is closed: clear the data structures and the view |
| 1327 | * |
| 1328 | * @param signal |
| 1329 | * the signal received |
| 1330 | */ |
| 1331 | @TmfSignalHandler |
| 1332 | public void traceClosed(final TmfTraceClosedSignal signal) { |
| 1333 | synchronized (fBuildThreadMap) { |
| 1334 | for (ITmfTrace trace : getTracesToBuild(signal.getTrace())) { |
| 1335 | BuildThread buildThread = fBuildThreadMap.remove(trace); |
| 1336 | if (buildThread != null) { |
| 1337 | buildThread.cancel(); |
| 1338 | } |
| 1339 | } |
| 1340 | } |
| 1341 | fMarkerEventSourcesMap.remove(signal.getTrace()); |
| 1342 | synchronized (fEntryListMap) { |
| 1343 | fEntryListMap.remove(signal.getTrace()); |
| 1344 | } |
| 1345 | fFiltersMap.remove(signal.getTrace()); |
| 1346 | if (signal.getTrace() == fTrace) { |
| 1347 | fTrace = null; |
| 1348 | fEditorFile = null; |
| 1349 | fStartTime = SWT.DEFAULT; |
| 1350 | fEndTime = SWT.DEFAULT; |
| 1351 | if (fZoomThread != null) { |
| 1352 | fZoomThread.cancel(); |
| 1353 | fZoomThread = null; |
| 1354 | } |
| 1355 | refresh(); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | /** |
| 1360 | * Handler for the selection range signal. |
| 1361 | * |
| 1362 | * @param signal |
| 1363 | * The signal that's received |
| 1364 | * @since 1.0 |
| 1365 | */ |
| 1366 | @TmfSignalHandler |
| 1367 | public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) { |
| 1368 | if (signal.getSource() == this || fTrace == null) { |
| 1369 | return; |
| 1370 | } |
| 1371 | final long beginTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1372 | final long endTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1373 | |
| 1374 | Display.getDefault().asyncExec(new Runnable() { |
| 1375 | @Override |
| 1376 | public void run() { |
| 1377 | if (fTimeGraphWrapper.isDisposed()) { |
| 1378 | return; |
| 1379 | } |
| 1380 | if (beginTime == endTime) { |
| 1381 | fTimeGraphWrapper.getTimeGraphViewer().setSelectedTime(beginTime, true); |
| 1382 | } else { |
| 1383 | fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(beginTime, endTime, true); |
| 1384 | } |
| 1385 | synchingToTime(fTimeGraphWrapper.getTimeGraphViewer().getSelectionBegin()); |
| 1386 | } |
| 1387 | }); |
| 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * Handler for the window range signal. |
| 1392 | * |
| 1393 | * @param signal |
| 1394 | * The signal that's received |
| 1395 | * @since 1.0 |
| 1396 | */ |
| 1397 | @TmfSignalHandler |
| 1398 | public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal) { |
| 1399 | if (signal.getSource() == this || fTrace == null) { |
| 1400 | return; |
| 1401 | } |
| 1402 | if (signal.getCurrentRange().getIntersection(fTrace.getTimeRange()) == null) { |
| 1403 | return; |
| 1404 | } |
| 1405 | final long startTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1406 | final long endTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1407 | Display.getDefault().asyncExec(new Runnable() { |
| 1408 | @Override |
| 1409 | public void run() { |
| 1410 | if (fTimeGraphWrapper.isDisposed()) { |
| 1411 | return; |
| 1412 | } |
| 1413 | fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime); |
| 1414 | startZoomThread(startTime, endTime); |
| 1415 | } |
| 1416 | }); |
| 1417 | } |
| 1418 | |
| 1419 | /** |
| 1420 | * @param signal the format of the timestamps was updated. |
| 1421 | */ |
| 1422 | @TmfSignalHandler |
| 1423 | public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal){ |
| 1424 | fTimeGraphWrapper.refresh(); |
| 1425 | } |
| 1426 | |
| 1427 | // ------------------------------------------------------------------------ |
| 1428 | // Internal |
| 1429 | // ------------------------------------------------------------------------ |
| 1430 | |
| 1431 | private void loadTrace(final ITmfTrace trace) { |
| 1432 | if (fZoomThread != null) { |
| 1433 | fZoomThread.cancel(); |
| 1434 | fZoomThread = null; |
| 1435 | } |
| 1436 | if (fTrace != null) { |
| 1437 | /* save the filters of the previous trace */ |
| 1438 | fFiltersMap.put(fTrace, fTimeGraphWrapper.getFilters()); |
| 1439 | } |
| 1440 | fTrace = trace; |
| 1441 | fEditorFile = TmfTraceManager.getInstance().getTraceEditorFile(trace); |
| 1442 | synchronized (fEntryListMap) { |
| 1443 | fEntryList = fEntryListMap.get(fTrace); |
| 1444 | if (fEntryList == null) { |
| 1445 | rebuild(); |
| 1446 | } else { |
| 1447 | fStartTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1448 | fEndTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1449 | refresh(); |
| 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | /** |
| 1455 | * Forces a rebuild of the entries list, even if entries already exist for this trace |
| 1456 | */ |
| 1457 | protected void rebuild() { |
| 1458 | setStartTime(Long.MAX_VALUE); |
| 1459 | setEndTime(Long.MIN_VALUE); |
| 1460 | refresh(); |
| 1461 | ITmfTrace viewTrace = fTrace; |
| 1462 | if (viewTrace == null) { |
| 1463 | return; |
| 1464 | } |
| 1465 | List<IMarkerEventSource> markerEventSources = new ArrayList<>(); |
| 1466 | synchronized (fBuildThreadMap) { |
| 1467 | for (ITmfTrace trace : getTracesToBuild(viewTrace)) { |
| 1468 | if (trace == null) { |
| 1469 | break; |
| 1470 | } |
| 1471 | markerEventSources.addAll(TmfTraceAdapterManager.getAdapters(trace, IMarkerEventSource.class)); |
| 1472 | BuildThread buildThread = new BuildThread(trace, viewTrace, getName()); |
| 1473 | fBuildThreadMap.put(trace, buildThread); |
| 1474 | buildThread.start(); |
| 1475 | } |
| 1476 | } |
| 1477 | fMarkerEventSourcesMap.put(viewTrace, markerEventSources); |
| 1478 | } |
| 1479 | |
| 1480 | /** |
| 1481 | * Method called when synching to a given timestamp. Inheriting classes can |
| 1482 | * perform actions here to update the view at the given timestamp. |
| 1483 | * |
| 1484 | * @param time |
| 1485 | * The currently selected time |
| 1486 | */ |
| 1487 | protected void synchingToTime(long time) { |
| 1488 | |
| 1489 | } |
| 1490 | |
| 1491 | /** |
| 1492 | * Return the list of traces whose data or analysis results will be used to |
| 1493 | * populate the view. By default, if the trace is an experiment, the traces |
| 1494 | * under it will be returned, otherwise, the trace itself is returned. |
| 1495 | * |
| 1496 | * A build thread will be started for each trace returned by this method, |
| 1497 | * some of which may receive events in live streaming mode. |
| 1498 | * |
| 1499 | * @param trace |
| 1500 | * The trace associated with this view |
| 1501 | * @return List of traces with data to display |
| 1502 | */ |
| 1503 | protected @NonNull Iterable<ITmfTrace> getTracesToBuild(@NonNull ITmfTrace trace) { |
| 1504 | return TmfTraceManager.getTraceSet(trace); |
| 1505 | } |
| 1506 | |
| 1507 | /** |
| 1508 | * Build the entries list to show in this time graph |
| 1509 | * |
| 1510 | * Called from the BuildThread |
| 1511 | * |
| 1512 | * @param trace |
| 1513 | * The trace being built |
| 1514 | * @param parentTrace |
| 1515 | * The parent of the trace set, or the trace itself |
| 1516 | * @param monitor |
| 1517 | * The progress monitor object |
| 1518 | */ |
| 1519 | protected abstract void buildEventList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor); |
| 1520 | |
| 1521 | /** |
| 1522 | * Gets the list of event for an entry in a given timerange |
| 1523 | * |
| 1524 | * @param entry |
| 1525 | * The entry to get events for |
| 1526 | * @param startTime |
| 1527 | * Start of the time range |
| 1528 | * @param endTime |
| 1529 | * End of the time range |
| 1530 | * @param resolution |
| 1531 | * The resolution |
| 1532 | * @param monitor |
| 1533 | * The progress monitor object |
| 1534 | * @return The list of events for the entry |
| 1535 | */ |
| 1536 | protected abstract @Nullable List<@NonNull ITimeEvent> getEventList(@NonNull TimeGraphEntry entry, |
| 1537 | long startTime, long endTime, long resolution, |
| 1538 | @NonNull IProgressMonitor monitor); |
| 1539 | |
| 1540 | /** |
| 1541 | * Gets the list of links (displayed as arrows) for a trace in a given |
| 1542 | * timerange. Default implementation returns an empty list. |
| 1543 | * |
| 1544 | * @param startTime |
| 1545 | * Start of the time range |
| 1546 | * @param endTime |
| 1547 | * End of the time range |
| 1548 | * @param resolution |
| 1549 | * The resolution |
| 1550 | * @param monitor |
| 1551 | * The progress monitor object |
| 1552 | * @return The list of link events |
| 1553 | */ |
| 1554 | protected @Nullable List<@NonNull ILinkEvent> getLinkList(long startTime, long endTime, |
| 1555 | long resolution, @NonNull IProgressMonitor monitor) { |
| 1556 | return new ArrayList<>(); |
| 1557 | } |
| 1558 | |
| 1559 | /** |
| 1560 | * Gets the list of view-specific marker categories. Default implementation |
| 1561 | * returns an empty list. |
| 1562 | * |
| 1563 | * @return The list of marker categories |
| 1564 | * @since 2.0 |
| 1565 | */ |
| 1566 | protected @NonNull List<String> getViewMarkerCategories() { |
| 1567 | return new ArrayList<>(); |
| 1568 | } |
| 1569 | |
| 1570 | /** |
| 1571 | * Gets the list of view-specific markers for a trace in a given time range. |
| 1572 | * Default implementation returns an empty list. |
| 1573 | * |
| 1574 | * @param startTime |
| 1575 | * Start of the time range |
| 1576 | * @param endTime |
| 1577 | * End of the time range |
| 1578 | * @param resolution |
| 1579 | * The resolution |
| 1580 | * @param monitor |
| 1581 | * The progress monitor object |
| 1582 | * @return The list of marker events |
| 1583 | * @since 2.0 |
| 1584 | */ |
| 1585 | protected @NonNull List<IMarkerEvent> getViewMarkerList(long startTime, long endTime, |
| 1586 | long resolution, @NonNull IProgressMonitor monitor) { |
| 1587 | return new ArrayList<>(); |
| 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * Gets the list of trace-specific markers for a trace in a given time range. |
| 1592 | * |
| 1593 | * @param startTime |
| 1594 | * Start of the time range |
| 1595 | * @param endTime |
| 1596 | * End of the time range |
| 1597 | * @param resolution |
| 1598 | * The resolution |
| 1599 | * @param monitor |
| 1600 | * The progress monitor object |
| 1601 | * @return The list of marker events |
| 1602 | * @since 2.0 |
| 1603 | */ |
| 1604 | protected @NonNull List<IMarkerEvent> getTraceMarkerList(long startTime, long endTime, |
| 1605 | long resolution, @NonNull IProgressMonitor monitor) { |
| 1606 | List<IMarkerEvent> markers = new ArrayList<>(); |
| 1607 | for (IMarkerEventSource markerEventSource : getMarkerEventSources(fTrace)) { |
| 1608 | for (String category : markerEventSource.getMarkerCategories()) { |
| 1609 | if (monitor.isCanceled()) { |
| 1610 | break; |
| 1611 | } |
| 1612 | markers.addAll(markerEventSource.getMarkerList(checkNotNull(category), startTime, endTime, resolution, monitor)); |
| 1613 | } |
| 1614 | } |
| 1615 | return markers; |
| 1616 | } |
| 1617 | |
| 1618 | /** |
| 1619 | * Get the list of current marker categories. |
| 1620 | * |
| 1621 | * @return The list of marker categories |
| 1622 | * @since 2.0 |
| 1623 | */ |
| 1624 | private @NonNull List<String> getMarkerCategories() { |
| 1625 | Set<String> categories = new HashSet<>(getViewMarkerCategories()); |
| 1626 | for (IMarkerEventSource markerEventSource : getMarkerEventSources(fTrace)) { |
| 1627 | categories.addAll(markerEventSource.getMarkerCategories()); |
| 1628 | } |
| 1629 | return new ArrayList<>(categories); |
| 1630 | } |
| 1631 | |
| 1632 | /** |
| 1633 | * Gets the list of marker event sources for a given trace. |
| 1634 | * |
| 1635 | * @param trace |
| 1636 | * The trace |
| 1637 | * @return The list of marker event sources |
| 1638 | * @since 2.0 |
| 1639 | */ |
| 1640 | private @NonNull List<IMarkerEventSource> getMarkerEventSources(ITmfTrace trace) { |
| 1641 | List<IMarkerEventSource> markerEventSources = fMarkerEventSourcesMap.get(trace); |
| 1642 | if (markerEventSources == null) { |
| 1643 | markerEventSources = checkNotNull(Collections.<IMarkerEventSource>emptyList()); |
| 1644 | } |
| 1645 | return markerEventSources; |
| 1646 | } |
| 1647 | |
| 1648 | /** |
| 1649 | * Refresh the display |
| 1650 | */ |
| 1651 | protected void refresh() { |
| 1652 | final boolean zoomThread = Thread.currentThread() instanceof ZoomThread; |
| 1653 | TmfUiRefreshHandler.getInstance().queueUpdate(this, new Runnable() { |
| 1654 | @Override |
| 1655 | public void run() { |
| 1656 | if (fTimeGraphWrapper.isDisposed()) { |
| 1657 | return; |
| 1658 | } |
| 1659 | boolean hasEntries = false; |
| 1660 | synchronized (fEntryListMap) { |
| 1661 | fEntryList = fEntryListMap.get(fTrace); |
| 1662 | if (fEntryList == null) { |
| 1663 | fEntryList = new CopyOnWriteArrayList<>(); |
| 1664 | } else if (fEntryComparator != null) { |
| 1665 | List<TimeGraphEntry> list = new ArrayList<>(fEntryList); |
| 1666 | Collections.sort(list, fEntryComparator); |
| 1667 | for (ITimeGraphEntry entry : list) { |
| 1668 | sortChildren(entry, fEntryComparator); |
| 1669 | } |
| 1670 | fEntryList.clear(); |
| 1671 | fEntryList.addAll(list); |
| 1672 | } |
| 1673 | hasEntries = !fEntryList.isEmpty(); |
| 1674 | } |
| 1675 | boolean inputChanged = fEntryList != fTimeGraphWrapper.getInput(); |
| 1676 | if (inputChanged) { |
| 1677 | fTimeGraphWrapper.setInput(fEntryList); |
| 1678 | /* restore the previously saved filters, if any */ |
| 1679 | fTimeGraphWrapper.setFilters(fFiltersMap.get(fTrace)); |
| 1680 | fTimeGraphWrapper.getTimeGraphViewer().setLinks(null); |
| 1681 | fTimeGraphWrapper.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile)); |
| 1682 | fTimeGraphWrapper.getTimeGraphViewer().setMarkerCategories(getMarkerCategories()); |
| 1683 | fTimeGraphWrapper.getTimeGraphViewer().setMarkers(null); |
| 1684 | resetColumnSorting(); |
| 1685 | } else { |
| 1686 | fTimeGraphWrapper.refresh(); |
| 1687 | } |
| 1688 | long startBound = (fStartTime == Long.MAX_VALUE ? SWT.DEFAULT : fStartTime); |
| 1689 | long endBound = (fEndTime == Long.MIN_VALUE ? SWT.DEFAULT : fEndTime); |
| 1690 | fTimeGraphWrapper.getTimeGraphViewer().setTimeBounds(startBound, endBound); |
| 1691 | |
| 1692 | TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext(); |
| 1693 | long selectionBeginTime = fTrace == null ? SWT.DEFAULT : ctx.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1694 | long selectionEndTime = fTrace == null ? SWT.DEFAULT : ctx.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1695 | long startTime = fTrace == null ? SWT.DEFAULT : ctx.getWindowRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1696 | long endTime = fTrace == null ? SWT.DEFAULT : ctx.getWindowRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
| 1697 | startTime = (fStartTime == Long.MAX_VALUE ? SWT.DEFAULT : Math.max(startTime, fStartTime)); |
| 1698 | endTime = (fEndTime == Long.MIN_VALUE ? SWT.DEFAULT : Math.min(endTime, fEndTime)); |
| 1699 | fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime, false); |
| 1700 | fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime); |
| 1701 | |
| 1702 | if (inputChanged && selectionBeginTime != SWT.DEFAULT) { |
| 1703 | synchingToTime(selectionBeginTime); |
| 1704 | } |
| 1705 | |
| 1706 | if (fTimeGraphWrapper instanceof TimeGraphComboWrapper && !fPackDone) { |
| 1707 | for (TreeColumn column : ((TimeGraphComboWrapper) fTimeGraphWrapper).getTreeViewer().getTree().getColumns()) { |
| 1708 | column.pack(); |
| 1709 | } |
| 1710 | if (hasEntries) { |
| 1711 | fPackDone = true; |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | // reveal selection |
| 1716 | if (fIsRevealSelection && fTimeGraphWrapper instanceof TimeGraphComboWrapper) { |
| 1717 | fIsRevealSelection = false; |
| 1718 | ITimeGraphEntry entry1 = fTimeGraphWrapper.getTimeGraphViewer().getSelection(); |
| 1719 | fTimeGraphWrapper.getTimeGraphViewer().setSelection(entry1); |
| 1720 | } |
| 1721 | |
| 1722 | if (!zoomThread) { |
| 1723 | startZoomThread(startTime, endTime); |
| 1724 | } |
| 1725 | |
| 1726 | } |
| 1727 | }); |
| 1728 | } |
| 1729 | |
| 1730 | /** |
| 1731 | * Redraw the canvas |
| 1732 | */ |
| 1733 | protected void redraw() { |
| 1734 | synchronized (fSyncObj) { |
| 1735 | if (fRedrawState == State.IDLE) { |
| 1736 | fRedrawState = State.BUSY; |
| 1737 | } else { |
| 1738 | fRedrawState = State.PENDING; |
| 1739 | return; |
| 1740 | } |
| 1741 | } |
| 1742 | Display.getDefault().asyncExec(new Runnable() { |
| 1743 | @Override |
| 1744 | public void run() { |
| 1745 | if (fTimeGraphWrapper.isDisposed()) { |
| 1746 | return; |
| 1747 | } |
| 1748 | fTimeGraphWrapper.redraw(); |
| 1749 | fTimeGraphWrapper.update(); |
| 1750 | synchronized (fSyncObj) { |
| 1751 | if (fRedrawState == State.PENDING) { |
| 1752 | fRedrawState = State.IDLE; |
| 1753 | redraw(); |
| 1754 | } else { |
| 1755 | fRedrawState = State.IDLE; |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | }); |
| 1760 | } |
| 1761 | |
| 1762 | private void sortChildren(ITimeGraphEntry entry, Comparator<ITimeGraphEntry> comparator) { |
| 1763 | if (entry instanceof TimeGraphEntry) { |
| 1764 | ((TimeGraphEntry) entry).sortChildren(comparator); |
| 1765 | } |
| 1766 | for (ITimeGraphEntry child : entry.getChildren()) { |
| 1767 | sortChildren(child, comparator); |
| 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | /** |
| 1772 | * Start or restart the zoom thread. |
| 1773 | * |
| 1774 | * @param startTime |
| 1775 | * the zoom start time |
| 1776 | * @param endTime |
| 1777 | * the zoom end time |
| 1778 | * @since 2.0 |
| 1779 | */ |
| 1780 | protected final void startZoomThread(long startTime, long endTime) { |
| 1781 | fDirty.incrementAndGet(); |
| 1782 | boolean restart = false; |
| 1783 | if (fZoomThread != null) { |
| 1784 | fZoomThread.cancel(); |
| 1785 | if (fZoomThread.fZoomStartTime == startTime && fZoomThread.fZoomEndTime == endTime) { |
| 1786 | restart = true; |
| 1787 | } |
| 1788 | } |
| 1789 | long resolution = Math.max(1, (endTime - startTime) / fDisplayWidth); |
| 1790 | fZoomThread = createZoomThread(startTime, endTime, resolution, restart); |
| 1791 | if (fZoomThread != null) { |
| 1792 | fZoomThread.start(); |
| 1793 | } else { |
| 1794 | fDirty.decrementAndGet(); |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | /** |
| 1799 | * Create a zoom thread. |
| 1800 | * |
| 1801 | * @param startTime |
| 1802 | * the zoom start time |
| 1803 | * @param endTime |
| 1804 | * the zoom end time |
| 1805 | * @param resolution |
| 1806 | * the resolution |
| 1807 | * @param restart |
| 1808 | * true if restarting zoom for the same time range |
| 1809 | * @return a zoom thread |
| 1810 | * @since 1.1 |
| 1811 | */ |
| 1812 | protected @Nullable ZoomThread createZoomThread(long startTime, long endTime, long resolution, boolean restart) { |
| 1813 | final List<TimeGraphEntry> entryList = fEntryList; |
| 1814 | if (entryList == null) { |
| 1815 | return null; |
| 1816 | } |
| 1817 | return new ZoomThreadByEntry(entryList, startTime, endTime, resolution); |
| 1818 | } |
| 1819 | |
| 1820 | private void makeActions() { |
| 1821 | fPreviousResourceAction = fTimeGraphWrapper.getTimeGraphViewer().getPreviousItemAction(); |
| 1822 | fPreviousResourceAction.setText(getPrevText()); |
| 1823 | fPreviousResourceAction.setToolTipText(getPrevTooltip()); |
| 1824 | fNextResourceAction = fTimeGraphWrapper.getTimeGraphViewer().getNextItemAction(); |
| 1825 | fNextResourceAction.setText(getNextText()); |
| 1826 | fNextResourceAction.setToolTipText(getNextTooltip()); |
| 1827 | } |
| 1828 | |
| 1829 | private void contributeToActionBars() { |
| 1830 | IActionBars bars = getViewSite().getActionBars(); |
| 1831 | fillLocalToolBar(bars.getToolBarManager()); |
| 1832 | fillLocalMenu(bars.getMenuManager()); |
| 1833 | } |
| 1834 | |
| 1835 | /** |
| 1836 | * Add actions to local tool bar manager |
| 1837 | * |
| 1838 | * @param manager the tool bar manager |
| 1839 | */ |
| 1840 | protected void fillLocalToolBar(IToolBarManager manager) { |
| 1841 | if (fFilterColumns != null && fFilterLabelProvider != null && fFilterColumns.length > 0) { |
| 1842 | manager.add(fTimeGraphWrapper.getShowFilterDialogAction()); |
| 1843 | } |
| 1844 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getShowLegendAction()); |
| 1845 | manager.add(new Separator()); |
| 1846 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getResetScaleAction()); |
| 1847 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousEventAction()); |
| 1848 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextEventAction()); |
| 1849 | manager.add(new Separator()); |
| 1850 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getToggleBookmarkAction()); |
| 1851 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousMarkerAction()); |
| 1852 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextMarkerAction()); |
| 1853 | manager.add(new Separator()); |
| 1854 | manager.add(fPreviousResourceAction); |
| 1855 | manager.add(fNextResourceAction); |
| 1856 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomInAction()); |
| 1857 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomOutAction()); |
| 1858 | manager.add(new Separator()); |
| 1859 | } |
| 1860 | |
| 1861 | /** |
| 1862 | * Add actions to local menu manager |
| 1863 | * |
| 1864 | * @param manager the tool bar manager |
| 1865 | * @since 2.0 |
| 1866 | */ |
| 1867 | protected void fillLocalMenu(IMenuManager manager) { |
| 1868 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getMarkersMenu()); |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * @since 1.0 |
| 1873 | */ |
| 1874 | @Override |
| 1875 | public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() { |
| 1876 | if (fTimeGraphWrapper == null) { |
| 1877 | return null; |
| 1878 | } |
| 1879 | return fTimeGraphWrapper.getTimeViewAlignmentInfo(); |
| 1880 | } |
| 1881 | |
| 1882 | /** |
| 1883 | * @since 1.0 |
| 1884 | */ |
| 1885 | @Override |
| 1886 | public int getAvailableWidth(int requestedOffset) { |
| 1887 | if (fTimeGraphWrapper == null) { |
| 1888 | return 0; |
| 1889 | } |
| 1890 | return fTimeGraphWrapper.getAvailableWidth(requestedOffset); |
| 1891 | } |
| 1892 | |
| 1893 | /** |
| 1894 | * @since 1.0 |
| 1895 | */ |
| 1896 | @Override |
| 1897 | public void performAlign(int offset, int width) { |
| 1898 | if (fTimeGraphWrapper != null) { |
| 1899 | fTimeGraphWrapper.performAlign(offset, width); |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | /** |
| 1904 | * Returns whether or not the time graph view is dirty. The time graph view |
| 1905 | * is considered dirty if it has yet to completely update its model. |
| 1906 | * |
| 1907 | * @return true if the time graph view has yet to completely update its |
| 1908 | * model, false otherwise |
| 1909 | * @since 2.0 |
| 1910 | */ |
| 1911 | public boolean isDirty() { |
| 1912 | if (fZoomThread == null) { |
| 1913 | return false; |
| 1914 | } |
| 1915 | return fDirty.get() != 0 || fZoomThread.getZoomStartTime() != fTimeGraphWrapper.getTimeGraphViewer().getTime0() || fZoomThread.getZoomEndTime() != fTimeGraphWrapper.getTimeGraphViewer().getTime1(); |
| 1916 | } |
| 1917 | |
| 1918 | private void createColumnSelectionListener(TreeViewer treeViewer) { |
| 1919 | for (int i = 0; i < fColumnComparators.length; i++) { |
| 1920 | final Comparator<ITimeGraphEntry> comp = fColumnComparators[i]; |
| 1921 | final Tree tree = treeViewer.getTree(); |
| 1922 | final TreeColumn column = tree.getColumn(i); |
| 1923 | |
| 1924 | if (comp != null) { |
| 1925 | column.addSelectionListener(new SelectionAdapter() { |
| 1926 | @Override |
| 1927 | public void widgetSelected(SelectionEvent e) { |
| 1928 | TreeColumn prevSortcolumn = tree.getSortColumn(); |
| 1929 | if (prevSortcolumn == column) { |
| 1930 | fDirection = (fDirection == SWT.DOWN) ? SWT.UP : SWT.DOWN; |
| 1931 | } else { |
| 1932 | fDirection = SWT.DOWN; |
| 1933 | } |
| 1934 | tree.setSortColumn(column); |
| 1935 | tree.setSortDirection(fDirection); |
| 1936 | Comparator<ITimeGraphEntry> comparator = comp; |
| 1937 | if (comparator instanceof ITimeGraphEntryComparator) { |
| 1938 | ((ITimeGraphEntryComparator) comparator).setDirection(fDirection); |
| 1939 | } |
| 1940 | if (fDirection != SWT.DOWN) { |
| 1941 | comparator = checkNotNull(Collections.reverseOrder(comparator)); |
| 1942 | } |
| 1943 | setEntryComparator(comparator); |
| 1944 | fIsRevealSelection = true; |
| 1945 | if (fTimeGraphWrapper instanceof TimeGraphComboWrapper) { |
| 1946 | ((TimeGraphComboWrapper) fTimeGraphWrapper).getTreeViewer().getControl().setFocus(); |
| 1947 | } |
| 1948 | refresh(); |
| 1949 | } |
| 1950 | }); |
| 1951 | } |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | private void resetColumnSorting() { |
| 1956 | if ((fTimeGraphWrapper instanceof TimeGraphComboWrapper) && (fColumnComparators != null)) { |
| 1957 | TreeViewer treeViewer = ((TimeGraphComboWrapper) fTimeGraphWrapper).getTreeViewer(); |
| 1958 | fDirection = SWT.DOWN; |
| 1959 | if ((fInitialSortColumn < fColumnComparators.length) && (fColumnComparators[fInitialSortColumn] != null)) { |
| 1960 | setEntryComparator(fColumnComparators[fInitialSortColumn]); |
| 1961 | } |
| 1962 | final Tree tree = treeViewer.getTree(); |
| 1963 | final TreeColumn column = tree.getColumn(fInitialSortColumn); |
| 1964 | tree.setSortDirection(fDirection); |
| 1965 | tree.setSortColumn(column); |
| 1966 | } |
| 1967 | } |
| 1968 | } |