1 /*******************************************************************************
2 * Copyright (c) 2013, 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 * Patrick Tasse - Add support for folder elements
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
;
16 import java
.util
.ArrayList
;
17 import java
.util
.HashMap
;
18 import java
.util
.List
;
21 import org
.eclipse
.core
.resources
.IFolder
;
22 import org
.eclipse
.core
.resources
.IResource
;
23 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
24 import org
.eclipse
.core
.runtime
.IPath
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModule
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisOutput
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisManager
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.osgi
.framework
.Bundle
;
33 * Class for project elements of type analysis modules
35 * @author Geneviève Bastien
38 public class TmfAnalysisElement
extends TmfProjectModelElement
{
40 private final String fAnalysisId
;
46 * Name of the analysis
50 * Parent of the analysis
52 * The analysis module id
54 protected TmfAnalysisElement(String name
, IResource resource
, ITmfProjectModelElement parent
, String id
) {
55 super(name
, resource
, parent
);
57 parent
.addChild(this);
60 // ------------------------------------------------------------------------
61 // TmfProjectModelElement
62 // ------------------------------------------------------------------------
65 void refreshChildren() {
66 /* Refresh the outputs of this analysis */
67 Map
<String
, TmfAnalysisOutputElement
> childrenMap
= new HashMap
<>();
68 for (TmfAnalysisOutputElement output
: getAvailableOutputs()) {
69 childrenMap
.put(output
.getName(), output
);
72 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
78 /** Get base path for resource */
79 IPath path
= getProject().getTracesFolder().getPath();
80 if (fResource
instanceof IFolder
) {
81 path
= ((IFolder
) fResource
).getFullPath();
85 * We can get a list of available outputs once the analysis is
86 * instantiated when the trace is opened
88 ITmfProjectModelElement parent
= getParent();
89 if (parent
instanceof TmfCommonProjectElement
) {
90 ITmfTrace trace
= ((TmfCommonProjectElement
) parent
).getTrace();
96 IAnalysisModule module
= trace
.getAnalysisModule(fAnalysisId
);
102 for (IAnalysisOutput output
: module
.getOutputs()) {
103 TmfAnalysisOutputElement outputElement
= childrenMap
.remove(output
.getName());
104 if (outputElement
== null) {
105 IFolder newresource
= ResourcesPlugin
.getWorkspace().getRoot().getFolder(path
.append(output
.getName()));
106 outputElement
= new TmfAnalysisOutputElement(output
.getName(), newresource
, this, output
);
108 outputElement
.refreshChildren();
111 /* Remove outputs that are not children of this analysis anymore */
112 for (TmfAnalysisOutputElement output
: childrenMap
.values()) {
117 // ------------------------------------------------------------------------
119 // ------------------------------------------------------------------------
122 * Get the list of analysis output model elements under this analysis
124 * @return Array of analysis output elements
126 public List
<TmfAnalysisOutputElement
> getAvailableOutputs() {
127 List
<ITmfProjectModelElement
> children
= getChildren();
128 List
<TmfAnalysisOutputElement
> outputs
= new ArrayList
<>();
129 for (ITmfProjectModelElement child
: children
) {
130 if (child
instanceof TmfAnalysisOutputElement
) {
131 outputs
.add((TmfAnalysisOutputElement
) child
);
138 * Gets the analysis id of this module
140 * @return The analysis id
142 public String
getAnalysisId() {
147 * Gets the help message for this analysis
149 * @return The help message
151 public String
getHelpMessage() {
152 ITmfProjectModelElement parent
= getParent();
154 if (parent
instanceof TmfTraceElement
) {
155 TmfTraceElement traceElement
= (TmfTraceElement
) parent
;
156 ITmfTrace trace
= traceElement
.getTrace();
158 IAnalysisModule module
= trace
.getAnalysisModule(fAnalysisId
);
159 if (module
!= null) {
160 return module
.getHelpText();
165 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
166 if (helper
== null) {
170 return helper
.getHelpText();
174 * Gets the icon file name for the analysis
176 * @return The analysis icon file name
178 public String
getIconFile() {
179 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
180 if (helper
== null) {
183 return helper
.getIcon();
187 * Gets the bundle this analysis is from
189 * @return The analysis bundle
191 public Bundle
getBundle() {
192 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
193 if (helper
== null) {
196 return helper
.getBundle();
199 /** Delete all outputs under this analysis element */
200 private void deleteOutputs() {
201 for (TmfAnalysisOutputElement output
: getAvailableOutputs()) {
207 * Make sure the trace this analysis is associated to is the currently
210 public void activateParent() {
211 ITmfProjectModelElement parent
= getParent();
213 if (parent
instanceof TmfTraceElement
) {
214 TmfTraceElement traceElement
= (TmfTraceElement
) parent
;
215 TmfOpenTraceHelper
.openTraceFromElement(traceElement
);