| 1 | /***************************************************************************** |
| 2 | * Copyright (c) 2007, 2013 Intel Corporation, Ericsson |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * Intel Corporation - Initial API and implementation |
| 10 | * Ruslan A. Scherbakov, Intel - Initial API and implementation |
| 11 | * Alexander N. Alexeev, Intel - Add monitors statistics support |
| 12 | * Alvaro Sanchez-Leon - Adapted for TMF |
| 13 | * Patrick Tasse - Refactoring |
| 14 | *****************************************************************************/ |
| 15 | |
| 16 | package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; |
| 17 | |
| 18 | import java.util.ArrayList; |
| 19 | import java.util.List; |
| 20 | |
| 21 | import org.eclipse.jface.action.Action; |
| 22 | import org.eclipse.jface.viewers.ISelectionProvider; |
| 23 | import org.eclipse.jface.viewers.ViewerFilter; |
| 24 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
| 25 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; |
| 26 | import org.eclipse.linuxtools.internal.tmf.ui.Messages; |
| 27 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend; |
| 28 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; |
| 29 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; |
| 30 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider2; |
| 31 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; |
| 32 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl; |
| 33 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphScale; |
| 34 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler; |
| 35 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils; |
| 36 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; |
| 37 | import org.eclipse.swt.SWT; |
| 38 | import org.eclipse.swt.events.ControlAdapter; |
| 39 | import org.eclipse.swt.events.ControlEvent; |
| 40 | import org.eclipse.swt.events.KeyAdapter; |
| 41 | import org.eclipse.swt.events.KeyEvent; |
| 42 | import org.eclipse.swt.events.MenuDetectListener; |
| 43 | import org.eclipse.swt.events.MouseEvent; |
| 44 | import org.eclipse.swt.events.MouseWheelListener; |
| 45 | import org.eclipse.swt.events.SelectionAdapter; |
| 46 | import org.eclipse.swt.events.SelectionEvent; |
| 47 | import org.eclipse.swt.events.SelectionListener; |
| 48 | import org.eclipse.swt.graphics.Rectangle; |
| 49 | import org.eclipse.swt.layout.FillLayout; |
| 50 | import org.eclipse.swt.layout.GridData; |
| 51 | import org.eclipse.swt.layout.GridLayout; |
| 52 | import org.eclipse.swt.widgets.Composite; |
| 53 | import org.eclipse.swt.widgets.Control; |
| 54 | import org.eclipse.swt.widgets.ScrollBar; |
| 55 | import org.eclipse.swt.widgets.Slider; |
| 56 | |
| 57 | /** |
| 58 | * Generic time graph viewer implementation |
| 59 | * |
| 60 | * @version 1.0 |
| 61 | * @author Patrick Tasse, and others |
| 62 | */ |
| 63 | public class TimeGraphViewer implements ITimeDataProvider2, SelectionListener { |
| 64 | |
| 65 | private static final int DEFAULT_NAME_WIDTH = 200; |
| 66 | private static final int MIN_NAME_WIDTH = 6; |
| 67 | private static final int MAX_NAME_WIDTH = 1000; |
| 68 | private static final int DEFAULT_HEIGHT = 22; |
| 69 | private static final long RECENTERING_MARGIN_FACTOR = 50; |
| 70 | |
| 71 | private long fMinTimeInterval; |
| 72 | private ITimeGraphEntry fSelectedEntry; |
| 73 | private long fBeginTime; |
| 74 | private long fEndTime; |
| 75 | private long fTime0; |
| 76 | private long fTime1; |
| 77 | private long fSelectionBegin = 0; |
| 78 | private long fSelectionEnd = 0; |
| 79 | private long fTime0Bound; |
| 80 | private long fTime1Bound; |
| 81 | private long fTime0ExtSynch = 0; |
| 82 | private long fTime1ExtSynch = 0; |
| 83 | private boolean fTimeRangeFixed; |
| 84 | private int fNameWidthPref = DEFAULT_NAME_WIDTH; |
| 85 | private int fMinNameWidth = MIN_NAME_WIDTH; |
| 86 | private int fNameWidth; |
| 87 | private Composite fDataViewer; |
| 88 | |
| 89 | private TimeGraphControl fTimeGraphCtrl; |
| 90 | private TimeGraphScale fTimeScaleCtrl; |
| 91 | private Slider fVerticalScrollBar; |
| 92 | private TimeGraphColorScheme fColorScheme; |
| 93 | private ITimeGraphPresentationProvider fTimeGraphProvider; |
| 94 | |
| 95 | private List<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<ITimeGraphSelectionListener>(); |
| 96 | private List<ITimeGraphTimeListener> fTimeListeners = new ArrayList<ITimeGraphTimeListener>(); |
| 97 | private List<ITimeGraphRangeListener> fRangeListeners = new ArrayList<ITimeGraphRangeListener>(); |
| 98 | |
| 99 | // Time format, using Epoch reference, Relative time format(default) or Number |
| 100 | private TimeFormat fTimeFormat = TimeFormat.RELATIVE; |
| 101 | private int fBorderWidth = 0; |
| 102 | private int fTimeScaleHeight = DEFAULT_HEIGHT; |
| 103 | |
| 104 | private Action fResetScaleAction; |
| 105 | private Action fShowLegendAction; |
| 106 | private Action fNextEventAction; |
| 107 | private Action fPrevEventAction; |
| 108 | private Action fNextItemAction; |
| 109 | private Action fPreviousItemAction; |
| 110 | private Action fZoomInAction; |
| 111 | private Action fZoomOutAction; |
| 112 | |
| 113 | /** |
| 114 | * Standard constructor |
| 115 | * |
| 116 | * @param parent |
| 117 | * The parent UI composite object |
| 118 | * @param style |
| 119 | * The style to use |
| 120 | */ |
| 121 | public TimeGraphViewer(Composite parent, int style) { |
| 122 | createDataViewer(parent, style); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Sets the timegraph provider used by this timegraph viewer. |
| 127 | * |
| 128 | * @param timeGraphProvider the timegraph provider |
| 129 | */ |
| 130 | public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) { |
| 131 | fTimeGraphProvider = timeGraphProvider; |
| 132 | fTimeGraphCtrl.setTimeGraphProvider(timeGraphProvider); |
| 133 | TimeGraphTooltipHandler toolTipHandler = new TimeGraphTooltipHandler(fTimeGraphProvider, this); |
| 134 | toolTipHandler.activateHoverHelp(fTimeGraphCtrl); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Sets or clears the input for this time graph viewer. |
| 139 | * The input array should only contain top-level elements. |
| 140 | * |
| 141 | * @param input The input of this time graph viewer, or <code>null</code> if none |
| 142 | */ |
| 143 | public void setInput(ITimeGraphEntry[] input) { |
| 144 | ITimeGraphEntry[] realInput = input; |
| 145 | |
| 146 | if (fTimeGraphCtrl != null) { |
| 147 | if (realInput == null) { |
| 148 | realInput = new ITimeGraphEntry[0]; |
| 149 | } |
| 150 | setTimeRange(realInput); |
| 151 | fVerticalScrollBar.setEnabled(true); |
| 152 | setTopIndex(0); |
| 153 | fSelectionBegin = 0; |
| 154 | fSelectionEnd = 0; |
| 155 | fSelectedEntry = null; |
| 156 | refreshAllData(realInput); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Refresh the view |
| 162 | */ |
| 163 | public void refresh() { |
| 164 | setTimeRange(fTimeGraphCtrl.getTraces()); |
| 165 | fVerticalScrollBar.setEnabled(true); |
| 166 | refreshAllData(fTimeGraphCtrl.getTraces()); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Callback for when the control is moved |
| 171 | * |
| 172 | * @param e |
| 173 | * The caller event |
| 174 | */ |
| 175 | public void controlMoved(ControlEvent e) { |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Callback for when the control is resized |
| 180 | * |
| 181 | * @param e |
| 182 | * The caller event |
| 183 | */ |
| 184 | public void controlResized(ControlEvent e) { |
| 185 | resizeControls(); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Handler for when the model is updated. Called from the display order in |
| 190 | * the API |
| 191 | * |
| 192 | * @param traces |
| 193 | * The traces in the model |
| 194 | * @param start |
| 195 | * The start time |
| 196 | * @param end |
| 197 | * The end time |
| 198 | * @param updateTimeBounds |
| 199 | * Should we updated the time bounds too |
| 200 | */ |
| 201 | public void modelUpdate(ITimeGraphEntry[] traces, long start, |
| 202 | long end, boolean updateTimeBounds) { |
| 203 | if (null != fTimeGraphCtrl) { |
| 204 | updateInternalData(traces, start, end); |
| 205 | if (updateTimeBounds) { |
| 206 | fTimeRangeFixed = true; |
| 207 | // set window to match limits |
| 208 | setStartFinishTime(fTime0Bound, fTime1Bound); |
| 209 | } else { |
| 210 | fTimeGraphCtrl.redraw(); |
| 211 | fTimeScaleCtrl.redraw(); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * @return The string representing the view type |
| 218 | */ |
| 219 | protected String getViewTypeStr() { |
| 220 | return "viewoption.threads"; //$NON-NLS-1$ |
| 221 | } |
| 222 | |
| 223 | int getMarginWidth() { |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | int getMarginHeight() { |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | void loadOptions() { |
| 232 | fMinTimeInterval = 1; |
| 233 | fSelectionBegin = -1; |
| 234 | fSelectionEnd = -1; |
| 235 | fNameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$ |
| 236 | fNameWidthPref, fMinNameWidth, MAX_NAME_WIDTH); |
| 237 | } |
| 238 | |
| 239 | void saveOptions() { |
| 240 | Utils.saveIntOption(getPreferenceString("namewidth"), fNameWidth); //$NON-NLS-1$ |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Create a data viewer. |
| 245 | * |
| 246 | * @param parent |
| 247 | * Parent composite |
| 248 | * @param style |
| 249 | * Style to use |
| 250 | * @return The new data viewer |
| 251 | */ |
| 252 | protected Control createDataViewer(Composite parent, int style) { |
| 253 | loadOptions(); |
| 254 | fColorScheme = new TimeGraphColorScheme(); |
| 255 | fDataViewer = new Composite(parent, style) { |
| 256 | @Override |
| 257 | public void redraw() { |
| 258 | fTimeScaleCtrl.redraw(); |
| 259 | fTimeGraphCtrl.redraw(); |
| 260 | super.redraw(); |
| 261 | } |
| 262 | }; |
| 263 | GridLayout gl = new GridLayout(2, false); |
| 264 | gl.marginHeight = fBorderWidth; |
| 265 | gl.marginWidth = 0; |
| 266 | gl.verticalSpacing = 0; |
| 267 | gl.horizontalSpacing = 0; |
| 268 | fDataViewer.setLayout(gl); |
| 269 | |
| 270 | fTimeScaleCtrl = new TimeGraphScale(fDataViewer, fColorScheme); |
| 271 | fTimeScaleCtrl.setTimeProvider(this); |
| 272 | fTimeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false)); |
| 273 | fTimeScaleCtrl.setHeight(fTimeScaleHeight); |
| 274 | |
| 275 | fVerticalScrollBar = new Slider(fDataViewer, SWT.VERTICAL | SWT.NO_FOCUS); |
| 276 | fVerticalScrollBar.setLayoutData(new GridData(SWT.DEFAULT, SWT.FILL, false, true, 1, 2)); |
| 277 | fVerticalScrollBar.addSelectionListener(new SelectionAdapter() { |
| 278 | @Override |
| 279 | public void widgetSelected(SelectionEvent e) { |
| 280 | setTopIndex(fVerticalScrollBar.getSelection()); |
| 281 | } |
| 282 | }); |
| 283 | fVerticalScrollBar.setEnabled(false); |
| 284 | |
| 285 | fTimeGraphCtrl = createTimeGraphControl(fDataViewer, fColorScheme); |
| 286 | |
| 287 | fTimeGraphCtrl.setTimeProvider(this); |
| 288 | fTimeGraphCtrl.setTimeGraphScale(fTimeScaleCtrl); |
| 289 | fTimeGraphCtrl.addSelectionListener(this); |
| 290 | fTimeGraphCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2)); |
| 291 | fTimeGraphCtrl.addMouseWheelListener(new MouseWheelListener() { |
| 292 | @Override |
| 293 | public void mouseScrolled(MouseEvent e) { |
| 294 | adjustVerticalScrollBar(); |
| 295 | } |
| 296 | }); |
| 297 | fTimeGraphCtrl.addKeyListener(new KeyAdapter() { |
| 298 | @Override |
| 299 | public void keyPressed(KeyEvent e) { |
| 300 | adjustVerticalScrollBar(); |
| 301 | } |
| 302 | }); |
| 303 | |
| 304 | Composite filler = new Composite(fDataViewer, SWT.NONE); |
| 305 | GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false); |
| 306 | gd.heightHint = fTimeGraphCtrl.getHorizontalBar().getSize().y; |
| 307 | filler.setLayoutData(gd); |
| 308 | filler.setLayout(new FillLayout()); |
| 309 | |
| 310 | fTimeGraphCtrl.addControlListener(new ControlAdapter() { |
| 311 | @Override |
| 312 | public void controlResized(ControlEvent event) { |
| 313 | resizeControls(); |
| 314 | } |
| 315 | }); |
| 316 | resizeControls(); |
| 317 | fDataViewer.update(); |
| 318 | adjustVerticalScrollBar(); |
| 319 | return fDataViewer; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Dispose the view. |
| 324 | */ |
| 325 | public void dispose() { |
| 326 | saveOptions(); |
| 327 | fTimeGraphCtrl.dispose(); |
| 328 | fDataViewer.dispose(); |
| 329 | fColorScheme.dispose(); |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Create a new time graph control. |
| 334 | * |
| 335 | * @param parent |
| 336 | * The parent composite |
| 337 | * @param colors |
| 338 | * The color scheme |
| 339 | * @return The new TimeGraphControl |
| 340 | * @since 2.0 |
| 341 | */ |
| 342 | protected TimeGraphControl createTimeGraphControl(Composite parent, |
| 343 | TimeGraphColorScheme colors) { |
| 344 | return new TimeGraphControl(parent, colors); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Resize the controls |
| 349 | */ |
| 350 | public void resizeControls() { |
| 351 | Rectangle r = fDataViewer.getClientArea(); |
| 352 | if (r.isEmpty()) { |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | int width = r.width; |
| 357 | if (fNameWidth > width - fMinNameWidth) { |
| 358 | fNameWidth = width - fMinNameWidth; |
| 359 | } |
| 360 | if (fNameWidth < fMinNameWidth) { |
| 361 | fNameWidth = fMinNameWidth; |
| 362 | } |
| 363 | adjustVerticalScrollBar(); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Try to set most convenient time range for display. |
| 368 | * |
| 369 | * @param traces |
| 370 | * The traces in the model |
| 371 | */ |
| 372 | public void setTimeRange(ITimeGraphEntry traces[]) { |
| 373 | fEndTime = 0; |
| 374 | fBeginTime = -1; |
| 375 | for (int i = 0; i < traces.length; i++) { |
| 376 | ITimeGraphEntry entry = traces[i]; |
| 377 | if (entry.getEndTime() >= entry.getStartTime() && entry.getEndTime() > 0) { |
| 378 | if (fBeginTime < 0 || entry.getStartTime() < fBeginTime) { |
| 379 | fBeginTime = entry.getStartTime(); |
| 380 | } |
| 381 | if (entry.getEndTime() > fEndTime) { |
| 382 | fEndTime = entry.getEndTime(); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | if (fBeginTime < 0) { |
| 388 | fBeginTime = 0; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Recalculate the time bounds |
| 394 | */ |
| 395 | public void setTimeBounds() { |
| 396 | fTime0Bound = fBeginTime; |
| 397 | if (fTime0Bound < 0) { |
| 398 | fTime0Bound = 0; |
| 399 | } |
| 400 | fTime1Bound = fEndTime; |
| 401 | if (!fTimeRangeFixed) { |
| 402 | fTime0 = fTime0Bound; |
| 403 | fTime1 = fTime1Bound; |
| 404 | } |
| 405 | if (fTime1 - fTime0 < fMinTimeInterval) { |
| 406 | fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * @param traces |
| 412 | * @param start |
| 413 | * @param end |
| 414 | */ |
| 415 | void updateInternalData(ITimeGraphEntry[] traces, long start, long end) { |
| 416 | ITimeGraphEntry[] realTraces = traces; |
| 417 | |
| 418 | if (null == realTraces) { |
| 419 | realTraces = new ITimeGraphEntry[0]; |
| 420 | } |
| 421 | if ((start == 0 && end == 0) || start < 0 || end < 0) { |
| 422 | // Start and end time are unspecified and need to be determined from |
| 423 | // individual processes |
| 424 | setTimeRange(realTraces); |
| 425 | } else { |
| 426 | fBeginTime = start; |
| 427 | fEndTime = end; |
| 428 | } |
| 429 | |
| 430 | refreshAllData(realTraces); |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * @param traces |
| 435 | */ |
| 436 | private void refreshAllData(ITimeGraphEntry[] traces) { |
| 437 | setTimeBounds(); |
| 438 | if (fSelectionBegin < fBeginTime) { |
| 439 | fSelectionBegin = fBeginTime; |
| 440 | } else if (fSelectionBegin > fEndTime) { |
| 441 | fSelectionBegin = fEndTime; |
| 442 | } |
| 443 | if (fSelectionEnd < fBeginTime) { |
| 444 | fSelectionEnd = fBeginTime; |
| 445 | } else if (fSelectionEnd > fEndTime) { |
| 446 | fSelectionEnd = fEndTime; |
| 447 | } |
| 448 | fTimeGraphCtrl.refreshData(traces); |
| 449 | fTimeScaleCtrl.redraw(); |
| 450 | adjustVerticalScrollBar(); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Callback for when this view is focused |
| 455 | */ |
| 456 | public void setFocus() { |
| 457 | if (null != fTimeGraphCtrl) { |
| 458 | fTimeGraphCtrl.setFocus(); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Get the current focus status of this view. |
| 464 | * |
| 465 | * @return If the view is currently focused, or not |
| 466 | */ |
| 467 | public boolean isInFocus() { |
| 468 | return fTimeGraphCtrl.isInFocus(); |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Get the view's current selection |
| 473 | * |
| 474 | * @return The entry that is selected |
| 475 | */ |
| 476 | public ITimeGraphEntry getSelection() { |
| 477 | return fTimeGraphCtrl.getSelectedTrace(); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Get the index of the current selection |
| 482 | * |
| 483 | * @return The index |
| 484 | */ |
| 485 | public int getSelectionIndex() { |
| 486 | return fTimeGraphCtrl.getSelectedIndex(); |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | public long getTime0() { |
| 491 | return fTime0; |
| 492 | } |
| 493 | |
| 494 | @Override |
| 495 | public long getTime1() { |
| 496 | return fTime1; |
| 497 | } |
| 498 | |
| 499 | @Override |
| 500 | public long getMinTimeInterval() { |
| 501 | return fMinTimeInterval; |
| 502 | } |
| 503 | |
| 504 | @Override |
| 505 | public int getNameSpace() { |
| 506 | return fNameWidth; |
| 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public void setNameSpace(int width) { |
| 511 | fNameWidth = width; |
| 512 | int w = fTimeGraphCtrl.getClientArea().width; |
| 513 | if (fNameWidth > w - MIN_NAME_WIDTH) { |
| 514 | fNameWidth = w - MIN_NAME_WIDTH; |
| 515 | } |
| 516 | if (fNameWidth < MIN_NAME_WIDTH) { |
| 517 | fNameWidth = MIN_NAME_WIDTH; |
| 518 | } |
| 519 | fTimeGraphCtrl.adjustScrolls(); |
| 520 | fTimeGraphCtrl.redraw(); |
| 521 | fTimeScaleCtrl.redraw(); |
| 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public int getTimeSpace() { |
| 526 | int w = fTimeGraphCtrl.getClientArea().width; |
| 527 | return w - fNameWidth; |
| 528 | } |
| 529 | |
| 530 | @SuppressWarnings("deprecation") |
| 531 | @Deprecated |
| 532 | @Override |
| 533 | public long getSelectedTime() { |
| 534 | return fSelectionBegin; |
| 535 | } |
| 536 | |
| 537 | @Override |
| 538 | public long getBeginTime() { |
| 539 | return fBeginTime; |
| 540 | } |
| 541 | |
| 542 | @Override |
| 543 | public long getEndTime() { |
| 544 | return fEndTime; |
| 545 | } |
| 546 | |
| 547 | @Override |
| 548 | public long getMaxTime() { |
| 549 | return fTime1Bound; |
| 550 | } |
| 551 | |
| 552 | @Override |
| 553 | public long getMinTime() { |
| 554 | return fTime0Bound; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * @since 2.1 |
| 559 | */ |
| 560 | @Override |
| 561 | public long getSelectionBegin() { |
| 562 | return fSelectionBegin; |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * @since 2.1 |
| 567 | */ |
| 568 | @Override |
| 569 | public long getSelectionEnd() { |
| 570 | return fSelectionEnd; |
| 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public void setStartFinishTimeNotify(long time0, long time1) { |
| 575 | setStartFinishTime(time0, time1); |
| 576 | notifyRangeListeners(time0, time1); |
| 577 | } |
| 578 | |
| 579 | @Override |
| 580 | public void notifyStartFinishTime() { |
| 581 | notifyRangeListeners(fTime0, fTime1); |
| 582 | } |
| 583 | |
| 584 | @Override |
| 585 | public void setStartFinishTime(long time0, long time1) { |
| 586 | fTime0 = time0; |
| 587 | if (fTime0 < fTime0Bound) { |
| 588 | fTime0 = fTime0Bound; |
| 589 | } |
| 590 | if (fTime0 > fTime1Bound) { |
| 591 | fTime0 = fTime1Bound; |
| 592 | } |
| 593 | fTime1 = time1; |
| 594 | if (fTime1 < fTime0Bound) { |
| 595 | fTime1 = fTime0Bound; |
| 596 | } |
| 597 | if (fTime1 > fTime1Bound) { |
| 598 | fTime1 = fTime1Bound; |
| 599 | } |
| 600 | if (fTime1 - fTime0 < fMinTimeInterval) { |
| 601 | fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval); |
| 602 | } |
| 603 | fTimeRangeFixed = true; |
| 604 | fTimeGraphCtrl.adjustScrolls(); |
| 605 | fTimeGraphCtrl.redraw(); |
| 606 | fTimeScaleCtrl.redraw(); |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * Set the time bounds to the provided values |
| 611 | * |
| 612 | * @param beginTime |
| 613 | * The start time of the window |
| 614 | * @param endTime |
| 615 | * The end time |
| 616 | */ |
| 617 | public void setTimeBounds(long beginTime, long endTime) { |
| 618 | fBeginTime = beginTime; |
| 619 | fEndTime = endTime; |
| 620 | fTime0Bound = beginTime; |
| 621 | fTime1Bound = endTime; |
| 622 | fTimeGraphCtrl.adjustScrolls(); |
| 623 | } |
| 624 | |
| 625 | @Override |
| 626 | public void resetStartFinishTime() { |
| 627 | setStartFinishTime(fTime0Bound, fTime1Bound); |
| 628 | fTimeRangeFixed = false; |
| 629 | } |
| 630 | |
| 631 | @Override |
| 632 | public void setSelectedTimeNotify(long time, boolean ensureVisible) { |
| 633 | setSelectedTimeInt(time, ensureVisible, true); |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public void setSelectedTime(long time, boolean ensureVisible) { |
| 638 | setSelectedTimeInt(time, ensureVisible, false); |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * @since 2.1 |
| 643 | */ |
| 644 | @Override |
| 645 | public void setSelectionRangeNotify(long beginTime, long endTime) { |
| 646 | boolean changed = (beginTime != fSelectionBegin || endTime != fSelectionEnd); |
| 647 | fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime)); |
| 648 | fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime)); |
| 649 | fTimeGraphCtrl.redraw(); |
| 650 | fTimeScaleCtrl.redraw(); |
| 651 | if (changed) { |
| 652 | notifyTimeListeners(fSelectionBegin, fSelectionEnd); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * @since 2.1 |
| 658 | */ |
| 659 | @Override |
| 660 | public void setSelectionRange(long beginTime, long endTime) { |
| 661 | fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime)); |
| 662 | fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime)); |
| 663 | fTimeGraphCtrl.redraw(); |
| 664 | fTimeScaleCtrl.redraw(); |
| 665 | } |
| 666 | |
| 667 | private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) { |
| 668 | long time0 = fTime0; |
| 669 | long time1 = fTime1; |
| 670 | if (ensureVisible) { |
| 671 | long timeSpace = (fTime1 - fTime0) / RECENTERING_MARGIN_FACTOR; |
| 672 | long timeMid = (fTime1 - fTime0) / 2; |
| 673 | if (time < fTime0 + timeSpace) { |
| 674 | long dt = fTime0 - time + timeMid; |
| 675 | fTime0 -= dt; |
| 676 | fTime1 -= dt; |
| 677 | } else if (time > fTime1 - timeSpace) { |
| 678 | long dt = time - fTime1 + timeMid; |
| 679 | fTime0 += dt; |
| 680 | fTime1 += dt; |
| 681 | } |
| 682 | if (fTime0 < fTime0Bound) { |
| 683 | fTime1 = Math.min(fTime1Bound, fTime1 + (fTime0Bound - fTime0)); |
| 684 | fTime0 = fTime0Bound; |
| 685 | } else if (fTime1 > fTime1Bound) { |
| 686 | fTime0 = Math.max(fTime0Bound, fTime0 - (fTime1 - fTime1Bound)); |
| 687 | fTime1 = fTime1Bound; |
| 688 | } |
| 689 | } |
| 690 | if (fTime1 - fTime0 < fMinTimeInterval) { |
| 691 | fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval); |
| 692 | } |
| 693 | fTimeGraphCtrl.adjustScrolls(); |
| 694 | fTimeGraphCtrl.redraw(); |
| 695 | fTimeScaleCtrl.redraw(); |
| 696 | |
| 697 | boolean notifySelectedTime = (time != fSelectionBegin || time != fSelectionEnd); |
| 698 | fSelectionBegin = time; |
| 699 | fSelectionEnd = time; |
| 700 | |
| 701 | if (doNotify && ((time0 != fTime0) || (time1 != fTime1))) { |
| 702 | notifyRangeListeners(fTime0, fTime1); |
| 703 | } |
| 704 | |
| 705 | if (doNotify && notifySelectedTime) { |
| 706 | notifyTimeListeners(fSelectionBegin, fSelectionEnd); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | @Override |
| 711 | public void widgetDefaultSelected(SelectionEvent e) { |
| 712 | if (fSelectedEntry != getSelection()) { |
| 713 | fSelectedEntry = getSelection(); |
| 714 | notifySelectionListeners(fSelectedEntry); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | @Override |
| 719 | public void widgetSelected(SelectionEvent e) { |
| 720 | if (fSelectedEntry != getSelection()) { |
| 721 | fSelectedEntry = getSelection(); |
| 722 | notifySelectionListeners(fSelectedEntry); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * Callback for when the next event is selected |
| 728 | */ |
| 729 | public void selectNextEvent() { |
| 730 | fTimeGraphCtrl.selectNextEvent(); |
| 731 | adjustVerticalScrollBar(); |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * Callback for when the previous event is selected |
| 736 | */ |
| 737 | public void selectPrevEvent() { |
| 738 | fTimeGraphCtrl.selectPrevEvent(); |
| 739 | adjustVerticalScrollBar(); |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * Callback for when the next item is selected |
| 744 | */ |
| 745 | public void selectNextItem() { |
| 746 | fTimeGraphCtrl.selectNextTrace(); |
| 747 | adjustVerticalScrollBar(); |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * Callback for when the previous item is selected |
| 752 | */ |
| 753 | public void selectPrevItem() { |
| 754 | fTimeGraphCtrl.selectPrevTrace(); |
| 755 | adjustVerticalScrollBar(); |
| 756 | } |
| 757 | |
| 758 | /** |
| 759 | * Callback for the show legend action |
| 760 | */ |
| 761 | public void showLegend() { |
| 762 | if (fDataViewer == null || fDataViewer.isDisposed()) { |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | TimeGraphLegend.open(fDataViewer.getShell(), fTimeGraphProvider); |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * Callback for the Zoom In action |
| 771 | */ |
| 772 | public void zoomIn() { |
| 773 | fTimeGraphCtrl.zoomIn(); |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Callback for the Zoom Out action |
| 778 | */ |
| 779 | public void zoomOut() { |
| 780 | fTimeGraphCtrl.zoomOut(); |
| 781 | } |
| 782 | |
| 783 | private String getPreferenceString(String string) { |
| 784 | return getViewTypeStr() + "." + string; //$NON-NLS-1$ |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Add a selection listener |
| 789 | * |
| 790 | * @param listener |
| 791 | * The listener to add |
| 792 | */ |
| 793 | public void addSelectionListener(ITimeGraphSelectionListener listener) { |
| 794 | fSelectionListeners.add(listener); |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * Remove a selection listener |
| 799 | * |
| 800 | * @param listener |
| 801 | * The listener to remove |
| 802 | */ |
| 803 | public void removeSelectionListener(ITimeGraphSelectionListener listener) { |
| 804 | fSelectionListeners.remove(listener); |
| 805 | } |
| 806 | |
| 807 | private void notifySelectionListeners(ITimeGraphEntry selection) { |
| 808 | TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection); |
| 809 | |
| 810 | for (ITimeGraphSelectionListener listener : fSelectionListeners) { |
| 811 | listener.selectionChanged(event); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * Add a time listener |
| 817 | * |
| 818 | * @param listener |
| 819 | * The listener to add |
| 820 | */ |
| 821 | public void addTimeListener(ITimeGraphTimeListener listener) { |
| 822 | fTimeListeners.add(listener); |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * Remove a time listener |
| 827 | * |
| 828 | * @param listener |
| 829 | * The listener to remove |
| 830 | */ |
| 831 | public void removeTimeListener(ITimeGraphTimeListener listener) { |
| 832 | fTimeListeners.remove(listener); |
| 833 | } |
| 834 | |
| 835 | private void notifyTimeListeners(long startTime, long endTime) { |
| 836 | TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, startTime, endTime); |
| 837 | |
| 838 | for (ITimeGraphTimeListener listener : fTimeListeners) { |
| 839 | listener.timeSelected(event); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * Add a range listener |
| 845 | * |
| 846 | * @param listener |
| 847 | * The listener to add |
| 848 | */ |
| 849 | public void addRangeListener(ITimeGraphRangeListener listener) { |
| 850 | fRangeListeners.add(listener); |
| 851 | } |
| 852 | |
| 853 | /** |
| 854 | * Remove a range listener |
| 855 | * |
| 856 | * @param listener |
| 857 | * The listener to remove |
| 858 | */ |
| 859 | public void removeRangeListener(ITimeGraphRangeListener listener) { |
| 860 | fRangeListeners.remove(listener); |
| 861 | } |
| 862 | |
| 863 | private void notifyRangeListeners(long startTime, long endTime) { |
| 864 | // Check if the time has actually changed from last notification |
| 865 | if (startTime != fTime0ExtSynch || endTime != fTime1ExtSynch) { |
| 866 | // Notify Time Scale Selection Listeners |
| 867 | TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime); |
| 868 | |
| 869 | for (ITimeGraphRangeListener listener : fRangeListeners) { |
| 870 | listener.timeRangeUpdated(event); |
| 871 | } |
| 872 | |
| 873 | // update external synch timers |
| 874 | updateExtSynchTimers(); |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * Callback to set a selected event in the view |
| 880 | * |
| 881 | * @param event |
| 882 | * The event that was selected |
| 883 | * @param source |
| 884 | * The source of this selection event |
| 885 | */ |
| 886 | public void setSelectedEvent(ITimeEvent event, Object source) { |
| 887 | if (event == null || source == this) { |
| 888 | return; |
| 889 | } |
| 890 | fSelectedEntry = event.getEntry(); |
| 891 | fTimeGraphCtrl.selectItem(fSelectedEntry, false); |
| 892 | |
| 893 | setSelectedTimeInt(event.getTime(), true, true); |
| 894 | adjustVerticalScrollBar(); |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Set the seeked time of a trace |
| 899 | * |
| 900 | * @param trace |
| 901 | * The trace that was seeked |
| 902 | * @param time |
| 903 | * The target time |
| 904 | * @param source |
| 905 | * The source of this seek event |
| 906 | */ |
| 907 | public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) { |
| 908 | if (trace == null || source == this) { |
| 909 | return; |
| 910 | } |
| 911 | fSelectedEntry = trace; |
| 912 | fTimeGraphCtrl.selectItem(trace, false); |
| 913 | |
| 914 | setSelectedTimeInt(time, true, true); |
| 915 | } |
| 916 | |
| 917 | /** |
| 918 | * Callback for a trace selection |
| 919 | * |
| 920 | * @param trace |
| 921 | * The trace that was selected |
| 922 | */ |
| 923 | public void setSelection(ITimeGraphEntry trace) { |
| 924 | fSelectedEntry = trace; |
| 925 | fTimeGraphCtrl.selectItem(trace, false); |
| 926 | adjustVerticalScrollBar(); |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * Callback for a time window selection |
| 931 | * |
| 932 | * @param time0 |
| 933 | * Start time of the range |
| 934 | * @param time1 |
| 935 | * End time of the range |
| 936 | * @param source |
| 937 | * Source of the event |
| 938 | */ |
| 939 | public void setSelectVisTimeWindow(long time0, long time1, Object source) { |
| 940 | if (source == this) { |
| 941 | return; |
| 942 | } |
| 943 | |
| 944 | setStartFinishTime(time0, time1); |
| 945 | |
| 946 | // update notification time values since we are now in synch with the |
| 947 | // external application |
| 948 | updateExtSynchTimers(); |
| 949 | } |
| 950 | |
| 951 | /** |
| 952 | * update the cache timers used to identify the need to send a time window |
| 953 | * update to external registered listeners |
| 954 | */ |
| 955 | private void updateExtSynchTimers() { |
| 956 | // last time notification cache |
| 957 | fTime0ExtSynch = fTime0; |
| 958 | fTime1ExtSynch = fTime1; |
| 959 | } |
| 960 | |
| 961 | /** |
| 962 | * @since 2.0 |
| 963 | */ |
| 964 | @Override |
| 965 | public TimeFormat getTimeFormat() { |
| 966 | return fTimeFormat; |
| 967 | } |
| 968 | |
| 969 | /** |
| 970 | * @param tf the {@link TimeFormat} used to display timestamps |
| 971 | * @since 2.0 |
| 972 | */ |
| 973 | public void setTimeFormat(TimeFormat tf) { |
| 974 | this.fTimeFormat = tf; |
| 975 | } |
| 976 | |
| 977 | /** |
| 978 | * Retrieve the border width |
| 979 | * |
| 980 | * @return The width |
| 981 | */ |
| 982 | public int getBorderWidth() { |
| 983 | return fBorderWidth; |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * Set the border width |
| 988 | * |
| 989 | * @param borderWidth |
| 990 | * The width |
| 991 | */ |
| 992 | public void setBorderWidth(int borderWidth) { |
| 993 | if (borderWidth > -1) { |
| 994 | this.fBorderWidth = borderWidth; |
| 995 | GridLayout gl = (GridLayout)fDataViewer.getLayout(); |
| 996 | gl.marginHeight = borderWidth; |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * Retrieve the height of the header |
| 1002 | * |
| 1003 | * @return The height |
| 1004 | */ |
| 1005 | public int getHeaderHeight() { |
| 1006 | return fTimeScaleHeight; |
| 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * Set the height of the header |
| 1011 | * |
| 1012 | * @param headerHeight |
| 1013 | * The height to set |
| 1014 | */ |
| 1015 | public void setHeaderHeight(int headerHeight) { |
| 1016 | if (headerHeight > -1) { |
| 1017 | this.fTimeScaleHeight = headerHeight; |
| 1018 | fTimeScaleCtrl.setHeight(headerHeight); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * Retrieve the height of an item row |
| 1024 | * |
| 1025 | * @return The height |
| 1026 | */ |
| 1027 | public int getItemHeight() { |
| 1028 | if (fTimeGraphCtrl != null) { |
| 1029 | return fTimeGraphCtrl.getItemHeight(); |
| 1030 | } |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * Set the height of an item row |
| 1036 | * |
| 1037 | * @param rowHeight |
| 1038 | * The height to set |
| 1039 | */ |
| 1040 | public void setItemHeight(int rowHeight) { |
| 1041 | if (fTimeGraphCtrl != null) { |
| 1042 | fTimeGraphCtrl.setItemHeight(rowHeight); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | /** |
| 1047 | * Set the minimum item width |
| 1048 | * |
| 1049 | * @param width |
| 1050 | * The min width |
| 1051 | */ |
| 1052 | public void setMinimumItemWidth(int width) { |
| 1053 | if (fTimeGraphCtrl != null) { |
| 1054 | fTimeGraphCtrl.setMinimumItemWidth(width); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * Set the width for the name column |
| 1060 | * |
| 1061 | * @param width The width |
| 1062 | */ |
| 1063 | public void setNameWidthPref(int width) { |
| 1064 | fNameWidthPref = width; |
| 1065 | if (width == 0) { |
| 1066 | fMinNameWidth = 0; |
| 1067 | fNameWidth = 0; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * Retrieve the configure width for the name column |
| 1073 | * |
| 1074 | * @param width |
| 1075 | * Unused? |
| 1076 | * @return The width |
| 1077 | */ |
| 1078 | public int getNameWidthPref(int width) { |
| 1079 | return fNameWidthPref; |
| 1080 | } |
| 1081 | |
| 1082 | /** |
| 1083 | * Returns the primary control associated with this viewer. |
| 1084 | * |
| 1085 | * @return the SWT control which displays this viewer's content |
| 1086 | */ |
| 1087 | public Control getControl() { |
| 1088 | return fDataViewer; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * Returns the time graph control associated with this viewer. |
| 1093 | * |
| 1094 | * @return the time graph control |
| 1095 | * @since 2.0 |
| 1096 | */ |
| 1097 | public TimeGraphControl getTimeGraphControl() { |
| 1098 | return fTimeGraphCtrl; |
| 1099 | } |
| 1100 | |
| 1101 | /** |
| 1102 | * Returns the time graph scale associated with this viewer. |
| 1103 | * |
| 1104 | * @return the time graph scale |
| 1105 | * @since 2.0 |
| 1106 | */ |
| 1107 | public TimeGraphScale getTimeGraphScale() { |
| 1108 | return fTimeScaleCtrl; |
| 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * Return the x coordinate corresponding to a time |
| 1113 | * |
| 1114 | * @param time the time |
| 1115 | * @return the x coordinate corresponding to the time |
| 1116 | * |
| 1117 | * @since 2.0 |
| 1118 | */ |
| 1119 | public int getXForTime(long time) { |
| 1120 | return fTimeGraphCtrl.getXForTime(time); |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * Return the time corresponding to an x coordinate |
| 1125 | * |
| 1126 | * @param x the x coordinate |
| 1127 | * @return the time corresponding to the x coordinate |
| 1128 | * |
| 1129 | * @since 2.0 |
| 1130 | */ |
| 1131 | public long getTimeAtX(int x) { |
| 1132 | return fTimeGraphCtrl.getTimeAtX(x); |
| 1133 | } |
| 1134 | |
| 1135 | /** |
| 1136 | * Get the selection provider |
| 1137 | * |
| 1138 | * @return the selection provider |
| 1139 | */ |
| 1140 | public ISelectionProvider getSelectionProvider() { |
| 1141 | return fTimeGraphCtrl; |
| 1142 | } |
| 1143 | |
| 1144 | /** |
| 1145 | * Wait for the cursor |
| 1146 | * |
| 1147 | * @param waitInd |
| 1148 | * Wait indefinitely? |
| 1149 | */ |
| 1150 | public void waitCursor(boolean waitInd) { |
| 1151 | fTimeGraphCtrl.waitCursor(waitInd); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Get the horizontal scroll bar object |
| 1156 | * |
| 1157 | * @return The scroll bar |
| 1158 | */ |
| 1159 | public ScrollBar getHorizontalBar() { |
| 1160 | return fTimeGraphCtrl.getHorizontalBar(); |
| 1161 | } |
| 1162 | |
| 1163 | /** |
| 1164 | * Get the vertical scroll bar object |
| 1165 | * |
| 1166 | * @return The scroll bar |
| 1167 | */ |
| 1168 | public Slider getVerticalBar() { |
| 1169 | return fVerticalScrollBar; |
| 1170 | } |
| 1171 | |
| 1172 | /** |
| 1173 | * Set the given index as the top one |
| 1174 | * |
| 1175 | * @param index |
| 1176 | * The index that will go to the top |
| 1177 | */ |
| 1178 | public void setTopIndex(int index) { |
| 1179 | fTimeGraphCtrl.setTopIndex(index); |
| 1180 | adjustVerticalScrollBar(); |
| 1181 | } |
| 1182 | |
| 1183 | /** |
| 1184 | * Retrieve the current top index |
| 1185 | * |
| 1186 | * @return The top index |
| 1187 | */ |
| 1188 | public int getTopIndex() { |
| 1189 | return fTimeGraphCtrl.getTopIndex(); |
| 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * Set the expanded state of an entry |
| 1194 | * |
| 1195 | * @param entry |
| 1196 | * The entry to expand/collapse |
| 1197 | * @param expanded |
| 1198 | * True for expanded, false for collapsed |
| 1199 | */ |
| 1200 | public void setExpandedState(ITimeGraphEntry entry, boolean expanded) { |
| 1201 | fTimeGraphCtrl.setExpandedState(entry, expanded); |
| 1202 | adjustVerticalScrollBar(); |
| 1203 | } |
| 1204 | |
| 1205 | /** |
| 1206 | * Collapses all nodes of the viewer's tree, starting with the root. |
| 1207 | * |
| 1208 | * @since 2.0 |
| 1209 | */ |
| 1210 | public void collapseAll() { |
| 1211 | fTimeGraphCtrl.collapseAll(); |
| 1212 | adjustVerticalScrollBar(); |
| 1213 | } |
| 1214 | |
| 1215 | /** |
| 1216 | * Expands all nodes of the viewer's tree, starting with the root. |
| 1217 | * |
| 1218 | * @since 2.0 |
| 1219 | */ |
| 1220 | public void expandAll() { |
| 1221 | fTimeGraphCtrl.expandAll(); |
| 1222 | adjustVerticalScrollBar(); |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Get the number of sub-elements when expanded |
| 1227 | * |
| 1228 | * @return The element count |
| 1229 | */ |
| 1230 | public int getExpandedElementCount() { |
| 1231 | return fTimeGraphCtrl.getExpandedElementCount(); |
| 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * Get the sub-elements |
| 1236 | * |
| 1237 | * @return The array of entries that are below this one |
| 1238 | */ |
| 1239 | public ITimeGraphEntry[] getExpandedElements() { |
| 1240 | return fTimeGraphCtrl.getExpandedElements(); |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * Add a tree listener |
| 1245 | * |
| 1246 | * @param listener |
| 1247 | * The listener to add |
| 1248 | */ |
| 1249 | public void addTreeListener(ITimeGraphTreeListener listener) { |
| 1250 | fTimeGraphCtrl.addTreeListener(listener); |
| 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * Remove a tree listener |
| 1255 | * |
| 1256 | * @param listener |
| 1257 | * The listener to remove |
| 1258 | */ |
| 1259 | public void removeTreeListener(ITimeGraphTreeListener listener) { |
| 1260 | fTimeGraphCtrl.removeTreeListener(listener); |
| 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * Get the reset scale action. |
| 1265 | * |
| 1266 | * @return The Action object |
| 1267 | */ |
| 1268 | public Action getResetScaleAction() { |
| 1269 | if (fResetScaleAction == null) { |
| 1270 | // resetScale |
| 1271 | fResetScaleAction = new Action() { |
| 1272 | @Override |
| 1273 | public void run() { |
| 1274 | resetStartFinishTime(); |
| 1275 | notifyStartFinishTime(); |
| 1276 | } |
| 1277 | }; |
| 1278 | fResetScaleAction.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText); |
| 1279 | fResetScaleAction.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText); |
| 1280 | fResetScaleAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU)); |
| 1281 | } |
| 1282 | return fResetScaleAction; |
| 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * Get the show legend action. |
| 1287 | * |
| 1288 | * @return The Action object |
| 1289 | */ |
| 1290 | public Action getShowLegendAction() { |
| 1291 | if (fShowLegendAction == null) { |
| 1292 | // showLegend |
| 1293 | fShowLegendAction = new Action() { |
| 1294 | @Override |
| 1295 | public void run() { |
| 1296 | showLegend(); |
| 1297 | } |
| 1298 | }; |
| 1299 | fShowLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText); |
| 1300 | fShowLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText); |
| 1301 | fShowLegendAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND)); |
| 1302 | } |
| 1303 | |
| 1304 | return fShowLegendAction; |
| 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * Get the the next event action. |
| 1309 | * |
| 1310 | * @return The action object |
| 1311 | */ |
| 1312 | public Action getNextEventAction() { |
| 1313 | if (fNextEventAction == null) { |
| 1314 | fNextEventAction = new Action() { |
| 1315 | @Override |
| 1316 | public void run() { |
| 1317 | selectNextEvent(); |
| 1318 | } |
| 1319 | }; |
| 1320 | |
| 1321 | fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText); |
| 1322 | fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText); |
| 1323 | fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT)); |
| 1324 | } |
| 1325 | |
| 1326 | return fNextEventAction; |
| 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * Get the previous event action. |
| 1331 | * |
| 1332 | * @return The Action object |
| 1333 | */ |
| 1334 | public Action getPreviousEventAction() { |
| 1335 | if (fPrevEventAction == null) { |
| 1336 | fPrevEventAction = new Action() { |
| 1337 | @Override |
| 1338 | public void run() { |
| 1339 | selectPrevEvent(); |
| 1340 | } |
| 1341 | }; |
| 1342 | |
| 1343 | fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText); |
| 1344 | fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText); |
| 1345 | fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT)); |
| 1346 | } |
| 1347 | |
| 1348 | return fPrevEventAction; |
| 1349 | } |
| 1350 | |
| 1351 | /** |
| 1352 | * Get the next item action. |
| 1353 | * |
| 1354 | * @return The Action object |
| 1355 | */ |
| 1356 | public Action getNextItemAction() { |
| 1357 | if (fNextItemAction == null) { |
| 1358 | |
| 1359 | fNextItemAction = new Action() { |
| 1360 | @Override |
| 1361 | public void run() { |
| 1362 | selectNextItem(); |
| 1363 | } |
| 1364 | }; |
| 1365 | fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText); |
| 1366 | fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText); |
| 1367 | fNextItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM)); |
| 1368 | } |
| 1369 | return fNextItemAction; |
| 1370 | } |
| 1371 | |
| 1372 | /** |
| 1373 | * Get the previous item action. |
| 1374 | * |
| 1375 | * @return The Action object |
| 1376 | */ |
| 1377 | public Action getPreviousItemAction() { |
| 1378 | if (fPreviousItemAction == null) { |
| 1379 | |
| 1380 | fPreviousItemAction = new Action() { |
| 1381 | @Override |
| 1382 | public void run() { |
| 1383 | selectPrevItem(); |
| 1384 | } |
| 1385 | }; |
| 1386 | fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText); |
| 1387 | fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText); |
| 1388 | fPreviousItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM)); |
| 1389 | } |
| 1390 | return fPreviousItemAction; |
| 1391 | } |
| 1392 | |
| 1393 | /** |
| 1394 | * Get the zoom in action |
| 1395 | * |
| 1396 | * @return The Action object |
| 1397 | */ |
| 1398 | public Action getZoomInAction() { |
| 1399 | if (fZoomInAction == null) { |
| 1400 | fZoomInAction = new Action() { |
| 1401 | @Override |
| 1402 | public void run() { |
| 1403 | zoomIn(); |
| 1404 | } |
| 1405 | }; |
| 1406 | fZoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText); |
| 1407 | fZoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText); |
| 1408 | fZoomInAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU)); |
| 1409 | } |
| 1410 | return fZoomInAction; |
| 1411 | } |
| 1412 | |
| 1413 | /** |
| 1414 | * Get the zoom out action |
| 1415 | * |
| 1416 | * @return The Action object |
| 1417 | */ |
| 1418 | public Action getZoomOutAction() { |
| 1419 | if (fZoomOutAction == null) { |
| 1420 | fZoomOutAction = new Action() { |
| 1421 | @Override |
| 1422 | public void run() { |
| 1423 | zoomOut(); |
| 1424 | } |
| 1425 | }; |
| 1426 | fZoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText); |
| 1427 | fZoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText); |
| 1428 | fZoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU)); |
| 1429 | } |
| 1430 | return fZoomOutAction; |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | private void adjustVerticalScrollBar() { |
| 1435 | int topIndex = fTimeGraphCtrl.getTopIndex(); |
| 1436 | int countPerPage = fTimeGraphCtrl.countPerPage(); |
| 1437 | int expandedElementCount = fTimeGraphCtrl.getExpandedElementCount(); |
| 1438 | if (topIndex + countPerPage > expandedElementCount) { |
| 1439 | fTimeGraphCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage)); |
| 1440 | } |
| 1441 | |
| 1442 | int selection = fTimeGraphCtrl.getTopIndex(); |
| 1443 | int min = 0; |
| 1444 | int max = Math.max(1, expandedElementCount - 1); |
| 1445 | int thumb = Math.min(max, Math.max(1, countPerPage - 1)); |
| 1446 | int increment = 1; |
| 1447 | int pageIncrement = Math.max(1, countPerPage); |
| 1448 | fVerticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement); |
| 1449 | } |
| 1450 | |
| 1451 | /** |
| 1452 | * @param listener a {@link MenuDetectListener} |
| 1453 | * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener) |
| 1454 | * @since 1.2 |
| 1455 | */ |
| 1456 | public void addTimeGraphEntryMenuListener(MenuDetectListener listener) { |
| 1457 | fTimeGraphCtrl.addTimeGraphEntryMenuListener(listener); |
| 1458 | } |
| 1459 | |
| 1460 | /** |
| 1461 | * @param listener a {@link MenuDetectListener} |
| 1462 | * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener) |
| 1463 | * @since 1.2 |
| 1464 | */ |
| 1465 | public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) { |
| 1466 | fTimeGraphCtrl.removeTimeGraphEntryMenuListener(listener); |
| 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * @param listener a {@link MenuDetectListener} |
| 1471 | * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener) |
| 1472 | * @since 1.2 |
| 1473 | */ |
| 1474 | public void addTimeEventMenuListener(MenuDetectListener listener) { |
| 1475 | fTimeGraphCtrl.addTimeEventMenuListener(listener); |
| 1476 | } |
| 1477 | |
| 1478 | /** |
| 1479 | * @param listener a {@link MenuDetectListener} |
| 1480 | * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener) |
| 1481 | * @since 1.2 |
| 1482 | */ |
| 1483 | public void removeTimeEventMenuListener(MenuDetectListener listener) { |
| 1484 | fTimeGraphCtrl.removeTimeEventMenuListener(listener); |
| 1485 | } |
| 1486 | |
| 1487 | /** |
| 1488 | * @param filter The filter object to be attached to the view |
| 1489 | * @since 2.0 |
| 1490 | */ |
| 1491 | public void addFilter(ViewerFilter filter) { |
| 1492 | fTimeGraphCtrl.addFilter(filter); |
| 1493 | refresh(); |
| 1494 | } |
| 1495 | |
| 1496 | /** |
| 1497 | * @param filter The filter object to be attached to the view |
| 1498 | * @since 2.0 |
| 1499 | */ |
| 1500 | public void removeFilter(ViewerFilter filter) { |
| 1501 | fTimeGraphCtrl.removeFilter(filter); |
| 1502 | refresh(); |
| 1503 | } |
| 1504 | |
| 1505 | } |