Commit | Line | Data |
---|---|---|
048bde85 | 1 | /******************************************************************************* |
38fad53e | 2 | * Copyright (c) 2016 École Polytechnique de Montréal and others |
048bde85 GB |
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 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
6eca054d | 13 | package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module; |
048bde85 GB |
14 | |
15 | import java.io.File; | |
16 | import java.io.IOException; | |
1a23419e | 17 | import java.util.List; |
537572cd | 18 | import java.util.Map; |
048bde85 | 19 | |
048bde85 GB |
20 | import javax.xml.parsers.ParserConfigurationException; |
21 | ||
44b06bb9 | 22 | import org.eclipse.jdt.annotation.NonNull; |
6eca054d | 23 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils; |
38fad53e | 24 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis; |
6eca054d | 25 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; |
2bdf0193 AM |
26 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator; |
27 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings; | |
3b5dc745 | 28 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternDensityView; |
38fad53e | 29 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternLatencyTableView; |
c8e5d00e | 30 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternScatterGraphView; |
5b901f94 | 31 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternStatisticsView; |
6eca054d | 32 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph.XmlTimeGraphView; |
2bdf0193 | 33 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart.XmlXYView; |
2bdf0193 AM |
34 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; |
35 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisOutput; | |
36 | import org.eclipse.tracecompass.tmf.core.analysis.ITmfNewAnalysisModuleListener; | |
38fad53e | 37 | import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems; |
048bde85 | 38 | import org.w3c.dom.Document; |
1a23419e FW |
39 | import org.w3c.dom.Element; |
40 | import org.w3c.dom.NodeList; | |
048bde85 GB |
41 | import org.xml.sax.SAXException; |
42 | ||
43 | /** | |
44 | * This class searches all XML files to find outputs applicable to the newly | |
45 | * created analysis | |
46 | * | |
47 | * @author Geneviève Bastien | |
48 | */ | |
49 | public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener { | |
50 | ||
51 | /** String separating data elements for the output properties */ | |
8ecd89fa | 52 | public static final @NonNull String DATA_SEPARATOR = ";;;"; //$NON-NLS-1$ |
048bde85 | 53 | |
2e9d15a9 GB |
54 | /** |
55 | * Enum to match the name of a view's XML element to its view ID. | |
56 | */ | |
44b06bb9 GB |
57 | public static enum ViewType { |
58 | /** | |
59 | * Time graph view element | |
60 | */ | |
87c5447c | 61 | TIME_GRAPH_VIEW(TmfXmlUiStrings.TIME_GRAPH_VIEW, XmlTimeGraphView.ID), |
44b06bb9 GB |
62 | /** |
63 | * XY chart view element | |
64 | */ | |
87c5447c | 65 | XY_VIEW(TmfXmlUiStrings.XY_VIEW, XmlXYView.ID); |
2e9d15a9 | 66 | |
44b06bb9 | 67 | private final @NonNull String fXmlElem; |
2e9d15a9 GB |
68 | private final String fViewId; |
69 | ||
44b06bb9 | 70 | private ViewType(@NonNull String xmlElem, String viewId) { |
2e9d15a9 GB |
71 | fXmlElem = xmlElem; |
72 | fViewId = viewId; | |
73 | } | |
74 | ||
44b06bb9 GB |
75 | /** |
76 | * Get the XML element corresponding to this view type | |
77 | * | |
78 | * @return The XML element corresponding to this type | |
79 | */ | |
80 | public @NonNull String getXmlElem() { | |
2e9d15a9 GB |
81 | return fXmlElem; |
82 | } | |
83 | ||
44b06bb9 | 84 | private String getViewId() { |
2e9d15a9 GB |
85 | return fViewId; |
86 | } | |
87 | } | |
88 | ||
38fad53e JCK |
89 | /** |
90 | * Enum for latency view type. | |
91 | * | |
92 | * @author Jean-Christian Kouame | |
38fad53e JCK |
93 | */ |
94 | public static enum LatencyViewType { | |
95 | ||
96 | /** | |
97 | * Latency Table View type | |
98 | */ | |
c8e5d00e JCK |
99 | LATENCY_TABLE(PatternLatencyTableView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyTable), |
100 | ||
101 | /** | |
102 | * Latency Scatter View type | |
103 | */ | |
3b5dc745 JCK |
104 | SCATTER_GRAPH(PatternScatterGraphView.ID, Messages.TmfXmlAnalysisOutputSource_ScatterGraphTitle), |
105 | ||
106 | /** | |
107 | * Latency Density View type | |
108 | */ | |
5b901f94 JCK |
109 | DENSITY_VIEW(PatternDensityView.ID, Messages.TmfXmlAnalysisOutputSource_DensityChartTitle), |
110 | ||
111 | /** | |
112 | * Latency Statistic View type | |
113 | */ | |
114 | STATISTIC_VIEW(PatternStatisticsView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle); | |
38fad53e JCK |
115 | |
116 | private @NonNull String fLatencyViewId; | |
117 | private String fLatencyViewLabel; | |
118 | ||
119 | private LatencyViewType(@NonNull String viewId, String label) { | |
120 | fLatencyViewId = viewId; | |
121 | fLatencyViewLabel = label; | |
122 | } | |
123 | ||
124 | /** | |
125 | * Get the ID of the latency view | |
126 | * | |
127 | * @return The ID | |
128 | */ | |
129 | public String getViewId() { | |
130 | return fLatencyViewId; | |
131 | } | |
132 | ||
133 | /** | |
134 | * Get the label of the view | |
135 | * | |
136 | * @return The label | |
137 | */ | |
138 | public String getLabel() { | |
139 | return fLatencyViewLabel; | |
140 | } | |
141 | } | |
87c5447c | 142 | |
048bde85 GB |
143 | @Override |
144 | public void moduleCreated(IAnalysisModule module) { | |
537572cd BH |
145 | Map<String, File> files = XmlUtils.listFiles(); |
146 | for (File xmlFile : files.values()) { | |
048bde85 GB |
147 | if (!XmlUtils.xmlValidate(xmlFile).isOK()) { |
148 | continue; | |
149 | } | |
150 | ||
151 | try { | |
f10786aa | 152 | Document doc = XmlUtils.getDocumentFromFile(xmlFile); |
048bde85 GB |
153 | |
154 | /* get state provider views if the analysis has state systems */ | |
38fad53e | 155 | if (module instanceof ITmfAnalysisModuleWithStateSystems) { |
2e9d15a9 GB |
156 | for (ViewType viewType : ViewType.values()) { |
157 | NodeList ssViewNodes = doc.getElementsByTagName(viewType.getXmlElem()); | |
158 | for (int i = 0; i < ssViewNodes.getLength(); i++) { | |
159 | Element node = (Element) ssViewNodes.item(i); | |
160 | ||
161 | /* Check if analysis is the right one */ | |
162 | List<Element> headNodes = XmlUtils.getChildElements(node, TmfXmlStrings.HEAD); | |
163 | if (headNodes.size() != 1) { | |
164 | continue; | |
165 | } | |
1a23419e | 166 | |
2e9d15a9 GB |
167 | List<Element> analysisNodes = XmlUtils.getChildElements(headNodes.get(0), TmfXmlStrings.ANALYSIS); |
168 | for (Element analysis : analysisNodes) { | |
169 | String analysisId = analysis.getAttribute(TmfXmlStrings.ID); | |
170 | if (analysisId.equals(module.getId())) { | |
171 | String viewId = viewType.getViewId(); | |
44b06bb9 | 172 | IAnalysisOutput output = new TmfXmlViewOutput(viewId, viewType); |
2e9d15a9 GB |
173 | output.setOutputProperty(TmfXmlUiStrings.XML_OUTPUT_DATA, node.getAttribute(TmfXmlStrings.ID) + DATA_SEPARATOR + xmlFile.getAbsolutePath(), false); |
174 | module.registerOutput(output); | |
175 | } | |
1a23419e FW |
176 | } |
177 | } | |
178 | } | |
179 | } | |
38fad53e | 180 | |
c8e5d00e | 181 | // Add the latency views for pattern analysis |
38fad53e JCK |
182 | if (module instanceof XmlPatternAnalysis) { |
183 | for (LatencyViewType viewType : LatencyViewType.values()) { | |
184 | IAnalysisOutput output = new TmfXmlLatencyViewOutput(viewType.getViewId(), viewType.getLabel()); | |
185 | output.setOutputProperty(TmfXmlUiStrings.XML_LATENCY_OUTPUT_DATA, module.getId() + DATA_SEPARATOR + viewType.getLabel(), false); | |
186 | module.registerOutput(output); | |
187 | } | |
188 | } | |
189 | ||
048bde85 GB |
190 | } catch (ParserConfigurationException | SAXException | IOException e) { |
191 | Activator.logError("Error opening XML file", e); //$NON-NLS-1$ | |
192 | } | |
193 | } | |
194 | } | |
195 | ||
196 | } |