Commit | Line | Data |
---|---|---|
c392540b | 1 | /******************************************************************************* |
e0752744 | 2 | * Copyright (c) 2011, 2012 Ericsson |
f8177ba2 | 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 | |
f8177ba2 | 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; | |
20 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
21 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; | |
22 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
23 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; | |
24 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; | |
c392540b FC |
25 | import org.eclipse.swt.widgets.Composite; |
26 | ||
27 | /** | |
c392540b | 28 | * This control provides a group containing a text control. |
f8177ba2 FC |
29 | * |
30 | * @version 2.0 | |
b544077e | 31 | * @author Francois Chouinard |
c392540b FC |
32 | */ |
33 | public class HistogramTimeRangeControl extends HistogramTextControl { | |
34 | ||
35 | // ------------------------------------------------------------------------ | |
36 | // Construction | |
37 | // ------------------------------------------------------------------------ | |
f8177ba2 | 38 | |
b544077e | 39 | /** |
f8177ba2 FC |
40 | * Constructor with given group and text values. |
41 | * | |
b544077e BH |
42 | * @param parentView The parent histogram view. |
43 | * @param parent The parent composite | |
f8177ba2 FC |
44 | * @param groupLabel A group value |
45 | * @param value A text value | |
46 | * @since 2.0 | |
b544077e | 47 | */ |
f8177ba2 FC |
48 | public HistogramTimeRangeControl(HistogramView parentView, Composite parent, |
49 | String groupLabel, long value) | |
50 | { | |
51 | super(parentView, parent, groupLabel, value); | |
52 | TmfSignalManager.register(this); | |
c392540b FC |
53 | } |
54 | ||
f8177ba2 FC |
55 | /* (non-Javadoc) |
56 | * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#dispose() | |
b544077e | 57 | */ |
f8177ba2 FC |
58 | @Override |
59 | public void dispose() { | |
60 | TmfSignalManager.deregister(this); | |
c392540b FC |
61 | } |
62 | ||
63 | // ------------------------------------------------------------------------ | |
64 | // Operations | |
65 | // ------------------------------------------------------------------------ | |
66 | ||
b544077e BH |
67 | /* |
68 | * (non-Javadoc) | |
69 | * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#updateValue() | |
70 | */ | |
c392540b FC |
71 | @Override |
72 | protected void updateValue() { | |
da7bdcbc PT |
73 | if (getValue() == Long.MIN_VALUE) { |
74 | fTextValue.setText(""); //$NON-NLS-1$ | |
75 | return; | |
76 | } | |
f8177ba2 FC |
77 | String string = fTextValue.getText(); |
78 | long value = getValue(); | |
79 | try { | |
80 | value = TmfTimestampFormat.getDefaulIntervalFormat().parseValue(string); | |
81 | } catch (ParseException e) { | |
c392540b | 82 | } |
f8177ba2 FC |
83 | fParentView.updateTimeRange(value); |
84 | } | |
85 | ||
86 | @Override | |
87 | public void setValue(long time) { | |
da7bdcbc PT |
88 | if (time != Long.MIN_VALUE) { |
89 | ITmfTimestamp ts = new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE); | |
90 | super.setValue(time, ts.toString(TmfTimestampFormat.getDefaulIntervalFormat())); | |
91 | } else { | |
92 | super.setValue(time, ""); //$NON-NLS-1$ | |
93 | } | |
f8177ba2 FC |
94 | } |
95 | ||
96 | // ------------------------------------------------------------------------ | |
97 | // Signal Handlers | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
100 | /** | |
101 | * Format the interval and update the display. Compute the new text size, | |
102 | * adjust the text and group widgets and then refresh the view layout. | |
103 | * | |
104 | * @param signal the incoming signal | |
105 | * @since 2.0 | |
106 | */ | |
107 | @TmfSignalHandler | |
108 | public void intervalFormatUpdated(TmfTimestampFormatUpdateSignal signal) { | |
109 | setValue(getValue()); | |
c392540b FC |
110 | } |
111 | ||
112 | } |