aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis-Michel Mathurin2014-05-01 14:12:25 (EDT)
committerPaul Webster2014-05-09 10:10:44 (EDT)
commite8045f88265bcd700f23d42d8e6ba94be5af7fa3 (patch)
treefb61909757ee75ed19bf7f3c87dc4c0c24723224
parente97c7076d2865c39778e5b7fde9433dd44657f3d (diff)
downloadeclipse.platform.ui-e8045f88265bcd700f23d42d8e6ba94be5af7fa3.zip
eclipse.platform.ui-e8045f88265bcd700f23d42d8e6ba94be5af7fa3.tar.gz
eclipse.platform.ui-e8045f88265bcd700f23d42d8e6ba94be5af7fa3.tar.bz2
Bug 431798 - EModelService.findElements does not find bindings andrefs/changes/44/25844/2
bindingtables Change-Id: I367035da94b80bfe7368e365d5f02fb01cc8352d Signed-off-by: Louis-Michel Mathurin <mathurin.lm@gmail.com>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java10
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EModelServiceFindTest.java30
2 files changed, 38 insertions, 2 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 bf69160..67b46f5 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
@@ -23,6 +23,7 @@ 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.MKeyBinding;
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;
@@ -160,7 +161,7 @@ public class ModelServiceImpl implements EModelService {
children.addAll(app.getCommands());
} else if (clazz.equals(MBindingContext.class)) {
children.addAll(app.getBindingContexts());
- } else if (clazz.equals(MBindingTable.class)) {
+ } else if (clazz.equals(MBindingTable.class) || clazz.equals(MKeyBinding.class)) {
children.addAll(app.getBindingTables());
}
// } else { only look for these if specifically asked.
@@ -182,6 +183,13 @@ public class ModelServiceImpl implements EModelService {
}
}
+ if (searchRoot instanceof MBindingTable) {
+ MBindingTable bindingTable = (MBindingTable) searchRoot;
+ for (MKeyBinding child : bindingTable.getBindings()) {
+ findElementsRecursive(child, clazz, matcher, elements, searchFlags);
+ }
+ }
+
// Check regular containers
if (searchRoot instanceof MElementContainer<?>) {
if (searchRoot instanceof MPerspectiveStack) {
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 def9807..0ca4ac9 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
@@ -19,7 +19,10 @@ import org.eclipse.e4.ui.internal.workbench.ModelServiceImpl;
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.MBindingTable;
+import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
import org.eclipse.e4.ui.model.application.commands.MHandler;
+import org.eclipse.e4.ui.model.application.commands.MKeyBinding;
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;
@@ -364,7 +367,7 @@ public class EModelServiceFindTest extends TestCase {
handler1.setElementId("handler1");
application.getHandlers().add(handler1);
- MHandler handler2 = CommandsFactoryImpl.eINSTANCE.createHandler();
+ MHandler handler2 = MCommandsFactory.INSTANCE.createHandler();
handler2.setElementId("handler2");
application.getHandlers().add(handler2);
@@ -387,6 +390,31 @@ public class EModelServiceFindTest extends TestCase {
assertNull(foundHandler);
}
+ public void testFindMKeyBindings() {
+ MApplication application = createApplication();
+ EModelService modelService = (EModelService) application.getContext()
+ .get(EModelService.class.getName());
+ assertNotNull(modelService);
+
+ MBindingTable bindingTable = MCommandsFactory.INSTANCE
+ .createBindingTable();
+ MKeyBinding keyBinding = MCommandsFactory.INSTANCE.createKeyBinding();
+ bindingTable.getBindings().add(keyBinding);
+
+ application.getBindingTables().add(bindingTable);
+
+ List<MKeyBinding> elements = modelService.findElements(application,
+ MKeyBinding.class, EModelService.ANYWHERE, new Selector() {
+ @Override
+ public boolean select(MApplicationElement element) {
+ return (element instanceof MKeyBinding);
+ }
+ });
+
+ assertEquals(1, elements.size());
+ assertEquals(keyBinding, elements.get(0));
+ }
+
public void testBug314685() {
MApplication application = createApplication();
application.setContext(applicationContext);