Commit | Line | Data |
---|---|---|
c392540b | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2011, 2014 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 | ||
2bdf0193 | 16 | package org.eclipse.tracecompass.tmf.ui.views.histogram; |
c392540b | 17 | |
f8177ba2 FC |
18 | import java.text.ParseException; |
19 | ||
c392540b | 20 | import org.eclipse.swt.widgets.Composite; |
2bdf0193 AM |
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; | |
c392540b FC |
28 | |
29 | /** | |
c392540b | 30 | * This control provides a group containing a text control. |
6256d8ad | 31 | * |
b544077e | 32 | * @author Francois Chouinard |
c392540b FC |
33 | */ |
34 | public class HistogramCurrentTimeControl extends HistogramTextControl { | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Construction | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
b544077e | 40 | /** |
f8177ba2 | 41 | * Standard constructor |
6256d8ad | 42 | * |
b544077e BH |
43 | * @param parentView A parent histogram view |
44 | * @param parent A parent composite to draw in | |
720d67cb | 45 | * @param label A label |
f8177ba2 | 46 | * @param value A value |
b544077e | 47 | */ |
f8177ba2 | 48 | public HistogramCurrentTimeControl(HistogramView parentView, Composite parent, |
720d67cb | 49 | String label, long value) |
f8177ba2 | 50 | { |
720d67cb | 51 | super(parentView, parent, label, value); |
c392540b FC |
52 | } |
53 | ||
54 | // ------------------------------------------------------------------------ | |
55 | // Operations | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
58 | @Override | |
59 | protected void updateValue() { | |
da7bdcbc PT |
60 | if (getValue() == Long.MIN_VALUE) { |
61 | fTextValue.setText(""); //$NON-NLS-1$ | |
62 | return; | |
63 | } | |
f8177ba2 | 64 | String string = fTextValue.getText(); |
65cdf787 | 65 | long value = getValue(); |
f8177ba2 | 66 | try { |
06441eb5 | 67 | value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue()); |
f8177ba2 FC |
68 | } catch (ParseException e) { |
69 | } | |
c392540b | 70 | if (getValue() != value) { |
e0fce55b | 71 | // Make sure that the new time is within range |
faa38350 PT |
72 | ITmfTrace trace = fParentView.getTrace(); |
73 | if (trace != null) { | |
74 | TmfTimeRange range = trace.getTimeRange(); | |
dcb3cda5 BH |
75 | long startTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
76 | long endTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
e0fce55b FC |
77 | if (value < startTime) { |
78 | value = startTime; | |
79 | } else if (value > endTime) { | |
80 | value = endTime; | |
81 | } | |
82 | } | |
83 | ||
84 | // Set and propagate | |
c392540b | 85 | setValue(value); |
720d67cb | 86 | updateSelectionTime(value); |
65cdf787 PT |
87 | } else { |
88 | setValue(value); | |
c392540b FC |
89 | } |
90 | } | |
91 | ||
720d67cb PT |
92 | /** |
93 | * Update the selection time | |
94 | * | |
95 | * @param time | |
96 | * the new selected time | |
720d67cb PT |
97 | */ |
98 | protected void updateSelectionTime(long time) { | |
99 | fParentView.updateSelectionTime(time, time); | |
100 | } | |
101 | ||
f8177ba2 FC |
102 | @Override |
103 | public void setValue(long time) { | |
da7bdcbc PT |
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 | } | |
f8177ba2 FC |
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 | |
f8177ba2 FC |
120 | */ |
121 | @TmfSignalHandler | |
122 | public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { | |
123 | setValue(getValue()); | |
124 | } | |
125 | ||
c392540b | 126 | } |