tmf.xml: Move all .core and .ui packages to internal
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.ui / src / org / eclipse / tracecompass / internal / tmf / analysis / xml / ui / module / TmfXmlViewOutput.java
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
13 package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
19 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
20 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
21 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource.ViewType;
22 import org.eclipse.tracecompass.tmf.ui.analysis.TmfAnalysisViewOutput;
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;
38 private final @NonNull ViewType fViewType;
39
40 /**
41 * Constructor
42 *
43 * @param viewid
44 * id of the view to display as output
45 */
46 public TmfXmlViewOutput(String viewid) {
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
57 */
58 public TmfXmlViewOutput(String viewid, @NonNull ViewType viewType) {
59 super(viewid);
60 fViewType = viewType;
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 }
82 Element viewElement = XmlUtils.getElementInFile(filePath, fViewType.getXmlElem(), viewId);
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 }
This page took 0.0348 seconds and 5 git commands to generate.