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 | ||
f8177ba2 FC |
19 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
20 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; | |
21 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; | |
3bd46eef AM |
22 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
23 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
24 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
25 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat; | |
faa38350 | 26 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
c392540b FC |
27 | import org.eclipse.swt.widgets.Composite; |
28 | ||
29 | /** | |
c392540b | 30 | * This control provides a group containing a text control. |
6256d8ad | 31 | * |
f8177ba2 | 32 | * @version 1.1 |
b544077e | 33 | * @author Francois Chouinard |
c392540b FC |
34 | */ |
35 | public class HistogramCurrentTimeControl extends HistogramTextControl { | |
36 | ||
37 | // ------------------------------------------------------------------------ | |
38 | // Construction | |
39 | // ------------------------------------------------------------------------ | |
40 | ||
b544077e | 41 | /** |
f8177ba2 | 42 | * Standard constructor |
6256d8ad | 43 | * |
b544077e BH |
44 | * @param parentView A parent histogram view |
45 | * @param parent A parent composite to draw in | |
f8177ba2 FC |
46 | * @param groupLabel A group value |
47 | * @param value A value | |
48 | * @since 2.0 | |
b544077e | 49 | */ |
f8177ba2 FC |
50 | public HistogramCurrentTimeControl(HistogramView parentView, Composite parent, |
51 | String groupLabel, long value) | |
52 | { | |
53 | super(parentView, parent, groupLabel, value); | |
54 | TmfSignalManager.register(this); | |
c392540b FC |
55 | } |
56 | ||
f8177ba2 FC |
57 | /* (non-Javadoc) |
58 | * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#dispose() | |
b544077e | 59 | */ |
f8177ba2 FC |
60 | @Override |
61 | public void dispose() { | |
62 | TmfSignalManager.deregister(this); | |
c392540b FC |
63 | } |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // Operations | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | @Override | |
70 | protected void updateValue() { | |
da7bdcbc PT |
71 | if (getValue() == Long.MIN_VALUE) { |
72 | fTextValue.setText(""); //$NON-NLS-1$ | |
73 | return; | |
74 | } | |
f8177ba2 FC |
75 | String string = fTextValue.getText(); |
76 | long value = 0; | |
77 | try { | |
06441eb5 | 78 | value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue()); |
f8177ba2 FC |
79 | } catch (ParseException e) { |
80 | } | |
c392540b | 81 | if (getValue() != value) { |
e0fce55b | 82 | // Make sure that the new time is within range |
faa38350 PT |
83 | ITmfTrace trace = fParentView.getTrace(); |
84 | if (trace != null) { | |
85 | TmfTimeRange range = trace.getTimeRange(); | |
dcb3cda5 BH |
86 | long startTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
87 | long endTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
e0fce55b FC |
88 | if (value < startTime) { |
89 | value = startTime; | |
90 | } else if (value > endTime) { | |
91 | value = endTime; | |
92 | } | |
93 | } | |
94 | ||
95 | // Set and propagate | |
c392540b FC |
96 | setValue(value); |
97 | fParentView.updateCurrentEventTime(value); | |
98 | } | |
99 | } | |
100 | ||
f8177ba2 FC |
101 | @Override |
102 | public void setValue(long time) { | |
da7bdcbc PT |
103 | if (time != Long.MIN_VALUE) { |
104 | super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString()); | |
105 | } else { | |
106 | super.setValue(time, ""); //$NON-NLS-1$ | |
107 | } | |
f8177ba2 FC |
108 | } |
109 | ||
110 | // ------------------------------------------------------------------------ | |
111 | // Signal Handlers | |
112 | // ------------------------------------------------------------------------ | |
113 | ||
114 | /** | |
115 | * Format the timestamp and update the display. Compute the new text size, | |
116 | * adjust the text and group widgets and then refresh the view layout. | |
117 | * | |
118 | * @param signal the incoming signal | |
119 | * @since 2.0 | |
120 | */ | |
121 | @TmfSignalHandler | |
122 | public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { | |
123 | setValue(getValue()); | |
124 | } | |
125 | ||
c392540b | 126 | } |