From 1c6b99d9ec9b8a47a19420609e65ea38a32b4b76 Mon Sep 17 00:00:00 2001 From: Oleg Besedin Date: Mon, 9 Jan 2012 13:58:40 -0500 Subject: Bug 368187 - Services pre-API cleanup --- .../ui/internal/workbench/swt/E4Application.java | 151 ++++++++++----------- .../src/org/eclipse/e4/ui/tests/UIAllTests.java | 2 - .../e4/ui/tests/workbench/Bug318460Test.java | 136 ------------------- 3 files changed, 72 insertions(+), 217 deletions(-) delete mode 100644 tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/Bug318460Test.java diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java index 599e0c463a1..7980e0a072b 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java @@ -24,11 +24,8 @@ import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IProduct; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.RegistryFactory; -import org.eclipse.core.runtime.Status; -import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -37,7 +34,6 @@ import org.eclipse.e4.core.services.adapter.Adapter; import org.eclipse.e4.core.services.contributions.IContributionFactory; import org.eclipse.e4.core.services.log.ILoggerProvider; import org.eclipse.e4.core.services.log.Logger; -import org.eclipse.e4.core.services.statusreporter.StatusReporter; import org.eclipse.e4.core.services.translation.TranslationProviderFactory; import org.eclipse.e4.core.services.translation.TranslationService; import org.eclipse.e4.ui.di.UISynchronize; @@ -53,11 +49,8 @@ import org.eclipse.e4.ui.internal.workbench.ResourceHandler; import org.eclipse.e4.ui.internal.workbench.WorkbenchLogger; import org.eclipse.e4.ui.model.application.MAddon; import org.eclipse.e4.ui.model.application.MApplication; -import org.eclipse.e4.ui.model.application.ui.MContext; -import org.eclipse.e4.ui.model.application.ui.MElementContainer; import org.eclipse.e4.ui.model.application.ui.MUIElement; import org.eclipse.e4.ui.model.application.ui.advanced.MArea; -import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; import org.eclipse.e4.ui.model.application.ui.advanced.impl.AdvancedFactoryImpl; import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; @@ -72,7 +65,6 @@ import org.eclipse.e4.ui.workbench.lifecycle.PreSave; import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions; import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals; import org.eclipse.e4.ui.workbench.modeling.EModelService; -import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.e4.ui.workbench.modeling.EPlaceholderResolver; import org.eclipse.e4.ui.workbench.swt.internal.copy.WorkbenchSWTMessages; import org.eclipse.emf.common.util.URI; @@ -495,77 +487,78 @@ public class E4Application implements IApplication { // setup for commands and handlers appContext.set(IServiceConstants.ACTIVE_PART, new ActivePartLookupFunction()); - appContext.set(EPartService.PART_SERVICE_ROOT, new ContextFunction() { - private void log() { - StatusReporter statusReporter = (StatusReporter) appContext - .get(StatusReporter.class.getName()); - statusReporter.report(new Status(IStatus.ERROR, - WorkbenchSWTActivator.PI_RENDERERS, - "Internal error, please post the trace to bug 315270", - new Exception()), StatusReporter.LOG); - } - - @Override - public Object compute(IEclipseContext context) { - MContext perceivedRoot = (MContext) context.get(MWindow.class - .getName()); - if (perceivedRoot == null) { - perceivedRoot = (MContext) context.get(MApplication.class - .getName()); - if (perceivedRoot == null) { - IEclipseContext ctxt = appContext.getActiveChild(); - if (ctxt == null) { - return null; - } - log(); - return ctxt.get(MWindow.class); - } - } - - IEclipseContext current = perceivedRoot.getContext(); - if (current == null) { - IEclipseContext ctxt = appContext.getActiveChild(); - if (ctxt == null) { - return null; - } - log(); - return ctxt.get(MWindow.class); - } - - IEclipseContext next = current.getActiveChild(); - MPerspective candidate = null; - while (next != null) { - current = next; - MPerspective perspective = current.get(MPerspective.class); - if (perspective != null) { - candidate = perspective; - } - next = current.getActiveChild(); - } - - if (candidate != null) { - return candidate; - } - - // we need to consider detached windows - MUIElement window = (MUIElement) current.get(MWindow.class - .getName()); - if (window == null) { - IEclipseContext ctxt = appContext.getActiveChild(); - if (ctxt == null) { - return null; - } - log(); - return ctxt.get(MWindow.class); - } - MElementContainer parent = window.getParent(); - while (parent != null && !(parent instanceof MApplication)) { - window = parent; - parent = parent.getParent(); - } - return window; - } - }); + // appContext.set(EPartService.PART_SERVICE_ROOT, new ContextFunction() + // { + // private void log() { + // StatusReporter statusReporter = (StatusReporter) appContext + // .get(StatusReporter.class.getName()); + // statusReporter.report(new Status(IStatus.ERROR, + // WorkbenchSWTActivator.PI_RENDERERS, + // "Internal error, please post the trace to bug 315270", + // new Exception()), StatusReporter.LOG); + // } + // + // @Override + // public Object compute(IEclipseContext context) { + // MContext perceivedRoot = (MContext) context.get(MWindow.class + // .getName()); + // if (perceivedRoot == null) { + // perceivedRoot = (MContext) context.get(MApplication.class + // .getName()); + // if (perceivedRoot == null) { + // IEclipseContext ctxt = appContext.getActiveChild(); + // if (ctxt == null) { + // return null; + // } + // log(); + // return ctxt.get(MWindow.class); + // } + // } + // + // IEclipseContext current = perceivedRoot.getContext(); + // if (current == null) { + // IEclipseContext ctxt = appContext.getActiveChild(); + // if (ctxt == null) { + // return null; + // } + // log(); + // return ctxt.get(MWindow.class); + // } + // + // IEclipseContext next = current.getActiveChild(); + // MPerspective candidate = null; + // while (next != null) { + // current = next; + // MPerspective perspective = current.get(MPerspective.class); + // if (perspective != null) { + // candidate = perspective; + // } + // next = current.getActiveChild(); + // } + // + // if (candidate != null) { + // return candidate; + // } + // + // // we need to consider detached windows + // MUIElement window = (MUIElement) current.get(MWindow.class + // .getName()); + // if (window == null) { + // IEclipseContext ctxt = appContext.getActiveChild(); + // if (ctxt == null) { + // return null; + // } + // log(); + // return ctxt.get(MWindow.class); + // } + // MElementContainer parent = window.getParent(); + // while (parent != null && !(parent instanceof MApplication)) { + // window = parent; + // parent = parent.getParent(); + // } + // return window; + // } + // }); appContext.set(IServiceConstants.ACTIVE_SHELL, new ActiveChildLookupFunction(IServiceConstants.ACTIVE_SHELL, diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java index c50d4ac4828..06c4e2db427 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java @@ -22,7 +22,6 @@ import org.eclipse.e4.ui.tests.application.ResourceHandlerTest; import org.eclipse.e4.ui.tests.application.StartupTestSuite; import org.eclipse.e4.ui.tests.reconciler.ModelReconcilerTestSuite; import org.eclipse.e4.ui.tests.workbench.Bug308317Test; -import org.eclipse.e4.ui.tests.workbench.Bug318460Test; import org.eclipse.e4.ui.tests.workbench.ContextTest; import org.eclipse.e4.ui.tests.workbench.HandlerTest; import org.eclipse.e4.ui.tests.workbench.InjectionEventTest; @@ -49,7 +48,6 @@ public class UIAllTests extends TestSuite { addTest(StartupTestSuite.suite()); addTestSuite(Bug299755Test.class); addTestSuite(Bug308220Test.class); - addTestSuite(Bug318460Test.class); addTestSuite(Bug320857Test.class); addTestSuite(PartRenderingEngineTests.class); addTestSuite(SashRendererTest.class); diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/Bug318460Test.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/Bug318460Test.java deleted file mode 100644 index 6d52a867189..00000000000 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/Bug318460Test.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.e4.ui.tests.workbench; - -import javax.inject.Inject; -import javax.inject.Named; -import junit.framework.TestCase; -import org.eclipse.e4.core.contexts.ContextFunction; -import org.eclipse.e4.core.contexts.ContextInjectionFactory; -import org.eclipse.e4.core.contexts.EclipseContextFactory; -import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.core.di.annotations.Optional; -import org.eclipse.e4.ui.internal.workbench.E4Workbench; -import org.eclipse.e4.ui.internal.workbench.swt.E4Application; -import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; -import org.eclipse.e4.ui.model.application.MApplication; -import org.eclipse.e4.ui.model.application.impl.ApplicationFactoryImpl; -import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; -import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack; -import org.eclipse.e4.ui.model.application.ui.advanced.impl.AdvancedFactoryImpl; -import org.eclipse.e4.ui.model.application.ui.basic.MWindow; -import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicFactoryImpl; -import org.eclipse.e4.ui.workbench.modeling.EPartService; - -public class Bug318460Test extends TestCase { - protected IEclipseContext appContext; - protected E4Workbench wb; - - @Override - protected void setUp() throws Exception { - appContext = E4Application.createDefaultContext(); - appContext.set(E4Workbench.PRESENTATION_URI_ARG, - PartRenderingEngine.engineURI); - } - - @Override - protected void tearDown() throws Exception { - if (wb != null) { - wb.close(); - } - appContext.dispose(); - } - - public void testBug318460_A() { - IEclipseContext context = EclipseContextFactory.create(); - - context.set(EPartService.PART_SERVICE_ROOT, new ContextFunction() { - @Override - public Object compute(IEclipseContext context) { - return context.getActiveLeaf(); - } - }); - - RootContainerConsumer consumer = ContextInjectionFactory.make( - RootContainerConsumer.class, context); - Object o = ContextInjectionFactory.make(Object.class, context); - - IEclipseContext childContextA = context.createChild(); - IEclipseContext childContextB = context.createChild(); - - childContextA.activate(); - assertEquals(childContextA, consumer.root); - - childContextB.activate(); - assertEquals(childContextB, consumer.root); - - ContextInjectionFactory.uninject(o, context); - - childContextA.activate(); - assertEquals(childContextA, consumer.root); - } - - public void testBug318460_B() { - MApplication application = ApplicationFactoryImpl.eINSTANCE - .createApplication(); - final MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); - application.getChildren().add(window); - application.setSelectedElement(window); - - MPerspectiveStack perspectiveStack = AdvancedFactoryImpl.eINSTANCE - .createPerspectiveStack(); - window.getChildren().add(perspectiveStack); - window.setSelectedElement(perspectiveStack); - - application.setContext(appContext); - appContext.set(MApplication.class.getName(), application); - - wb = new E4Workbench(application, appContext); - wb.createAndRunUI(window); - - RootContainerConsumer consumer = ContextInjectionFactory.make( - RootContainerConsumer.class, window.getContext()); - Object o = ContextInjectionFactory.make(Object.class, - window.getContext()); - - MPerspective perspectiveA = AdvancedFactoryImpl.eINSTANCE - .createPerspective(); - perspectiveStack.getChildren().add(perspectiveA); - perspectiveStack.setSelectedElement(perspectiveA); - - assertEquals(perspectiveA, consumer.root); - - MPerspective perspectiveB = AdvancedFactoryImpl.eINSTANCE - .createPerspective(); - perspectiveStack.getChildren().add(perspectiveB); - perspectiveStack.setSelectedElement(perspectiveB); - - assertEquals(perspectiveB, consumer.root); - - ContextInjectionFactory.uninject(o, window.getContext()); - - perspectiveStack.setSelectedElement(perspectiveA); - assertEquals(perspectiveA, consumer.root); - } - - static class RootContainerConsumer { - - Object root; - - @Inject - void inject(@Named(EPartService.PART_SERVICE_ROOT) @Optional Object root) { - this.root = root; - } - - } - -} -- cgit v1.2.3