1 | package de.uka.ipd.sdq.sensorframework.visualisation.menu; |
2 | |
3 | import java.util.ArrayList; |
4 | |
5 | import org.eclipse.core.runtime.IConfigurationElement; |
6 | import org.eclipse.core.runtime.Platform; |
7 | import org.eclipse.jface.action.ActionContributionItem; |
8 | import org.eclipse.jface.action.IContributionItem; |
9 | import org.eclipse.ui.actions.CompoundContributionItem; |
10 | |
11 | import de.uka.ipd.sdq.sensorframework.adapter.AdapterRegistry; |
12 | import de.uka.ipd.sdq.sensorframework.adapter.IAdapterFactory; |
13 | |
14 | |
15 | /** |
16 | * A compound contribution is a contribution item consisting of a dynamic list |
17 | * of contribution items. |
18 | */ |
19 | public class VisualisationMenuItemContributions extends CompoundContributionItem { |
20 | |
21 | /* (non-Javadoc) |
22 | * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() |
23 | */ |
24 | @Override |
25 | public IContributionItem[] getContributionItems() { |
26 | ArrayList<IContributionItem> items = new ArrayList<IContributionItem>(); |
27 | for(IConfigurationElement configurationElement : Platform.getExtensionRegistry(). |
28 | getConfigurationElementsFor("de.uka.ipd.sdq.sensorframework.visualisation")){ |
29 | String executableObject = configurationElement.getAttribute("acceptsData"); |
30 | try { |
31 | Class<?> viewerAcceptsClass = Class.forName(executableObject); |
32 | for (IAdapterFactory f : AdapterRegistry.singleton().getAllAvailableFactories(viewerAcceptsClass)) { |
33 | String displayName = configurationElement.getAttribute("displayName"); |
34 | displayName = displayName.replace("{0}", f.getMetricLabel()); |
35 | items.add(new ActionContributionItem( |
36 | new OpenAction(displayName, |
37 | f.getAdapterFactoryID(), |
38 | configurationElement.getAttribute("editorID")))); |
39 | } |
40 | } catch (Exception e) { |
41 | e.printStackTrace(); |
42 | } |
43 | } |
44 | return items.toArray(new IContributionItem[]{}); |
45 | } |
46 | |
47 | public VisualisationMenuItemContributions() { |
48 | // TODO Auto-generated constructor stub |
49 | } |
50 | |
51 | public VisualisationMenuItemContributions(String id) { |
52 | super(id); |
53 | // TODO Auto-generated constructor stub |
54 | } |
55 | } |