Refactor TmfRequest
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramCurrentTimeControl.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 *******************************************************************************/
14
15 package org.eclipse.linuxtools.tmf.ui.views.histogram;
16
17 import java.text.ParseException;
18
19 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
20 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
21 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
22 import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat;
23 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
24 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
25 import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
26 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
27 import org.eclipse.swt.widgets.Composite;
28
29 /**
30 * This control provides a group containing a text control.
31 *
32 * @version 1.1
33 * @author Francois Chouinard
34 */
35 public class HistogramCurrentTimeControl extends HistogramTextControl {
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
40
41 @SuppressWarnings("unused")
42 private long fTraceStartTime;
43
44 // ------------------------------------------------------------------------
45 // Construction
46 // ------------------------------------------------------------------------
47
48 /**
49 * Standard constructor
50 *
51 * @param parentView A parent histogram view
52 * @param parent A parent composite to draw in
53 * @param groupLabel A group value
54 * @param value A value
55 * @since 2.0
56 */
57 public HistogramCurrentTimeControl(HistogramView parentView, Composite parent,
58 String groupLabel, long value)
59 {
60 super(parentView, parent, groupLabel, value);
61 TmfSignalManager.register(this);
62 }
63
64 /* (non-Javadoc)
65 * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#dispose()
66 */
67 @Override
68 public void dispose() {
69 TmfSignalManager.deregister(this);
70 }
71
72 // ------------------------------------------------------------------------
73 // Operations
74 // ------------------------------------------------------------------------
75
76 @Override
77 protected void updateValue() {
78 if (getValue() == Long.MIN_VALUE) {
79 fTextValue.setText(""); //$NON-NLS-1$
80 return;
81 }
82 String string = fTextValue.getText();
83 long value = 0;
84 try {
85 value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
86 } catch (ParseException e) {
87 }
88 if (getValue() != value) {
89 // Make sure that the new time is within range
90 ITmfTrace trace = fParentView.getTrace();
91 if (trace != null) {
92 TmfTimeRange range = trace.getTimeRange();
93 long startTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
94 long endTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
95 if (value < startTime) {
96 value = startTime;
97 } else if (value > endTime) {
98 value = endTime;
99 }
100 }
101
102 // Set and propagate
103 setValue(value);
104 fParentView.updateCurrentEventTime(value);
105 }
106 }
107
108 @Override
109 public void setValue(long time) {
110 if (time != Long.MIN_VALUE) {
111 super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString());
112 } else {
113 super.setValue(time, ""); //$NON-NLS-1$
114 }
115 }
116
117 // ------------------------------------------------------------------------
118 // Signal Handlers
119 // ------------------------------------------------------------------------
120
121 /**
122 * Format the timestamp and update the display. Compute the new text size,
123 * adjust the text and group widgets and then refresh the view layout.
124 *
125 * @param signal the incoming signal
126 * @since 2.0
127 */
128 @TmfSignalHandler
129 public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) {
130 setValue(getValue());
131 }
132
133 }
This page took 0.033656 seconds and 6 git commands to generate.