1 /*******************************************************************************
2 * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others.
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
;
19 import java
.util
.regex
.Pattern
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.TmfXmlUiStrings
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.StateSystemUtils
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
26 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.ITmfXmlModelFactory
;
27 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.ITmfXmlStateAttribute
;
28 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.TmfXmlLocation
;
29 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.readonly
.TmfXmlReadOnlyModelFactory
;
30 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.IXmlStateSystemContainer
;
31 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
33 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
34 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
35 import org
.w3c
.dom
.Element
;
38 * An XML-defined entry, or row, to display in the XML state system view
40 * @author Florian Wininger
42 public class XmlEntry
extends TimeGraphEntry
implements IXmlStateSystemContainer
{
44 private static final String EMPTY_STRING
= ""; //$NON-NLS-1$
46 /** Type of resource */
47 public static enum EntryDisplayType
{
48 /** Entries without events to display (filler rows, etc.) */
50 /** Entries with time events */
54 private final ITmfTrace fTrace
;
55 private final EntryDisplayType fType
;
56 private final int fBaseQuark
;
57 private final int fDisplayQuark
;
58 private final String fParentId
;
59 private final String fId
;
60 private final @NonNull ITmfStateSystem fSs
;
61 private final Element fElement
;
67 * The quark matching this entry, or <code>-1</code> if no quark
69 * The quark containing the value to display. It was needed by
70 * the caller to get the start and end time of this entry, so we
71 * receive it as parameter from him.
73 * The trace on which we are working (FIXME: is this parameter
76 * The name of this entry. It will be overridden if a "name" XML
77 * tag is specified in the entryElement. It will also be used as
78 * the ID of this entry if no "id" XML tag is specified. It
79 * typically is the attribute name corresponding the the base
82 * The start time of this entry lifetime
84 * The end time of this entry
86 * The display type of this entry
88 * The state system this entry belongs to
90 * The XML element describing this entry. This element will be
91 * used to determine, if available, the parent, ID, name and
92 * other display option of this entry
94 public XmlEntry(int baseQuark
, int displayQuark
, ITmfTrace trace
, String name
, long startTime
, long endTime
, EntryDisplayType type
, @NonNull ITmfStateSystem ss
, Element entryElement
) {
95 super(name
, startTime
, endTime
);
98 fBaseQuark
= baseQuark
;
99 fDisplayQuark
= displayQuark
;
101 fElement
= entryElement
;
103 /* Get the parent if specified */
104 List
<Element
> elements
= XmlUtils
.getChildElements(fElement
, TmfXmlUiStrings
.PARENT_ELEMENT
);
105 if (elements
.size() > 0) {
106 fParentId
= getFirstValue(elements
.get(0));
108 fParentId
= EMPTY_STRING
;
111 /* Get the name of this entry */
112 elements
= XmlUtils
.getChildElements(fElement
, TmfXmlUiStrings
.NAME_ELEMENT
);
113 if (elements
.size() > 0) {
114 String nameFromSs
= getFirstValue(elements
.get(0));
115 if (!nameFromSs
.isEmpty()) {
120 /* Get the id of this entry */
121 elements
= XmlUtils
.getChildElements(fElement
, TmfXmlUiStrings
.ID_ELEMENT
);
122 if (elements
.size() > 0) {
123 fId
= getFirstValue(elements
.get(0));
134 * The quark matching this entry, or <code>-1</code> if no quark
136 * The trace on which we are working
138 * The exec_name of this entry
140 * The state system this entry belongs to
142 public XmlEntry(int baseQuark
, ITmfTrace trace
, String name
, @NonNull ITmfStateSystem ss
) {
143 super(name
, ss
.getStartTime(), ss
.getCurrentEndTime());
145 fType
= EntryDisplayType
.NULL
;
146 fBaseQuark
= baseQuark
;
147 fDisplayQuark
= baseQuark
;
150 fParentId
= EMPTY_STRING
;
154 /** Return the state value of the first interval with a non-null value */
155 private String
getFirstValue(Element stateAttribute
) {
156 if (stateAttribute
== null) {
157 throw new IllegalArgumentException();
160 ITmfXmlModelFactory factory
= TmfXmlReadOnlyModelFactory
.getInstance();
161 ITmfXmlStateAttribute display
= factory
.createStateAttribute(stateAttribute
, this);
162 int quark
= display
.getAttributeQuark(fBaseQuark
, null);
163 if (quark
!= IXmlStateSystemContainer
.ERROR_QUARK
) {
164 ITmfStateInterval firstInterval
= StateSystemUtils
.queryUntilNonNullValue(fSs
, quark
, getStartTime(), getEndTime());
165 if (firstInterval
!= null) {
166 return firstInterval
.getStateValue().toString();
173 * Get the trace this entry was taken from
175 * @return the entry's trace
177 public ITmfTrace
getTrace() {
182 * Get the entry Type of this entry. Uses the inner EntryDisplayType enum.
184 * @return The entry type
186 public EntryDisplayType
getType() {
191 * Get the quark from which to get the time event intervals for this entry.
193 * @return The attribute quark containing the intervals to display
195 public int getDisplayQuark() {
196 return fDisplayQuark
;
200 * Get this entry's ID
202 * @return The id of the entry.
204 public String
getId() {
209 * Return the entry's parent ID. It corresponds to another entry's ID
210 * received from the {@link #getId()} method.
212 * @return The parent ID of this entry
214 public String
getParentId() {
219 public boolean hasTimeEvents() {
220 if (fType
== EntryDisplayType
.NULL
) {
227 * Add a child to this entry of type XmlEntry
232 public void addChild(XmlEntry entry
) {
234 for (index
= 0; index
< getChildren().size(); index
++) {
235 XmlEntry other
= (XmlEntry
) getChildren().get(index
);
236 if (entry
.getType().compareTo(other
.getType()) < 0) {
238 } else if (entry
.getType().equals(other
.getType())) {
239 if (entry
.getName().compareTo(other
.getName()) < 0) {
245 entry
.setParent(this);
246 addChild(index
, entry
);
250 * Return the state system this entry is associated to
252 * @return The state system, or <code>null</code> if the state system can't
257 public ITmfStateSystem
getStateSystem() {
262 public String
getAttributeValue(String name
) {
267 public Iterable
<TmfXmlLocation
> getLocations() {
268 return Collections
.EMPTY_SET
;
272 public Iterator
<@NonNull ITimeEvent
> getTimeEventsIterator() {
273 return super.getTimeEventsIterator();
277 public boolean matches(@NonNull Pattern pattern
) {
278 if (pattern
.matcher(getName()).find()) {
281 if (pattern
.matcher(fId
).find()) {
284 return pattern
.matcher(fParentId
).find();