aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis-Michel Mathurin2014-04-01 14:39:39 (EDT)
committerPaul Webster2014-04-04 10:07:53 (EDT)
commitcf7be5c8f93e003afa54c4928cda1d57130ce10f (patch)
treebda06538cefb6858392c0eeb1be38c6b4ff2e0f3
parent91731f4bcd236f0df32c52bcae00eedd949a72de (diff)
downloadeclipse.platform.ui-cf7be5c8f93e003afa54c4928cda1d57130ce10f.zip
eclipse.platform.ui-cf7be5c8f93e003afa54c4928cda1d57130ce10f.tar.gz
eclipse.platform.ui-cf7be5c8f93e003afa54c4928cda1d57130ce10f.tar.bz2
Bug 431714 - EModelService.findElements does not find handlers andrefs/changes/15/24315/7
commands and Bug 431798 - EModelService.findElements does not find bindings and bindingtables - I added more tests and also provided a resource file. This is easier to read for a tester and also easier to add elements -Optimize the search tree a little bit for better performance Change-Id: I67fe64e75d05dce3e24544ebeefbef9a60bd9f13 Signed-off-by: Louis-Michel Mathurin <mathurin.lm@agiledss.com>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java83
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EModelService.java2
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EModelServiceFindTest.java469
-rw-r--r--tests/org.eclipse.e4.ui.tests/xmi/SearchModelElement.e4xmi92
4 files changed, 457 insertions, 189 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 23cf86c..5c150c1 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,6 +19,10 @@ 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.MBindingContext;
+import org.eclipse.e4.ui.model.application.commands.MBindingTable;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
+import org.eclipse.e4.ui.model.application.commands.MHandler;
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;
@@ -146,14 +150,46 @@ public class ModelServiceImpl implements EModelService {
}
}
+ if (searchRoot instanceof MApplication && (searchFlags == ANYWHERE)) {
+ MApplication app = (MApplication) searchRoot;
+
+ List<MApplicationElement> children = new ArrayList<MApplicationElement>();
+ if (clazz != null) {
+ if (clazz.equals(MHandler.class)) {
+ children.addAll(app.getHandlers());
+ } else if (clazz.equals(MCommand.class)) {
+ children.addAll(app.getCommands());
+ } else if (clazz.equals(MBindingContext.class)) {
+ children.addAll(app.getBindingContexts());
+ } else if (clazz.equals(MBindingTable.class)) {
+ children.addAll(app.getBindingTables());
+ }
+ } else {
+ children.addAll(app.getHandlers());
+ children.addAll(app.getCommands());
+ children.addAll(app.getBindingContexts());
+ children.addAll(app.getBindingTables());
+ }
+
+ for (MApplicationElement child : children) {
+ findElementsRecursive(child, clazz, matcher, elements, searchFlags);
+ }
+ }
+
+ if (searchRoot instanceof MBindingContext && (searchFlags == ANYWHERE)) {
+ MBindingContext bindingContext = (MBindingContext) searchRoot;
+ for (MBindingContext child : bindingContext.getChildren()) {
+ findElementsRecursive(child, clazz, matcher, elements, searchFlags);
+ }
+ }
+
// Check regular containers
if (searchRoot instanceof MElementContainer<?>) {
if (searchRoot instanceof MPerspectiveStack) {
- if ((searchFlags & IN_ANY_PERSPECTIVE) != 0) {
+ if ((searchFlags & IN_ANY_PERSPECTIVE ) != 0) {
// Search *all* the perspectives
MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) searchRoot;
- List<MUIElement> children = container.getChildren();
- for (MUIElement child : children) {
+ for (MUIElement child : container.getChildren()) {
findElementsRecursive(child, clazz, matcher, elements, searchFlags);
}
} else if ((searchFlags & IN_ACTIVE_PERSPECTIVE) != 0) {
@@ -164,16 +200,21 @@ public class ModelServiceImpl implements EModelService {
}
} else if ((searchFlags & IN_SHARED_AREA) != 0 && searchRoot instanceof MUIElement) {
// Only recurse through the shared areas
- List<MArea> areas = findElements((MUIElement) searchRoot, null, MArea.class,
- null);
+ List<MArea> areas = findElements((MUIElement) searchRoot, null, MArea.class,null);
for (MArea area : areas) {
findElementsRecursive(area, clazz, matcher, elements, searchFlags);
}
- }
+ } else if ((searchFlags & IN_PART) != 0) {
+ List<MPart> parts = findElements((MUIElement) searchRoot, null, MPart.class, null);
+ for (MPart part : parts) {
+ for (MHandler handler : part.getHandlers()) {
+ findElementsRecursive(handler, clazz, matcher, elements, searchFlags);
+ }
+ }
+ }
} else {
MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) searchRoot;
- List<MUIElement> children = container.getChildren();
- for (MUIElement child : children) {
+ for (MUIElement child : container.getChildren()) {
findElementsRecursive(child, clazz, matcher, elements, searchFlags);
}
}
@@ -189,7 +230,7 @@ public class ModelServiceImpl implements EModelService {
}
// Search Detached Windows
- if (searchRoot instanceof MWindow) {
+ if (searchRoot instanceof MWindow && searchFlags != IN_PART) {
MWindow window = (MWindow) searchRoot;
for (MWindow dw : window.getWindows()) {
findElementsRecursive(dw, clazz, matcher, elements, searchFlags);
@@ -199,6 +240,18 @@ public class ModelServiceImpl implements EModelService {
if (menu != null && (searchFlags & IN_MAIN_MENU) != 0) {
findElementsRecursive(menu, clazz, matcher, elements, searchFlags);
}
+
+ // Check for Handlers
+ if (searchFlags == ANYWHERE) {
+
+ if (menu != null) {
+ findElementsRecursive(menu, clazz, matcher, elements, searchFlags);
+ }
+
+ for (MHandler child : window.getHandlers()) {
+ findElementsRecursive(child, clazz, matcher, elements, searchFlags);
+ }
+ }
}
if (searchRoot instanceof MPerspective) {
@@ -218,17 +271,23 @@ public class ModelServiceImpl implements EModelService {
}
}
- if (searchRoot instanceof MPart && (searchFlags & IN_PART) != 0) {
+ if (searchRoot instanceof MPart) {
MPart part = (MPart) searchRoot;
- for (MMenu menu : part.getMenus()) {
- findElementsRecursive(menu, clazz, matcher, elements, searchFlags);
+ if (searchFlags != IN_MAIN_MENU) {
+ for (MMenu menu : part.getMenus()) {
+ findElementsRecursive(menu, clazz, matcher, elements, searchFlags);
+ }
}
MToolBar toolBar = part.getToolbar();
if (toolBar != null) {
findElementsRecursive(toolBar, clazz, matcher, elements, searchFlags);
}
+
+ for (MHandler child : part.getHandlers()) {
+ findElementsRecursive(child, clazz, matcher, elements, searchFlags);
+ }
}
}
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 225808e..72f301c 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
@@ -76,7 +76,7 @@ public interface EModelService {
public static final int IN_MAIN_MENU = 0x20;
/**
- * Returned Location if the element is in a menu or a tool bar of an MPart
+ * Returned Location if the element is in a MPart
*
* @since 1.1
*/
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 a8c0c8f..d6b99ad 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
@@ -14,12 +14,14 @@ import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.ui.internal.workbench.E4XMIResource;
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.MBindingContext;
+import org.eclipse.e4.ui.model.application.commands.MBindingTable;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
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;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
@@ -31,14 +33,15 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
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.model.application.ui.menu.MMenu;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
-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;
+import org.eclipse.e4.ui.workbench.modeling.ElementMatcher;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
public class EModelServiceFindTest extends TestCase {
@@ -59,67 +62,38 @@ public class EModelServiceFindTest extends TestCase {
}
private MApplication createApplication() {
- MApplication app = ApplicationFactoryImpl.eINSTANCE.createApplication();
+ URI uri = URI.createPlatformPluginURI(
+ "org.eclipse.e4.ui.tests/xmi/SearchModelElement.e4xmi", true);
+ ResourceSet set = new ResourceSetImpl();
+ Resource resource = set.getResource(uri, true);
+
+ assertNotNull(resource);
+ assertEquals(E4XMIResource.class, resource.getClass());
+ assertEquals(1, resource.getContents().size());
+ MApplication app = (MApplication) resource.getContents().get(0);
app.setContext(applicationContext);
- MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
- window.setElementId("singleValidId");
- app.getChildren().add(window);
-
- MMenu mainMenu = MenuFactoryImpl.eINSTANCE.createMenu();
- window.setMainMenu(mainMenu);
-
- MMenu mainMenuItem = MenuFactoryImpl.eINSTANCE.createMenu();
- mainMenu.getChildren().add(mainMenuItem);
-
- MPartSashContainer psc = BasicFactoryImpl.eINSTANCE
- .createPartSashContainer();
- psc.setElementId("twoValidIds");
- psc.getTags().add("oneValidTag");
- window.getChildren().add(psc);
-
- MPartStack stack = BasicFactoryImpl.eINSTANCE.createPartStack();
- stack.getTags().add("twoValidTags");
- psc.getChildren().add(stack);
-
- MPart part1 = BasicFactoryImpl.eINSTANCE.createPart();
- part1.setElementId("twoValidIds");
- stack.getChildren().add(part1);
- MPart part2 = BasicFactoryImpl.eINSTANCE.createPart();
- part2.getTags().add("twoValidTags");
- part2.getTags().add("secondTag");
- stack.getChildren().add(part2);
-
- MPart part3 = BasicFactoryImpl.eINSTANCE.createPart();
- psc.getChildren().add(part3);
-
- MMenu menu = MenuFactoryImpl.eINSTANCE.createMenu();
- menu.setElementId("menuId");
- part1.getMenus().add(menu);
-
- MMenu menuItem1 = MenuFactoryImpl.eINSTANCE.createMenu();
- menuItem1.setElementId("menuItem1Id");
- menu.getChildren().add(menuItem1);
+ return app;
+ }
- MMenu menuItem2 = MenuFactoryImpl.eINSTANCE.createMenu();
- menuItem2.setElementId("menuItem2Id");
- menu.getChildren().add(menuItem2);
+ private Selector getSelector(String id, Class<?> clazz, List<String> tags) {
+ return new ElementMatcher(id, clazz, tags);
+ }
- MToolBar toolBar = MenuFactoryImpl.eINSTANCE.createToolBar();
- toolBar.setElementId("toolBarId");
- part2.setToolbar(toolBar);
+ private Selector getSelector(String id) {
+ return getSelector(id, null, null);
+ }
- MToolControl toolControl1 = MenuFactoryImpl.eINSTANCE
- .createToolControl();
- toolControl1.setElementId("toolControl1Id");
- toolBar.getChildren().add(toolControl1);
+ private Selector getSelector(Class<?> clazz) {
+ return getSelector(null, clazz, null);
+ }
- MToolControl toolControl2 = MenuFactoryImpl.eINSTANCE
- .createToolControl();
- toolControl2.setElementId("toolControl2Id");
- toolBar.getChildren().add(toolControl2);
+ private Selector getSelector() {
+ return getSelector(null, null, null);
+ }
- return app;
+ private Selector getSelector(List<String> tags) {
+ return getSelector(null, null, tags);
}
public void testFindElementsIdOnly() {
@@ -129,27 +103,29 @@ public class EModelServiceFindTest extends TestCase {
.get(EModelService.class.getName());
assertNotNull(modelService);
- List<MUIElement> elements1 = modelService.findElements(application,
- "singleValidId", null, null);
- assertEquals(elements1.size(), 1);
+ List<? extends MApplicationElement> elements;
- List<MUIElement> elements2 = modelService.findElements(application,
- "twoValidIds", null, null);
- assertEquals(elements2.size(), 2);
+ elements = modelService.findElements(application, null,
+ EModelService.ANYWHERE, getSelector("singleValidId"));
+ assertEquals(1, elements.size());
- List<MUIElement> elements3 = modelService.findElements(application,
- "invalidId", null, null);
- assertEquals(elements3.size(), 0);
+ elements = modelService.findElements(application, null,
+ EModelService.ANYWHERE, getSelector("twoValidIds"));
+ assertEquals(2, elements.size());
- List<MUIElement> elements4 = modelService.findElements(application,
- "menuItem1Id", null, null, EModelService.ANYWHERE
- | EModelService.IN_MAIN_MENU | EModelService.IN_PART);
- assertEquals(1, elements4.size());
+ elements = modelService.findElements(application, null,
+ EModelService.ANYWHERE, getSelector("invalidId"));
+ assertEquals(0, elements.size());
- List<MUIElement> elements5 = modelService.findElements(application,
- "toolControl1Id", null, null, EModelService.ANYWHERE
- | EModelService.IN_MAIN_MENU | EModelService.IN_PART);
- assertEquals(1, elements5.size());
+ elements = modelService.findElements(application, null,
+ EModelService.ANYWHERE | EModelService.IN_MAIN_MENU
+ | EModelService.IN_PART, getSelector("menuItem1Id"));
+ assertEquals(1, elements.size());
+
+ elements = modelService.findElements(application, null,
+ EModelService.ANYWHERE | EModelService.IN_MAIN_MENU
+ | EModelService.IN_PART, getSelector("toolControl1Id"));
+ assertEquals(1, elements.size());
}
public void testFindElementsTypeOnly() {
@@ -159,35 +135,38 @@ public class EModelServiceFindTest extends TestCase {
.get(EModelService.class.getName());
assertNotNull(modelService);
- List<MPart> parts = modelService.findElements(application, null,
- MPart.class, null);
- assertEquals(parts.size(), 3);
+ List<? extends MApplicationElement> elements;
- List<MPartStack> stacks = modelService.findElements(application, null,
- MPartStack.class, null);
- assertEquals(stacks.size(), 1);
+ elements = modelService.findElements(application, MPart.class,
+ EModelService.ANYWHERE, getSelector(MPart.class));
+ assertEquals(5, elements.size());
+
+ elements = modelService.findElements(application, MPartStack.class,
+ EModelService.ANYWHERE, getSelector(MPartStack.class));
+ assertEquals(3, elements.size());
List<MDirtyable> dirtyableElements = modelService.findElements(
- application, null, MDirtyable.class, null);
- assertEquals(dirtyableElements.size(), 3);
+ application, MDirtyable.class, EModelService.ANYWHERE,
+ getSelector(MDirtyable.class));
+ assertEquals(5, dirtyableElements.size());
- List<MMenuElement> menuElements = modelService.findElements(
- application, null, MMenuElement.class, null,
+ elements = modelService.findElements(application, MMenuElement.class,
EModelService.ANYWHERE | EModelService.IN_MAIN_MENU
- | EModelService.IN_PART);
- assertEquals(5, menuElements.size());
+ | EModelService.IN_PART,
+ getSelector(MMenuElement.class));
+ assertEquals(13, elements.size());
- List<MToolBarElement> toolBarElements = modelService.findElements(
- application, null, MToolBarElement.class, null,
- EModelService.ANYWHERE | EModelService.IN_MAIN_MENU
- | EModelService.IN_PART);
- assertEquals(2, toolBarElements.size());
+ elements = modelService.findElements(application,
+ MToolBarElement.class, EModelService.ANYWHERE
+ | EModelService.IN_MAIN_MENU | EModelService.IN_PART,
+ getSelector(MToolBarElement.class));
+ assertEquals(2, elements.size());
// Should find all the elements
- List<MUIElement> uiElements = modelService.findElements(application,
- null, null, null, EModelService.ANYWHERE
- | EModelService.IN_MAIN_MENU | EModelService.IN_PART);
- assertEquals(15, uiElements.size());
+ elements = modelService.findElements(application, null,
+ EModelService.ANYWHERE | EModelService.IN_MAIN_MENU
+ | EModelService.IN_PART, getSelector());
+ assertEquals(40, elements.size());
// Should match 0 since String is not an MUIElement
List<String> strings = modelService.findElements(application, null,
@@ -206,33 +185,33 @@ public class EModelServiceFindTest extends TestCase {
tags.add("oneValidTag");
List<MUIElement> oneTags = modelService.findElements(application, null,
- null, tags);
+ EModelService.ANYWHERE, getSelector(tags));
assertEquals(oneTags.size(), 1);
tags.clear();
tags.add("twoValidTags");
List<MUIElement> twoTags = modelService.findElements(application, null,
- null, tags);
+ EModelService.ANYWHERE, getSelector(tags));
assertEquals(twoTags.size(), 2);
tags.clear();
tags.add("invalidTag");
List<MUIElement> invalidTags = modelService.findElements(application,
- null, null, tags);
+ null, EModelService.ANYWHERE, getSelector(tags));
assertEquals(invalidTags.size(), 0);
tags.clear();
tags.add("twoValidTags");
tags.add("secondTag");
List<MUIElement> combinedTags = modelService.findElements(application,
- null, null, tags);
+ null, EModelService.ANYWHERE, getSelector(tags));
assertEquals(combinedTags.size(), 1);
tags.clear();
tags.add("oneValidTag");
tags.add("secondTag");
List<MUIElement> unmatchedTags = modelService.findElements(application,
- null, null, tags);
+ null, EModelService.ANYWHERE, getSelector(tags));
assertEquals(unmatchedTags.size(), 0);
}
@@ -246,26 +225,36 @@ public class EModelServiceFindTest extends TestCase {
List<String> tags = new ArrayList<String>();
tags.add("oneValidTag");
- List<MPartSashContainer> idAndType = modelService.findElements(
- application, "twoValidIds", MPartSashContainer.class, tags);
- assertEquals(idAndType.size(), 1);
+ List<? extends MApplicationElement> elements;
+
+ elements = modelService.findElements(application, null,
+ EModelService.IN_PART, getSelector("singleValidId"));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application,
+ MPartSashContainer.class, EModelService.ANYWHERE,
+ getSelector("twoValidIds", MPartSashContainer.class, tags));
+ assertEquals(1, elements.size());
List<MPartSashContainer> typeAndTag = modelService.findElements(
- application, null, MPartSashContainer.class, tags);
- assertEquals(typeAndTag.size(), 1);
+ application, MPartSashContainer.class, EModelService.ANYWHERE,
+ getSelector(tags));
+ assertEquals(1, typeAndTag.size());
List<MUIElement> idAndTag = modelService.findElements(application,
- "twoValidIds", null, tags);
- assertEquals(idAndTag.size(), 1);
+ null, EModelService.ANYWHERE,
+ getSelector("twoValidIds", null, tags));
+ assertEquals(1, idAndTag.size());
List<MPartSashContainer> idAndTypeAndTags = modelService.findElements(
- application, "twoValidIds", MPartSashContainer.class, null);
- assertEquals(idAndTypeAndTags.size(), 1);
+ application, MPartSashContainer.class, EModelService.ANYWHERE,
+ getSelector("twoValidIds", MPartSashContainer.class, null));
+ assertEquals(1, idAndTypeAndTags.size());
List<MPartSashContainer> badIdAndTypeAndTags = modelService
- .findElements(application, "invalidId",
- MPartSashContainer.class, null);
- assertEquals(badIdAndTypeAndTags.size(), 0);
+ .findElements(application, MPartSashContainer.class,
+ EModelService.ANYWHERE, getSelector("invalidId"));
+ assertEquals(0, badIdAndTypeAndTags.size());
}
public void testFindElements_NullCheck() {
@@ -304,49 +293,50 @@ public class EModelServiceFindTest extends TestCase {
.get(EModelService.class.getName());
assertNotNull(modelService);
- List<MToolBarElement> toolBarElements = modelService.findElements(
- application, null, MToolBarElement.class, null,
- EModelService.IN_ANY_PERSPECTIVE);
- assertEquals(0, toolBarElements.size());
-
- toolBarElements = modelService.findElements(application, null,
- MToolBarElement.class, null, EModelService.IN_ANY_PERSPECTIVE
- | EModelService.IN_PART);
- assertEquals(2, toolBarElements.size());
-
- List<MMenuElement> menuElements = modelService.findElements(
- application, null, MMenuElement.class, null,
- EModelService.IN_ANY_PERSPECTIVE);
- assertEquals(0, menuElements.size());
-
- menuElements = modelService.findElements(application, null,
- MMenuElement.class, null, EModelService.IN_ANY_PERSPECTIVE
- | EModelService.IN_PART);
- assertEquals(3, menuElements.size());
-
- menuElements = modelService.findElements(application, null,
- MMenuElement.class, null, EModelService.IN_ANY_PERSPECTIVE
- | EModelService.IN_MAIN_MENU);
- 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;
+ Class<? extends MApplicationElement> clazz;
+ List<? extends MApplicationElement> elements;
+
+ clazz = MToolBarElement.class;
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ANY_PERSPECTIVE, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ANY_PERSPECTIVE | EModelService.IN_PART,
+ getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.ANYWHERE, getSelector(clazz));
+ assertEquals(2, elements.size());
+
+ clazz = MMenuElement.class;
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ANY_PERSPECTIVE, getSelector(clazz));
+ assertEquals(4, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ANY_PERSPECTIVE | EModelService.IN_PART,
+ getSelector(clazz));
+ assertEquals(4, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ACTIVE_PERSPECTIVE, getSelector(clazz));
+ assertEquals(3, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ACTIVE_PERSPECTIVE | EModelService.IN_PART,
+ getSelector(clazz));
+ assertEquals(3, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ANY_PERSPECTIVE | EModelService.IN_MAIN_MENU,
+ getSelector(clazz));
+ assertEquals(13, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_MAIN_MENU, getSelector(clazz));
+ assertEquals(9, elements.size());
}
public void testFindHandler() {
@@ -356,31 +346,48 @@ public class EModelServiceFindTest extends TestCase {
.get(EModelService.class.getName());
assertNotNull(modelService);
- MHandler handler1 = CommandsFactoryImpl.eINSTANCE.createHandler();
- handler1.setElementId("handler1");
- application.getHandlers().add(handler1);
+ Class<? extends MApplicationElement> clazz = MHandler.class;
+ List<? extends MApplicationElement> elements;
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.ANYWHERE, getSelector("handler1", clazz, null));
+ assertEquals(1, elements.size());
- MHandler handler2 = CommandsFactoryImpl.eINSTANCE.createHandler();
- handler2.setElementId("handler2");
- application.getHandlers().add(handler2);
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_PART, getSelector("handler1", clazz, null));
+ assertEquals(0, elements.size());
- MHandler foundHandler = null;
+ elements = modelService.findElements(application, clazz,
+ EModelService.ANYWHERE, getSelector("invalidId", clazz, null));
+ assertEquals(0, elements.size());
- foundHandler = findHandler(modelService, application, "handler1");
- assertNotNull(foundHandler);
- assertSame(handler1, foundHandler);
+ elements = modelService.findElements(application, null, MHandler.class,
+ null);
+ assertEquals(8, elements.size());
- foundHandler = findHandler(modelService, application, "invalidId");
- assertNull(foundHandler);
+ elements = modelService.findElements(application, clazz,
+ EModelService.ANYWHERE, getSelector(clazz));
+ assertEquals(8, elements.size());
- foundHandler = findHandler(modelService, null, "handler1");
- assertNull(foundHandler);
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_PART, getSelector(clazz));
+ assertEquals(4, elements.size());
- foundHandler = findHandler(modelService, application, "");
- assertNull(foundHandler);
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ANY_PERSPECTIVE, getSelector(clazz));
+ assertEquals(4, elements.size());
- foundHandler = findHandler(modelService, application, null);
- assertNull(foundHandler);
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ACTIVE_PERSPECTIVE, getSelector(clazz));
+ assertEquals(3, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_TRIM, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_SHARED_AREA, getSelector(clazz));
+ assertEquals(1, elements.size());
}
public void testBug314685() {
@@ -428,4 +435,114 @@ public class EModelServiceFindTest extends TestCase {
assertEquals(1, elements.size());
assertEquals(part, elements.get(0));
}
+
+ public void testFind_MCommands() {
+ MApplication application = createApplication();
+
+ EModelService modelService = (EModelService) application.getContext()
+ .get(EModelService.class.getName());
+ assertNotNull(modelService);
+
+ Class<MCommand> clazz = MCommand.class;
+ List<MCommand> elements = null;
+
+ elements = modelService.findElements(application, null, clazz, null,
+ EModelService.ANYWHERE);
+ assertEquals(1, elements.size());
+
+ elements = modelService.findElements(application, null, clazz, null,
+ EModelService.IN_PART);
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, null, clazz, null,
+ EModelService.IN_ANY_PERSPECTIVE);
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, null, clazz, null,
+ EModelService.IN_ACTIVE_PERSPECTIVE);
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, null, clazz, null,
+ EModelService.IN_TRIM);
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, null, clazz, null,
+ EModelService.IN_SHARED_AREA);
+ assertEquals(0, elements.size());
+ }
+
+ public void testFind_MBindingContext() {
+ MApplication application = createApplication();
+
+ EModelService modelService = (EModelService) application.getContext()
+ .get(EModelService.class.getName());
+ assertNotNull(modelService);
+
+ Class<MBindingContext> clazz = MBindingContext.class;
+ List<MBindingContext> elements = null;
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.ANYWHERE,
+ getSelector("org.eclipse.ui.contexts.window", clazz, null));
+ assertEquals(1, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.ANYWHERE, getSelector(clazz));
+ assertEquals(3, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_PART, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ANY_PERSPECTIVE, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ACTIVE_PERSPECTIVE, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_TRIM, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_SHARED_AREA, getSelector(clazz));
+ assertEquals(0, elements.size());
+ }
+
+ public void testFind_MBindingTable() {
+ MApplication application = createApplication();
+
+ EModelService modelService = (EModelService) application.getContext()
+ .get(EModelService.class.getName());
+ assertNotNull(modelService);
+
+ Class<MBindingTable> clazz = MBindingTable.class;
+ List<MBindingTable> elements = null;
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.ANYWHERE, getSelector(clazz));
+ assertEquals(1, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_PART, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ANY_PERSPECTIVE, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_ACTIVE_PERSPECTIVE, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_TRIM, getSelector(clazz));
+ assertEquals(0, elements.size());
+
+ elements = modelService.findElements(application, clazz,
+ EModelService.IN_SHARED_AREA, getSelector(clazz));
+ assertEquals(0, elements.size());
+ }
}
diff --git a/tests/org.eclipse.e4.ui.tests/xmi/SearchModelElement.e4xmi b/tests/org.eclipse.e4.ui.tests/xmi/SearchModelElement.e4xmi
new file mode 100644
index 0000000..49b05bd
--- /dev/null
+++ b/tests/org.eclipse.e4.ui.tests/xmi/SearchModelElement.e4xmi
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_vmWS8LmvEeOEGLtlJRjA-g" elementId="org.eclipse.e4.ide.application" bindingContexts="_vmWS-bmvEeOEGLtlJRjA-g">
+ <children xsi:type="basic:TrimmedWindow" xmi:id="_vmWS8bmvEeOEGLtlJRjA-g" label="" width="500" height="400">
+ <children xsi:type="advanced:PerspectiveStack" xmi:id="_vmXhF7mvEeOEGLtlJRjA-g" selectedElement="_vmXhGLmvEeOEGLtlJRjA-g">
+ <children xsi:type="advanced:Perspective" xmi:id="_vmXhGLmvEeOEGLtlJRjA-g">
+ <children xsi:type="basic:PartSashContainer" xmi:id="_FAcHMLrHEeODX5-c16SbUg" elementId="twoValidIds">
+ <tags>oneValidTag</tags>
+ <children xsi:type="basic:PartStack" xmi:id="_F8tiMLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.partstack.1">
+ <tags>twoValidTags</tags>
+ <children xsi:type="basic:Part" xmi:id="_GXkSMLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.part.0">
+ <handlers xmi:id="_HCEnwLrHEeODX5-c16SbUg" elementId="twoValidIds"/>
+ <menus xmi:id="_HbnJILrHEeODX5-c16SbUg" elementId="menuId">
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_ESaHELrIEeODX5-c16SbUg" elementId="menuItem1Id"/>
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_HdgKELrIEeODX5-c16SbUg" elementId="menuItem2Id"/>
+ </menus>
+ </children>
+ <children xsi:type="basic:Part" xmi:id="_4BMNELrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.part.1">
+ <tags>twoValidTags</tags>
+ <tags>secondTag</tags>
+ </children>
+ </children>
+ </children>
+ <children xsi:type="advanced:Area" xmi:id="_K8_lMLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.area.0">
+ <children xsi:type="basic:Part" xmi:id="_M0J7ILrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.part.2">
+ <handlers xmi:id="_NZKssLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.handler.5"/>
+ </children>
+ </children>
+ <children xsi:type="advanced:Placeholder" xmi:id="_AohrwLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.placeholder.0" ref="_z9dHULrGEeODX5-c16SbUg"/>
+ </children>
+ <children xsi:type="advanced:Perspective" xmi:id="_QS9kULrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.perspective.0">
+ <children xsi:type="basic:PartSashContainer" xmi:id="_RFqzoLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.partsashcontainer.2">
+ <children xsi:type="basic:PartStack" xmi:id="_ReBpQLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.partstack.2">
+ <children xsi:type="basic:Part" xmi:id="_Rz5LkLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.part.3">
+ <handlers xmi:id="_SQscULrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.handler.6"/>
+ <menus xmi:id="_Sr5xoLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.menu.2"/>
+ </children>
+ </children>
+ </children>
+ </children>
+ </children>
+ <handlers xmi:id="_qPM5ULrGEeODX5-c16SbUg" elementId="handler1"/>
+ <handlers xmi:id="_VnxhULrREeODX5-c16SbUg" elementId="handler2"/>
+ <mainMenu xmi:id="_vmXhELmvEeOEGLtlJRjA-g" elementId="menu:org.eclipse.ui.main.menu">
+ <children xsi:type="menu:Menu" xmi:id="_vmXhEbmvEeOEGLtlJRjA-g" elementId="aaaa.main.menu.0" label="File">
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_vmXhErmvEeOEGLtlJRjA-g" label="Open" iconURI=""/>
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_vmXhE7mvEeOEGLtlJRjA-g" label="Save" iconURI=""/>
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_vmXhFLmvEeOEGLtlJRjA-g" label="Quit"/>
+ </children>
+ <children xsi:type="menu:Menu" xmi:id="_vmXhFbmvEeOEGLtlJRjA-g" elementId="aaaa.main.menu.1" label="Help">
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_vmXhFrmvEeOEGLtlJRjA-g" label="About"/>
+ </children>
+ </mainMenu>
+ <windows xsi:type="basic:TrimmedWindow" xmi:id="_b8MSELqXEeOEGLtlJRjA-g" elementId="singleValidId">
+ <handlers xmi:id="_tINt0LrGEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.handler.2"/>
+ <mainMenu xmi:id="_c3PlELqXEeOEGLtlJRjA-g" elementId="aaaa.menu.1">
+ <children xsi:type="menu:Menu" xmi:id="_u2PV4LrGEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.menu.0"/>
+ </mainMenu>
+ </windows>
+ <sharedElements xsi:type="basic:PartSashContainer" xmi:id="_z9dHULrGEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.partsashcontainer.0">
+ <children xsi:type="basic:PartStack" xmi:id="_0ljCELrGEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.partstack.0">
+ <children xsi:type="basic:Part" xmi:id="_2WCvULrGEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.part.0">
+ <handlers xmi:id="_22iNQLrGEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.handler.3"/>
+ </children>
+ </children>
+ </sharedElements>
+ <trimBars xmi:id="_V8R9QLrHEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.trimbar.0">
+ <children xsi:type="menu:ToolBar" xmi:id="_WSnZoLrHEeODX5-c16SbUg" elementId="toolBarId">
+ <children xsi:type="menu:ToolControl" xmi:id="_KgnHALrOEeODX5-c16SbUg" elementId="toolControl1Id"/>
+ <children xsi:type="menu:ToolControl" xmi:id="_LB4oELrOEeODX5-c16SbUg" elementId="toolControl2Id"/>
+ </children>
+ </trimBars>
+ </children>
+ <handlers xmi:id="_cJHIYLrGEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.handler.0"/>
+ <bindingTables xmi:id="_vmW6ArmvEeOEGLtlJRjA-g" bindingContext="_vmWS-bmvEeOEGLtlJRjA-g">
+ <bindings xmi:id="_vmW6A7mvEeOEGLtlJRjA-g" keySequence="M1+Q"/>
+ <bindings xmi:id="_vmW6BrmvEeOEGLtlJRjA-g" keySequence="M1+O"/>
+ <bindings xmi:id="_vmW6CbmvEeOEGLtlJRjA-g" keySequence="M1+S"/>
+ <bindings xmi:id="_vmW6DLmvEeOEGLtlJRjA-g" keySequence="M1+A"/>
+ </bindingTables>
+ <rootContext xmi:id="_vmWS-bmvEeOEGLtlJRjA-g" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="In Dialog and Windows">
+ <children xmi:id="_vmWS-rmvEeOEGLtlJRjA-g" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
+ <children xmi:id="_vmWS-7mvEeOEGLtlJRjA-g" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
+ </rootContext>
+ <commands xmi:id="_flFgALrGEeODX5-c16SbUg" elementId="org.eclipse.e4.ui.tests.command.0"/>
+ <addons xmi:id="_vmWS8rmvEeOEGLtlJRjA-g" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
+ <addons xmi:id="_vmWS87mvEeOEGLtlJRjA-g" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
+ <addons xmi:id="_vmWS9LmvEeOEGLtlJRjA-g" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
+ <addons xmi:id="_vmWS9bmvEeOEGLtlJRjA-g" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
+ <addons xmi:id="_vmWS9rmvEeOEGLtlJRjA-g" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
+ <addons xmi:id="_vmWS97mvEeOEGLtlJRjA-g" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
+ <addons xmi:id="_vmWS-LmvEeOEGLtlJRjA-g" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
+</application:Application>