summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRemy Suen2011-07-12 13:54:26 (EDT)
committer Paul Webster2011-08-25 10:21:52 (EDT)
commit3b0a9fad140ffff9ca3810da2fe22e1aa79f7d26 (patch)
treea0ba6239aa7f59fe3dece7a4069a0ed42936b2a8
parent4b7ada3e1dff45dbf452fe9168b773959fe57621 (diff)
downloadeclipse.platform.ui-3b0a9fad140ffff9ca3810da2fe22e1aa79f7d26.zip
eclipse.platform.ui-3b0a9fad140ffff9ca3810da2fe22e1aa79f7d26.tar.gz
eclipse.platform.ui-3b0a9fad140ffff9ca3810da2fe22e1aa79f7d26.tar.bz2
Bug 350089 [Compatibility] MPEP context activation effects
Source/Refactor menu Change the MultiPageEditorSite implementation to create specific NestableContextServices when an IContextService is requested from it. This allows the context service to activate and deactivate itself based on which page the editor is currently showing.
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java42
1 files changed, 40 insertions, 2 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java
index 1b4968e..5a59d93 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -12,6 +12,7 @@ package org.eclipse.ui.part;
import java.util.ArrayList;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ILabelDecorator;
@@ -29,11 +30,14 @@ import org.eclipse.ui.INestableKeyBindingService;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.internal.KeyBindingService;
import org.eclipse.ui.internal.PartSite;
import org.eclipse.ui.internal.PopupMenuExtender;
import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.eclipse.ui.internal.contexts.NestableContextService;
+import org.eclipse.ui.internal.expressions.ActivePartExpression;
import org.eclipse.ui.internal.handlers.LegacyHandlerService;
import org.eclipse.ui.internal.part.IMultiPageEditorSiteHolder;
import org.eclipse.ui.internal.services.INestable;
@@ -101,8 +105,12 @@ public class MultiPageEditorSite implements IEditorSite, INestable {
*/
private final ServiceLocator serviceLocator;
+ private NestableContextService contextService;
+
private IEclipseContext context;
+ private boolean active = false;
+
/**
* Creates a site for the given editor nested within the given multi-page
* editor.
@@ -151,6 +159,17 @@ public class MultiPageEditorSite implements IEditorSite, INestable {
}
});
+ context.set(IContextService.class.getName(), new ContextFunction() {
+ @Override
+ public Object compute(IEclipseContext ctxt) {
+ if (contextService == null) {
+ contextService = new NestableContextService(ctxt.getParent().get(
+ IContextService.class), new ActivePartExpression(multiPageEditor));
+ }
+ return contextService;
+ }
+ });
+
// create a local handler service so that when this page
// activates/deactivates, its handlers will also be taken into/out of
// consideration during handler lookups
@@ -165,8 +184,13 @@ public class MultiPageEditorSite implements IEditorSite, INestable {
* @since 3.2
*/
public final void activate() {
+ active = true;
context.activate();
serviceLocator.activate();
+
+ if (contextService != null) {
+ contextService.activate();
+ }
}
/**
@@ -176,6 +200,11 @@ public class MultiPageEditorSite implements IEditorSite, INestable {
* @since 3.2
*/
public final void deactivate() {
+ active = false;
+ if (contextService != null) {
+ contextService.deactivate();
+ }
+
serviceLocator.deactivate();
context.deactivate();
}
@@ -205,6 +234,10 @@ public class MultiPageEditorSite implements IEditorSite, INestable {
service = null;
}
+ if (contextService != null) {
+ contextService.dispose();
+ }
+
if (serviceLocator != null) {
serviceLocator.dispose();
}
@@ -396,7 +429,12 @@ public class MultiPageEditorSite implements IEditorSite, INestable {
}
public final Object getService(final Class key) {
- return serviceLocator.getService(key);
+ Object service = serviceLocator.getService(key);
+ if (active && service instanceof INestable) {
+ // services need to know that it is currently in an active state
+ ((INestable) service).activate();
+ }
+ return service;
}
/**