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