1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast;
19
20 import java.util.Arrays;
21 import java.util.LinkedList;
22 import java.util.List;
23
24 import org.apache.log4j.ConsoleAppender;
25 import org.apache.log4j.Logger;
26 import org.apache.log4j.PatternLayout;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.core.runtime.IConfigurationElement;
29 import org.eclipse.core.runtime.IPath;
30 import org.eclipse.core.runtime.Platform;
31 import org.eclipse.jface.resource.ImageDescriptor;
32 import org.eclipse.ui.plugin.AbstractUIPlugin;
33 import org.osgi.framework.BundleContext;
34
35 import pl.edu.agh.cast.data.converter.ConverterReference;
36 import pl.edu.agh.cast.data.converter.ConverterSpecification;
37 import pl.edu.agh.cast.resource.IVisualResource;
38 import pl.edu.agh.cast.resource.IVisualResourcesProvider;
39 import pl.edu.agh.cast.util.Configuration;
40 import pl.edu.agh.cast.util.logging.LoggingUtil;
41
42
43
44
45
46
47 public class Activator extends AbstractUIPlugin {
48
49
50
51
52 public static final String PLUGIN_ID = "pl.edu.agh.cast";
53
54
55
56
57 public static final String STD_OUT_ERR_FILE = ".stdouterr";
58
59
60
61
62 public static final String NO_STD_OUT_ERR_REDIRECT = "-nostdouterr";
63
64 private static final String STATISTIC_EXTENSION_ID = "pl.edu.agh.cast.statistics";
65
66
67
68
69 public static final String STATISTIC_NAME = "name";
70
71
72
73
74 public static final String STATISTIC_CLASS = "point";
75
76
77
78
79 public static final String STATISTIC_TARGET_LABEL = "target_label";
80
81
82
83
84 public static final String STATISTIC_SOURCE_LABEL = "source_label";
85
86
87
88
89 public static final String STATISTIC_DESCRIPTION = "description";
90
91 private static final String NODE_ICON_EXTENSION_ID = "pl.edu.agh.cast.nodeIcons";
92
93
94
95
96 public static final String NODE_ICON_FACTORY = "factory";
97
98
99
100
101 private static final String RESOURCES_PROVIDER_EXTENSION_ID = "pl.edu.agh.cast.resource.provider";
102
103
104
105
106 private static final String RESOURCES_PROVIDER_CLASS = "point";
107
108
109
110
111
112
113 public static final String RESOURCE_TAG_EDITOR = "EditorIcon";
114
115
116
117
118
119
120 public static final String RESOURCE_TAG_DATA_MODEL = "DataModelIcon";
121
122
123
124
125 private static final String DS_CONVERTER_EXTENSION_ID = "pl.edu.agh.cast.data.converter";
126
127
128
129
130 private static final String DS_CONVERTER_SPECIFICATION_CLASS = "specification";
131
132
133
134
135 private static final String DS_CONVERTER_SPECIFICATION_NAME = "name";
136
137
138
139
140 private static final String DS_CONVERTER_SPECIFICATION_DESCRIPTION = "description";
141
142
143 private static Activator plugin;
144
145
146 private static Logger log;
147
148
149
150
151 public Activator() {
152 plugin = this;
153
154 if (!Arrays.asList(Platform.getApplicationArgs()).contains(NO_STD_OUT_ERR_REDIRECT)) {
155 try {
156 IPath stdPath = Platform.getLocation().append(".metadata").append(STD_OUT_ERR_FILE);
157 LoggingUtil.rebindStdOutErr(stdPath.toFile());
158 } catch (Exception e) {
159 getLogger().error("Failed to rebind standard output and error streams", e);
160 }
161 }
162 }
163
164
165
166
167
168
169 public static Logger getLogger() {
170 if (log == null) {
171 Configuration.getInstance();
172 log = Logger.getLogger(Activator.class);
173
174 if (!log.getAllAppenders().hasMoreElements()) {
175
176 log.addAppender(new ConsoleAppender(new PatternLayout("%5p [%t] (%F:%L) - %m%n")));
177 }
178 }
179 return log;
180 }
181
182
183
184
185
186
187 @Override
188 public void start(BundleContext context) throws Exception {
189 super.start(context);
190 }
191
192
193
194
195
196
197 @Override
198 public void stop(BundleContext context) throws Exception {
199 plugin = null;
200 super.stop(context);
201 }
202
203
204
205
206
207
208 public static Activator getDefault() {
209 return plugin;
210 }
211
212
213
214
215
216
217
218
219 public static ImageDescriptor getImageDescriptor(String path) {
220 return imageDescriptorFromPlugin(PLUGIN_ID, path);
221 }
222
223
224
225
226
227
228 public static IConfigurationElement[] getStatisticsConfigurations() {
229 return Platform.getExtensionRegistry().getConfigurationElementsFor(STATISTIC_EXTENSION_ID);
230 }
231
232
233
234
235
236
237 public static IConfigurationElement[] getNodeIconsConfigurations() {
238 return Platform.getExtensionRegistry().getConfigurationElementsFor(NODE_ICON_EXTENSION_ID);
239 }
240
241
242
243
244
245
246
247
248 public static List<IVisualResourcesProvider> getResourcesProviders() {
249
250 IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
251 RESOURCES_PROVIDER_EXTENSION_ID);
252
253 List<IVisualResourcesProvider> providers = new LinkedList<IVisualResourcesProvider>();
254
255 for (IConfigurationElement element : elements) {
256 try {
257 providers.add((IVisualResourcesProvider)element.createExecutableExtension(RESOURCES_PROVIDER_CLASS));
258 } catch (CoreException e) {
259 log.warn(String.format("Failed to instantiate IVisualResourceProvider provided by extension: %1$s ",
260 element.getDeclaringExtension().getUniqueIdentifier()), e);
261 continue;
262 }
263 }
264 return providers;
265 }
266
267
268
269
270
271
272
273 public static List<ConverterReference> getDataSetConverterReferences() {
274
275 IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
276 DS_CONVERTER_EXTENSION_ID);
277
278 List<ConverterReference> references = new LinkedList<ConverterReference>();
279
280 for (IConfigurationElement element : elements) {
281 ConverterReference reference = new ConverterReference();
282 reference.setName(element.getAttribute(DS_CONVERTER_SPECIFICATION_NAME));
283 reference.setDescription(element.getAttribute(DS_CONVERTER_SPECIFICATION_DESCRIPTION));
284 try {
285 reference.setSpecification((ConverterSpecification)element
286 .createExecutableExtension(DS_CONVERTER_SPECIFICATION_CLASS));
287 } catch (CoreException e) {
288 log.warn(String.format("Failed to instantiate ConverterSpecification provided by extension: %1$s ",
289 element.getDeclaringExtension().getUniqueIdentifier()), e);
290 continue;
291 }
292 references.add(reference);
293 }
294 return references;
295 }
296
297 }