1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 * Geneviève Bastien - Move code to provide base classes for time graph view
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
19 import java
.util
.concurrent
.CopyOnWriteArrayList
;
22 * An entry for use in the time graph views
26 public class TimeGraphEntry
implements ITimeGraphEntry
{
29 private TimeGraphEntry fParent
= null;
31 /** List of child entries */
32 private final List
<TimeGraphEntry
> fChildren
= new CopyOnWriteArrayList
<>();
34 /** Name of this entry (text to show) */
36 private long fStartTime
= -1;
37 private long fEndTime
= -1;
38 private List
<ITimeEvent
> fEventList
= new ArrayList
<>();
39 private List
<ITimeEvent
> fZoomedEventList
= new ArrayList
<>();
45 * The name of this entry
47 * The start time of this entry
49 * The end time of this entry
51 public TimeGraphEntry(String name
, long startTime
, long endTime
) {
53 fStartTime
= startTime
;
57 // ---------------------------------------------
58 // Getters and setters
59 // ---------------------------------------------
62 public ITimeGraphEntry
getParent() {
67 * Sets the entry's parent
69 * @param entry The new parent entry
71 protected void setParent(TimeGraphEntry entry
) {
76 public boolean hasChildren() {
77 return fChildren
.size() > 0;
81 public List
<TimeGraphEntry
> getChildren() {
86 public String
getName() {
91 * Update the entry name
94 * the updated entry name
96 public void setName(String name
) {
101 public long getStartTime() {
106 public long getEndTime() {
111 * Updates the end time
118 public void updateEndTime(long endTime
) {
119 fEndTime
= Math
.max(endTime
, fEndTime
);
123 public boolean hasTimeEvents() {
128 public Iterator
<ITimeEvent
> getTimeEventsIterator() {
129 if (hasTimeEvents()) {
130 return new EventIterator(fEventList
, fZoomedEventList
);
136 public Iterator
<ITimeEvent
> getTimeEventsIterator(long startTime
, long stopTime
, long visibleDuration
) {
137 if (!hasTimeEvents()) {
140 return new EventIterator(fEventList
, fZoomedEventList
, startTime
, stopTime
);
144 * Add an event to this entry's event list. If necessary, update the start
145 * and end time of the entry. If the event list's last event starts at the
146 * same time as the event to add, it is replaced by the new event.
149 * The time event to add
151 public void addEvent(ITimeEvent event
) {
152 long start
= event
.getTime();
153 long end
= start
+ event
.getDuration();
154 synchronized (fEventList
) {
155 int lastIndex
= fEventList
.size() - 1;
156 if (lastIndex
>= 0 && fEventList
.get(lastIndex
).getTime() == event
.getTime()) {
157 fEventList
.set(lastIndex
, event
);
159 fEventList
.add(event
);
161 if (fStartTime
== -1 || start
< fStartTime
) {
164 if (fEndTime
== -1 || end
> fEndTime
) {
171 * Set the general event list of this entry.
174 * The list of time events
176 public void setEventList(List
<ITimeEvent
> eventList
) {
177 if (eventList
!= null) {
178 fEventList
= new ArrayList
<>(eventList
);
180 fEventList
= new ArrayList
<>();
185 * Set the zoomed event list of this entry.
188 * The list of time events
190 public void setZoomedEventList(List
<ITimeEvent
> eventList
) {
191 if (eventList
!= null) {
192 fZoomedEventList
= new ArrayList
<>(eventList
);
194 fZoomedEventList
= new ArrayList
<>();
199 * Add a child entry to this one
204 public void addChild(TimeGraphEntry child
) {
205 child
.fParent
= this;
206 fChildren
.add(child
);
210 public String
toString() {
211 return getClass().getSimpleName() + '(' + fName
+ ')';
This page took 0.037068 seconds and 6 git commands to generate.