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
;
18 import java
.util
.concurrent
.CountDownLatch
;
20 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
21 import org
.eclipse
.jdt
.annotation
.Nullable
;
22 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
25 import org
.eclipse
.tracecompass
.internal
.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
extends AbstractXmlViewInfo
{
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 /* Initialization is completed when name is set */
40 private final CountDownLatch fInitialized
= new CountDownLatch(1);
41 /** This is the ID of the view described in the XML file */
42 private @Nullable String fId
= null;
43 private @Nullable String fFilePath
= null;
44 // If true, properties were set but not saved to persistent storage
45 private boolean fIsDirty
= false;
53 public XmlViewInfo(String viewId
) {
55 /* Cannot get the properties yet, need to wait for the name */
59 * Waits for the view info's initialization to be completed. This happens
60 * once the name has been set
62 * @return Whether the initialization has completed successfully
64 public boolean waitForInitialization() {
67 } catch (InterruptedException e
) {
74 * Set the data for this view and retrieves from it the view ID and the file
75 * path of the XML element this view uses.
78 * A string of the form "XML view ID" +
79 * {@link TmfXmlAnalysisOutputSource#DATA_SEPARATOR} +
80 * "path of the file containing the XML element"
83 public synchronized void setViewData(String data
) {
84 String
[] idFile
= data
.split(TmfXmlAnalysisOutputSource
.DATA_SEPARATOR
);
85 fId
= (idFile
.length
> 0) ? idFile
[0] : null;
86 fFilePath
= (idFile
.length
> 1) ? idFile
[1] : null;
87 String viewName
= getName();
88 if (viewName
!= null) {
96 public synchronized void setName(String name
) {
101 IDialogSettings settings
= getPersistentPropertyStore();
102 fId
= settings
.get(XML_VIEW_ID_PROPERTY
);
103 fFilePath
= settings
.get(XML_VIEW_FILE_PROPERTY
);
105 fInitialized
.countDown();
109 protected void savePersistentData() {
110 IDialogSettings settings
= getPersistentPropertyStore();
112 settings
.put(XML_VIEW_ID_PROPERTY
, fId
);
113 settings
.put(XML_VIEW_FILE_PROPERTY
, fFilePath
);
117 * Retrieve the XML element corresponding to the view
120 * The XML tag corresponding to the view element (the type of
122 * @return The view {@link Element}
124 public @Nullable Element
getViewElement(String xmlTag
) {
129 Element viewElement
= XmlUtils
.getElementInFile(fFilePath
, xmlTag
, id
);
134 * Get the view title from the header information of the XML view element.
137 * The XML view element from which to get the title
138 * @return The view title
140 public @Nullable String
getViewTitle(Element viewElement
) {
141 List
<Element
> heads
= XmlUtils
.getChildElements(viewElement
, TmfXmlStrings
.HEAD
);
144 if (!heads
.isEmpty()) {
145 Element head
= heads
.get(0);
146 /* Set the title of this view from the label in the header */
147 List
<Element
> labels
= XmlUtils
.getChildElements(head
, TmfXmlStrings
.LABEL
);
148 for (Element label
: labels
) {
149 if (!label
.getAttribute(TmfXmlStrings
.VALUE
).isEmpty()) {
150 title
= label
.getAttribute(TmfXmlStrings
.VALUE
);
159 * Get the list of analysis IDs this view is for, as listed in the header of
163 * The XML view element from which to get the analysis IDs
164 * @return The list of all analysis IDs this view is for
166 public Set
<String
> getViewAnalysisIds(Element viewElement
) {
167 List
<Element
> heads
= XmlUtils
.getChildElements(viewElement
, TmfXmlStrings
.HEAD
);
169 Set
<String
> analysisIds
= new HashSet
<>();
170 if (!heads
.isEmpty()) {
171 Element head
= heads
.get(0);
173 /* Get the application analysis from the view's XML header */
174 List
<Element
> applicableAnalysis
= XmlUtils
.getChildElements(head
, TmfXmlStrings
.ANALYSIS
);
175 for (Element oneAnalysis
: applicableAnalysis
) {
176 analysisIds
.add(oneAnalysis
.getAttribute(TmfXmlStrings
.ID
));