1 /*******************************************************************************
2 * Copyright (c) 2014 É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 * Florian Wininger - Initial API and implementation
11 * Geneviève Bastien - Review of the initial implementation
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.views
.timegraph
;
16 import java
.util
.Collections
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
20 import org
.eclipse
.jdt
.annotation
.NonNull
;
21 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.TmfXmlUiStrings
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.StateSystemUtils
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
25 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.ITmfXmlModelFactory
;
26 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.ITmfXmlStateAttribute
;
27 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.TmfXmlLocation
;
28 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.readonly
.TmfXmlReadOnlyModelFactory
;
29 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.IXmlStateSystemContainer
;
30 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
33 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
34 import org
.w3c
.dom
.Element
;
37 * An XML-defined entry, or row, to display in the XML state system view
39 * @author Florian Wininger
41 public class XmlEntry
extends TimeGraphEntry
implements IXmlStateSystemContainer
{
43 private static final String EMPTY_STRING
= ""; //$NON-NLS-1$
45 /** Type of resource */
46 public static enum EntryDisplayType
{
47 /** Entries without events to display (filler rows, etc.) */
49 /** Entries with time events */
53 private final ITmfTrace fTrace
;
54 private final EntryDisplayType fType
;
55 private final int fBaseQuark
;
56 private final int fDisplayQuark
;
57 private final String fParentId
;
58 private final String fId
;
59 private final @NonNull ITmfStateSystem fSs
;
60 private final Element fElement
;
66 * The quark matching this entry, or <code>-1</code> if no quark
68 * The quark containing the value to display. It was needed by
69 * the caller to get the start and end time of this entry, so we
70 * receive it as parameter from him.
72 * The trace on which we are working (FIXME: is this parameter
75 * The name of this entry. It will be overridden if a "name" XML
76 * tag is specified in the entryElement. It will also be used as
77 * the ID of this entry if no "id" XML tag is specified. It
78 * typically is the attribute name corresponding the the base
81 * The start time of this entry lifetime
83 * The end time of this entry
85 * The display type of this entry
87 * The state system this entry belongs to
89 * The XML element describing this entry. This element will be
90 * used to determine, if available, the parent, ID, name and
91 * other display option of this entry
93 public XmlEntry(int baseQuark
, int displayQuark
, ITmfTrace trace
, String name
, long startTime
, long endTime
, EntryDisplayType type
, @NonNull ITmfStateSystem ss
, Element entryElement
) {
94 super(name
, startTime
, endTime
);
97 fBaseQuark
= baseQuark
;
98 fDisplayQuark
= displayQuark
;
100 fElement
= entryElement
;
102 /* Get the parent if specified */
103 List
<Element
> elements
= XmlUtils
.getChildElements(fElement
, TmfXmlUiStrings
.PARENT_ELEMENT
);
104 if (elements
.size() > 0) {
105 fParentId
= getFirstValue(elements
.get(0));
107 fParentId
= EMPTY_STRING
;
110 /* Get the name of this entry */
111 elements
= XmlUtils
.getChildElements(fElement
, TmfXmlUiStrings
.NAME_ELEMENT
);
112 if (elements
.size() > 0) {
113 String nameFromSs
= getFirstValue(elements
.get(0));
114 if (!nameFromSs
.isEmpty()) {
119 /* Get the id of this entry */
120 elements
= XmlUtils
.getChildElements(fElement
, TmfXmlUiStrings
.ID_ELEMENT
);
121 if (elements
.size() > 0) {
122 fId
= getFirstValue(elements
.get(0));
133 * The quark matching this entry, or <code>-1</code> if no quark
135 * The trace on which we are working
137 * The exec_name of this entry
139 * The state system this entry belongs to
141 public XmlEntry(int baseQuark
, ITmfTrace trace
, String name
, @NonNull ITmfStateSystem ss
) {
142 super(name
, ss
.getStartTime(), ss
.getCurrentEndTime());
144 fType
= EntryDisplayType
.NULL
;
145 fBaseQuark
= baseQuark
;
146 fDisplayQuark
= baseQuark
;
149 fParentId
= EMPTY_STRING
;
153 /** Return the state value of the first interval with a non-null value */
154 private String
getFirstValue(Element stateAttribute
) {
155 if (stateAttribute
== null) {
156 throw new IllegalArgumentException();
159 ITmfXmlModelFactory factory
= TmfXmlReadOnlyModelFactory
.getInstance();
160 ITmfXmlStateAttribute display
= factory
.createStateAttribute(stateAttribute
, this);
161 int quark
= display
.getAttributeQuark(fBaseQuark
, null);
162 if (quark
!= IXmlStateSystemContainer
.ERROR_QUARK
) {
163 ITmfStateInterval firstInterval
= StateSystemUtils
.queryUntilNonNullValue(fSs
, quark
, getStartTime(), getEndTime());
164 if (firstInterval
!= null) {
165 return firstInterval
.getStateValue().toString();
172 * Get the trace this entry was taken from
174 * @return the entry's trace
176 public ITmfTrace
getTrace() {
181 * Get the entry Type of this entry. Uses the inner EntryDisplayType enum.
183 * @return The entry type
185 public EntryDisplayType
getType() {
190 * Get the quark from which to get the time event intervals for this entry.
192 * @return The attribute quark containing the intervals to display
194 public int getDisplayQuark() {
195 return fDisplayQuark
;
199 * Get this entry's ID
201 * @return The id of the entry.
203 public String
getId() {
208 * Return the entry's parent ID. It corresponds to another entry's ID
209 * received from the {@link #getId()} method.
211 * @return The parent ID of this entry
213 public String
getParentId() {
218 public boolean hasTimeEvents() {
219 if (fType
== EntryDisplayType
.NULL
) {
226 * Add a child to this entry of type XmlEntry
231 public void addChild(XmlEntry entry
) {
233 for (index
= 0; index
< getChildren().size(); index
++) {
234 XmlEntry other
= (XmlEntry
) getChildren().get(index
);
235 if (entry
.getType().compareTo(other
.getType()) < 0) {
237 } else if (entry
.getType().equals(other
.getType())) {
238 if (entry
.getName().compareTo(other
.getName()) < 0) {
244 entry
.setParent(this);
245 addChild(index
, entry
);
249 * Return the state system this entry is associated to
251 * @return The state system, or <code>null</code> if the state system can't
256 public ITmfStateSystem
getStateSystem() {
261 public String
getAttributeValue(String name
) {
266 public Iterable
<TmfXmlLocation
> getLocations() {
267 return Collections
.EMPTY_SET
;
271 public Iterator
<@NonNull ITimeEvent
> getTimeEventsIterator() {
272 return super.getTimeEventsIterator();