1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
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
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 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
;
17 import java
.text
.ParseException
;
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
.TmfExperimentUpdatedSignal
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalManager
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
31 * This control provides a group containing a text control.
34 * @author Francois Chouinard
36 public class HistogramCurrentTimeControl
extends HistogramTextControl
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 private long fExperimentStartTime
;
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
49 * Standard constructor
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
57 public HistogramCurrentTimeControl(HistogramView parentView
, Composite parent
,
58 String groupLabel
, long value
)
60 super(parentView
, parent
, groupLabel
, value
);
61 TmfSignalManager
.register(this);
65 * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#dispose()
68 public void dispose() {
69 TmfSignalManager
.deregister(this);
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 protected void updateValue() {
78 String string
= fTextValue
.getText();
81 value
= TmfTimestampFormat
.getDefaulTimeFormat().parseValue(string
, fExperimentStartTime
);
82 } catch (ParseException e
) {
85 if (getValue() != value
) {
86 // Make sure that the new time is within range
87 TmfExperiment exp
= TmfExperiment
.getCurrentExperiment();
89 TmfTimeRange range
= exp
.getTimeRange();
90 long startTime
= range
.getStartTime().getValue();
91 long endTime
= range
.getEndTime().getValue();
92 if (value
< startTime
) {
94 } else if (value
> endTime
) {
101 fParentView
.updateCurrentEventTime(value
);
106 public void setValue(long time
) {
107 super.setValue(time
, new TmfTimestamp(time
, ITmfTimestamp
.NANOSECOND_SCALE
).toString());
110 // ------------------------------------------------------------------------
112 // ------------------------------------------------------------------------
115 * Update the initial time value
117 * @param signal the time range signal
121 public void experimentRangeUpdated(final TmfExperimentUpdatedSignal signal
) {
122 fExperimentStartTime
= signal
.getExperiment().getTimeRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
130 * Format the timestamp and update the display. Compute the new text size,
131 * adjust the text and group widgets and then refresh the view layout.
133 * @param signal the incoming signal
137 public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal
) {
138 setValue(getValue());