/
TimeGraphControl.java
4351 lines (4036 loc) · 155 KB
/
TimeGraphControl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
* Copyright (c) 2007, 2022 Intel Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Intel Corporation - Initial API and implementation
* Ruslan A. Scherbakov, Intel - Initial API and implementation
* Alvaro Sanchez-Leon, Ericsson - Updated for TMF
* Patrick Tasse, Ericsson - Refactoring
* Geneviève Bastien, École Polytechnique de Montréal - Move code to
* provide base classes for time graph view
* Add display of links between items
* Xavier Raynaud, Kalray - Code optimization
* Generoso Pagano, Inria - Support for drag selection listeners
*****************************************************************************/
package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.MenuDetectListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.MouseWheelListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.events.TypedEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils;
import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog;
import org.eclipse.tracecompass.common.core.math.SaturatedArithmetic;
import org.eclipse.tracecompass.internal.provisional.tmf.ui.model.IStylePresentationProvider;
import org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets.timegraph.ITimeGraphStylePresentationProvider;
import org.eclipse.tracecompass.internal.tmf.ui.Activator;
import org.eclipse.tracecompass.internal.tmf.ui.ITmfUIPreferences;
import org.eclipse.tracecompass.internal.tmf.ui.util.LineClipper;
import org.eclipse.tracecompass.internal.tmf.ui.util.SymbolHelper;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredEntry;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredItem;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredSegment;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredState;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTinyState;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTransparentState;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.PostDrawEvent;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.model.TimeGraphLineEntry;
import org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.model.TimeLineEvent;
import org.eclipse.tracecompass.tmf.core.model.CoreFilterProperty;
import org.eclipse.tracecompass.tmf.core.model.OutputElementStyle;
import org.eclipse.tracecompass.tmf.core.model.StyleProperties;
import org.eclipse.tracecompass.tmf.core.model.StyleProperties.BorderStyle;
import org.eclipse.tracecompass.tmf.core.model.StyleProperties.SymbolType;
import org.eclipse.tracecompass.tmf.core.model.StyleProperties.VerticalAlign;
import org.eclipse.tracecompass.tmf.core.presentation.RGBAColor;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
import org.eclipse.tracecompass.tmf.ui.colors.RGBAUtil;
import org.eclipse.tracecompass.tmf.ui.model.StyleManager;
import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo;
import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentSignal;
import org.eclipse.tracecompass.tmf.ui.views.FormatTimeUtils;
import org.eclipse.tracecompass.tmf.ui.views.FormatTimeUtils.Resolution;
import org.eclipse.tracecompass.tmf.ui.views.FormatTimeUtils.TimeFormat;
import org.eclipse.tracecompass.tmf.ui.views.ITmfTimeAligned;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphColorListener;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphTreeListener;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphViewerFilterListener;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphTreeExpansionEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
import com.google.common.collect.Iterables;
/**
* Time graph control implementation
*
* @author Alvaro Sanchez-Leon
* @author Patrick Tasse
*/
public class TimeGraphControl extends TimeGraphBaseControl
implements FocusListener, KeyListener, MouseMoveListener, MouseListener,
MouseWheelListener, MouseTrackListener, TraverseListener, ISelectionProvider,
MenuDetectListener, ITmfTimeGraphDrawingHelper, ITimeGraphColorListener, ControlListener, Listener {
/**
* Default state width ratio
*
* @since 4.1
*/
public static final float DEFAULT_STATE_WIDTH = 1.0f;
/**
* Default link width ratio
*
* @since 4.1
*/
public static final float DEFAULT_LINK_WIDTH = 0.1f;
/**
* Constant indicating that all levels of the time graph should be expanded
*/
public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
private static final @NonNull Logger LOGGER = TraceCompassLog.getLogger(TimeGraphControl.class);
private static final @NonNull String HIGHLIGHTED_BOUND_COLOR = "#ff3300"; //$NON-NLS-1$
private static final @NonNull RGBAColor BLACK = new RGBAColor(0, 0, 0, 255);
private static final int OPAQUE = 255;
private static final int HIGHLIGHTED_BOUND_WIDTH = 4;
private static final int DRAG_MARGIN = 5;
private static final int DRAG_NONE = 0;
private static final int DRAG_TRACE_ITEM = 1;
private static final int DRAG_SPLIT_LINE = 2;
private static final int DRAG_ZOOM = 3;
private static final int DRAG_SELECTION = 4;
/**
* Get item height from provider
*/
private static final int CUSTOM_ITEM_HEIGHT = -1;
private static final int MIN_MIDLINE_HEIGHT = 3;
private static final double ZOOM_FACTOR = 1.5;
private static final double ZOOM_IN_FACTOR = 0.8;
private static final double ZOOM_OUT_FACTOR = 1.25;
private static final int SNAP_WIDTH = 3;
private static final int ARROW_HOVER_MAX_DIST = 5;
/**
* base to height ratio
*/
private static final double ARROW_RATIO = Math.sqrt(3) / 2;
private static final int NO_STATUS = -1;
private static final int STATUS_WITHOUT_CURSOR_TIME = -2;
private static final int MAX_LABEL_LENGTH = 256;
private static final int VERTICAL_ZOOM_DELAY = 400;
private static final String PREFERRED_WIDTH = "width"; //$NON-NLS-1$
/**
* The alpha color component value for dimmed events
*
* @since 4.0
*/
private static final int DIMMED_ALPHA_COEFFICIENT = 4;
/** Resource manager */
private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
/** Color map for event types */
private Color[] fEventColorMap = null;
private ITimeDataProvider fTimeProvider;
private ITableLabelProvider fLabelProvider;
private IStatusLineManager fStatusLineManager = null;
private Tree fTree = null;
private TimeGraphScale fTimeGraphScale = null;
private boolean fIsInFocus = false;
private boolean fMouseOverSplitLine = false;
private int fGlobalItemHeight = CUSTOM_ITEM_HEIGHT;
private int fHeightAdjustment = 0;
private int fMaxItemHeight = 0;
private boolean fBlendSubPixelEvents = false;
private int fMinimumItemWidth = 0;
private int fTopIndex = 0;
private int fDragState = DRAG_NONE;
private boolean fDragBeginMarker = false;
private int fDragButton;
private int fDragX0 = 0;
private int fDragX = 0;
private ITimeGraphEntry fDragEntry = null;
private boolean fHasNamespaceFocus = false;
/**
* Used to preserve accuracy of modified selection
*/
private long fDragTime0 = 0;
private int fIdealNameSpace = 0;
private boolean fAutoResizeColumns = true;
private long fTime0bak;
private long fTime1bak;
private ITimeGraphPresentationProvider fTimeGraphProvider = null;
private ItemData fItemData = null;
private List<IMarkerEvent> fMarkers = null;
private boolean fMarkersVisible = true;
private List<SelectionListener> fSelectionListeners;
private List<ITimeGraphTimeListener> fDragSelectionListeners;
private final List<ISelectionChangedListener> fSelectionChangedListeners = new ArrayList<>();
private final List<ITimeGraphTreeListener> fTreeListeners = new ArrayList<>();
private final List<ITimeGraphViewerFilterListener> fViewerFilterListeners = new ArrayList<>();
private final List<MenuDetectListener> fTimeGraphEntryMenuListeners = new ArrayList<>();
private final List<MenuDetectListener> fTimeEventMenuListeners = new ArrayList<>();
private final Cursor fDragCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_HAND);
private final Cursor fResizeCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_CROSS);
private final Cursor fWaitCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_WAIT);
private final Cursor fZoomCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_SIZEWE);
private final Set<@NonNull ViewerFilter> fFilters = new LinkedHashSet<>();
private MenuDetectEvent fPendingMenuDetectEvent = null;
private boolean fGridLinesVisible = true;
private final Color fGray = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
private final @NonNull RGBAColor fGrayColor = new RGBAColor((RGBAUtil.fromRGBA(fGray.getRGBA())));
private final @NonNull RGBAColor fTransparentGrayColor = new RGBAColor(fGrayColor.getRed(), fGrayColor.getGreen(), fGrayColor.getBlue(), fGrayColor.getAlpha() / 4);
private Color fGridLineColor = fGray;
private boolean fLabelsVisible = true;
private boolean fMidLinesVisible = true;
private boolean fHideArrows = false;
private int fAutoExpandLevel = ALL_LEVELS;
private Entry<ITimeGraphEntry, Integer> fVerticalZoomAlignEntry = null;
private long fVerticalZoomAlignTime = 0;
private int fBorderWidth = 0;
private int fHeaderHeight = 0;
private int fLastTransparentX = -1;
private boolean fFilterActive;
private boolean fHasSavedFilters;
private boolean fHideEmptyRowsFilterActive;
private List<DeferredEntry> fPostDrawEntries = new ArrayList<>();
private List<PostDrawEvent> fPostDrawArrows = new ArrayList<>();
private List<DeferredSegment> fPoints = new ArrayList<>();
private List<DeferredLine> fLines = new ArrayList<>();
private List<Rectangle> fSelectedRectangles = new ArrayList<>();
private @Nullable Point fSize = null;
private @Nullable Rectangle fBounds = null;
private final @NonNull String fPaintScopeLabel = getClass().getCanonicalName() + "#paint"; //$NON-NLS-1$
private final @NonNull String fBackgroundScopeLabel = getClass().getCanonicalName() + "#drawBackground"; //$NON-NLS-1$
private final @NonNull String fGridLinesScopeLabel = getClass().getCanonicalName() + "#drawGridlines"; //$NON-NLS-1$
private final @NonNull String fBgmScopeLabel = getClass().getCanonicalName() + "#drawBgMarkers"; //$NON-NLS-1$
private final @NonNull String fItemsScopeLabel = getClass().getCanonicalName() + "#drawItems"; //$NON-NLS-1$
private final @NonNull String fLinksScopeLabel = getClass().getCanonicalName() + "#drawLinks"; //$NON-NLS-1$
private final @NonNull String fMarkersScopeLabel = getClass().getCanonicalName() + "#drawMarkers"; //$NON-NLS-1$
private final @NonNull String fDrawItemsCountLabel = fItemsScopeLabel + "#count"; //$NON-NLS-1$
private final @NonNull String fDrawMarkersCountLabel = fMarkersScopeLabel + "#count"; //$NON-NLS-1$
private final @NonNull String fDrawLinksCountLabel = fLinksScopeLabel + "#count"; //$NON-NLS-1$
private DeferredEntry fCurrentDeferredEntry;
/**
* Standard constructor
*
* @param parent
* The parent composite object
* @param colors
* The color scheme to use
*/
public TimeGraphControl(Composite parent, TimeGraphColorScheme colors) {
super(parent, colors, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
fItemData = new ItemData();
addControlListener(this);
addFocusListener(this);
addMouseListener(this);
addMouseMoveListener(this);
addMouseTrackListener(this);
addMouseWheelListener(this);
addTraverseListener(this);
addKeyListener(this);
addMenuDetectListener(this);
addListener(SWT.MouseWheel, this);
addDisposeListener(e -> fResourceManager.dispose());
}
/**
* Sets the timegraph provider used by this timegraph viewer.
*
* @param timeGraphProvider
* the timegraph provider
*/
public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {
fTimeGraphProvider = timeGraphProvider;
timeGraphProvider.setDrawingHelper(this);
timeGraphProvider.addColorListener(this);
StateItem[] stateItems = fTimeGraphProvider.getStateTable();
colorSettingsChanged(stateItems);
}
/**
* Gets the timegraph provider used by this timegraph viewer.
*
* @return the timegraph provider, or <code>null</code> if not set.
*/
public ITimeGraphPresentationProvider getTimeGraphProvider() {
return fTimeGraphProvider;
}
/**
* Gets the time data provider used by this viewer.
*
* @return The time data provider, or <code>null</code> if not set
* @since 2.1
*/
public ITimeDataProvider getTimeDataProvider() {
return fTimeProvider;
}
/**
* Gets the color map used by this timegraph viewer.
*
* @return a color map, or <code>null</code> if not set.
*/
public Color[] getEventColorMap() {
return fEventColorMap;
}
/**
* Assign the given time provider
*
* @param timeProvider
* The time provider
*/
public void setTimeProvider(ITimeDataProvider timeProvider) {
fTimeProvider = timeProvider;
redraw();
}
/**
* Set the label provider for the name space
*
* @param labelProvider
* The label provider
* @since 2.3
*/
public void setLabelProvider(ITableLabelProvider labelProvider) {
fLabelProvider = labelProvider;
redraw();
}
/**
* Get the label provider for the name space
*
* @return The label provider
* @since 2.3
*/
public ITableLabelProvider getLabelProvider() {
return fLabelProvider;
}
/**
* Assign the status line manager
*
* @param statusLineManager
* The status line manager, or null to disable status line
* messages
*/
public void setStatusLineManager(IStatusLineManager statusLineManager) {
if (fStatusLineManager != null && statusLineManager == null) {
fStatusLineManager.setMessage(""); //$NON-NLS-1$
}
fStatusLineManager = statusLineManager;
}
/**
* Assign the tree that represents the name space header
*
* @param tree
* The tree
* @since 2.3
*/
public void setTree(Tree tree) {
fTree = tree;
}
/**
* Returns the tree control associated with this time graph control. The
* tree is only used for column handling of the name space and contains no
* tree items.
*
* @return the tree control
* @since 2.3
*/
public Tree getTree() {
return fTree;
}
/**
* Sets the columns for this time graph control's name space.
*
* @param columnNames
* the column names
* @since 2.3
*/
public void setColumns(String[] columnNames) {
Tree tree = getTree();
for (TreeColumn column : tree.getColumns()) {
column.dispose();
}
ControlListener controlListener = new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
if (fAutoResizeColumns && ((TreeColumn) e.widget).getWidth() < (Integer) e.widget.getData(PREFERRED_WIDTH)) {
fAutoResizeColumns = false;
}
redraw();
}
@Override
public void controlMoved(ControlEvent e) {
redraw();
}
};
for (String columnName : columnNames) {
TreeColumn column = new TreeColumn(tree, SWT.LEFT);
column.setMoveable(true);
column.setText(columnName);
column.pack();
column.setData(PREFERRED_WIDTH, column.getWidth());
column.addControlListener(controlListener);
}
}
/**
* Assign the time graph scale
*
* @param timeGraphScale
* The time graph scale
*/
public void setTimeGraphScale(TimeGraphScale timeGraphScale) {
fTimeGraphScale = timeGraphScale;
}
/**
* Add a selection listener
*
* @param listener
* The listener to add
*/
public void addSelectionListener(SelectionListener listener) {
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
if (null == fSelectionListeners) {
fSelectionListeners = new ArrayList<>();
}
fSelectionListeners.add(listener);
}
/**
* Remove a selection listener
*
* @param listener
* The listener to remove
*/
public void removeSelectionListener(SelectionListener listener) {
if (null != fSelectionListeners) {
fSelectionListeners.remove(listener);
}
}
/**
* Selection changed callback
*/
public void fireSelectionChanged() {
if (null != fSelectionListeners) {
Iterator<SelectionListener> it = fSelectionListeners.iterator();
while (it.hasNext()) {
SelectionListener listener = it.next();
listener.widgetSelected(null);
}
}
for (ISelectionChangedListener listener : fSelectionChangedListeners) {
listener.selectionChanged(new SelectionChangedEvent(this, getSelection()));
}
}
/**
* Default selection callback
*/
public void fireDefaultSelection() {
if (null != fSelectionListeners) {
Iterator<SelectionListener> it = fSelectionListeners.iterator();
while (it.hasNext()) {
SelectionListener listener = it.next();
listener.widgetDefaultSelected(null);
}
}
}
/**
* Add a drag selection listener
*
* @param listener
* The listener to add
*/
public void addDragSelectionListener(ITimeGraphTimeListener listener) {
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
if (null == fDragSelectionListeners) {
fDragSelectionListeners = new ArrayList<>();
}
fDragSelectionListeners.add(listener);
}
/**
* Remove a drag selection listener
*
* @param listener
* The listener to remove
*/
public void removeDragSelectionListener(ITimeGraphTimeListener listener) {
if (null != fDragSelectionListeners) {
fDragSelectionListeners.remove(listener);
}
}
/**
* Drag Selection changed callback
*
* @param start
* Time interval start
* @param end
* Time interval end
*/
public void fireDragSelectionChanged(long start, long end) {
// check for backward intervals
long beginTime;
long endTime;
if (start > end) {
beginTime = end;
endTime = start;
} else {
beginTime = start;
endTime = end;
}
// call the listeners
if (null != fDragSelectionListeners) {
Iterator<ITimeGraphTimeListener> it = fDragSelectionListeners.iterator();
while (it.hasNext()) {
ITimeGraphTimeListener listener = it.next();
listener.timeSelected(new TimeGraphTimeEvent(this, beginTime, endTime));
}
}
}
/**
* Get the traces in the model
*
* @return The array of traces
*/
public ITimeGraphEntry[] getTraces() {
return fItemData.getEntries();
}
/**
* Refresh the data for the thing
*/
public void refreshData() {
fItemData.refreshData();
redraw();
}
/**
* Refresh data for the given traces
*
* @param traces
* The traces to refresh
*/
public void refreshData(ITimeGraphEntry[] traces) {
fItemData.refreshData(traces);
redraw();
}
/**
* Refresh the links (arrows) of this widget
*
* @param events
* The link event list
*/
public void refreshArrows(List<ILinkEvent> events) {
fItemData.refreshArrows(events);
}
/**
* Get the links (arrows) of this widget
*
* @return The unmodifiable link event list
*
* @since 1.1
*/
public List<ILinkEvent> getArrows() {
return Collections.unmodifiableList(fItemData.fLinks);
}
boolean ensureVisibleItem(int idx, boolean redraw) {
boolean changed = false;
int index = idx;
if (index < 0) {
for (index = 0; index < fItemData.fExpandedItems.length; index++) {
if (fItemData.fExpandedItems[index].fSelected) {
break;
}
}
}
if (index >= fItemData.fExpandedItems.length) {
return changed;
}
if (index < fTopIndex) {
setTopIndex(index);
if (redraw) {
redraw();
}
changed = true;
} else {
int page = countPerPage();
if (index >= fTopIndex + page) {
setTopIndex(index - page + 1);
if (redraw) {
redraw();
}
changed = true;
}
}
return changed;
}
/**
* Assign the given index as the top one
*
* @param idx
* The index
*/
public void setTopIndex(int idx) {
int index = Math.min(idx, fItemData.fExpandedItems.length - countPerPage());
index = Math.max(0, index);
fTopIndex = index;
redraw();
}
/**
* Set the top index so that the requested element is at the specified
* position.
*
* @param entry
* the time graph entry to be positioned
* @param y
* the requested y-coordinate
* @since 2.0
*/
public void setElementPosition(ITimeGraphEntry entry, int y) {
Item item = fItemData.fItemMap.get(entry);
if (item == null || item.fExpandedIndex == -1) {
return;
}
int index = item.fExpandedIndex;
Rectangle itemRect = getItemRect(getClientArea(), index);
int delta = itemRect.y + itemRect.height - y;
int topIndex = getItemIndexAtY(delta);
if (topIndex != -1) {
setTopIndex(topIndex);
} else {
if (delta < 0) {
setTopIndex(0);
} else {
setTopIndex(getExpandedElementCount());
}
}
}
/**
* Sets the auto-expand level to be used for new entries discovered when
* calling {@link #refreshData()} or
* {@link #refreshData(ITimeGraphEntry[])}. The value 0 means that there is
* no auto-expand; 1 means that top-level entries are expanded, but not
* their children; 2 means that top-level entries are expanded, and their
* children, but not grand-children; and so on.
* <p>
* The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
* </p>
*
* @param level
* non-negative level, or <code>ALL_LEVELS</code> to expand all
* levels of the tree
*/
public void setAutoExpandLevel(int level) {
fAutoExpandLevel = level;
}
/**
* Returns the auto-expand level.
*
* @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
* the tree are expanded automatically
* @see #setAutoExpandLevel
*/
public int getAutoExpandLevel() {
return fAutoExpandLevel;
}
/**
* Get the expanded state of a given entry.
*
* @param entry
* The entry
* @return true if the entry is expanded, false if collapsed
* @since 1.1
*/
public boolean getExpandedState(ITimeGraphEntry entry) {
Item item = fItemData.fItemMap.get(entry);
return (item != null ? item.fExpanded : false);
}
/**
* Set the expanded state of a given entry
*
* @param entry
* The entry
* @param expanded
* True if expanded, false if collapsed
*/
public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
Item item = fItemData.findItem(entry);
if (item != null && item.fExpanded != expanded) {
item.fExpanded = expanded;
fItemData.updateExpandedItems();
redraw();
}
}
/**
* Set the expanded state of a given list of entries
*
* @param entries
* The list of entries
* @param expanded
* True if expanded, false if collapsed
* @since 3.1
*/
public void setExpandedState(Iterable<ITimeGraphEntry> entries, boolean expanded) {
for (ITimeGraphEntry entry : entries) {
Item item = fItemData.findItem(entry);
if (item != null) {
item.fExpanded = expanded;
}
}
fItemData.updateExpandedItems();
redraw();
}
/**
* Set the expanded state of a given entry to certain relative level. It
* will call fireTreeEvent() for each changed entry. At the end it will call
* redraw().
*
* @param entry
* The entry
* @param level
* level to expand to or negative for all levels
* @param expanded
* True if expanded, false if collapsed
*/
private void setExpandedState(ITimeGraphEntry entry, int level, boolean expanded) {
setExpandedStateInt(entry, level, expanded);
redraw();
}
/**
* Set the expanded state of a given entry and its children to the first
* level that has one collapsed entry.
*
* @param entry
* The entry
*/
private void setExpandedStateLevel(ITimeGraphEntry entry) {
int level = findExpandedLevel(entry);
if (level >= 0) {
setExpandedStateInt(entry, level, true);
redraw();
}
}
/*
* Inner class for finding relative level with at least one collapsed entry.
*/
private class SearchNode {
SearchNode(ITimeGraphEntry e, int l) {
entry = e;
level = l;
}
ITimeGraphEntry entry;
int level;
}
/**
* Finds the relative level with at least one collapsed entry.
*
* @param entry
* the start entry
* @return the found level or -1 if all levels are already expanded.
*/
private int findExpandedLevel(ITimeGraphEntry entry) {
Queue<SearchNode> queue = new LinkedList<>();
SearchNode root = new SearchNode(entry, 0);
queue.add(root);
while (!queue.isEmpty()) {
SearchNode node = queue.remove();
if (node.entry.hasChildren() && !getExpandedState(node.entry)) {
return node.level;
}
for (ITimeGraphEntry e : node.entry.getChildren()) {
if (e.hasChildren()) {
SearchNode n = new SearchNode(e, node.level + 1);
queue.add(n);
}
}
}
return -1;
}
/**
* Set the expanded state of a given entry to certain relative level. It
* will call fireTreeEvent() for each changed entry. No redraw is done.
*
* @param entry
* The entry
* @param level
* level to expand to or negative for all levels
* @param expanded
* True if expanded, false if collapsed
*/
private void setExpandedStateInt(ITimeGraphEntry entry, int aLevel, boolean expanded) {
int level = aLevel;
if ((level > 0) || (level < 0)) {
level--;
if (entry.hasChildren()) {
for (ITimeGraphEntry e : entry.getChildren()) {
setExpandedStateInt(e, level, expanded);
}
}
}
Item item = fItemData.findItem(entry);
if (item != null && item.fExpanded != expanded) {
item.fExpanded = expanded;
fItemData.updateExpandedItems();
fireTreeEvent(item.fEntry, item.fExpanded);
}
}
/**
* Collapses all nodes of the viewer's tree, starting with the root.
*/
public void collapseAll() {
for (Item item : fItemData.fItems) {
item.fExpanded = false;
}
fItemData.updateExpandedItems();
redraw();
}
/**
* Expands all nodes of the viewer's tree, starting with the root.
*/
public void expandAll() {
for (Item item : fItemData.fItems) {
item.fExpanded = true;
}
fItemData.updateExpandedItems();
redraw();
}
/**
* Add a tree listener
*
* @param listener
* The listener to add
*/
public void addTreeListener(ITimeGraphTreeListener listener) {
if (!fTreeListeners.contains(listener)) {
fTreeListeners.add(listener);
}
}
/**
* Remove a tree listener
*
* @param listener
* The listener to remove
*/
public void removeTreeListener(ITimeGraphTreeListener listener) {
if (fTreeListeners.contains(listener)) {
fTreeListeners.remove(listener);
}
}
/**
* Tree event callback
*
* @param entry
* The affected entry
* @param expanded
* The expanded state (true for expanded, false for collapsed)
*/
public void fireTreeEvent(ITimeGraphEntry entry, boolean expanded) {
TimeGraphTreeExpansionEvent event = new TimeGraphTreeExpansionEvent(this, entry);
for (ITimeGraphTreeListener listener : fTreeListeners) {
if (expanded) {
listener.treeExpanded(event);
} else {
listener.treeCollapsed(event);
}
}
}
/**
* Add a viewer filter listener
*
* @param listener
* The listener to add
* @since 3.2
*/
public void addViewerFilterListener(ITimeGraphViewerFilterListener listener) {