Commit | Line | Data |
---|---|---|
048bde85 GB |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.analysis.xml.ui.module; |
048bde85 GB |
14 | |
15 | import java.util.List; | |
16 | ||
17 | import org.eclipse.jdt.annotation.NonNull; | |
2bdf0193 AM |
18 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings; |
19 | import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils; | |
20 | import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; | |
21 | import org.eclipse.tracecompass.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource.ViewType; | |
22 | import org.eclipse.tracecompass.tmf.ui.analysis.TmfAnalysisViewOutput; | |
048bde85 GB |
23 | import org.w3c.dom.Element; |
24 | ||
25 | /** | |
26 | * Class overriding the default analysis view output for XML views. These views | |
27 | * may have labels defined in the XML element and those label will be used as | |
28 | * the name of the view | |
29 | * | |
30 | * @author Geneviève Bastien | |
31 | * | |
32 | * TODO: We shouldn't have to do a new class here, we should be able to | |
33 | * set the name in the parent instead | |
34 | */ | |
35 | public class TmfXmlViewOutput extends TmfAnalysisViewOutput { | |
36 | ||
37 | private String fLabel = null; | |
44b06bb9 | 38 | private final @NonNull ViewType fViewType; |
048bde85 GB |
39 | |
40 | /** | |
41 | * Constructor | |
42 | * | |
43 | * @param viewid | |
44 | * id of the view to display as output | |
45 | */ | |
46 | public TmfXmlViewOutput(String viewid) { | |
44b06bb9 GB |
47 | this(viewid, ViewType.TIME_GRAPH_VIEW); |
48 | } | |
49 | ||
50 | /** | |
51 | * Constructor | |
52 | * | |
53 | * @param viewid | |
54 | * id of the view to display as output | |
55 | * @param viewType | |
56 | * type of view this output is for | |
44b06bb9 GB |
57 | */ |
58 | public TmfXmlViewOutput(String viewid, @NonNull ViewType viewType) { | |
048bde85 | 59 | super(viewid); |
44b06bb9 | 60 | fViewType = viewType; |
048bde85 GB |
61 | } |
62 | ||
63 | @Override | |
64 | public String getName() { | |
65 | if (fLabel == null) { | |
66 | return super.getName(); | |
67 | } | |
68 | return fLabel; | |
69 | } | |
70 | ||
71 | @Override | |
72 | public void setOutputProperty(@NonNull String key, String value, boolean immediate) { | |
73 | super.setOutputProperty(key, value, immediate); | |
74 | /* Find the label of the view */ | |
75 | if (key.equals(TmfXmlUiStrings.XML_OUTPUT_DATA)) { | |
76 | String[] idFile = value.split(TmfXmlAnalysisOutputSource.DATA_SEPARATOR); | |
77 | String viewId = (idFile.length > 0) ? idFile[0] : null; | |
78 | String filePath = (idFile.length > 1) ? idFile[1] : null; | |
79 | if ((viewId == null) || (filePath == null)) { | |
80 | return; | |
81 | } | |
44b06bb9 | 82 | Element viewElement = XmlUtils.getElementInFile(filePath, fViewType.getXmlElem(), viewId); |
048bde85 GB |
83 | if (viewElement == null) { |
84 | return; | |
85 | } | |
86 | List<Element> heads = XmlUtils.getChildElements(viewElement, TmfXmlStrings.HEAD); | |
87 | if (heads.size() != 1) { | |
88 | return; | |
89 | } | |
90 | Element headElement = heads.get(0); | |
91 | List<Element> label = XmlUtils.getChildElements(headElement, TmfXmlStrings.LABEL); | |
92 | if (label.isEmpty()) { | |
93 | return; | |
94 | } | |
95 | Element labelElement = label.get(0); | |
96 | fLabel = labelElement.getAttribute(TmfXmlStrings.VALUE); | |
97 | } | |
98 | } | |
99 | } |