--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.eclipse.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Thu Jul 29 10:54:11 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
--- /dev/null
+#Thu Jul 29 11:00:39 CEST 2010
+eclipse.preferences.version=1
+resolve.requirebundle=false
--- /dev/null
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Argeo Eclipse UI
+Bundle-SymbolicName: org.argeo.eclipse.ui
+Bundle-Version: 0.2.1.SNAPSHOT
+Bundle-Activator: org.argeo.eclipse.ui.ArgeoUiPlugin
+Bundle-Vendor: Argeo
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Import-Package: org.springframework.beans.factory;version="2.5.6.SEC01",
+ org.springframework.context;version="2.5.6.SEC01",
+ org.springframework.core.io.support;version="2.5.6.SEC01"
+Export-Package: org.argeo.eclipse.spring,
+ org.argeo.eclipse.ui
--- /dev/null
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .
--- /dev/null
+package org.argeo.eclipse.spring;\r
+\r
+import static java.text.MessageFormat.format;\r
+\r
+import org.osgi.framework.Bundle;\r
+import org.osgi.framework.BundleContext;\r
+import org.osgi.framework.FrameworkUtil;\r
+import org.osgi.framework.InvalidSyntaxException;\r
+import org.osgi.util.tracker.ServiceTracker;\r
+import org.springframework.context.ApplicationContext;\r
+\r
+/**\r
+ * @author Heiko Seeberger\r
+ */\r
+public class ApplicationContextTracker {\r
+\r
+ private static final String FILTER = "(&(objectClass=org.springframework.context.ApplicationContext)" //$NON-NLS-1$\r
+ + "(org.springframework.context.service.name={0}))"; //$NON-NLS-1$\r
+\r
+ private ServiceTracker applicationContextServiceTracker;\r
+\r
+ /**\r
+ * @param contributorBundle\r
+ * OSGi bundle for which the Spring application context is to be\r
+ * tracked. Must not be null!\r
+ * @param factoryBundleContext\r
+ * BundleContext object which can be used to track services\r
+ * @throws IllegalArgumentException\r
+ * if the given bundle is null.\r
+ */\r
+ public ApplicationContextTracker(final Bundle contributorBundle, final BundleContext factoryBundleContext) {\r
+ final String filter = format(FILTER, contributorBundle.getSymbolicName());\r
+ try {\r
+ applicationContextServiceTracker = new ServiceTracker(\r
+ factoryBundleContext, FrameworkUtil.createFilter(filter), null);\r
+ applicationContextServiceTracker.open();\r
+ } catch (final InvalidSyntaxException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public void close() {\r
+ if (applicationContextServiceTracker != null) {\r
+ applicationContextServiceTracker.close();\r
+ }\r
+ }\r
+\r
+ public ApplicationContext getApplicationContext() {\r
+ ApplicationContext applicationContext = null;\r
+ if (applicationContextServiceTracker != null) {\r
+ try {\r
+ applicationContext = (ApplicationContext) applicationContextServiceTracker\r
+ .waitForService(5000);\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return applicationContext;\r
+ }\r
+\r
+ @Override\r
+ protected void finalize() throws Throwable {\r
+ close();\r
+ super.finalize();\r
+ }\r
+}\r
--- /dev/null
+package org.argeo.eclipse.spring;\r
+\r
+import org.argeo.eclipse.ui.ArgeoUiPlugin;\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IConfigurationElement;\r
+import org.eclipse.core.runtime.IExecutableExtension;\r
+import org.eclipse.core.runtime.IExecutableExtensionFactory;\r
+import org.eclipse.core.runtime.IExtension;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.osgi.framework.Bundle;\r
+import org.osgi.framework.BundleException;\r
+import org.springframework.context.ApplicationContext;\r
+\r
+/**\r
+ * The Spring Extension Factory builds a bridge between the Eclipse Extension\r
+ * Registry and the Spring Framework (especially Spring Dynamic Modules).\r
+ * \r
+ * It allows you to define your extension as a spring bean within the spring\r
+ * application context of your bundle. If you would like to use this bean as an\r
+ * instance of an extension (an Eclipse RCP view, for example) you define the\r
+ * extension with this spring extension factory as the class to be created.\r
+ * \r
+ * To let the spring extension factory pick the right bean from your application\r
+ * context you need to set the bean id to the same value as the id of the view\r
+ * within the view definition, for example. This is important if your extension\r
+ * definition contains more than one element, where each element has its own id.\r
+ * \r
+ * If the extension definition elements themselves have no id attribute the\r
+ * spring extension factory uses the id of the extension itself to identify the\r
+ * bean.\r
+ * \r
+ * @author Martin Lippert\r
+ */\r
+public class SpringExtensionFactory implements IExecutableExtensionFactory,\r
+ IExecutableExtension {\r
+\r
+ private Object bean;\r
+\r
+ public Object create() throws CoreException {\r
+ return bean;\r
+ }\r
+\r
+ public void setInitializationData(IConfigurationElement config,\r
+ String propertyName, Object data) throws CoreException {\r
+ String beanName = getBeanName(data, config);\r
+ ApplicationContext appContext = getApplicationContext(config);\r
+\r
+ if (beanName != null && appContext != null) {\r
+ this.bean = appContext.getBean(beanName);\r
+ if (this.bean instanceof IExecutableExtension) {\r
+ ((IExecutableExtension) this.bean).setInitializationData(\r
+ config, propertyName, data);\r
+ }\r
+ }\r
+ }\r
+\r
+ private String getBeanName(Object data, IConfigurationElement config) {\r
+ \r
+ // try the specific bean id the extension defines\r
+ if (data != null && data.toString().length() > 0) {\r
+ return data.toString();\r
+ }\r
+\r
+ // try the id of the config element\r
+ if (config.getAttribute("id") != null) {\r
+ return config.getAttribute("id");\r
+ }\r
+\r
+ // try the id of the extension element itself\r
+ if (config.getParent() != null\r
+ && config.getParent() instanceof IExtension) {\r
+ IExtension extensionDefinition = (IExtension) config.getParent();\r
+ return extensionDefinition.getSimpleIdentifier();\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ private ApplicationContext getApplicationContext(\r
+ IConfigurationElement config) {\r
+ String contributorName = config.getContributor().getName();\r
+ Bundle contributorBundle = Platform.getBundle(contributorName);\r
+\r
+ if (contributorBundle.getState() != Bundle.ACTIVE && contributorBundle.getState() != Bundle.STARTING) {\r
+ try {\r
+ System.out.println("starting bundle: " + contributorBundle.getSymbolicName());\r
+ contributorBundle.start();\r
+ } catch (BundleException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker(\r
+ contributorBundle, ArgeoUiPlugin.getDefault().getBundleContext());\r
+ ApplicationContext applicationContext = null;\r
+ try {\r
+ applicationContext = applicationContextTracker\r
+ .getApplicationContext();\r
+ } finally {\r
+ applicationContextTracker.close();\r
+ }\r
+ return applicationContext;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.argeo.eclipse.ui;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ArgeoUiPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.argeo.eclipse.ui";
+
+ private final static String SPRING_OSGI_EXTENDER = "org.springframework.osgi.extender";
+
+ // The shared instance
+ private static ArgeoUiPlugin plugin;
+
+ private BundleContext bundleContext;
+
+ /**
+ * The constructor
+ */
+ public ArgeoUiPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ bundleContext = context;
+
+ // Make sure that the Spring OSGi extender is started
+ Bundle osgiExtBundle = Platform.getBundle(SPRING_OSGI_EXTENDER);
+ if (osgiExtBundle != null)
+ osgiExtBundle.start();
+ else
+ throw new Exception("Spring OSGi Extender not found");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static ArgeoUiPlugin getDefault() {
+ return plugin;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+}
--- /dev/null
+package org.argeo.eclipse.ui;
+
+public class TreeObject {
+ private String name;
+ private TreeParent parent;
+
+ public TreeObject(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setParent(TreeParent parent) {
+ this.parent = parent;
+ }
+
+ public TreeParent getParent() {
+ return parent;
+ }
+
+ public String toString() {
+ return getName();
+ }
+}
--- /dev/null
+package org.argeo.eclipse.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TreeParent extends TreeObject {
+ private List<TreeObject> children;
+
+ private boolean loaded;
+
+ public TreeParent(String name) {
+ super(name);
+ children = new ArrayList<TreeObject>();
+ loaded = false;
+ }
+
+ public synchronized void addChild(TreeObject child) {
+ loaded = true;
+ children.add(child);
+ child.setParent(this);
+ }
+
+ public synchronized void removeChild(TreeObject child) {
+ children.remove(child);
+ child.setParent(null);
+ }
+
+ public synchronized void clearChildren() {
+ loaded = false;
+ children.clear();
+ }
+
+ public synchronized TreeObject[] getChildren() {
+ return (TreeObject[]) children.toArray(new TreeObject[children.size()]);
+ }
+
+ public synchronized boolean hasChildren() {
+ return children.size() > 0;
+ }
+
+ public synchronized Boolean isLoaded() {
+ return loaded;
+ }
+}