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
.List
;
18 import org
.eclipse
.core
.resources
.IFolder
;
19 import org
.eclipse
.core
.resources
.IResource
;
20 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
21 import org
.eclipse
.core
.runtime
.IPath
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModule
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisOutput
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisManager
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.osgi
.framework
.Bundle
;
30 * Class for project elements of type analysis modules
32 * @author Geneviève Bastien
35 public class TmfAnalysisElement
extends TmfProjectModelElement
{
37 private final String fAnalysisId
;
43 * Name of the analysis
47 * Parent of the analysis
49 * The analysis module id
51 protected TmfAnalysisElement(String name
, IResource resource
, ITmfProjectModelElement parent
, String id
) {
52 super(name
, resource
, parent
);
57 private void refreshOutputs() {
58 List
<TmfAnalysisOutputElement
> outputs
= getAvailableOutputs();
61 getChildren().clear();
63 /* Add the children again */
64 for (TmfAnalysisOutputElement module
: outputs
) {
71 * Get the list of analysis elements
73 * @return Array of analysis elements
75 public List
<TmfAnalysisOutputElement
> getAvailableOutputs() {
76 List
<TmfAnalysisOutputElement
> list
= new ArrayList
<TmfAnalysisOutputElement
>();
78 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
83 /** Get base path for resource */
84 IPath path
= getProject().getTracesFolder().getPath();
85 if (fResource
instanceof IFolder
) {
86 path
= ((IFolder
) fResource
).getFullPath();
89 /* We can get a list of available outputs once the analysis is instantiated when the trace is opened */
90 ITmfProjectModelElement parent
= getParent();
91 if (parent
instanceof TmfTraceElement
) {
92 ITmfTrace trace
= ((TmfTraceElement
) parent
).getTrace();
97 IAnalysisModule module
= trace
.getAnalysisModule(fAnalysisId
);
102 for (IAnalysisOutput output
: module
.getOutputs()) {
103 if (fResource
instanceof IFolder
) {
104 IFolder newresource
= ResourcesPlugin
.getWorkspace().getRoot().getFolder(path
.append(output
.getName()));
105 TmfAnalysisOutputElement out
= new TmfAnalysisOutputElement(output
.getName(), newresource
, this, output
);
114 public TmfProjectElement
getProject() {
115 return getParent().getProject();
119 * Gets the analysis id of this module
121 * @return The analysis id
123 public String
getAnalysisId() {
128 * Gets the help message for this analysis
130 * @return The help message
132 public String
getHelpMessage() {
133 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
134 if (helper
== null) {
138 return helper
.getHelpText();
142 * Gets the icon file name for the analysis
144 * @return The analysis icon file name
146 public String
getIconFile() {
147 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
148 if (helper
== null) {
151 return helper
.getIcon();
155 * Gets the bundle this analysis is from
157 * @return The analysis bundle
159 public Bundle
getBundle() {
160 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(fAnalysisId
);
161 if (helper
== null) {
164 return helper
.getBundle();
168 * Make sure the trace this analysis is associated to is the currently selected one
170 public void activateParent() {
171 ITmfProjectModelElement parent
= getParent();
173 if (parent
instanceof TmfTraceElement
) {
174 TmfTraceElement traceElement
= (TmfTraceElement
) parent
;
175 TmfOpenTraceHelper
.openTraceFromElement(traceElement
);