1 /*******************************************************************************
2 * Copyright (c) 2013 É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
.linuxtools
.tmf
.ui
.project
.model
;
15 import java
.util
.ArrayList
;
16 import java
.util
.HashMap
;
17 import java
.util
.List
;
20 import org
.eclipse
.core
.resources
.IFolder
;
21 import org
.eclipse
.core
.resources
.IResource
;
22 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
23 import org
.eclipse
.core
.runtime
.IPath
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModule
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisOutput
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisManager
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
29 import org
.osgi
.framework
.Bundle
;
32 * Class for project elements of type analysis modules
34 * @author Geneviève Bastien
37 public class TmfAnalysisElement
extends TmfProjectModelElement
{
39 private final String fAnalysisId
;
45 * Name of the analysis
49 * Parent of the analysis
51 * The analysis module id
53 protected TmfAnalysisElement(String name
, IResource resource
, ITmfProjectModelElement parent
, String id
) {
54 super(name
, resource
, parent
);
56 parent
.addChild(this);
59 // ------------------------------------------------------------------------
60 // TmfProjectModelElement
61 // ------------------------------------------------------------------------
64 void refreshChildren() {
65 /* Refresh the outputs of this analysis */
66 Map
<String
, TmfAnalysisOutputElement
> childrenMap
= new HashMap
<>();
67 for (TmfAnalysisOutputElement output
: getAvailableOutputs()) {
68 childrenMap
.put(output
.getName(), output
);
71 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
77 /** Get base path for resource */
78 IPath path
= getProject().getTracesFolder().getPath();
79 if (fResource
instanceof IFolder
) {
80 path
= ((IFolder
) fResource
).getFullPath();
84 * We can get a list of available outputs once the analysis is
85 * instantiated when the trace is opened
87 ITmfProjectModelElement parent
= getParent();
88 if (parent
instanceof TmfTraceElement
) {
89 ITmfTrace trace
= ((TmfTraceElement
) parent
).getTrace();
95 IAnalysisModule module
= trace
.getAnalysisModule(fAnalysisId
);
101 for (IAnalysisOutput output
: module
.getOutputs()) {
102 TmfAnalysisOutputElement outputElement
= childrenMap
.remove(output
.getName());
103 if (outputElement
== null) {
104 IFolder newresource
= ResourcesPlugin
.getWorkspace().getRoot().getFolder(path
.append(output
.getName()));
105 outputElement
= new TmfAnalysisOutputElement(output
.getName(), newresource
, this, output
);
107 outputElement
.refreshChildren();
110 /* Remove outputs that are not children of this analysis anymore */
111 for (TmfAnalysisOutputElement output
: childrenMap
.values()) {
116 // ------------------------------------------------------------------------
118 // ------------------------------------------------------------------------
121 * Get the list of analysis output model elements under this analysis
123 * @return Array of analysis output elements
125 public List
<TmfAnalysisOutputElement
> getAvailableOutputs() {
126 List
<ITmfProjectModelElement
> children
= getChildren();
127 List
<TmfAnalysisOutputElement
> outputs
= new ArrayList
<>();
128 for (ITmfProjectModelElement child
: children
) {
129 if (child
instanceof TmfAnalysisOutputElement
) {
130 outputs
.add((TmfAnalysisOutputElement
) child
);
137 public TmfProjectElement
getProject() {
138 return getParent().getProject();
142 * Gets the analysis id of this module
144 * @return The analysis id
146 public String
getAnalysisId() {
151 * Gets the help message for this analysis
153 * @return The help message
155 public String
getHelpMessage() {
156 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
157 if (helper
== null) {
161 return helper
.getHelpText();
165 * Gets the icon file name for the analysis
167 * @return The analysis icon file name
169 public String
getIconFile() {
170 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
171 if (helper
== null) {
174 return helper
.getIcon();
178 * Gets the bundle this analysis is from
180 * @return The analysis bundle
182 public Bundle
getBundle() {
183 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
184 if (helper
== null) {
187 return helper
.getBundle();
190 /** Delete all outputs under this analysis element */
191 private void deleteOutputs() {
192 for (TmfAnalysisOutputElement output
: getAvailableOutputs()) {
198 * Make sure the trace this analysis is associated to is the currently
201 public void activateParent() {
202 ITmfProjectModelElement parent
= getParent();
204 if (parent
instanceof TmfTraceElement
) {
205 TmfTraceElement traceElement
= (TmfTraceElement
) parent
;
206 TmfOpenTraceHelper
.openTraceFromElement(traceElement
);