ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramCurrentTimeControl.java
CommitLineData
c392540b 1/*******************************************************************************
c8422608 2 * Copyright (c) 2011, 2013 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
65cdf787 13 * Patrick Tasse - Update value handling
c392540b
FC
14 *******************************************************************************/
15
e0752744 16package org.eclipse.linuxtools.tmf.ui.views.histogram;
c392540b 17
f8177ba2
FC
18import java.text.ParseException;
19
f8177ba2 20import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
f8177ba2 21import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
3bd46eef
AM
22import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
23import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
24import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
25import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat;
faa38350 26import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
c392540b
FC
27import 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 */
35public 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
720d67cb 46 * @param label A label
f8177ba2
FC
47 * @param value A value
48 * @since 2.0
b544077e 49 */
f8177ba2 50 public HistogramCurrentTimeControl(HistogramView parentView, Composite parent,
720d67cb 51 String label, long value)
f8177ba2 52 {
720d67cb 53 super(parentView, parent, label, value);
c392540b
FC
54 }
55
56 // ------------------------------------------------------------------------
57 // Operations
58 // ------------------------------------------------------------------------
59
60 @Override
61 protected void updateValue() {
da7bdcbc
PT
62 if (getValue() == Long.MIN_VALUE) {
63 fTextValue.setText(""); //$NON-NLS-1$
64 return;
65 }
f8177ba2 66 String string = fTextValue.getText();
65cdf787 67 long value = getValue();
f8177ba2 68 try {
06441eb5 69 value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
f8177ba2
FC
70 } catch (ParseException e) {
71 }
c392540b 72 if (getValue() != value) {
e0fce55b 73 // Make sure that the new time is within range
faa38350
PT
74 ITmfTrace trace = fParentView.getTrace();
75 if (trace != null) {
76 TmfTimeRange range = trace.getTimeRange();
dcb3cda5
BH
77 long startTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
78 long endTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
e0fce55b
FC
79 if (value < startTime) {
80 value = startTime;
81 } else if (value > endTime) {
82 value = endTime;
83 }
84 }
85
86 // Set and propagate
c392540b 87 setValue(value);
720d67cb 88 updateSelectionTime(value);
65cdf787
PT
89 } else {
90 setValue(value);
c392540b
FC
91 }
92 }
93
720d67cb
PT
94 /**
95 * Update the selection time
96 *
97 * @param time
98 * the new selected time
99 * @since 2.2
100 */
101 protected void updateSelectionTime(long time) {
102 fParentView.updateSelectionTime(time, time);
103 }
104
f8177ba2
FC
105 @Override
106 public void setValue(long time) {
da7bdcbc
PT
107 if (time != Long.MIN_VALUE) {
108 super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString());
109 } else {
110 super.setValue(time, ""); //$NON-NLS-1$
111 }
f8177ba2
FC
112 }
113
114 // ------------------------------------------------------------------------
115 // Signal Handlers
116 // ------------------------------------------------------------------------
117
118 /**
119 * Format the timestamp and update the display. Compute the new text size,
120 * adjust the text and group widgets and then refresh the view layout.
121 *
122 * @param signal the incoming signal
123 * @since 2.0
124 */
125 @TmfSignalHandler
126 public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) {
127 setValue(getValue());
128 }
129
c392540b 130}
This page took 0.081595 seconds and 5 git commands to generate.