Commit | Line | Data |
---|---|---|
c392540b | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2011, 2013 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 |
65cdf787 | 13 | * Patrick Tasse - Update value handling |
c392540b FC |
14 | *******************************************************************************/ |
15 | ||
e0752744 | 16 | package org.eclipse.linuxtools.tmf.ui.views.histogram; |
c392540b | 17 | |
f8177ba2 FC |
18 | import java.text.ParseException; |
19 | ||
f8177ba2 | 20 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
f8177ba2 | 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.TmfTimestamp; | |
24 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat; | |
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); | |
c392540b FC |
52 | } |
53 | ||
54 | // ------------------------------------------------------------------------ | |
55 | // Operations | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
58 | @Override | |
59 | protected void updateValue() { | |
da7bdcbc PT |
60 | if (getValue() == Long.MIN_VALUE) { |
61 | fTextValue.setText(""); //$NON-NLS-1$ | |
62 | return; | |
63 | } | |
f8177ba2 FC |
64 | String string = fTextValue.getText(); |
65 | long value = getValue(); | |
66 | try { | |
67 | value = TmfTimestampFormat.getDefaulIntervalFormat().parseValue(string); | |
720d67cb PT |
68 | if (value < 1) { |
69 | value = getValue(); | |
70 | } | |
f8177ba2 | 71 | } catch (ParseException e) { |
c392540b | 72 | } |
65cdf787 PT |
73 | if (getValue() != value) { |
74 | fParentView.updateTimeRange(value); | |
75 | } else { | |
76 | setValue(value); | |
77 | } | |
f8177ba2 FC |
78 | } |
79 | ||
80 | @Override | |
81 | public void setValue(long time) { | |
da7bdcbc PT |
82 | if (time != Long.MIN_VALUE) { |
83 | ITmfTimestamp ts = new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE); | |
84 | super.setValue(time, ts.toString(TmfTimestampFormat.getDefaulIntervalFormat())); | |
85 | } else { | |
86 | super.setValue(time, ""); //$NON-NLS-1$ | |
87 | } | |
f8177ba2 FC |
88 | } |
89 | ||
90 | // ------------------------------------------------------------------------ | |
91 | // Signal Handlers | |
92 | // ------------------------------------------------------------------------ | |
93 | ||
94 | /** | |
95 | * Format the interval and update the display. Compute the new text size, | |
96 | * adjust the text and group widgets and then refresh the view layout. | |
97 | * | |
98 | * @param signal the incoming signal | |
99 | * @since 2.0 | |
100 | */ | |
101 | @TmfSignalHandler | |
102 | public void intervalFormatUpdated(TmfTimestampFormatUpdateSignal signal) { | |
103 | setValue(getValue()); | |
c392540b FC |
104 | } |
105 | ||
106 | } |