Commit | Line | Data |
---|---|---|
1a23419e FW |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 École Polytechnique de Montréal | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Florian Wininger - Initial API and implementation | |
11 | * Geneviève Bastien - Review of the initial implementation | |
12 | *******************************************************************************/ | |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph; |
1a23419e FW |
15 | |
16 | import java.util.Collections; | |
17 | import java.util.List; | |
18 | ||
19 | import org.eclipse.jdt.annotation.NonNull; | |
2bdf0193 | 20 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings; |
e894a508 | 21 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
1dd75589 | 22 | import org.eclipse.tracecompass.statesystem.core.StateSystemUtils; |
e894a508 | 23 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; |
2bdf0193 AM |
24 | import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory; |
25 | import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute; | |
26 | import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation; | |
27 | import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory; | |
28 | import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer; | |
29 | import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils; | |
30 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
31 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry; | |
1a23419e FW |
32 | import org.w3c.dom.Element; |
33 | ||
34 | /** | |
35 | * An XML-defined entry, or row, to display in the XML state system view | |
36 | * | |
37 | * @author Florian Wininger | |
38 | */ | |
39 | public class XmlEntry extends TimeGraphEntry implements IXmlStateSystemContainer { | |
40 | ||
41 | private static final String EMPTY_STRING = ""; //$NON-NLS-1$ | |
42 | ||
43 | /** Type of resource */ | |
44 | public static enum EntryDisplayType { | |
45 | /** Entries without events to display (filler rows, etc.) */ | |
46 | NULL, | |
47 | /** Entries with time events */ | |
48 | DISPLAY | |
49 | } | |
50 | ||
51 | private final ITmfTrace fTrace; | |
52 | private final EntryDisplayType fType; | |
53 | private final int fBaseQuark; | |
54 | private final int fDisplayQuark; | |
55 | private final String fParentId; | |
56 | private final String fId; | |
57 | private final @NonNull ITmfStateSystem fSs; | |
58 | private final Element fElement; | |
59 | ||
60 | /** | |
61 | * Constructor | |
62 | * | |
63 | * @param baseQuark | |
64 | * The quark matching this entry, or <code>-1</code> if no quark | |
65 | * @param displayQuark | |
66 | * The quark containing the value to display. It was needed by | |
67 | * the caller to get the start and end time of this entry, so we | |
68 | * receive it as parameter from him. | |
69 | * @param trace | |
70 | * The trace on which we are working (FIXME: is this parameter | |
71 | * useful?) | |
72 | * @param name | |
73 | * The name of this entry. It will be overridden if a "name" XML | |
74 | * tag is specified in the entryElement. It will also be used as | |
75 | * the ID of this entry if no "id" XML tag is specified. It | |
76 | * typically is the attribute name corresponding the the base | |
77 | * quark. | |
78 | * @param startTime | |
79 | * The start time of this entry lifetime | |
80 | * @param endTime | |
81 | * The end time of this entry | |
82 | * @param type | |
83 | * The display type of this entry | |
84 | * @param ss | |
85 | * The state system this entry belongs to | |
86 | * @param entryElement | |
87 | * The XML element describing this entry. This element will be | |
88 | * used to determine, if available, the parent, ID, name and | |
89 | * other display option of this entry | |
90 | */ | |
91 | public XmlEntry(int baseQuark, int displayQuark, ITmfTrace trace, String name, long startTime, long endTime, EntryDisplayType type, @NonNull ITmfStateSystem ss, Element entryElement) { | |
92 | super(name, startTime, endTime); | |
93 | fTrace = trace; | |
94 | fType = type; | |
95 | fBaseQuark = baseQuark; | |
96 | fDisplayQuark = displayQuark; | |
97 | fSs = ss; | |
98 | fElement = entryElement; | |
99 | ||
100 | /* Get the parent if specified */ | |
101 | List<Element> elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.PARENT_ELEMENT); | |
102 | if (elements.size() > 0) { | |
103 | fParentId = getFirstValue(elements.get(0)); | |
104 | } else { | |
105 | fParentId = EMPTY_STRING; | |
106 | } | |
107 | ||
108 | /* Get the name of this entry */ | |
109 | elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.NAME_ELEMENT); | |
110 | if (elements.size() > 0) { | |
111 | String nameFromSs = getFirstValue(elements.get(0)); | |
112 | if (!nameFromSs.isEmpty()) { | |
113 | setName(nameFromSs); | |
114 | } | |
115 | } | |
116 | ||
117 | /* Get the id of this entry */ | |
118 | elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.ID_ELEMENT); | |
119 | if (elements.size() > 0) { | |
120 | fId = getFirstValue(elements.get(0)); | |
121 | } else { | |
122 | fId = name; | |
123 | } | |
124 | ||
125 | } | |
126 | ||
127 | /** | |
128 | * Constructor | |
129 | * | |
130 | * @param baseQuark | |
131 | * The quark matching this entry, or <code>-1</code> if no quark | |
132 | * @param trace | |
133 | * The trace on which we are working | |
134 | * @param name | |
135 | * The exec_name of this entry | |
136 | * @param ss | |
137 | * The state system this entry belongs to | |
138 | */ | |
139 | public XmlEntry(int baseQuark, ITmfTrace trace, String name, @NonNull ITmfStateSystem ss) { | |
140 | super(name, ss.getStartTime(), ss.getCurrentEndTime()); | |
141 | fTrace = trace; | |
142 | fType = EntryDisplayType.NULL; | |
143 | fBaseQuark = baseQuark; | |
144 | fDisplayQuark = baseQuark; | |
145 | fSs = ss; | |
146 | fElement = null; | |
147 | fParentId = EMPTY_STRING; | |
148 | fId = name; | |
149 | } | |
150 | ||
151 | /** Return the state value of the first interval with a non-null value */ | |
152 | private String getFirstValue(Element stateAttribute) { | |
0a35a36f | 153 | |
1a23419e FW |
154 | ITmfXmlModelFactory factory = TmfXmlReadOnlyModelFactory.getInstance(); |
155 | ITmfXmlStateAttribute display = factory.createStateAttribute(stateAttribute, this); | |
156 | int quark = display.getAttributeQuark(fBaseQuark); | |
157 | if (quark != IXmlStateSystemContainer.ERROR_QUARK) { | |
0a35a36f GB |
158 | ITmfStateInterval firstInterval = StateSystemUtils.queryUntilNonNullValue(fSs, quark, getStartTime(), getEndTime()); |
159 | if (firstInterval != null) { | |
160 | return firstInterval.getStateValue().toString(); | |
1a23419e FW |
161 | } |
162 | } | |
163 | return EMPTY_STRING; | |
164 | } | |
165 | ||
166 | /** | |
167 | * Get the trace this entry was taken from | |
168 | * | |
169 | * @return the entry's trace | |
170 | */ | |
171 | public ITmfTrace getTrace() { | |
172 | return fTrace; | |
173 | } | |
174 | ||
175 | /** | |
176 | * Get the entry Type of this entry. Uses the inner EntryDisplayType enum. | |
177 | * | |
178 | * @return The entry type | |
179 | */ | |
180 | public EntryDisplayType getType() { | |
181 | return fType; | |
182 | } | |
183 | ||
184 | /** | |
185 | * Get the quark from which to get the time event intervals for this entry. | |
186 | * | |
187 | * @return The attribute quark containing the intervals to display | |
188 | */ | |
189 | public int getDisplayQuark() { | |
190 | return fDisplayQuark; | |
191 | } | |
192 | ||
193 | /** | |
194 | * Get this entry's ID | |
195 | * | |
196 | * @return The id of the entry. | |
197 | */ | |
198 | public String getId() { | |
199 | return fId; | |
200 | } | |
201 | ||
202 | /** | |
203 | * Return the entry's parent ID. It corresponds to another entry's ID | |
204 | * received from the {@link #getId()} method. | |
205 | * | |
206 | * @return The parent ID of this entry | |
207 | */ | |
208 | public String getParentId() { | |
209 | return fParentId; | |
210 | } | |
211 | ||
212 | @Override | |
213 | public boolean hasTimeEvents() { | |
214 | if (fType == EntryDisplayType.NULL) { | |
215 | return false; | |
216 | } | |
217 | return true; | |
218 | } | |
219 | ||
220 | /** | |
221 | * Add a child to this entry of type XmlEntry | |
222 | * | |
223 | * @param entry | |
224 | * The entry to add | |
225 | */ | |
226 | public void addChild(XmlEntry entry) { | |
227 | int index; | |
228 | for (index = 0; index < getChildren().size(); index++) { | |
229 | XmlEntry other = (XmlEntry) getChildren().get(index); | |
230 | if (entry.getType().compareTo(other.getType()) < 0) { | |
231 | break; | |
232 | } else if (entry.getType().equals(other.getType())) { | |
233 | if (entry.getName().compareTo(other.getName()) < 0) { | |
234 | break; | |
235 | } | |
236 | } | |
237 | } | |
238 | ||
239 | entry.setParent(this); | |
a3188982 | 240 | addChild(index, entry); |
1a23419e FW |
241 | } |
242 | ||
243 | /** | |
244 | * Return the state system this entry is associated to | |
245 | * | |
246 | * @return The state system, or <code>null</code> if the state system can't | |
247 | * be found. | |
248 | */ | |
249 | @Override | |
250 | @NonNull | |
251 | public ITmfStateSystem getStateSystem() { | |
252 | return fSs; | |
253 | } | |
254 | ||
255 | @Override | |
256 | public String getAttributeValue(String name) { | |
257 | return name; | |
258 | } | |
259 | ||
260 | @Override | |
261 | public Iterable<TmfXmlLocation> getLocations() { | |
262 | return Collections.EMPTY_SET; | |
263 | } | |
264 | ||
265 | } |