]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/SlcLaunchShortcut.java
Improve JCR
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / osgi / SlcLaunchShortcut.java
1 package org.argeo.slc.ide.ui.launch.osgi;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.Iterator;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.eclipse.core.resources.IProject;
10 import org.eclipse.core.runtime.Assert;
11 import org.eclipse.jface.viewers.ISelection;
12 import org.eclipse.jface.viewers.IStructuredSelection;
13 import org.eclipse.osgi.service.resolver.BundleDescription;
14 import org.eclipse.pde.core.plugin.IPluginModelBase;
15 import org.eclipse.pde.core.plugin.PluginRegistry;
16
17 public class SlcLaunchShortcut extends AbstractOsgiLaunchShortcut {
18 private Boolean debug = false;
19
20 private String springOsgiExtenderId = "org.springframework.osgi.extender";
21 private String slcSupportEquinoxId = "org.argeo.slc.support.equinox";
22 // private String slcAgentId = "org.argeo.slc.agent";
23 // private String osgiBootId = "org.argeo.slc.osgiboot";
24
25 private ISelection selection = null;
26
27 private final List<String> defaultBundlesToStart = new ArrayList<String>();
28 public SlcLaunchShortcut() {
29 super();
30 defaultBundlesToStart.add(springOsgiExtenderId);
31 defaultBundlesToStart.add(slcSupportEquinoxId);
32 // defaultBundlesToStart.add(slcAgentId);
33 }
34
35 public void launch(ISelection selection, String mode) {
36 this.selection = selection;
37 this.name = new StringBuffer();
38
39 bundlesToStart = new ArrayList<String>();
40 bundlesToStart.addAll(defaultBundlesToStart);
41 // Evaluate selection
42 if (selection != null) {
43 addSelectedProjects(bundlesToStart);
44 }
45
46 super.launch(selection, mode);
47
48 // Reset
49 this.selection = null;
50 }
51
52 protected void addSelectedProjects(List<String> bundlesToStart) {
53 Assert.isNotNull(selection);
54
55 Map<String, IPluginModelBase> bundleProjects = new HashMap<String, IPluginModelBase>();
56 for (IPluginModelBase modelBase : PluginRegistry.getWorkspaceModels()) {
57 IProject bundleProject = modelBase.getUnderlyingResource()
58 .getProject();
59 bundleProjects.put(bundleProject.getName(), modelBase);
60 }
61
62 IStructuredSelection sSelection = (IStructuredSelection) selection;
63 for (Iterator<?> it = sSelection.iterator(); it.hasNext();) {
64 Object obj = it.next();
65 if (obj instanceof IProject) {
66 IProject project = (IProject) obj;
67 if (bundleProjects.containsKey(project.getName())) {
68 IPluginModelBase modelBase = bundleProjects.get(project
69 .getName());
70
71 BundleDescription bundleDescription = null;
72 if (modelBase.isFragmentModel()) {
73 BundleDescription[] hosts = modelBase
74 .getBundleDescription().getHost().getHosts();
75 for (BundleDescription bd : hosts) {
76 if (debug)
77 System.out.println("Host for "
78 + modelBase.getBundleDescription()
79 .getSymbolicName() + ": "
80 + bd.getSymbolicName());
81 bundleDescription = bd;
82 }
83 } else {
84 bundleDescription = modelBase.getBundleDescription();
85 }
86
87 if (bundleDescription != null) {
88 String symbolicName = bundleDescription
89 .getSymbolicName();
90 String bundleName = bundleDescription.getName();
91
92 bundlesToStart.add(symbolicName);
93
94 if (name.length() > 0)
95 name.append(" ");
96 if (bundleName != null)
97 name.append(bundleName);
98 else
99 name.append(symbolicName);
100 }
101 }
102 }
103 }
104 }
105 }