tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramCurrentTimeControl.java
index f995664cadf37d65199e2b2b557c85b97b731c2b..8b049675a9342ad96632faeaa132d2a283e16043 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
+ * Copyright (c) 2011, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -9,18 +9,27 @@
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
  *   Francois Chouinard - Moved from LTTng to TMF
+ *   Francois Chouinard - Simplified constructor, handle interval format change
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.views.histogram;
 
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import java.text.ParseException;
+
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.swt.widgets.Composite;
 
 /**
  * This control provides a group containing a text control.
  *
- * @version 1.0
+ * @version 1.1
  * @author Francois Chouinard
  */
 public class HistogramCurrentTimeControl extends HistogramTextControl {
@@ -30,29 +39,24 @@ public class HistogramCurrentTimeControl extends HistogramTextControl {
     // ------------------------------------------------------------------------
 
     /**
-     * Constructor with default group and text value.
+     * Standard constructor
      *
      * @param parentView A parent histogram view
      * @param parent A parent composite to draw in
-     * @param textStyle A test style
-     * @param groupStyle A group style
+     * @param groupLabel A group value
+     * @param value A value
+     * @since 2.0
      */
-    public HistogramCurrentTimeControl(HistogramView parentView, Composite parent, int textStyle, int groupStyle) {
-        this(parentView, parent, textStyle, groupStyle, "", HistogramUtils.nanosecondsToString(0L)); //$NON-NLS-1$
+    public HistogramCurrentTimeControl(HistogramView parentView, Composite parent,
+            String groupLabel, long value)
+    {
+        super(parentView, parent, groupLabel, value);
+        TmfSignalManager.register(this);
     }
 
-    /**
-     *
-     * Constructor
-     * @param parentView A parent histogram view
-     * @param parent A parent composite to draw in
-     * @param textStyle A test style
-     * @param groupStyle A group style
-     * @param groupValue A group value
-     * @param textValue A text value
-     */
-    public HistogramCurrentTimeControl(HistogramView parentView, Composite parent, int textStyle, int groupStyle, String groupValue, String textValue) {
-        super(parentView, parent, textStyle, groupStyle, groupValue, textValue);
+    @Override
+    public void dispose() {
+        TmfSignalManager.deregister(this);
     }
 
     // ------------------------------------------------------------------------
@@ -61,16 +65,23 @@ public class HistogramCurrentTimeControl extends HistogramTextControl {
 
     @Override
     protected void updateValue() {
-        String stringValue = fTextValue.getText();
-        long value = HistogramUtils.stringToNanoseconds(stringValue);
-
+        if (getValue() == Long.MIN_VALUE) {
+            fTextValue.setText(""); //$NON-NLS-1$
+            return;
+        }
+        String string = fTextValue.getText();
+        long value = 0;
+        try {
+            value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
+        } catch (ParseException e) {
+        }
         if (getValue() != value) {
             // Make sure that the new time is within range
-            TmfExperiment exp = TmfExperiment.getCurrentExperiment();
-            if (exp != null) {
-                TmfTimeRange range = exp.getTimeRange();
-                long startTime = range.getStartTime().normalize(0, -9).getValue();
-                long endTime = range.getEndTime().normalize(0, -9).getValue();
+            ITmfTrace trace = fParentView.getTrace();
+            if (trace != null) {
+                TmfTimeRange range = trace.getTimeRange();
+                long startTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+                long endTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
                 if (value < startTime) {
                     value = startTime;
                 } else if (value > endTime) {
@@ -84,4 +95,29 @@ public class HistogramCurrentTimeControl extends HistogramTextControl {
         }
     }
 
+    @Override
+    public void setValue(long time) {
+        if (time != Long.MIN_VALUE) {
+            super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString());
+        } else {
+            super.setValue(time, ""); //$NON-NLS-1$
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Signal Handlers
+    // ------------------------------------------------------------------------
+
+    /**
+     * Format the timestamp and update the display. Compute the new text size,
+     * adjust the text and group widgets and then refresh the view layout.
+     *
+     * @param signal the incoming signal
+     * @since 2.0
+     */
+    @TmfSignalHandler
+    public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) {
+        setValue(getValue());
+    }
+
 }
This page took 0.025333 seconds and 5 git commands to generate.