1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
;
15 import java
.util
.HashSet
;
16 import java
.util
.List
;
19 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
22 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
23 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
24 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.module
.TmfXmlAnalysisOutputSource
;
25 import org
.w3c
.dom
.Element
;
28 * Class that manages information about a view: its title, the file, etc.
30 * @author Geneviève Bastien
33 public class XmlViewInfo
extends AbstractXmlViewInfo
{
35 private static final String XML_VIEW_ID_PROPERTY
= "XmlViewId"; //$NON-NLS-1$
36 private static final String XML_VIEW_FILE_PROPERTY
= "XmlViewFile"; //$NON-NLS-1$
38 /** This is the ID of the view described in the XML file */
39 private @Nullable String fId
= null;
40 private @Nullable String fFilePath
= null;
48 public XmlViewInfo(String viewId
) {
51 IDialogSettings settings
= getPersistentPropertyStore();
52 fId
= settings
.get(XML_VIEW_ID_PROPERTY
);
53 fFilePath
= settings
.get(XML_VIEW_FILE_PROPERTY
);
57 * Set the data for this view and retrieves from it the view ID and the file
58 * path of the XML element this view uses.
61 * A string of the form "XML view ID" +
62 * {@link TmfXmlAnalysisOutputSource#DATA_SEPARATOR} +
63 * "path of the file containing the XML element"
66 public void setViewData(String data
) {
67 String
[] idFile
= data
.split(TmfXmlAnalysisOutputSource
.DATA_SEPARATOR
);
68 fId
= (idFile
.length
> 0) ? idFile
[0] : null;
69 fFilePath
= (idFile
.length
> 1) ? idFile
[1] : null;
74 protected void savePersistentData() {
75 IDialogSettings settings
= getPersistentPropertyStore();
77 settings
.put(XML_VIEW_ID_PROPERTY
, fId
);
78 settings
.put(XML_VIEW_FILE_PROPERTY
, fFilePath
);
82 * Retrieve the XML element corresponding to the view
85 * The XML tag corresponding to the view element (the type of
87 * @return The view {@link Element}
89 public @Nullable Element
getViewElement(String xmlTag
) {
94 Element viewElement
= XmlUtils
.getElementInFile(fFilePath
, xmlTag
, id
);
99 * Get the view title from the header information of the XML view element.
102 * The XML view element from which to get the title
103 * @return The view title
105 public @Nullable String
getViewTitle(Element viewElement
) {
106 List
<Element
> heads
= XmlUtils
.getChildElements(viewElement
, TmfXmlStrings
.HEAD
);
109 if (!heads
.isEmpty()) {
110 Element head
= heads
.get(0);
111 /* Set the title of this view from the label in the header */
112 List
<Element
> labels
= XmlUtils
.getChildElements(head
, TmfXmlStrings
.LABEL
);
113 for (Element label
: labels
) {
114 if (!label
.getAttribute(TmfXmlStrings
.VALUE
).isEmpty()) {
115 title
= label
.getAttribute(TmfXmlStrings
.VALUE
);
124 * Get the list of analysis IDs this view is for, as listed in the header of
128 * The XML view element from which to get the analysis IDs
129 * @return The list of all analysis IDs this view is for
131 public Set
<String
> getViewAnalysisIds(Element viewElement
) {
132 List
<Element
> heads
= XmlUtils
.getChildElements(viewElement
, TmfXmlStrings
.HEAD
);
134 Set
<String
> analysisIds
= new HashSet
<>();
135 if (!heads
.isEmpty()) {
136 Element head
= heads
.get(0);
138 /* Get the application analysis from the view's XML header */
139 List
<Element
> applicableAnalysis
= XmlUtils
.getChildElements(head
, TmfXmlStrings
.ANALYSIS
);
140 for (Element oneAnalysis
: applicableAnalysis
) {
141 analysisIds
.add(oneAnalysis
.getAttribute(TmfXmlStrings
.ID
));