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 AM |
23 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; |
24 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; | |
25 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; | |
2bdf0193 AM |
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.TimeGraphEntry; | |
1a23419e FW |
34 | import org.w3c.dom.Element; |
35 | ||
36 | /** | |
37 | * An XML-defined entry, or row, to display in the XML state system view | |
38 | * | |
39 | * @author Florian Wininger | |
40 | */ | |
41 | public class XmlEntry extends TimeGraphEntry implements IXmlStateSystemContainer { | |
42 | ||
43 | private static final String EMPTY_STRING = ""; //$NON-NLS-1$ | |
44 | ||
45 | /** Type of resource */ | |
46 | public static enum EntryDisplayType { | |
47 | /** Entries without events to display (filler rows, etc.) */ | |
48 | NULL, | |
49 | /** Entries with time events */ | |
50 | DISPLAY | |
51 | } | |
52 | ||
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; | |
61 | ||
62 | /** | |
63 | * Constructor | |
64 | * | |
65 | * @param baseQuark | |
66 | * The quark matching this entry, or <code>-1</code> if no quark | |
67 | * @param displayQuark | |
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. | |
71 | * @param trace | |
72 | * The trace on which we are working (FIXME: is this parameter | |
73 | * useful?) | |
74 | * @param name | |
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 | |
79 | * quark. | |
80 | * @param startTime | |
81 | * The start time of this entry lifetime | |
82 | * @param endTime | |
83 | * The end time of this entry | |
84 | * @param type | |
85 | * The display type of this entry | |
86 | * @param ss | |
87 | * The state system this entry belongs to | |
88 | * @param entryElement | |
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 | |
92 | */ | |
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); | |
95 | fTrace = trace; | |
96 | fType = type; | |
97 | fBaseQuark = baseQuark; | |
98 | fDisplayQuark = displayQuark; | |
99 | fSs = ss; | |
100 | fElement = entryElement; | |
101 | ||
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)); | |
106 | } else { | |
107 | fParentId = EMPTY_STRING; | |
108 | } | |
109 | ||
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()) { | |
115 | setName(nameFromSs); | |
116 | } | |
117 | } | |
118 | ||
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)); | |
123 | } else { | |
124 | fId = name; | |
125 | } | |
126 | ||
127 | } | |
128 | ||
129 | /** | |
130 | * Constructor | |
131 | * | |
132 | * @param baseQuark | |
133 | * The quark matching this entry, or <code>-1</code> if no quark | |
134 | * @param trace | |
135 | * The trace on which we are working | |
136 | * @param name | |
137 | * The exec_name of this entry | |
138 | * @param ss | |
139 | * The state system this entry belongs to | |
140 | */ | |
141 | public XmlEntry(int baseQuark, ITmfTrace trace, String name, @NonNull ITmfStateSystem ss) { | |
142 | super(name, ss.getStartTime(), ss.getCurrentEndTime()); | |
143 | fTrace = trace; | |
144 | fType = EntryDisplayType.NULL; | |
145 | fBaseQuark = baseQuark; | |
146 | fDisplayQuark = baseQuark; | |
147 | fSs = ss; | |
148 | fElement = null; | |
149 | fParentId = EMPTY_STRING; | |
150 | fId = name; | |
151 | } | |
152 | ||
153 | /** Return the state value of the first interval with a non-null value */ | |
154 | private String getFirstValue(Element stateAttribute) { | |
155 | ITmfXmlModelFactory factory = TmfXmlReadOnlyModelFactory.getInstance(); | |
156 | ITmfXmlStateAttribute display = factory.createStateAttribute(stateAttribute, this); | |
157 | int quark = display.getAttributeQuark(fBaseQuark); | |
158 | if (quark != IXmlStateSystemContainer.ERROR_QUARK) { | |
159 | try { | |
160 | /* Find the first attribute with a parent */ | |
1dd75589 | 161 | List<ITmfStateInterval> execNameIntervals = StateSystemUtils.queryHistoryRange(fSs, quark, getStartTime(), getEndTime()); |
1a23419e FW |
162 | for (ITmfStateInterval execNameInterval : execNameIntervals) { |
163 | ||
164 | if (!execNameInterval.getStateValue().isNull()) { | |
165 | return execNameInterval.getStateValue().toString(); | |
166 | } | |
167 | } | |
168 | } catch (AttributeNotFoundException | StateSystemDisposedException e) { | |
169 | } | |
170 | } | |
171 | return EMPTY_STRING; | |
172 | } | |
173 | ||
174 | /** | |
175 | * Get the trace this entry was taken from | |
176 | * | |
177 | * @return the entry's trace | |
178 | */ | |
179 | public ITmfTrace getTrace() { | |
180 | return fTrace; | |
181 | } | |
182 | ||
183 | /** | |
184 | * Get the entry Type of this entry. Uses the inner EntryDisplayType enum. | |
185 | * | |
186 | * @return The entry type | |
187 | */ | |
188 | public EntryDisplayType getType() { | |
189 | return fType; | |
190 | } | |
191 | ||
192 | /** | |
193 | * Get the quark from which to get the time event intervals for this entry. | |
194 | * | |
195 | * @return The attribute quark containing the intervals to display | |
196 | */ | |
197 | public int getDisplayQuark() { | |
198 | return fDisplayQuark; | |
199 | } | |
200 | ||
201 | /** | |
202 | * Get this entry's ID | |
203 | * | |
204 | * @return The id of the entry. | |
205 | */ | |
206 | public String getId() { | |
207 | return fId; | |
208 | } | |
209 | ||
210 | /** | |
211 | * Return the entry's parent ID. It corresponds to another entry's ID | |
212 | * received from the {@link #getId()} method. | |
213 | * | |
214 | * @return The parent ID of this entry | |
215 | */ | |
216 | public String getParentId() { | |
217 | return fParentId; | |
218 | } | |
219 | ||
220 | @Override | |
221 | public boolean hasTimeEvents() { | |
222 | if (fType == EntryDisplayType.NULL) { | |
223 | return false; | |
224 | } | |
225 | return true; | |
226 | } | |
227 | ||
228 | /** | |
229 | * Add a child to this entry of type XmlEntry | |
230 | * | |
231 | * @param entry | |
232 | * The entry to add | |
233 | */ | |
234 | public void addChild(XmlEntry entry) { | |
235 | int index; | |
236 | for (index = 0; index < getChildren().size(); index++) { | |
237 | XmlEntry other = (XmlEntry) getChildren().get(index); | |
238 | if (entry.getType().compareTo(other.getType()) < 0) { | |
239 | break; | |
240 | } else if (entry.getType().equals(other.getType())) { | |
241 | if (entry.getName().compareTo(other.getName()) < 0) { | |
242 | break; | |
243 | } | |
244 | } | |
245 | } | |
246 | ||
247 | entry.setParent(this); | |
a3188982 | 248 | addChild(index, entry); |
1a23419e FW |
249 | } |
250 | ||
251 | /** | |
252 | * Return the state system this entry is associated to | |
253 | * | |
254 | * @return The state system, or <code>null</code> if the state system can't | |
255 | * be found. | |
256 | */ | |
257 | @Override | |
258 | @NonNull | |
259 | public ITmfStateSystem getStateSystem() { | |
260 | return fSs; | |
261 | } | |
262 | ||
263 | @Override | |
264 | public String getAttributeValue(String name) { | |
265 | return name; | |
266 | } | |
267 | ||
268 | @Override | |
269 | public Iterable<TmfXmlLocation> getLocations() { | |
270 | return Collections.EMPTY_SET; | |
271 | } | |
272 | ||
273 | } |