TMF: Consolidate some view code into the AbstractTimeGraphView
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / model / TimeEvent.java
index 6cd1c0a699d8ea539e765a3f0cf814c1e517756a..8b1db841cef6c2c84f4c12095b812164f4a2994a 100644 (file)
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Patrick Tasse - Initial API and implementation
+ *   Geneviève Bastien - Added the fValue parameter to avoid subclassing
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
@@ -29,6 +30,13 @@ public class TimeEvent implements ITimeEvent {
     /** Duration of this time event */
     protected long fDuration;
 
+    private final int fValue;
+
+    /**
+     * Default value when no other value present
+     */
+    private static final int NOVALUE = Integer.MIN_VALUE;
+
     /**
      * Standard constructor
      *
@@ -40,9 +48,49 @@ public class TimeEvent implements ITimeEvent {
      *            The duration of the event
      */
     public TimeEvent(ITimeGraphEntry entry, long time, long duration) {
+        this(entry, time, duration, NOVALUE);
+
+    }
+
+    /**
+     * Constructor
+     *
+     * @param entry
+     *            The entry to which this time event is assigned
+     * @param time
+     *            The timestamp of this event
+     * @param duration
+     *            The duration of this event
+     * @param value
+     *            The status assigned to the event
+     * @since 2.1
+     */
+    public TimeEvent(ITimeGraphEntry entry, long time, long duration,
+            int value) {
         fEntry = entry;
         fTime = time;
         fDuration = duration;
+        fValue = value;
+    }
+
+    /**
+     * Get this event's status
+     *
+     * @return The integer matching this status
+     * @since 2.1
+     */
+    public int getValue() {
+        return fValue;
+    }
+
+    /**
+     * Return whether an event has a value
+     *
+     * @return true if the event has a value
+     * @since 2.1
+     */
+    public boolean hasValue() {
+        return (fValue != NOVALUE);
     }
 
     @Override
@@ -62,6 +110,6 @@ public class TimeEvent implements ITimeEvent {
 
     @Override
     public String toString() {
-        return "TimeEvent start=" + fTime + " end=" + (fTime + fDuration) + " duration=" + fDuration; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        return "TimeEvent start=" + fTime + " end=" + (fTime + fDuration) + " duration=" + fDuration + " value=" + (hasValue() ? fValue : "N/A"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
     }
 }
This page took 0.035951 seconds and 5 git commands to generate.