Commit | Line | Data |
---|---|---|
c068a752 GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 École Polytechnique de Montréal | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
14 | ||
15 | import java.util.ArrayList; | |
16 | import java.util.List; | |
17 | ||
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; | |
28 | ||
29 | /** | |
30 | * Class for project elements of type analysis modules | |
31 | * | |
32 | * @author Geneviève Bastien | |
33 | * @since 3.0 | |
34 | */ | |
35 | public class TmfAnalysisElement extends TmfProjectModelElement { | |
36 | ||
37 | private final String fAnalysisId; | |
38 | ||
39 | /** | |
40 | * Constructor | |
41 | * | |
42 | * @param name | |
43 | * Name of the analysis | |
44 | * @param resource | |
45 | * The resource | |
46 | * @param parent | |
47 | * Parent of the analysis | |
48 | * @param id | |
49 | * The analysis module id | |
50 | */ | |
51 | protected TmfAnalysisElement(String name, IResource resource, ITmfProjectModelElement parent, String id) { | |
52 | super(name, resource, parent); | |
53 | fAnalysisId = id; | |
54 | refreshOutputs(); | |
55 | } | |
56 | ||
57 | private void refreshOutputs() { | |
58 | List<TmfAnalysisOutputElement> outputs = getAvailableOutputs(); | |
59 | ||
60 | /* Remove children */ | |
61 | getChildren().clear(); | |
62 | ||
63 | /* Add the children again */ | |
64 | for (TmfAnalysisOutputElement module : outputs) { | |
65 | addChild(module); | |
66 | } | |
67 | ||
68 | } | |
69 | ||
70 | /** | |
71 | * Get the list of analysis elements | |
72 | * | |
73 | * @return Array of analysis elements | |
74 | */ | |
75 | public List<TmfAnalysisOutputElement> getAvailableOutputs() { | |
76 | List<TmfAnalysisOutputElement> list = new ArrayList<TmfAnalysisOutputElement>(); | |
77 | ||
78 | IAnalysisModuleHelper helper = TmfAnalysisManager.getAnalysisModule(fAnalysisId); | |
79 | if (helper == null) { | |
80 | return list; | |
81 | } | |
82 | ||
83 | /** Get base path for resource */ | |
84 | IPath path = getProject().getTracesFolder().getPath(); | |
85 | if (fResource instanceof IFolder) { | |
86 | path = ((IFolder) fResource).getFullPath(); | |
87 | } | |
88 | ||
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(); | |
93 | if (trace == null) { | |
94 | return list; | |
95 | } | |
96 | ||
97 | IAnalysisModule module = trace.getAnalysisModule(fAnalysisId); | |
98 | if (module == null) { | |
99 | return list; | |
100 | } | |
101 | ||
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); | |
106 | list.add(out); | |
107 | } | |
108 | } | |
109 | } | |
110 | return list; | |
111 | } | |
112 | ||
113 | @Override | |
114 | public TmfProjectElement getProject() { | |
115 | return getParent().getProject(); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Gets the analysis id of this module | |
120 | * | |
121 | * @return The analysis id | |
122 | */ | |
123 | public String getAnalysisId() { | |
124 | return fAnalysisId; | |
125 | } | |
126 | ||
127 | /** | |
128 | * Gets the help message for this analysis | |
129 | * | |
130 | * @return The help message | |
131 | */ | |
132 | public String getHelpMessage() { | |
133 | IAnalysisModuleHelper helper = TmfAnalysisManager.getAnalysisModule(fAnalysisId); | |
134 | if (helper == null) { | |
135 | return new String(); | |
136 | } | |
137 | ||
138 | return helper.getHelpText(); | |
139 | } | |
140 | ||
141 | /** | |
142 | * Gets the icon file name for the analysis | |
143 | * | |
144 | * @return The analysis icon file name | |
145 | */ | |
146 | public String getIconFile() { | |
147 | IAnalysisModuleHelper helper = TmfAnalysisManager.getAnalysisModule(fAnalysisId); | |
148 | if (helper == null) { | |
149 | return null; | |
150 | } | |
151 | return helper.getIcon(); | |
152 | } | |
153 | ||
154 | /** | |
155 | * Gets the bundle this analysis is from | |
156 | * | |
157 | * @return The analysis bundle | |
158 | */ | |
159 | public Bundle getBundle() { | |
160 | IAnalysisModuleHelper helper = TmfAnalysisManager.getAnalysisModule(fAnalysisId); | |
161 | if (helper == null) { | |
162 | return null; | |
163 | } | |
164 | return helper.getBundle(); | |
165 | } | |
166 | ||
167 | /** | |
168 | * Make sure the trace this analysis is associated to is the currently selected one | |
169 | */ | |
170 | public void activateParent() { | |
171 | ITmfProjectModelElement parent = getParent(); | |
172 | ||
173 | if (parent instanceof TmfTraceElement) { | |
174 | TmfTraceElement traceElement = (TmfTraceElement) parent; | |
175 | TmfOpenTraceHelper.openTraceFromElement(traceElement); | |
176 | } | |
177 | } | |
178 | } |