Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2016-03-05 07:37:12 +0000
committerTom Schindl2016-03-05 07:37:12 +0000
commitea5f7674098518f1d4365ac30c62e20b553d156d (patch)
treeed71d95f1bf7cbd62eb25fde20fffafb5c57bb18
parentacb52f053e3e2382a1dafa93c255d998121500f0 (diff)
downloadorg.eclipse.efxclipse-ea5f7674098518f1d4365ac30c62e20b553d156d.tar.gz
org.eclipse.efxclipse-ea5f7674098518f1d4365ac30c62e20b553d156d.tar.xz
org.eclipse.efxclipse-ea5f7674098518f1d4365ac30c62e20b553d156d.zip
Bug 489067 - @ContextValue should inject a Consumer instance
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider.xml7
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider_Value.xml7
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ConsumerAdapterProvider.java46
-rw-r--r--bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ConsumerAdapterProvider_Value.java47
4 files changed, 107 insertions, 0 deletions
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider.xml b/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider.xml
new file mode 100644
index 000000000..c3238eac7
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider.xml
@@ -0,0 +1,7 @@
+<?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.internal.ConsumerAdapterProvider">
+ <service>
+ <provide interface="org.eclipse.fx.core.adapter.AdapterProvider"/>
+ </service>
+ <implementation class="org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider"/>
+</scr:component> \ No newline at end of file
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider_Value.xml b/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider_Value.xml
new file mode 100644
index 000000000..29eab413c
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/OSGI-INF/services/org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider_Value.xml
@@ -0,0 +1,7 @@
+<?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.internal.ConsumerAdapterProvider_Value">
+ <service>
+ <provide interface="org.eclipse.fx.core.adapter.AdapterProvider"/>
+ </service>
+ <implementation class="org.eclipse.fx.core.di.context.internal.ConsumerAdapterProvider_Value"/>
+</scr:component> \ No newline at end of file
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ConsumerAdapterProvider.java b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ConsumerAdapterProvider.java
new file mode 100644
index 000000000..367354772
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ConsumerAdapterProvider.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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 java.util.function.Consumer;
+
+import org.eclipse.fx.core.adapter.AdapterProvider;
+import org.eclipse.fx.core.adapter.AdapterService.ValueAccess;
+import org.eclipse.fx.core.di.ContextBoundValue;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * Adapt an {@link ContextBoundValue} to a {@link Consumer}
+ */
+@SuppressWarnings("rawtypes")
+@Component
+public class ConsumerAdapterProvider implements AdapterProvider<ContextBoundValue, Consumer> {
+ @Override
+ public Class<ContextBoundValue> getSourceType() {
+ return ContextBoundValue.class;
+ }
+
+ @Override
+ public Class<Consumer> getTargetType() {
+ return Consumer.class;
+ }
+
+ @Override
+ public boolean canAdapt(ContextBoundValue sourceObject, Class<Consumer> targetType) {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Consumer adapt(final ContextBoundValue sourceObject, Class<Consumer> targetType, ValueAccess... valueAccess) {
+ return e -> sourceObject.publish(e);
+ }
+}
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ConsumerAdapterProvider_Value.java b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ConsumerAdapterProvider_Value.java
new file mode 100644
index 000000000..72cf60137
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/ConsumerAdapterProvider_Value.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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 java.util.function.Consumer;
+
+import org.eclipse.fx.core.adapter.AdapterProvider;
+import org.eclipse.fx.core.adapter.AdapterService.ValueAccess;
+import org.eclipse.fx.core.di.ContextBoundValue;
+import org.eclipse.fx.core.preferences.Value;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * Adapt an {@link ContextBoundValue} to a {@link Consumer}
+ */
+@SuppressWarnings("rawtypes")
+@Component
+public class ConsumerAdapterProvider_Value implements AdapterProvider<Value, Consumer> {
+ @Override
+ public Class<Value> getSourceType() {
+ return Value.class;
+ }
+
+ @Override
+ public Class<Consumer> getTargetType() {
+ return Consumer.class;
+ }
+
+ @Override
+ public boolean canAdapt(Value sourceObject, Class<Consumer> targetType) {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Consumer adapt(final Value sourceObject, Class<Consumer> targetType, ValueAccess... valueAccess) {
+ return e -> sourceObject.publish(e);
+ }
+}

Back to the top