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
.internal
.tmf
.analysis
.xml
.ui
.Activator
;
23 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
24 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
25 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.module
.TmfXmlAnalysisOutputSource
;
26 import org
.w3c
.dom
.Element
;
29 * Class that manages information about a view: its title, the file, etc.
31 * @author Geneviève Bastien
34 public class XmlViewInfo
{
36 private static final String XML_VIEW_ID_PROPERTY
= "XmlViewId"; //$NON-NLS-1$
37 private static final String XML_VIEW_FILE_PROPERTY
= "XmlViewFile"; //$NON-NLS-1$
39 private final String fViewId
;
40 private @Nullable String fId
= null;
41 private @Nullable String fFilePath
= null;
49 public XmlViewInfo(String viewId
) {
52 IDialogSettings settings
= getPersistentPropertyStore();
54 fId
= settings
.get(XML_VIEW_ID_PROPERTY
);
55 fFilePath
= settings
.get(XML_VIEW_FILE_PROPERTY
);
59 * Set the data for this view and retrieves from it the view ID and the file
60 * path of the XML element this view uses.
63 * A string of the form "XML view ID" +
64 * {@link TmfXmlAnalysisOutputSource#DATA_SEPARATOR} +
65 * "path of the file containing the XML element"
67 public void setViewData(String data
) {
68 String
[] idFile
= data
.split(TmfXmlAnalysisOutputSource
.DATA_SEPARATOR
);
69 fId
= (idFile
.length
> 0) ? idFile
[0] : null;
70 fFilePath
= (idFile
.length
> 1) ? idFile
[1] : null;
74 private IDialogSettings
getPersistentPropertyStore() {
75 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
76 IDialogSettings section
= settings
.getSection(fViewId
);
77 if (section
== null) {
78 section
= settings
.addNewSection(fViewId
);
79 if (section
== null) {
80 throw new IllegalStateException();
86 private void savePersistentData() {
87 IDialogSettings settings
= getPersistentPropertyStore();
89 settings
.put(XML_VIEW_ID_PROPERTY
, fId
);
90 settings
.put(XML_VIEW_FILE_PROPERTY
, fFilePath
);
94 * Retrieve the XML element corresponding to the view
97 * The XML tag corresponding to the view element (the type of
99 * @return The view {@link Element}
101 public @Nullable Element
getViewElement(String xmlTag
) {
106 Element viewElement
= XmlUtils
.getElementInFile(fFilePath
, xmlTag
, id
);
111 * Get the view title from the header information of the XML view element.
114 * The XML view element from which to get the title
115 * @return The view title
117 public @Nullable String
getViewTitle(Element viewElement
) {
118 List
<Element
> heads
= XmlUtils
.getChildElements(viewElement
, TmfXmlStrings
.HEAD
);
121 if (!heads
.isEmpty()) {
122 Element head
= heads
.get(0);
123 /* Set the title of this view from the label in the header */
124 List
<Element
> labels
= XmlUtils
.getChildElements(head
, TmfXmlStrings
.LABEL
);
125 for (Element label
: labels
) {
126 if (!label
.getAttribute(TmfXmlStrings
.VALUE
).isEmpty()) {
127 title
= label
.getAttribute(TmfXmlStrings
.VALUE
);
136 * Get the list of analysis IDs this view is for, as listed in the header of
140 * The XML view element from which to get the analysis IDs
141 * @return The list of all analysis IDs this view is for
143 public Set
<String
> getViewAnalysisIds(Element viewElement
) {
144 List
<Element
> heads
= XmlUtils
.getChildElements(viewElement
, TmfXmlStrings
.HEAD
);
146 Set
<String
> analysisIds
= new HashSet
<>();
147 if (!heads
.isEmpty()) {
148 Element head
= heads
.get(0);
150 /* Get the application analysis from the view's XML header */
151 List
<Element
> applicableAnalysis
= XmlUtils
.getChildElements(head
, TmfXmlStrings
.ANALYSIS
);
152 for (Element oneAnalysis
: applicableAnalysis
) {
153 analysisIds
.add(oneAnalysis
.getAttribute(TmfXmlStrings
.ID
));