tmf: Add support for time range selection
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramCurrentTimeControl.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.TmfTimeRange;
25 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
26 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat;
27 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
28 import org.eclipse.swt.widgets.Composite;
29
30 /**
31 * This control provides a group containing a text control.
32 *
33 * @version 1.1
34 * @author Francois Chouinard
35 */
36 public class HistogramCurrentTimeControl extends HistogramTextControl {
37
38 // ------------------------------------------------------------------------
39 // Construction
40 // ------------------------------------------------------------------------
41
42 /**
43 * Standard constructor
44 *
45 * @param parentView A parent histogram view
46 * @param parent A parent composite to draw in
47 * @param groupLabel A group value
48 * @param value A value
49 * @since 2.0
50 */
51 public HistogramCurrentTimeControl(HistogramView parentView, Composite parent,
52 String groupLabel, long value)
53 {
54 super(parentView, parent, groupLabel, value);
55 TmfSignalManager.register(this);
56 }
57
58 @Override
59 public void dispose() {
60 TmfSignalManager.deregister(this);
61 }
62
63 // ------------------------------------------------------------------------
64 // Operations
65 // ------------------------------------------------------------------------
66
67 @Override
68 protected void updateValue() {
69 if (getValue() == Long.MIN_VALUE) {
70 fTextValue.setText(""); //$NON-NLS-1$
71 return;
72 }
73 String string = fTextValue.getText();
74 long value = getValue();
75 try {
76 value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
77 } catch (ParseException e) {
78 }
79 if (getValue() != value) {
80 // Make sure that the new time is within range
81 ITmfTrace trace = fParentView.getTrace();
82 if (trace != null) {
83 TmfTimeRange range = trace.getTimeRange();
84 long startTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
85 long endTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
86 if (value < startTime) {
87 value = startTime;
88 } else if (value > endTime) {
89 value = endTime;
90 }
91 }
92
93 // Set and propagate
94 setValue(value);
95 fParentView.updateSelectionTime(value, value);
96 } else {
97 setValue(value);
98 }
99 }
100
101 @Override
102 public void setValue(long time) {
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 }
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
126 }
This page took 0.035341 seconds and 5 git commands to generate.