[WIP] CFV Refactor
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / provisional / tmf / ui / views / timegraph2 / TimeGraphModelViewer.java
1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
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
10 package org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2;
11
12 import org.eclipse.tracecompass.internal.provisional.tmf.core.views.timegraph2.ITimeGraphModelRenderProvider;
13 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
14
15 public abstract class TimeGraphModelViewer {
16
17 private static final long UNINITIALIZED = -1;
18
19 private final ITimeGraphModelRenderProvider fModelRenderProvider;
20 private final SignallingContext fSignallingContext;
21
22 private long fFullTimeGraphStartTime = 1;
23 private long fFullTimeGraphEndTime = 1;
24
25 private long fLatestVisibleRangeStartTime = UNINITIALIZED;
26 private long fLatestVisibleRangeEndTime = UNINITIALIZED;
27
28 protected TimeGraphModelViewer(ITimeGraphModelRenderProvider modelRenderProvider) {
29 fModelRenderProvider = modelRenderProvider;
30 fSignallingContext = new SignallingContext(this);
31 }
32
33 public void dispose() {
34 fSignallingContext.dispose();
35 }
36
37 // ------------------------------------------------------------------------
38 // Accessors
39 // ------------------------------------------------------------------------
40
41 public ITimeGraphModelRenderProvider getModelRenderProvider() {
42 return fModelRenderProvider;
43 }
44
45 protected SignallingContext getSignalingContext() {
46 return fSignallingContext;
47 }
48
49 protected long getFullTimeGraphStartTime() {
50 return fFullTimeGraphStartTime;
51 }
52
53 protected long getFullTimeGraphEndTime() {
54 return fFullTimeGraphEndTime;
55 }
56
57 // ------------------------------------------------------------------------
58 // Operations
59 // ------------------------------------------------------------------------
60
61 public final void repaintCurrentArea() {
62 ITmfTrace trace = fSignallingContext.getCurrentTrace();
63 long start = fLatestVisibleRangeStartTime;
64 long end = fLatestVisibleRangeEndTime;
65 if (trace == null || start == UNINITIALIZED || end == UNINITIALIZED) {
66 return;
67 }
68 paintArea(trace, fLatestVisibleRangeStartTime, fLatestVisibleRangeEndTime);
69 }
70
71 public final void seekVisibleRange(long visibleWindowStartTime, long visibleWindowEndTime) {
72 checkWindowTimeRange(visibleWindowStartTime, visibleWindowEndTime);
73
74 seekVisibleRangeImpl(visibleWindowStartTime, visibleWindowEndTime);
75 updateLatestVisibleRange(visibleWindowStartTime, visibleWindowEndTime);
76 }
77
78 protected final void paintArea(ITmfTrace trace, long windowStartTime, long windowEndTime) {
79 checkWindowTimeRange(windowStartTime, windowEndTime);
80
81 paintAreaImpl(trace, windowStartTime, windowEndTime);
82 }
83
84 protected final void drawSelection(long selectionStartTime, long selectionEndTime) {
85 checkWindowTimeRange(selectionStartTime, selectionEndTime);
86
87 drawSelectionImpl(selectionStartTime, selectionEndTime);
88 }
89
90 void updateLatestVisibleRange(long visibleWindowStartTime, long visibleWindowEndTime) {
91 fLatestVisibleRangeStartTime = visibleWindowStartTime;
92 fLatestVisibleRangeEndTime = visibleWindowEndTime;
93 }
94
95 /**
96 * Recompute the total virtual size of the time graph area, and assigns the
97 * given timestamps as the start and end positions.
98 *
99 * All subsquent operations (seek, paint, etc.) that use timestamp expect
100 * these timestamps to be within the range passed here!
101 *
102 * Should be called when the trace changes, or the trace's total time range
103 * is updated (while indexing, or in live cases).
104 */
105 protected void setTimeGraphAreaRange(long fullAreaStartTime, long fullAreaEndTime) {
106 checkTimeRange(fullAreaStartTime, fullAreaEndTime);
107
108 if (fFullTimeGraphStartTime == fullAreaStartTime &&
109 fFullTimeGraphEndTime == fullAreaEndTime) {
110 /* No need to update */
111 return;
112 }
113
114 fFullTimeGraphStartTime = fullAreaStartTime;
115 fFullTimeGraphEndTime = fullAreaEndTime;
116 }
117
118 // ------------------------------------------------------------------------
119 // Template methods
120 // ------------------------------------------------------------------------
121
122 /**
123 * This should be called whenever the visible window moves, including zoom
124 * level changes.
125 */
126 protected abstract void seekVisibleRangeImpl(long visibleWindowStartTime, long visibleWindowEndTime);
127
128 /**
129 * Paint an area of the viewer. This will also update the tree pane
130 * accordingly.
131 *
132 * It is encouraged to actually paint a bit more of the area on both sides,
133 * so that small scrolling and resizing operations do not require fetching
134 * new data to display the area.
135 */
136 protected abstract void paintAreaImpl(ITmfTrace trace, long windowStartTime, long windowEndTime);
137
138 /**
139 * Draw a new selection rectangle. The previous one, if any, will be
140 * removed.
141 */
142 protected abstract void drawSelectionImpl(long selectionStartTime, long selectionEndTime);
143
144 // ------------------------------------------------------------------------
145 // Operations
146 // ------------------------------------------------------------------------
147
148 private static void checkTimeRange(long rangeStart, long rangeEnd) {
149 if (rangeStart > rangeEnd) {
150 throw new IllegalArgumentException("Time range start " + rangeStart + "is after its end time " + rangeEnd); //$NON-NLS-1$ //$NON-NLS-2$
151 }
152 if (rangeStart < 0 || rangeEnd < 0) {
153 throw new IllegalArgumentException("One of the time range bounds is negative"); //$NON-NLS-1$
154 }
155 if (rangeStart == Long.MAX_VALUE) {
156 throw new IllegalArgumentException("You are trying to make me believe the range starts at " + //$NON-NLS-1$
157 rangeStart + ". I do not believe you."); //$NON-NLS-1$
158 }
159 if (rangeEnd == Long.MAX_VALUE) {
160 throw new IllegalArgumentException("You are trying to make me believe the range ends at " + //$NON-NLS-1$
161 rangeEnd + ". I do not believe you."); //$NON-NLS-1$
162 }
163 }
164
165 private void checkWindowTimeRange(long windowStartTime, long windowEndTime) {
166 checkTimeRange(windowStartTime, windowEndTime);
167
168 if (windowStartTime < fFullTimeGraphStartTime) {
169 throw new IllegalArgumentException("Requested window start time: " + windowStartTime +
170 " is smaller than trace start time " + fFullTimeGraphStartTime);
171 }
172 if (windowEndTime > fFullTimeGraphEndTime) {
173 throw new IllegalArgumentException("Requested window end time: " + windowEndTime +
174 " is greater than trace end time " + fFullTimeGraphEndTime);
175 }
176 }
177
178 }
This page took 0.036238 seconds and 5 git commands to generate.