Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSopot Cela2014-01-30 12:37:55 +0000
committerLars Vogel2014-01-30 16:26:56 +0000
commit156a8de419559c63907f5c794c5c5e2556815331 (patch)
tree2e78c17cc5035b723e9d2ce28daf5c70a797b308
parent059fbb24bd5da853e93a0548943ba83ffbf5d9d3 (diff)
downloadeclipse.platform.ui-156a8de419559c63907f5c794c5c5e2556815331.tar.gz
eclipse.platform.ui-156a8de419559c63907f5c794c5c5e2556815331.tar.xz
eclipse.platform.ui-156a8de419559c63907f5c794c5c5e2556815331.zip
Bug 426928 - Move HandlerProcessingAddon to use @Inject to register for
the events Change-Id: I660dec127abcbb2685b767c20c73e15b1cc629a7 Signed-off-by: Sopot Cela <sopotcela@gmail.com>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java145
2 files changed, 66 insertions, 82 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF
index 60c57215b58..76e6f3a65ca 100644
--- a/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF
@@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.0.0",
org.eclipse.emf.ecore.change;bundle-version="2.5.0",
org.eclipse.core.expressions;bundle-version="[3.4.200,4.0.0)",
org.eclipse.e4.ui.di;bundle-version="0.9.0",
- org.eclipse.emf.ecore.xmi;bundle-version="2.7.0"
+ org.eclipse.emf.ecore.xmi;bundle-version="2.7.0",
+ org.eclipse.e4.core.di.extensions
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.e4.ui.internal.workbench;
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java
index 9b8cc561ee6..bac38a924e6 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 IBM Corporation and others.
+ * Copyright (c) 2012, 2014 IBM Corporation 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
@@ -7,19 +7,19 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Sopot Cela - initial API and implementation
+ * Sopot Cela - initial API, implementation and fixes
******************************************************************************/
package org.eclipse.e4.ui.internal.workbench.addons;
import java.util.List;
import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.core.di.extensions.EventTopic;
import org.eclipse.e4.core.services.contributions.IContributionFactory;
-import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.commands.MHandler;
@@ -28,21 +28,14 @@ import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.osgi.service.event.Event;
-import org.osgi.service.event.EventHandler;
/**
* Process the additions and removals of handlers on the model
*/
public class HandlerProcessingAddon {
- private EventHandler eventHandler;
- private EventHandler contextHandler;
-
- @Inject
- private IEventBroker eventBroker;
-
/**
- * Registers the listeners
+ * Do initial check of handlers and their context upon creation
*
* @param application
* @param modelService
@@ -62,89 +55,79 @@ public class HandlerProcessingAddon {
}
}
}
-
- registerModelListeners();
}
- private void registerModelListeners() {
- eventHandler = new EventHandler() {
- public void handleEvent(Event event) {
- if ((event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MHandlerContainer)
- && (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MContext)) {
- MHandlerContainer handlerContainer = (MHandlerContainer) event
- .getProperty(UIEvents.EventTags.ELEMENT);
- if (UIEvents.EventTypes.ADD.equals(event.getProperty(UIEvents.EventTags.TYPE))) {
- if (event.getProperty(UIEvents.EventTags.NEW_VALUE) instanceof MHandler) {
- MHandler handler = (MHandler) event
- .getProperty(UIEvents.EventTags.NEW_VALUE);
- MContext mContext = (MContext) handlerContainer;
- IEclipseContext context = mContext.getContext();
- if (context != null) {
- processActiveHandler(handler, context);
- }
- }
- } else if (UIEvents.EventTypes.REMOVE.equals(event
- .getProperty(UIEvents.EventTags.TYPE))) {
- if (event.getProperty(UIEvents.EventTags.OLD_VALUE) instanceof MHandler) {
- MHandler handler = (MHandler) event
- .getProperty(UIEvents.EventTags.OLD_VALUE);
- MContext mContext = (MContext) handlerContainer;
- IEclipseContext context = mContext.getContext();
- if (context != null) {
- MCommand command = handler.getCommand();
- if (command != null) {
- String commandId = command.getElementId();
- EHandlerService handlerService = (EHandlerService) context
- .get(EHandlerService.class.getName());
- handlerService
- .deactivateHandler(commandId, handler.getObject());
- }
- }
+ /**
+ * Responds to the coming and goings of handlers in the application model by activating and
+ * deactivating them accordingly.
+ *
+ * @param event
+ * The event thrown in the event bus
+ */
+ @Inject
+ public void handleHandlerEvent(
+ @Optional @EventTopic(UIEvents.HandlerContainer.TOPIC_HANDLERS) Event event) {
+ if (event == null)
+ return;
+ if ((event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MHandlerContainer)
+ && (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MContext)) {
+ MHandlerContainer handlerContainer = (MHandlerContainer) event
+ .getProperty(UIEvents.EventTags.ELEMENT);
+ if (UIEvents.EventTypes.ADD.equals(event.getProperty(UIEvents.EventTags.TYPE))) {
+ if (event.getProperty(UIEvents.EventTags.NEW_VALUE) instanceof MHandler) {
+ MHandler handler = (MHandler) event.getProperty(UIEvents.EventTags.NEW_VALUE);
+ MContext mContext = (MContext) handlerContainer;
+ IEclipseContext context = mContext.getContext();
+ if (context != null) {
+ processActiveHandler(handler, context);
+ }
+ }
+ } else if (UIEvents.EventTypes.REMOVE
+ .equals(event.getProperty(UIEvents.EventTags.TYPE))) {
+ if (event.getProperty(UIEvents.EventTags.OLD_VALUE) instanceof MHandler) {
+ MHandler handler = (MHandler) event.getProperty(UIEvents.EventTags.OLD_VALUE);
+ MContext mContext = (MContext) handlerContainer;
+ IEclipseContext context = mContext.getContext();
+ if (context != null) {
+ MCommand command = handler.getCommand();
+ if (command != null) {
+ String commandId = command.getElementId();
+ EHandlerService handlerService = (EHandlerService) context
+ .get(EHandlerService.class.getName());
+ handlerService.deactivateHandler(commandId, handler.getObject());
}
-
}
-
}
}
- };
- contextHandler = new EventHandler() {
-
- public void handleEvent(Event event) {
- Object origin = event.getProperty(UIEvents.EventTags.ELEMENT);
- Object context = event.getProperty(UIEvents.EventTags.NEW_VALUE);
- if ((origin instanceof MHandlerContainer)
- && (UIEvents.EventTypes.SET.equals(event
- .getProperty(UIEvents.EventTags.TYPE)) && context instanceof IEclipseContext)) {
- MHandlerContainer handlerContainer = (MHandlerContainer) origin;
- IEclipseContext castedContext = (IEclipseContext) context;
- for (MHandler mHandler : handlerContainer.getHandlers()) {
- processActiveHandler(mHandler, castedContext);
- }
-
- }
+ }
- }
- };
- eventBroker.subscribe(UIEvents.HandlerContainer.TOPIC_HANDLERS, eventHandler);
- eventBroker.subscribe(UIEvents.Context.TOPIC_CONTEXT, contextHandler);
}
/**
- * Clean up
+ * Responds to the setting of contexts of handlers in the application model and reacts
+ * accordingly.
+ *
+ * @param event
+ * The event which signals the setting of the context.
*/
- @PreDestroy
- public void preDestroy() {
- unregisterModelListeners();
- }
- /**
- * Unregisters the listeners
- */
- private void unregisterModelListeners() {
- eventBroker.unsubscribe(eventHandler);
- eventBroker.unsubscribe(contextHandler);
+ @Inject
+ public void handleContextEvent(@Optional @EventTopic(UIEvents.Context.TOPIC_CONTEXT) Event event) {
+ if (event == null)
+ return;
+ Object origin = event.getProperty(UIEvents.EventTags.ELEMENT);
+ Object context = event.getProperty(UIEvents.EventTags.NEW_VALUE);
+ if ((origin instanceof MHandlerContainer)
+ && (UIEvents.EventTypes.SET.equals(event.getProperty(UIEvents.EventTags.TYPE)) && context instanceof IEclipseContext)) {
+ MHandlerContainer handlerContainer = (MHandlerContainer) origin;
+ IEclipseContext castedContext = (IEclipseContext) context;
+ for (MHandler mHandler : handlerContainer.getHandlers()) {
+ processActiveHandler(mHandler, castedContext);
+ }
+
+ }
}
/**

Back to the top