TMF: Consolidate some view code into the AbstractTimeGraphView
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesEntry.java
index 5b12b8661c0077fcc1ff0c1a5984d9e794821278..34d43c4185c81234394814e2ad54f6355ad0e1c0 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
+ * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,25 +8,20 @@
  *
  * Contributors:
  *   Patrick Tasse - Initial API and implementation
+ *   Geneviève Bastien - Move code to provide base classes for time graph view
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 import org.eclipse.linuxtools.lttng2.kernel.core.trace.LttngKernelTrace;
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.EventIterator;
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
 
 /**
  * An entry, or row, in the resource view
  *
  * @author Patrick Tasse
  */
-public class ResourcesEntry implements ITimeGraphEntry {
+public class ResourcesEntry extends TimeGraphEntry {
 
     /** Type of resource */
     public static enum Type {
@@ -37,113 +32,88 @@ public class ResourcesEntry implements ITimeGraphEntry {
         /** Entries for IRQs */
         IRQ,
         /** Entries for Soft IRQ */
-        SOFT_IRQ }
+        SOFT_IRQ
+    }
 
-    private final int fQuark;
-    private final LttngKernelTrace fTrace;
-    private ITimeGraphEntry fParent = null;
-    private final List<ITimeGraphEntry> children = null;
-    private final String fName;
-    private final Type fType;
     private final int fId;
-    private long fStartTime;
-    private long fEndTime;
-    private List<ITimeEvent> fEventList = new ArrayList<ITimeEvent>();
-    private List<ITimeEvent> fZoomedEventList = null;
+    private final Type fType;
+    private final int fQuark;
 
     /**
-     * Standard constructor
+     * Constructor
      *
      * @param quark
-     *            The quark of the state system attribute whose state is shown
-     *            on this row
+     *            The attribute quark matching the entry
      * @param trace
-     *            The trace that this view is talking about
+     *            The trace on which we are working
+     * @param name
+     *            The exec_name of this entry
+     * @param startTime
+     *            The start time of this entry lifetime
+     * @param endTime
+     *            The end time of this entry
      * @param type
-     *            Type of entry, see the Type enum
+     *            The type of this entry
      * @param id
-     *            The integer id associated with this entry or row
+     *            The id of this entry
      */
-    public ResourcesEntry(int quark, LttngKernelTrace trace, Type type, int id) {
-        fQuark = quark;
-        fTrace = trace;
-        fType = type;
+    public ResourcesEntry(int quark, LttngKernelTrace trace, String name, long startTime, long endTime, Type type, int id) {
+        super(quark, trace, name, startTime, endTime);
         fId = id;
-        fName = type.toString() + ' ' + Integer.toString(id);
-    }
-
-    @Override
-    public ITimeGraphEntry getParent() {
-        return fParent;
-    }
-
-    @Override
-    public boolean hasChildren() {
-        return children != null && children.size() > 0;
-    }
-
-    @Override
-    public List<ITimeGraphEntry> getChildren() {
-        return children;
-    }
-
-    @Override
-    public String getName() {
-        return fName;
-    }
-
-    @Override
-    public long getStartTime() {
-        return fStartTime;
-    }
-
-    @Override
-    public long getEndTime() {
-        return fEndTime;
-    }
-
-    @Override
-    public boolean hasTimeEvents() {
-        return true;
-    }
-
-    @Override
-    public Iterator<ITimeEvent> getTimeEventsIterator() {
-        return new EventIterator(fEventList, fZoomedEventList);
-    }
-
-    @Override
-    public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
-        return new EventIterator(fEventList, fZoomedEventList, startTime, stopTime);
+        fType = type;
+        fQuark = quark;
     }
 
     /**
-     * Assign a parent entry to this one, to organize them in a tree in the
-     * view.
+     * Constructor
      *
-     * @param parent
-     *            The parent entry
+     * @param trace
+     *            The trace on which we are working
+     * @param name
+     *            The exec_name of this entry
+     * @param startTime
+     *            The start time of this entry lifetime
+     * @param endTime
+     *            The end time of this entry
+     * @param id
+     *            The id of this entry
      */
-    public void setParent(ITimeGraphEntry parent) {
-        fParent = parent;
+    public ResourcesEntry(LttngKernelTrace trace, String name, long startTime, long endTime, int id) {
+        this(-1, trace, name, startTime, endTime, Type.NULL, id);
     }
 
     /**
-     * Retrieve the attribute quark that's represented by this entry.
+     * Constructor
      *
-     * @return The integer quark
+     * @param quark
+     *            The attribute quark matching the entry
+     * @param trace
+     *            The trace on which we are working
+     * @param startTime
+     *            The start time of this entry lifetime
+     * @param endTime
+     *            The end time of this entry
+     * @param type
+     *            The type of this entry
+     * @param id
+     *            The id of this entry
      */
-    public int getQuark() {
-        return fQuark;
+    public ResourcesEntry(int quark, LttngKernelTrace trace, long startTime, long endTime, Type type, int id) {
+        this(quark, trace, type.toString() + " " + id, startTime, endTime, type, id); //$NON-NLS-1$
     }
 
     /**
-     * Retrieve the trace that is associated to this Resource view.
+     * Get the entry's id
      *
-     * @return The LTTng 2 kernel trace
+     * @return the entry's id
      */
+    public int getId() {
+        return fId;
+    }
+
+    @Override
     public LttngKernelTrace getTrace() {
-        return fTrace;
+        return (LttngKernelTrace) super.getTrace();
     }
 
     /**
@@ -156,36 +126,43 @@ public class ResourcesEntry implements ITimeGraphEntry {
     }
 
     /**
-     * Get the integer ID associated with this entry.
+     * Retrieve the attribute quark that's represented by this entry.
      *
-     * @return The ID
+     * @return The integer quark The attribute quark matching the entry
      */
-    public int getId() {
-        return fId;
+    public int getQuark() {
+        return fQuark;
     }
 
-    /**
-     * Assign the target event list to this view.
-     *
-     * @param eventList
-     *            The list of time events
-     */
-    public void setEventList(List<ITimeEvent> eventList) {
-        fEventList = eventList;
-        if (eventList != null && eventList.size() > 0) {
-            fStartTime = eventList.get(0).getTime();
-            ITimeEvent lastEvent = eventList.get(eventList.size() - 1);
-            fEndTime = lastEvent.getTime() + lastEvent.getDuration();
+    @Override
+    public boolean hasTimeEvents() {
+        if (fType == Type.NULL) {
+            return false;
         }
+        return true;
     }
 
     /**
-     * Assign the zoomed event list to this view.
+     * Add a child to this entry of type ResourcesEntry
      *
-     * @param eventList
-     *            The list of "zoomed" time events
+     * @param entry
+     *            The entry to add
      */
-    public void setZoomedEventList(List<ITimeEvent> eventList) {
-        fZoomedEventList = eventList;
+    public void addChild(ResourcesEntry entry) {
+        int index;
+        for (index = 0; index < getChildren().size(); index++) {
+            ResourcesEntry other = (ResourcesEntry) getChildren().get(index);
+            if (entry.getType().compareTo(other.getType()) < 0) {
+                break;
+            } else if (entry.getType().equals(other.getType())) {
+                if (entry.getId() < other.getId()) {
+                    break;
+                }
+            }
+        }
+
+        entry.setParent(this);
+        getChildren().add(index, entry);
     }
+
 }
This page took 0.0292 seconds and 5 git commands to generate.