lttng: Support live updating of Control Flow view and Resources view
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / model / TimeGraphEntry.java
index 995828634dabf228d147f45e7395c7525cd5eab8..2b4b583ab95206b886c03d86c281e519df42ca31 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2012, 2014 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
@@ -16,6 +16,7 @@ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * An entry for use in the time graph views
@@ -28,7 +29,7 @@ public class TimeGraphEntry implements ITimeGraphEntry {
     private TimeGraphEntry fParent = null;
 
     /** List of child entries */
-    private final List<TimeGraphEntry> fChildren = new ArrayList<>();
+    private final List<TimeGraphEntry> fChildren = new CopyOnWriteArrayList<>();
 
     /** Name of this entry (text to show) */
     private String fName;
@@ -106,6 +107,18 @@ public class TimeGraphEntry implements ITimeGraphEntry {
         return fEndTime;
     }
 
+    /**
+     * Updates the end time
+     *
+     * @param endTime
+     *            the end time
+     *
+     * @since 3.0
+     */
+    public void updateEndTime(long endTime) {
+        fEndTime = Math.max(endTime, fEndTime);
+    }
+
     @Override
     public boolean hasTimeEvents() {
         return true;
@@ -129,16 +142,22 @@ public class TimeGraphEntry implements ITimeGraphEntry {
 
     /**
      * Add an event to this entry's event list. If necessary, update the start
-     * and end time of the entry.
+     * and end time of the entry. If the event list's last event starts at the
+     * same time as the event to add, it is replaced by the new event.
      *
      * @param event
-     *            The time event
+     *            The time event to add
      */
     public void addEvent(ITimeEvent event) {
         long start = event.getTime();
         long end = start + event.getDuration();
         synchronized (fEventList) {
-            fEventList.add(event);
+            int lastIndex = fEventList.size() - 1;
+            if (lastIndex >= 0 && fEventList.get(lastIndex).getTime() == event.getTime()) {
+                fEventList.set(lastIndex, event);
+            } else {
+                fEventList.add(event);
+            }
             if (fStartTime == -1 || start < fStartTime) {
                 fStartTime = start;
             }
This page took 0.02536 seconds and 5 git commands to generate.