Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles')
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF4
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/scopedobjectfactoryfunction.xml8
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di.context/build.properties3
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ScopedObjectFactoryFunction.java40
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di/src/org/eclipse/fx/core/di/ScopedObjectFactory.java26
5 files changed, 78 insertions, 3 deletions
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF b/bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF
index dc0a1ada6..327b13d5c 100644
--- a/bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/META-INF/MANIFEST.MF
@@ -44,5 +44,5 @@ Import-Package: javafx.animation;version="2.2.0";resolution:=optional,
javafx.util.converter;version="2.2.0";resolution:=optional,
javax.annotation;version="1.1.0",
javax.inject;version="1.0.0"
-Service-Component: OSGI-INF/services/obervableadapter.xml,OSGI-INF/services/fxpropertyadapter.xml,
- OSGI-INF/services/valuesupplier.xml
+Service-Component: OSGI-INF/services/obervableadapter.xml,OSGI-INF/services/fxpropertyadapter.xml,OSGI-INF/services/valuesupplier.xml,
+ OSGI-INF/services/scopedobjectfactoryfunction.xml
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/scopedobjectfactoryfunction.xml b/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/scopedobjectfactoryfunction.xml
new file mode 100644
index 000000000..53f4d2ca7
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/scopedobjectfactoryfunction.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.fx.core.di.context.scopedobjectfactoryfunction">
+ <implementation class="org.eclipse.fx.core.di.context.internal.ScopedObjectFactoryFunction"/>
+ <service>
+ <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
+ </service>
+ <property name="service.context.key" type="String" value="org.eclipse.fx.core.di.ScopedObjectFactory"/>
+</scr:component>
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/build.properties b/bundles/runtime/org.eclipse.fx.core.di.context/build.properties
index 20a57cbde..246e7fc12 100644
--- a/bundles/runtime/org.eclipse.fx.core.di.context/build.properties
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/build.properties
@@ -2,7 +2,8 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
OSGI-INF/,\
- OSGI-INF/services/valuesupplier.xml
+ OSGI-INF/services/valuesupplier.xml,\
+ OSGI-INF/services/scopedobjectfactoryfunction.xml
source.. = src/
additional.bundles = org.eclipse.jdt.annotation
jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ScopedObjectFactoryFunction.java b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ScopedObjectFactoryFunction.java
new file mode 100644
index 000000000..8d5fc1741
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ScopedObjectFactoryFunction.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.core.di.context.internal;
+
+import org.eclipse.e4.core.contexts.ContextFunction;
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.fx.core.di.ScopedObjectFactory;
+
+/**
+ * Context function to create requested object factory
+ */
+public class ScopedObjectFactoryFunction extends ContextFunction {
+ @Override
+ public Object compute(IEclipseContext context, String contextKey) {
+ return new ScopedObjectFactoryImpl(context);
+ }
+
+ static class ScopedObjectFactoryImpl implements ScopedObjectFactory {
+ private final IEclipseContext context;
+
+ ScopedObjectFactoryImpl(IEclipseContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public <C> C newInstance(Class<C> c) {
+ return ContextInjectionFactory.make(c, this.context);
+ }
+
+ }
+}
diff --git a/bundles/runtime/org.eclipse.fx.core.di/src/org/eclipse/fx/core/di/ScopedObjectFactory.java b/bundles/runtime/org.eclipse.fx.core.di/src/org/eclipse/fx/core/di/ScopedObjectFactory.java
new file mode 100644
index 000000000..e9fe34035
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.core.di/src/org/eclipse/fx/core/di/ScopedObjectFactory.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.core.di;
+
+/**
+ * An object factory is bound to the local context and is able to create instances using a the backing DI
+ * container
+ */
+public interface ScopedObjectFactory {
+ /**
+ * Create a new instance of the class
+ *
+ * @param c
+ * the class
+ * @return the instance
+ */
+ public <C> C newInstance(Class<C> c);
+}

Back to the top