tmf: Fix custom parser wizard preview table
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.ui / src / org / eclipse / linuxtools / tmf / analysis / xml / ui / module / TmfAnalysisModuleHelperXml.java
CommitLineData
97ed0cf0
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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.analysis.xml.ui.module;
14
15import java.io.File;
63c43609 16import java.util.Collections;
aa89118c 17import java.util.List;
97ed0cf0
FW
18
19import org.eclipse.core.runtime.Path;
54eae41f 20import org.eclipse.jdt.annotation.NonNull;
97ed0cf0 21import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator;
aa89118c 22import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils;
97ed0cf0
FW
23import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
24import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
25import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
26import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper;
048bde85 27import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager;
63c43609 28import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
97ed0cf0 29import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
aa89118c
GB
30import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
31import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
97ed0cf0 32import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
97ed0cf0
FW
33import org.osgi.framework.Bundle;
34import org.w3c.dom.Element;
97ed0cf0
FW
35
36/**
37 * Analysis module helpers for modules provided by XML files
38 *
39 * @author Geneviève Bastien
40 */
41public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
42
43 /**
44 * The types of analysis that can be XML-defined
45 */
46 public enum XmlAnalysisModuleType {
47 /** Analysis will be of type XmlStateSystemModule */
48 STATE_SYSTEM
49 }
50
51 private final File fSourceFile;
52 private final Element fSourceElement;
53 private final XmlAnalysisModuleType fType;
97ed0cf0
FW
54
55 /**
56 * Constructor
57 *
58 * @param xmlFile
59 * The XML file containing the details of this analysis
60 * @param node
61 * The XML node element
62 * @param type
63 * The type of analysis
64 */
65 public TmfAnalysisModuleHelperXml(File xmlFile, Element node, XmlAnalysisModuleType type) {
66 fSourceFile = xmlFile;
67 fSourceElement = node;
68 fType = type;
97ed0cf0
FW
69 }
70
71 @Override
72 public String getId() {
f47f1bbe 73 return fSourceElement.getAttribute(TmfXmlStrings.ID);
97ed0cf0
FW
74 }
75
76 @Override
77 public String getName() {
aa89118c
GB
78 String name = null;
79 /* Label may be available in XML header */
80 List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
81 if (head.size() == 1) {
82 List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
83 if (!labels.isEmpty()) {
84 name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
85 }
86 }
87
97ed0cf0
FW
88 if (name == null) {
89 name = getId();
90 }
91 return name;
92 }
93
94 @Override
95 public boolean isAutomatic() {
96 return false;
97 }
98
99 @Override
100 public String getHelpText() {
101 return new String();
102 }
103
54eae41f
GB
104 @Override
105 public String getHelpText(@NonNull ITmfTrace trace) {
106 return ""; //$NON-NLS-1$
107 }
108
97ed0cf0
FW
109 @Override
110 public String getIcon() {
111 return null;
112 }
113
114 @Override
115 public Bundle getBundle() {
116 return Activator.getDefault().getBundle();
117 }
118
119 @Override
aa89118c 120 public boolean appliesToTraceType(Class<? extends ITmfTrace> traceClass) {
97ed0cf0 121 /* Trace types may be available in XML header */
aa89118c
GB
122 List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
123 if (head.size() != 1) {
124 return true;
125 }
126 /*
127 * TODO: Test with custom trace types
128 */
129 List<Element> elements = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.TRACETYPE);
130 if (elements.isEmpty()) {
97ed0cf0
FW
131 return true;
132 }
133
aa89118c
GB
134 for (Element element : elements) {
135 String traceTypeId = element.getAttribute(TmfXmlStrings.ID);
136 TraceTypeHelper helper = TmfTraceType.getInstance().getTraceType(traceTypeId);
137 if ((helper != null) && helper.getTrace().getClass().isAssignableFrom(traceClass)) {
138 return true;
139 }
140 }
141 return false;
97ed0cf0
FW
142 }
143
63c43609
MR
144 @Override
145 public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
146 return Collections.EMPTY_SET;
147 }
148
149 @Override
150 public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
151 return Collections.EMPTY_SET;
152 }
153
97ed0cf0
FW
154 @Override
155 public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
156 String analysisid = getId();
157 IAnalysisModule module = null;
158 switch (fType) {
159 case STATE_SYSTEM:
160 module = new XmlStateSystemModule();
161 XmlStateSystemModule ssModule = (XmlStateSystemModule) module;
162 module.setId(analysisid);
163 ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
164
048bde85
GB
165 /*
166 * FIXME: There is no way to know if a module is automatic, so we
167 * default to true
168 */
169 ssModule.setAutomatic(true);
97ed0cf0 170
97ed0cf0
FW
171 break;
172 default:
173 break;
174
175 }
176 if (module != null) {
177 module.setTrace(trace);
048bde85 178 TmfAnalysisManager.analysisModuleCreated(module);
97ed0cf0
FW
179 }
180
181 return module;
182 }
183
184}
This page took 0.049576 seconds and 5 git commands to generate.