Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonas2013-02-21 11:05:28 -0500
committerjonas2013-02-21 11:05:28 -0500
commit769f4990d2e3e319e89a5a7cbe42e256b076fc11 (patch)
tree11509837f522a1700915ee7739de98d8688944c8
parent68f3b8693d2d1ec33956b436553d11c99235128a (diff)
downloadorg.eclipse.e4.tools-769f4990d2e3e319e89a5a7cbe42e256b076fc11.tar.gz
org.eclipse.e4.tools-769f4990d2e3e319e89a5a7cbe42e256b076fc11.tar.xz
org.eclipse.e4.tools-769f4990d2e3e319e89a5a7cbe42e256b076fc11.zip
added DIHandler
-rw-r--r--bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIHandler.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIHandler.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIHandler.java
new file mode 100644
index 00000000..1bb21838
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIHandler.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2012 EclipseSource München GmbH 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:
+ * Jonas Helming <jhelming@eclipsesource.com> - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.tools.compat.parts;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.ui.PlatformUI;
+/**
+ * This is a preliminary implementation of a Handler wrapper. It does not support @CanExecute yet
+ * @author Jonas
+ *
+ * @param <C>
+ */
+public class DIHandler<C> extends AbstractHandler {
+
+ private Class<C> clazz;
+ private C component;
+
+ public DIHandler(Class<C> clazz) {
+ this.clazz = clazz;
+ IEclipseContext context = getActiveContext();
+ component = ContextInjectionFactory.make(clazz, context);
+ }
+
+ private static IEclipseContext getActiveContext() {
+ IEclipseContext parentContext = getParentContext();
+ return parentContext.getActiveLeaf();
+ }
+
+ private static IEclipseContext getParentContext() {
+ return (IEclipseContext) PlatformUI.getWorkbench().getService(
+ IEclipseContext.class);
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ return ContextInjectionFactory.invoke(component, Execute.class,
+ getActiveContext());
+ }
+
+} \ No newline at end of file

Back to the top