Merge branch 'master' into lttng-luna
[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
FC
20import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
21import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
22import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
3bd46eef
AM
23import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
24import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
25import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
26import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat;
faa38350 27import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
c392540b
FC
28import org.eclipse.swt.widgets.Composite;
29
30/**
c392540b 31 * This control provides a group containing a text control.
6256d8ad 32 *
f8177ba2 33 * @version 1.1
b544077e 34 * @author Francois Chouinard
c392540b
FC
35 */
36public class HistogramCurrentTimeControl extends HistogramTextControl {
37
38 // ------------------------------------------------------------------------
39 // Construction
40 // ------------------------------------------------------------------------
41
b544077e 42 /**
f8177ba2 43 * Standard constructor
6256d8ad 44 *
b544077e
BH
45 * @param parentView A parent histogram view
46 * @param parent A parent composite to draw in
f8177ba2
FC
47 * @param groupLabel A group value
48 * @param value A value
49 * @since 2.0
b544077e 50 */
f8177ba2
FC
51 public HistogramCurrentTimeControl(HistogramView parentView, Composite parent,
52 String groupLabel, long value)
53 {
54 super(parentView, parent, groupLabel, value);
55 TmfSignalManager.register(this);
c392540b
FC
56 }
57
f8177ba2
FC
58 @Override
59 public void dispose() {
60 TmfSignalManager.deregister(this);
c392540b
FC
61 }
62
63 // ------------------------------------------------------------------------
64 // Operations
65 // ------------------------------------------------------------------------
66
67 @Override
68 protected void updateValue() {
da7bdcbc
PT
69 if (getValue() == Long.MIN_VALUE) {
70 fTextValue.setText(""); //$NON-NLS-1$
71 return;
72 }
f8177ba2 73 String string = fTextValue.getText();
65cdf787 74 long value = getValue();
f8177ba2 75 try {
06441eb5 76 value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
f8177ba2
FC
77 } catch (ParseException e) {
78 }
c392540b 79 if (getValue() != value) {
e0fce55b 80 // Make sure that the new time is within range
faa38350
PT
81 ITmfTrace trace = fParentView.getTrace();
82 if (trace != null) {
83 TmfTimeRange range = trace.getTimeRange();
dcb3cda5
BH
84 long startTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
85 long endTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
e0fce55b
FC
86 if (value < startTime) {
87 value = startTime;
88 } else if (value > endTime) {
89 value = endTime;
90 }
91 }
92
93 // Set and propagate
c392540b 94 setValue(value);
0fcf3b09 95 fParentView.updateSelectionTime(value, value);
65cdf787
PT
96 } else {
97 setValue(value);
c392540b
FC
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}
This page took 0.054959 seconds and 5 git commands to generate.