diff options
author | Eric Moffatt | 2014-04-01 18:39:39 +0000 |
---|---|---|
committer | Paul Webster | 2014-04-02 14:31:20 +0000 |
commit | 5bce3c23abc377df17fa805da69e234a64277a61 (patch) | |
tree | af46ce17c7996f4cd4e23e9dfc2f8ca64ce78af4 | |
parent | 14a935490c7453d16701de51c89fb4c475c02d6f (diff) | |
download | eclipse.platform.ui-5bce3c23abc377df17fa805da69e234a64277a61.tar.gz eclipse.platform.ui-5bce3c23abc377df17fa805da69e234a64277a61.tar.xz eclipse.platform.ui-5bce3c23abc377df17fa805da69e234a64277a61.zip |
Fix for Bug 431741 - EModelService#findHandler API should be removed
Change-Id: Ia7a082a714069b1ac348b0654a87e9d593692734
3 files changed, 26 insertions, 36 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java index 2f03c9129a8..23cf86c221f 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java @@ -19,8 +19,6 @@ import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.MApplicationElement; -import org.eclipse.e4.ui.model.application.commands.MHandler; -import org.eclipse.e4.ui.model.application.commands.MHandlerContainer; import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor; import org.eclipse.e4.ui.model.application.ui.MElementContainer; import org.eclipse.e4.ui.model.application.ui.MGenericTile; @@ -384,21 +382,6 @@ public class ModelServiceImpl implements EModelService { } @Override - public MHandler findHandler(MHandlerContainer handlerContainer, String id) { - if (handlerContainer == null || id == null || id.length() == 0) { - return null; - } - - for (MHandler handler : handlerContainer.getHandlers()) { - if (id.equals(handler.getElementId())) { - return handler; - } - } - - return null; - } - - @Override public void bringToTop(MUIElement element) { if (element instanceof MApplication) { return; diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EModelService.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EModelService.java index bfafc16caee..225808eb2c5 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EModelService.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EModelService.java @@ -14,8 +14,6 @@ package org.eclipse.e4.ui.workbench.modeling; import java.util.List; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.ui.model.application.MApplicationElement; -import org.eclipse.e4.ui.model.application.commands.MHandler; -import org.eclipse.e4.ui.model.application.commands.MHandlerContainer; import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor; import org.eclipse.e4.ui.model.application.ui.MElementContainer; import org.eclipse.e4.ui.model.application.ui.MSnippetContainer; @@ -270,18 +268,6 @@ public interface EModelService { public MUIElement findSnippet(MSnippetContainer snippetContainer, String id); /** - * Finds a handler by ID in a particular container - * - * @param handlerContainer - * The container to look in - * @param id - * The ID of the handler - * @return The handler or <code>null</code> if none is found - * @since 1.1 - */ - public MHandler findHandler(MHandlerContainer handlerContainer, String id); - - /** * Return the count of the children whose 'toBeRendered' flag is true * * @param element diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EModelServiceFindTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EModelServiceFindTest.java index 79c8b04013d..a8c0c8ffae6 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EModelServiceFindTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EModelServiceFindTest.java @@ -16,6 +16,7 @@ import junit.framework.TestCase; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.ui.internal.workbench.swt.E4Application; import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.MApplicationElement; import org.eclipse.e4.ui.model.application.commands.MHandler; import org.eclipse.e4.ui.model.application.commands.impl.CommandsFactoryImpl; import org.eclipse.e4.ui.model.application.impl.ApplicationFactoryImpl; @@ -36,6 +37,7 @@ import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement; import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; +import org.eclipse.e4.ui.workbench.Selector; import org.eclipse.e4.ui.workbench.modeling.EModelService; public class EModelServiceFindTest extends TestCase { @@ -328,6 +330,25 @@ public class EModelServiceFindTest extends TestCase { assertEquals(2, menuElements.size()); } + private MHandler findHandler(EModelService ms, + MApplicationElement searchRoot, final String id) { + if (searchRoot == null || id == null) + return null; + + List<MHandler> handlers = ms.findElements(searchRoot, MHandler.class, + EModelService.ANYWHERE, new Selector() { + @Override + public boolean select(MApplicationElement element) { + return element instanceof MHandler + && id.equals(element.getElementId()); + } + }); + if (handlers.size() > 0) { + return handlers.get(0); + } + return null; + } + public void testFindHandler() { MApplication application = createApplication(); @@ -345,20 +366,20 @@ public class EModelServiceFindTest extends TestCase { MHandler foundHandler = null; - foundHandler = modelService.findHandler(application, "handler1"); + foundHandler = findHandler(modelService, application, "handler1"); assertNotNull(foundHandler); assertSame(handler1, foundHandler); - foundHandler = modelService.findHandler(application, "invalidId"); + foundHandler = findHandler(modelService, application, "invalidId"); assertNull(foundHandler); - foundHandler = modelService.findHandler(null, "handler1"); + foundHandler = findHandler(modelService, null, "handler1"); assertNull(foundHandler); - foundHandler = modelService.findHandler(application, ""); + foundHandler = findHandler(modelService, application, ""); assertNull(foundHandler); - foundHandler = modelService.findHandler(application, null); + foundHandler = findHandler(modelService, application, null); assertNull(foundHandler); } |