Commit | Line | Data |
---|---|---|
c392540b | 1 | /******************************************************************************* |
e0752744 | 2 | * Copyright (c) 2011, 2012 Ericsson |
6256d8ad | 3 | * |
c392540b FC |
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 | |
6256d8ad | 8 | * |
c392540b FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
e0752744 | 11 | * Francois Chouinard - Moved from LTTng to TMF |
f8177ba2 | 12 | * Francois Chouinard - Simplified constructor, handle interval format change |
c392540b FC |
13 | *******************************************************************************/ |
14 | ||
e0752744 | 15 | package org.eclipse.linuxtools.tmf.ui.views.histogram; |
c392540b | 16 | |
f8177ba2 FC |
17 | import java.text.ParseException; |
18 | ||
19 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; | |
e0fce55b | 20 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
f8177ba2 FC |
21 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
22 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; | |
f8177ba2 FC |
23 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
24 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; | |
25 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; | |
faa38350 PT |
26 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; |
27 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
c392540b FC |
28 | import org.eclipse.swt.widgets.Composite; |
29 | ||
30 | /** | |
c392540b | 31 | * This control provides a group containing a text control. |
6256d8ad | 32 | * |
f8177ba2 | 33 | * @version 1.1 |
b544077e | 34 | * @author Francois Chouinard |
c392540b FC |
35 | */ |
36 | public class HistogramCurrentTimeControl extends HistogramTextControl { | |
37 | ||
f8177ba2 FC |
38 | // ------------------------------------------------------------------------ |
39 | // Attributes | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
faa38350 | 42 | private long fTraceStartTime; |
f8177ba2 | 43 | |
c392540b FC |
44 | // ------------------------------------------------------------------------ |
45 | // Construction | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
b544077e | 48 | /** |
f8177ba2 | 49 | * Standard constructor |
6256d8ad | 50 | * |
b544077e BH |
51 | * @param parentView A parent histogram view |
52 | * @param parent A parent composite to draw in | |
f8177ba2 FC |
53 | * @param groupLabel A group value |
54 | * @param value A value | |
55 | * @since 2.0 | |
b544077e | 56 | */ |
f8177ba2 FC |
57 | public HistogramCurrentTimeControl(HistogramView parentView, Composite parent, |
58 | String groupLabel, long value) | |
59 | { | |
60 | super(parentView, parent, groupLabel, value); | |
61 | TmfSignalManager.register(this); | |
c392540b FC |
62 | } |
63 | ||
f8177ba2 FC |
64 | /* (non-Javadoc) |
65 | * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#dispose() | |
b544077e | 66 | */ |
f8177ba2 FC |
67 | @Override |
68 | public void dispose() { | |
69 | TmfSignalManager.deregister(this); | |
c392540b FC |
70 | } |
71 | ||
72 | // ------------------------------------------------------------------------ | |
73 | // Operations | |
74 | // ------------------------------------------------------------------------ | |
75 | ||
76 | @Override | |
77 | protected void updateValue() { | |
f8177ba2 FC |
78 | String string = fTextValue.getText(); |
79 | long value = 0; | |
80 | try { | |
faa38350 | 81 | value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, fTraceStartTime); |
f8177ba2 FC |
82 | } catch (ParseException e) { |
83 | } | |
c392540b FC |
84 | |
85 | if (getValue() != value) { | |
e0fce55b | 86 | // Make sure that the new time is within range |
faa38350 PT |
87 | ITmfTrace trace = fParentView.getTrace(); |
88 | if (trace != null) { | |
89 | TmfTimeRange range = trace.getTimeRange(); | |
f8177ba2 FC |
90 | long startTime = range.getStartTime().getValue(); |
91 | long endTime = range.getEndTime().getValue(); | |
e0fce55b FC |
92 | if (value < startTime) { |
93 | value = startTime; | |
94 | } else if (value > endTime) { | |
95 | value = endTime; | |
96 | } | |
97 | } | |
98 | ||
99 | // Set and propagate | |
c392540b FC |
100 | setValue(value); |
101 | fParentView.updateCurrentEventTime(value); | |
102 | } | |
103 | } | |
104 | ||
f8177ba2 FC |
105 | @Override |
106 | public void setValue(long time) { | |
107 | super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString()); | |
108 | } | |
109 | ||
110 | // ------------------------------------------------------------------------ | |
111 | // Signal Handlers | |
112 | // ------------------------------------------------------------------------ | |
113 | ||
114 | /** | |
115 | * Update the initial time value | |
116 | * | |
117 | * @param signal the time range signal | |
118 | * @since 2.0 | |
119 | */ | |
120 | @TmfSignalHandler | |
faa38350 PT |
121 | public void traceUpdated(final TmfTraceUpdatedSignal signal) { |
122 | fTraceStartTime = signal.getTrace().getTimeRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
f8177ba2 FC |
123 | } |
124 | ||
125 | // ------------------------------------------------------------------------ | |
126 | // Signal Handlers | |
127 | // ------------------------------------------------------------------------ | |
128 | ||
129 | /** | |
130 | * Format the timestamp and update the display. Compute the new text size, | |
131 | * adjust the text and group widgets and then refresh the view layout. | |
132 | * | |
133 | * @param signal the incoming signal | |
134 | * @since 2.0 | |
135 | */ | |
136 | @TmfSignalHandler | |
137 | public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { | |
138 | setValue(getValue()); | |
139 | } | |
140 | ||
c392540b | 141 | } |