Merge branch 'master' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramTimeRangeControl.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson
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 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Moved from LTTng to TMF
12 * Francois Chouinard - Simplified constructor, handle interval format change
13 * Patrick Tasse - Update value handling
14 *******************************************************************************/
15
16 package org.eclipse.linuxtools.tmf.ui.views.histogram;
17
18 import java.text.ParseException;
19
20 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
21 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
22 import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
23 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
24 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
25 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat;
26 import org.eclipse.swt.widgets.Composite;
27
28 /**
29 * This control provides a group containing a text control.
30 *
31 * @version 2.0
32 * @author Francois Chouinard
33 */
34 public class HistogramTimeRangeControl extends HistogramTextControl {
35
36 // ------------------------------------------------------------------------
37 // Construction
38 // ------------------------------------------------------------------------
39
40 /**
41 * Constructor with given group and text values.
42 *
43 * @param parentView The parent histogram view.
44 * @param parent The parent composite
45 * @param groupLabel A group value
46 * @param value A text value
47 * @since 2.0
48 */
49 public HistogramTimeRangeControl(HistogramView parentView, Composite parent,
50 String groupLabel, long value)
51 {
52 super(parentView, parent, groupLabel, value);
53 TmfSignalManager.register(this);
54 }
55
56 @Override
57 public void dispose() {
58 TmfSignalManager.deregister(this);
59 }
60
61 // ------------------------------------------------------------------------
62 // Operations
63 // ------------------------------------------------------------------------
64
65 @Override
66 protected void updateValue() {
67 if (getValue() == Long.MIN_VALUE) {
68 fTextValue.setText(""); //$NON-NLS-1$
69 return;
70 }
71 String string = fTextValue.getText();
72 long value = getValue();
73 try {
74 value = TmfTimestampFormat.getDefaulIntervalFormat().parseValue(string);
75 } catch (ParseException e) {
76 }
77 if (getValue() != value) {
78 fParentView.updateTimeRange(value);
79 } else {
80 setValue(value);
81 }
82 }
83
84 @Override
85 public void setValue(long time) {
86 if (time != Long.MIN_VALUE) {
87 ITmfTimestamp ts = new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE);
88 super.setValue(time, ts.toString(TmfTimestampFormat.getDefaulIntervalFormat()));
89 } else {
90 super.setValue(time, ""); //$NON-NLS-1$
91 }
92 }
93
94 // ------------------------------------------------------------------------
95 // Signal Handlers
96 // ------------------------------------------------------------------------
97
98 /**
99 * Format the interval and update the display. Compute the new text size,
100 * adjust the text and group widgets and then refresh the view layout.
101 *
102 * @param signal the incoming signal
103 * @since 2.0
104 */
105 @TmfSignalHandler
106 public void intervalFormatUpdated(TmfTimestampFormatUpdateSignal signal) {
107 setValue(getValue());
108 }
109
110 }
This page took 0.032629 seconds and 5 git commands to generate.