TMF: Support multiple view types in XML analysis output source
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 26 Jun 2014 19:33:24 +0000 (15:33 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Mon, 7 Jul 2014 18:32:24 +0000 (14:32 -0400)
Change-Id: I0419a9290fb0b5bb40f82fccca3b1d16580fac38
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/29081
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java

index 0960c824dc39adb9c147e468c9486e7348e24eed..f8d6826c78de5e5bc93d2e3a6445ed01a213d6f8 100644 (file)
@@ -46,6 +46,29 @@ public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener
     /** String separating data elements for the output properties */
     public static final String DATA_SEPARATOR = ";;;"; //$NON-NLS-1$
 
+    /**
+     * Enum to match the name of a view's XML element to its view ID.
+     */
+    private static enum ViewType {
+        TIME_GRAPH_VIEW(TmfXmlUiStrings.TIME_GRAPH_VIEW, XmlTimeGraphView.ID);
+
+        private final String fXmlElem;
+        private final String fViewId;
+
+        private ViewType(String xmlElem, String viewId) {
+            fXmlElem = xmlElem;
+            fViewId = viewId;
+        }
+
+        public String getXmlElem() {
+            return fXmlElem;
+        }
+
+        public String getViewId() {
+            return fViewId;
+        }
+    }
+
     @Override
     public void moduleCreated(IAnalysisModule module) {
         IPath pathToFiles = XmlUtils.getXmlFilesPath();
@@ -67,23 +90,26 @@ public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener
 
                 /* get state provider views if the analysis has state systems */
                 if (module instanceof TmfStateSystemAnalysisModule) {
-                    NodeList ssViewNodes = doc.getElementsByTagName(TmfXmlUiStrings.TIME_GRAPH_VIEW);
-                    for (int i = 0; i < ssViewNodes.getLength(); i++) {
-                        Element node = (Element) ssViewNodes.item(i);
-
-                        /* Check if analysis is the right one */
-                        List<Element> headNodes = XmlUtils.getChildElements(node, TmfXmlStrings.HEAD);
-                        if (headNodes.size() != 1) {
-                            continue;
-                        }
+                    for (ViewType viewType : ViewType.values()) {
+                        NodeList ssViewNodes = doc.getElementsByTagName(viewType.getXmlElem());
+                        for (int i = 0; i < ssViewNodes.getLength(); i++) {
+                            Element node = (Element) ssViewNodes.item(i);
+
+                            /* Check if analysis is the right one */
+                            List<Element> headNodes = XmlUtils.getChildElements(node, TmfXmlStrings.HEAD);
+                            if (headNodes.size() != 1) {
+                                continue;
+                            }
 
-                        List<Element> analysisNodes = XmlUtils.getChildElements(headNodes.get(0), TmfXmlStrings.ANALYSIS);
-                        for (Element analysis : analysisNodes) {
-                            String analysisId = analysis.getAttribute(TmfXmlStrings.ID);
-                            if (analysisId.equals(module.getId())) {
-                                IAnalysisOutput output = new TmfXmlViewOutput(XmlTimeGraphView.ID);
-                                output.setOutputProperty(TmfXmlUiStrings.XML_OUTPUT_DATA, node.getAttribute(TmfXmlStrings.ID) + DATA_SEPARATOR + xmlFile.getAbsolutePath(), false);
-                                module.registerOutput(output);
+                            List<Element> analysisNodes = XmlUtils.getChildElements(headNodes.get(0), TmfXmlStrings.ANALYSIS);
+                            for (Element analysis : analysisNodes) {
+                                String analysisId = analysis.getAttribute(TmfXmlStrings.ID);
+                                if (analysisId.equals(module.getId())) {
+                                    String viewId = viewType.getViewId();
+                                    IAnalysisOutput output = new TmfXmlViewOutput(viewId);
+                                    output.setOutputProperty(TmfXmlUiStrings.XML_OUTPUT_DATA, node.getAttribute(TmfXmlStrings.ID) + DATA_SEPARATOR + xmlFile.getAbsolutePath(), false);
+                                    module.registerOutput(output);
+                                }
                             }
                         }
                     }
This page took 0.051927 seconds and 5 git commands to generate.