Bundle-SymbolicName: org.argeo.cms.ui.workbench.rap;singleton:=true
Bundle-Activator: org.argeo.security.ui.rap.SecureRapActivator
Bundle-ActivationPolicy: lazy
+
Require-Bundle: org.eclipse.rap.ui,org.eclipse.core.runtime
Import-Package: org.argeo.eclipse.spring,\
Bundle-Activator: org.argeo.security.ui.SecurityUiPlugin
Bundle-ActivationPolicy: lazy
-Require-Bundle: org.eclipse.core.runtime
+Require-Bundle: org.eclipse.core.runtime,\
+org.eclipse.core.commands
Import-Package: org.argeo.cms.auth,\
org.argeo.eclipse.spring,\
org.eclipse.ui.services,\
org.osgi.framework,\
org.springframework.core,\
+org.osgi.util.tracker,\
+org.springframework.beans.factory,\
+org.springframework.core.io.support,\
+!org.eclipse.core.runtime,\
*
--- /dev/null
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.eclipse.spring;\r
+\r
+import static java.text.MessageFormat.format;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.osgi.framework.Bundle;\r
+import org.osgi.framework.BundleContext;\r
+import org.osgi.framework.BundleException;\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
+ * Tracks Spring application context published as services.\r
+ * \r
+ * @author Heiko Seeberger\r
+ * @author Mathieu Baudier\r
+ */\r
+class ApplicationContextTracker {\r
+ private final static Log log = LogFactory\r
+ .getLog(ApplicationContextTracker.class);\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
+ public final static String APPLICATION_CONTEXT_TRACKER_TIMEOUT = "org.argeo.eclipse.spring.applicationContextTrackerTimeout";\r
+\r
+ private static Long defaultTimeout = Long.parseLong(System.getProperty(\r
+ APPLICATION_CONTEXT_TRACKER_TIMEOUT, "30000"));\r
+\r
+ @SuppressWarnings("rawtypes")\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
+ @SuppressWarnings({ "unchecked", "rawtypes" })\r
+ public ApplicationContextTracker(final Bundle contributorBundle,\r
+ final BundleContext factoryBundleContext) {\r
+ final String filter = format(FILTER,\r
+ contributorBundle.getSymbolicName());\r
+ try {\r
+ applicationContextServiceTracker = new ServiceTracker(\r
+ factoryBundleContext, FrameworkUtil.createFilter(filter),\r
+ null);\r
+ // applicationContextServiceTracker.open();\r
+ } catch (final InvalidSyntaxException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public void open() {\r
+ if (applicationContextServiceTracker != null) {\r
+ applicationContextServiceTracker.open();\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(defaultTimeout);\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
+ static ApplicationContext getApplicationContext(String bundleSymbolicName) {\r
+ Bundle contributorBundle = Platform.getBundle(bundleSymbolicName);\r
+ return getApplicationContext(contributorBundle);\r
+ }\r
+\r
+ static ApplicationContext getApplicationContext(\r
+ final Bundle contributorBundle) {\r
+ if (log.isTraceEnabled())\r
+ log.trace("Get application context for bundle " + contributorBundle);\r
+\r
+ // Start if not yet started (also if in STARTING state, may be lazy)\r
+ if (contributorBundle.getState() != Bundle.ACTIVE) {\r
+ if (log.isTraceEnabled())\r
+ log.trace("Starting bundle: "\r
+ + contributorBundle.getSymbolicName());\r
+ // Thread startBundle = new Thread("Start bundle "\r
+ // + contributorBundle.getSymbolicName()) {\r
+ // public void run() {\r
+ try {\r
+ contributorBundle.start();\r
+ } catch (BundleException e) {\r
+ log.error("Cannot start bundle " + contributorBundle, e);\r
+ }\r
+ // }\r
+ // };\r
+ // startBundle.start();\r
+ // try {\r
+ // startBundle.join(10 * 1000l);\r
+ // } catch (InterruptedException e) {\r
+ // // silent\r
+ // }\r
+ }\r
+\r
+ final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker(\r
+ contributorBundle, contributorBundle.getBundleContext());\r
+ ApplicationContext applicationContext = null;\r
+ try {\r
+ applicationContextTracker.open();\r
+ applicationContext = applicationContextTracker\r
+ .getApplicationContext();\r
+ } finally {\r
+ applicationContextTracker.close();\r
+ }\r
+ return applicationContext;\r
+ }\r
+}\r
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.spring;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.eclipse.ui.EclipseUiException;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.springframework.context.ApplicationContext;
+
+/** Allows to declare Eclipse commands as Spring beans */
+public class SpringCommandHandler implements IHandler {
+ private final static Log log = LogFactory
+ .getLog(SpringCommandHandler.class);
+
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public void dispose() {
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String commandId = event.getCommand().getId();
+ String bundleSymbolicName = commandId.substring(0,
+ commandId.lastIndexOf('.'));
+ try {
+ if (log.isTraceEnabled())
+ log.trace("Execute " + event + " via spring command handler "
+ + this);
+ // TODO: make it more flexible and robust
+ ApplicationContext applicationContext = ApplicationContextTracker
+ .getApplicationContext(bundleSymbolicName);
+ if (applicationContext == null)
+ throw new EclipseUiException("No application context found for "
+ + bundleSymbolicName);
+
+ // retrieve the command via its id
+ String beanName = event.getCommand().getId();
+
+ if (!applicationContext.containsBean(beanName)) {
+ if (beanName.startsWith(bundleSymbolicName))
+ beanName = beanName
+ .substring(bundleSymbolicName.length() + 1);
+ }
+
+ if (!applicationContext.containsBean(beanName))
+ throw new ExecutionException("No bean found with name "
+ + beanName + " in bundle " + bundleSymbolicName);
+ Object bean = applicationContext.getBean(beanName);
+
+ if (!(bean instanceof IHandler))
+ throw new ExecutionException("Bean with name " + beanName
+ + " and class " + bean.getClass()
+ + " does not implement the IHandler interface.");
+
+ IHandler handler = (IHandler) bean;
+ return handler.execute(event);
+ } catch (Exception e) {
+ // TODO: use eclipse error management
+ // log.error(e);
+ throw new ExecutionException("Cannot execute Spring command "
+ + commandId + " in bundle " + bundleSymbolicName, e);
+ }
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+}
--- /dev/null
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.eclipse.spring;\r
+\r
+import org.argeo.eclipse.ui.EclipseUiException;\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.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
+ * original code from: <a href=\r
+ * "http://martinlippert.blogspot.com/2008/10/new-version-of-spring-extension-factory.html"\r
+ * >Blog entry</a>\r
+ * \r
+ * @author Martin Lippert\r
+ * @author mbaudier\r
+ */\r
+public class SpringExtensionFactory implements IExecutableExtensionFactory,\r
+ IExecutableExtension {\r
+\r
+ private Object bean;\r
+\r
+ public Object create() throws CoreException {\r
+ if (bean == null)\r
+ throw new EclipseUiException("No underlying bean for extension");\r
+ return bean;\r
+ }\r
+\r
+ public void setInitializationData(IConfigurationElement config,\r
+ String propertyName, Object data) throws CoreException {\r
+ String bundleSymbolicName = config.getContributor().getName();\r
+ ApplicationContext applicationContext = ApplicationContextTracker\r
+ .getApplicationContext(bundleSymbolicName);\r
+ if (applicationContext == null)\r
+ throw new EclipseUiException(\r
+ "Cannot find application context for bundle "\r
+ + bundleSymbolicName);\r
+\r
+ String beanName = getBeanName(data, config);\r
+ if (beanName == null)\r
+ throw new EclipseUiException("Cannot find bean name for extension "\r
+ + config);\r
+\r
+ if (!applicationContext.containsBean(beanName)) {\r
+ if (beanName.startsWith(bundleSymbolicName))\r
+ beanName = beanName.substring(bundleSymbolicName.length() + 1);\r
+ }\r
+\r
+ if (!applicationContext.containsBean(beanName))\r
+ throw new EclipseUiException("No bean with name '" + beanName + "'");\r
+\r
+ this.bean = applicationContext.getBean(beanName);\r
+ if (this.bean instanceof IExecutableExtension) {\r
+ ((IExecutableExtension) this.bean).setInitializationData(config,\r
+ propertyName, data);\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
+}\r
Require-Bundle: org.eclipse.ui;resolution:=optional,\
org.eclipse.core.runtime,\
-org.eclipse.rap.ui;resolution:=optional,\
-org.eclipse.rap.ui.workbench;resolution:=optional
+#org.eclipse.rap.ui;resolution:=optional,\
+#org.eclipse.rap.ui.workbench;resolution:=optional
Import-Package: org.argeo.eclipse.ui.specific,\
org.eclipse.swt.widgets,\
org.osgi.framework,\
org.osgi.service.packageadmin,\
-org.osgi.util.tracker,\
-org.springframework.beans.factory,\
-org.springframework.core.io.support,\
!org.eclipse.core.runtime,\
+org.eclipse.swt,\
+org.eclipse.jface.window,\
*
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.eclipse.spring;\r
-\r
-import static java.text.MessageFormat.format;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.osgi.framework.Bundle;\r
-import org.osgi.framework.BundleContext;\r
-import org.osgi.framework.BundleException;\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
- * Tracks Spring application context published as services.\r
- * \r
- * @author Heiko Seeberger\r
- * @author Mathieu Baudier\r
- */\r
-class ApplicationContextTracker {\r
- private final static Log log = LogFactory\r
- .getLog(ApplicationContextTracker.class);\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
- public final static String APPLICATION_CONTEXT_TRACKER_TIMEOUT = "org.argeo.eclipse.spring.applicationContextTrackerTimeout";\r
-\r
- private static Long defaultTimeout = Long.parseLong(System.getProperty(\r
- APPLICATION_CONTEXT_TRACKER_TIMEOUT, "30000"));\r
-\r
- @SuppressWarnings("rawtypes")\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
- @SuppressWarnings({ "unchecked", "rawtypes" })\r
- public ApplicationContextTracker(final Bundle contributorBundle,\r
- final BundleContext factoryBundleContext) {\r
- final String filter = format(FILTER,\r
- contributorBundle.getSymbolicName());\r
- try {\r
- applicationContextServiceTracker = new ServiceTracker(\r
- factoryBundleContext, FrameworkUtil.createFilter(filter),\r
- null);\r
- // applicationContextServiceTracker.open();\r
- } catch (final InvalidSyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- public void open() {\r
- if (applicationContextServiceTracker != null) {\r
- applicationContextServiceTracker.open();\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(defaultTimeout);\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
- static ApplicationContext getApplicationContext(String bundleSymbolicName) {\r
- Bundle contributorBundle = Platform.getBundle(bundleSymbolicName);\r
- return getApplicationContext(contributorBundle);\r
- }\r
-\r
- static ApplicationContext getApplicationContext(\r
- final Bundle contributorBundle) {\r
- if (log.isTraceEnabled())\r
- log.trace("Get application context for bundle " + contributorBundle);\r
-\r
- // Start if not yet started (also if in STARTING state, may be lazy)\r
- if (contributorBundle.getState() != Bundle.ACTIVE) {\r
- if (log.isTraceEnabled())\r
- log.trace("Starting bundle: "\r
- + contributorBundle.getSymbolicName());\r
- // Thread startBundle = new Thread("Start bundle "\r
- // + contributorBundle.getSymbolicName()) {\r
- // public void run() {\r
- try {\r
- contributorBundle.start();\r
- } catch (BundleException e) {\r
- log.error("Cannot start bundle " + contributorBundle, e);\r
- }\r
- // }\r
- // };\r
- // startBundle.start();\r
- // try {\r
- // startBundle.join(10 * 1000l);\r
- // } catch (InterruptedException e) {\r
- // // silent\r
- // }\r
- }\r
-\r
- final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker(\r
- contributorBundle, contributorBundle.getBundleContext());\r
- ApplicationContext applicationContext = null;\r
- try {\r
- applicationContextTracker.open();\r
- applicationContext = applicationContextTracker\r
- .getApplicationContext();\r
- } finally {\r
- applicationContextTracker.close();\r
- }\r
- return applicationContext;\r
- }\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.spring;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.eclipse.ui.EclipseUiException;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.commands.IHandlerListener;
-import org.springframework.context.ApplicationContext;
-
-/** Allows to declare Eclipse commands as Spring beans */
-public class SpringCommandHandler implements IHandler {
- private final static Log log = LogFactory
- .getLog(SpringCommandHandler.class);
-
- public void addHandlerListener(IHandlerListener handlerListener) {
- }
-
- public void dispose() {
- }
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- String commandId = event.getCommand().getId();
- String bundleSymbolicName = commandId.substring(0,
- commandId.lastIndexOf('.'));
- try {
- if (log.isTraceEnabled())
- log.trace("Execute " + event + " via spring command handler "
- + this);
- // TODO: make it more flexible and robust
- ApplicationContext applicationContext = ApplicationContextTracker
- .getApplicationContext(bundleSymbolicName);
- if (applicationContext == null)
- throw new EclipseUiException("No application context found for "
- + bundleSymbolicName);
-
- // retrieve the command via its id
- String beanName = event.getCommand().getId();
-
- if (!applicationContext.containsBean(beanName)) {
- if (beanName.startsWith(bundleSymbolicName))
- beanName = beanName
- .substring(bundleSymbolicName.length() + 1);
- }
-
- if (!applicationContext.containsBean(beanName))
- throw new ExecutionException("No bean found with name "
- + beanName + " in bundle " + bundleSymbolicName);
- Object bean = applicationContext.getBean(beanName);
-
- if (!(bean instanceof IHandler))
- throw new ExecutionException("Bean with name " + beanName
- + " and class " + bean.getClass()
- + " does not implement the IHandler interface.");
-
- IHandler handler = (IHandler) bean;
- return handler.execute(event);
- } catch (Exception e) {
- // TODO: use eclipse error management
- // log.error(e);
- throw new ExecutionException("Cannot execute Spring command "
- + commandId + " in bundle " + bundleSymbolicName, e);
- }
- }
-
- public boolean isEnabled() {
- return true;
- }
-
- public boolean isHandled() {
- return true;
- }
-
- public void removeHandlerListener(IHandlerListener handlerListener) {
- }
-
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.eclipse.spring;\r
-\r
-import org.argeo.eclipse.ui.EclipseUiException;\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.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
- * original code from: <a href=\r
- * "http://martinlippert.blogspot.com/2008/10/new-version-of-spring-extension-factory.html"\r
- * >Blog entry</a>\r
- * \r
- * @author Martin Lippert\r
- * @author mbaudier\r
- */\r
-public class SpringExtensionFactory implements IExecutableExtensionFactory,\r
- IExecutableExtension {\r
-\r
- private Object bean;\r
-\r
- public Object create() throws CoreException {\r
- if (bean == null)\r
- throw new EclipseUiException("No underlying bean for extension");\r
- return bean;\r
- }\r
-\r
- public void setInitializationData(IConfigurationElement config,\r
- String propertyName, Object data) throws CoreException {\r
- String bundleSymbolicName = config.getContributor().getName();\r
- ApplicationContext applicationContext = ApplicationContextTracker\r
- .getApplicationContext(bundleSymbolicName);\r
- if (applicationContext == null)\r
- throw new EclipseUiException(\r
- "Cannot find application context for bundle "\r
- + bundleSymbolicName);\r
-\r
- String beanName = getBeanName(data, config);\r
- if (beanName == null)\r
- throw new EclipseUiException("Cannot find bean name for extension "\r
- + config);\r
-\r
- if (!applicationContext.containsBean(beanName)) {\r
- if (beanName.startsWith(bundleSymbolicName))\r
- beanName = beanName.substring(bundleSymbolicName.length() + 1);\r
- }\r
-\r
- if (!applicationContext.containsBean(beanName))\r
- throw new EclipseUiException("No bean with name '" + beanName + "'");\r
-\r
- this.bean = applicationContext.getBean(beanName);\r
- if (this.bean instanceof IExecutableExtension) {\r
- ((IExecutableExtension) this.bean).setInitializationData(config,\r
- propertyName, data);\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
-}\r
import org.argeo.jcr.JcrUtils;
import org.argeo.jcr.UserJcrUtils;
import org.eclipse.jface.preference.PreferenceStore;
-import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.BundleContext;
/**
* TODO: better integrate JCR and Eclipse:<br>
* - typing<br>
* - use eclipse preferences<br>
- * - better integrate with {@link ScopedPreferenceStore} provided by RAP
+ * - better integrate with <code>ScopedPreferenceStore</code> provided by RAP
*/
public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames {
private static final long serialVersionUID = 1854011367784598758L;