ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramCurrentTimeControl.java
index f43d968a8d182df40074be56bffaf95661901029..e94254484e1c4b1394971e27ccbac4f7ccc3bf9a 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
  *   Francois Chouinard - Initial API and implementation
  *   Francois Chouinard - Moved from LTTng to TMF
  *   Francois Chouinard - Simplified constructor, handle interval format change
+ *   Patrick Tasse - Update value handling
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.views.histogram;
 
 import java.text.ParseException;
 
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat;
 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.signal.TmfTraceUpdatedSignal;
+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;
 
@@ -35,12 +34,6 @@ import org.eclipse.swt.widgets.Composite;
  */
 public class HistogramCurrentTimeControl extends HistogramTextControl {
 
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private long fTraceStartTime;
-
     // ------------------------------------------------------------------------
     // Construction
     // ------------------------------------------------------------------------
@@ -50,23 +43,14 @@ public class HistogramCurrentTimeControl extends HistogramTextControl {
      *
      * @param parentView A parent histogram view
      * @param parent A parent composite to draw in
-     * @param groupLabel A group value
+     * @param label A label
      * @param value A value
      * @since 2.0
      */
     public HistogramCurrentTimeControl(HistogramView parentView, Composite parent,
-            String groupLabel, long value)
+            String label, long value)
     {
-        super(parentView, parent, groupLabel, value);
-        TmfSignalManager.register(this);
-    }
-
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramTextControl#dispose()
-     */
-    @Override
-    public void dispose() {
-        TmfSignalManager.deregister(this);
+        super(parentView, parent, label, value);
     }
 
     // ------------------------------------------------------------------------
@@ -75,20 +59,23 @@ public class HistogramCurrentTimeControl extends HistogramTextControl {
 
     @Override
     protected void updateValue() {
+        if (getValue() == Long.MIN_VALUE) {
+            fTextValue.setText(""); //$NON-NLS-1$
+            return;
+        }
         String string = fTextValue.getText();
-        long value = 0;
+        long value = getValue();
         try {
-            value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, fTraceStartTime);
+            value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
         } catch (ParseException e) {
         }
-
         if (getValue() != value) {
             // Make sure that the new time is within range
             ITmfTrace trace = fParentView.getTrace();
             if (trace != null) {
                 TmfTimeRange range = trace.getTimeRange();
-                long startTime = range.getStartTime().getValue();
-                long endTime = range.getEndTime().getValue();
+                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) {
@@ -98,28 +85,30 @@ public class HistogramCurrentTimeControl extends HistogramTextControl {
 
             // Set and propagate
             setValue(value);
-            fParentView.updateCurrentEventTime(value);
+            updateSelectionTime(value);
+        } else {
+            setValue(value);
         }
     }
 
-    @Override
-    public void setValue(long time) {
-        super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString());
-    }
-
-    // ------------------------------------------------------------------------
-    // Signal Handlers
-    // ------------------------------------------------------------------------
-
     /**
-     * Update the initial time value
+     * Update the selection time
      *
-     * @param signal the time range signal
-     * @since 2.0
+     * @param time
+     *            the new selected time
+     * @since 2.2
      */
-    @TmfSignalHandler
-    public void traceUpdated(final TmfTraceUpdatedSignal signal) {
-        fTraceStartTime = signal.getTrace().getTimeRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+    protected void updateSelectionTime(long time) {
+        fParentView.updateSelectionTime(time, time);
+    }
+
+    @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$
+        }
     }
 
     // ------------------------------------------------------------------------
This page took 0.044551 seconds and 5 git commands to generate.