1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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 * Patrick Tasse - Update value handling
14 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
;
18 import java
.text
.ParseException
;
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
;
31 * This control provides a group containing a text control.
34 * @author Francois Chouinard
36 public class HistogramCurrentTimeControl
extends HistogramTextControl
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
43 * Standard constructor
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
51 public HistogramCurrentTimeControl(HistogramView parentView
, Composite parent
,
52 String groupLabel
, long value
)
54 super(parentView
, parent
, groupLabel
, value
);
55 TmfSignalManager
.register(this);
59 public void dispose() {
60 TmfSignalManager
.deregister(this);
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
68 protected void updateValue() {
69 if (getValue() == Long
.MIN_VALUE
) {
70 fTextValue
.setText(""); //$NON-NLS-1$
73 String string
= fTextValue
.getText();
74 long value
= getValue();
76 value
= TmfTimestampFormat
.getDefaulTimeFormat().parseValue(string
, getValue());
77 } catch (ParseException e
) {
79 if (getValue() != value
) {
80 // Make sure that the new time is within range
81 ITmfTrace trace
= fParentView
.getTrace();
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
) {
88 } else if (value
> endTime
) {
95 fParentView
.updateSelectionTime(value
, value
);
102 public void setValue(long time
) {
103 if (time
!= Long
.MIN_VALUE
) {
104 super.setValue(time
, new TmfTimestamp(time
, ITmfTimestamp
.NANOSECOND_SCALE
).toString());
106 super.setValue(time
, ""); //$NON-NLS-1$
110 // ------------------------------------------------------------------------
112 // ------------------------------------------------------------------------
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.
118 * @param signal the incoming signal
122 public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal
) {
123 setValue(getValue());