Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java3
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java34
2 files changed, 31 insertions, 6 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
index a15a5b40143..8a595c87340 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
@@ -926,7 +926,8 @@ public class PartRenderingEngine implements IPresentationEngine {
IEclipseContext lclContext = ctxt.getContext();
if (lclContext != null) {
IEclipseContext parentContext = lclContext.getParent();
- IEclipseContext child = parentContext.getActiveChild();
+ IEclipseContext child = parentContext != null ? parentContext
+ .getActiveChild() : null;
if (child == lclContext) {
child.deactivate();
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
index 1d968cacc5a..d5a73c5d0ab 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 IBM Corporation and others.
+ * Copyright (c) 2010, 2013 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
@@ -237,10 +237,15 @@ public class MenuHelper {
Expression visWhen = new Expression() {
@Override
public EvaluationResult evaluate(IEvaluationContext context) {
- EHandlerService service = (EHandlerService) context
- .getVariable(EHandlerService.class.getName());
- ICommandService commandService = (ICommandService) context
- .getVariable(ICommandService.class.getName());
+ EHandlerService service = getFromContext(context,
+ EHandlerService.class);
+ ICommandService commandService = getFromContext(context,
+ ICommandService.class);
+ if (service == null || commandService == null) {
+ WorkbenchPlugin
+ .log("Could not retrieve EHandlerService or ICommandService from context evaluation context."); //$NON-NLS-1$
+ return EvaluationResult.FALSE;
+ }
Command c = commandService.getCommand(commandId);
ParameterizedCommand generateCommand = ParameterizedCommand
.generateCommand(c, Collections.EMPTY_MAP);
@@ -274,6 +279,25 @@ public class MenuHelper {
return null;
}
+ /**
+ * Do a type-safe extraction of an object from the evalation context
+ *
+ * @param context
+ * the evaluation context
+ * @param expectedType
+ * the expected type
+ * @return an object of the expected type or <code>null</code>
+ * @throws NullPointerException
+ * if either argument is <code>null</code>
+ */
+ protected static <T> T getFromContext(IEvaluationContext context, Class<T> expectedType) {
+ if (context == null || expectedType == null) {
+ throw new NullPointerException();
+ }
+ final Object rawValue = context.getVariable(expectedType.getName());
+ return (expectedType.isInstance(rawValue)) ? expectedType.cast(rawValue) : null;
+ }
+
/*
* Support Utilities
*/

Back to the top