aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWojciech Sudol2013-12-06 04:40:11 (EST)
committerGerrit Code Review @ Eclipse.org2013-12-18 09:45:28 (EST)
commit5ed75b1ca32405897472e499d5734f9d95aed127 (patch)
tree11cfa1b3788d347ce54dee88639a56d06f5cbc4a
parent9d4f71484d3b007fe86e292d00c5ecb02b9de5ab (diff)
downloadeclipse.platform.ui-5ed75b1ca32405897472e499d5734f9d95aed127.zip
eclipse.platform.ui-5ed75b1ca32405897472e499d5734f9d95aed127.tar.gz
eclipse.platform.ui-5ed75b1ca32405897472e499d5734f9d95aed127.tar.bz2
Bug 383403 - [Model] EModelService.findElement() does not find allrefs/changes/11/19311/8
elements Change-Id: I5c5ae8d3c7f6120a6f704af823e9ec601a7d4636 Signed-off-by: Wojciech Sudol <wojciech.sudol@pl.ibm.com>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java43
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EModelService.java21
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EModelServiceFindTest.java127
3 files changed, 188 insertions, 3 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 0222a1a..8dc3cfb 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,8 @@ 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;
@@ -40,6 +42,8 @@ import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.basic.MWindowElement;
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.MToolBar;
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
import org.eclipse.e4.ui.model.internal.ModelUtils;
import org.eclipse.e4.ui.workbench.IPresentationEngine;
@@ -216,7 +220,13 @@ public class ModelServiceImpl implements EModelService {
for (MWindow dw : window.getWindows()) {
findElementsRecursive(dw, id, type, tagsToMatch, elements, searchFlags);
}
+
+ MMenu menu = window.getMainMenu();
+ if (menu != null && (searchFlags & IN_MAIN_MENU) != 0) {
+ findElementsRecursive(menu, id, type, tagsToMatch, elements, searchFlags);
+ }
}
+
if (searchRoot instanceof MPerspective) {
MPerspective persp = (MPerspective) searchRoot;
for (MWindow dw : persp.getWindows()) {
@@ -233,6 +243,19 @@ public class ModelServiceImpl implements EModelService {
findElementsRecursive(ph.getRef(), id, type, tagsToMatch, elements, searchFlags);
}
}
+
+ if (searchRoot instanceof MPart && (searchFlags & IN_PART) != 0) {
+ MPart part = (MPart) searchRoot;
+
+ for (MMenu menu : part.getMenus()) {
+ findElementsRecursive(menu, id, type, tagsToMatch, elements, searchFlags);
+ }
+
+ MToolBar toolBar = part.getToolbar();
+ if (toolBar != null) {
+ findElementsRecursive(toolBar, id, type, tagsToMatch, elements, searchFlags);
+ }
+ }
}
/*
@@ -404,6 +427,26 @@ public class ModelServiceImpl implements EModelService {
/*
* (non-Javadoc)
*
+ * @see org.eclipse.e4.ui.workbench.modeling.EModelService#findHandler(org.eclipse.e4.ui.model.
+ * application.commands.MHandlerContainer, java.lang.String)
+ */
+ 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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see
* org.eclipse.e4.ui.workbench.modeling.EModelService#bringToTop(org.eclipse.e4.ui.model.application
* .ui.MUIElement)
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 857533c..4c14c18 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,6 +14,8 @@ 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;
@@ -67,6 +69,12 @@ public interface EModelService {
/** Returned Location if the element is in an MTrimBar */
public static final int IN_TRIM = 0x10;
+ /** Returned Location if the element is in a main menu of an MWindow */
+ public static final int IN_MAIN_MENU = 0x20;
+
+ /** Returned Location if the element is in a menu or a tool bar of an MPart */
+ public static final int IN_PART = 0x40;
+
// 'Standard' searches
/** Searches for elements in the UI that the user is currently seeing (excluding trim) */
@@ -75,7 +83,7 @@ public interface EModelService {
/** Searches for elements in the UI that the user is currently seeing */
public static final int ANYWHERE = OUTSIDE_PERSPECTIVE | IN_ANY_PERSPECTIVE | IN_SHARED_AREA
- | IN_TRIM;
+ | IN_TRIM | IN_MAIN_MENU | IN_PART;
/**
* Searches for elements in the UI that the user is currently seeing that are OUTSIDE the
@@ -255,6 +263,17 @@ 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
+ */
+ 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 dde8d0c..d73d0b5 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 IBM Corporation and others.
+ * Copyright (c) 2009, 2013 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
@@ -16,6 +16,8 @@ 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.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;
@@ -28,6 +30,12 @@ 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.modeling.EModelService;
public class EModelServiceFindTest extends TestCase {
@@ -55,6 +63,12 @@ public class EModelServiceFindTest extends TestCase {
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");
@@ -77,6 +91,32 @@ public class EModelServiceFindTest extends TestCase {
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);
+
+ MMenu menuItem2 = MenuFactoryImpl.eINSTANCE.createMenu();
+ menuItem2.setElementId("menuItem2Id");
+ menu.getChildren().add(menuItem2);
+
+ MToolBar toolBar = MenuFactoryImpl.eINSTANCE.createToolBar();
+ toolBar.setElementId("toolBarId");
+ part2.setToolbar(toolBar);
+
+ MToolControl toolControl1 = MenuFactoryImpl.eINSTANCE
+ .createToolControl();
+ toolControl1.setElementId("toolControl1Id");
+ toolBar.getChildren().add(toolControl1);
+
+ MToolControl toolControl2 = MenuFactoryImpl.eINSTANCE
+ .createToolControl();
+ toolControl2.setElementId("toolControl2Id");
+ toolBar.getChildren().add(toolControl2);
+
return app;
}
@@ -98,6 +138,14 @@ public class EModelServiceFindTest extends TestCase {
List<MUIElement> elements3 = modelService.findElements(application,
"invalidId", null, null);
assertEquals(elements3.size(), 0);
+
+ List<MUIElement> elements4 = modelService.findElements(application,
+ "menuItem1Id", null, null);
+ assertEquals(1, elements4.size());
+
+ List<MUIElement> elements5 = modelService.findElements(application,
+ "toolControl1Id", null, null);
+ assertEquals(1, elements5.size());
}
public void testFindElementsTypeOnly() {
@@ -119,10 +167,18 @@ public class EModelServiceFindTest extends TestCase {
application, null, MDirtyable.class, null);
assertEquals(dirtyableElements.size(), 3);
+ List<MMenuElement> menuElements = modelService.findElements(
+ application, null, MMenuElement.class, null);
+ assertEquals(5, menuElements.size());
+
+ List<MToolBarElement> toolBarElements = modelService.findElements(
+ application, null, MToolBarElement.class, null);
+ assertEquals(2, toolBarElements.size());
+
// Should find all the elements
List<MUIElement> uiElements = modelService.findElements(application,
null, null, null);
- assertEquals(uiElements.size(), 7);
+ assertEquals(uiElements.size(), 15);
// Should match 0 since String is not an MUIElement
List<String> strings = modelService.findElements(application, null,
@@ -232,6 +288,73 @@ public class EModelServiceFindTest extends TestCase {
}
}
+ public void testFlags() {
+ MApplication application = createApplication();
+
+ EModelService modelService = (EModelService) application.getContext()
+ .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());
+ }
+
+ public void testFindHandler() {
+ MApplication application = createApplication();
+
+ EModelService modelService = (EModelService) application.getContext()
+ .get(EModelService.class.getName());
+ assertNotNull(modelService);
+
+ MHandler handler1 = CommandsFactoryImpl.eINSTANCE.createHandler();
+ handler1.setElementId("handler1");
+ application.getHandlers().add(handler1);
+
+ MHandler handler2 = CommandsFactoryImpl.eINSTANCE.createHandler();
+ handler2.setElementId("handler2");
+ application.getHandlers().add(handler2);
+
+ MHandler foundHandler = null;
+
+ foundHandler = modelService.findHandler(application, "handler1");
+ assertNotNull(foundHandler);
+ assertSame(handler1, foundHandler);
+
+ foundHandler = modelService.findHandler(application, "invalidId");
+ assertNull(foundHandler);
+
+ foundHandler = modelService.findHandler(null, "handler1");
+ assertNull(foundHandler);
+
+ foundHandler = modelService.findHandler(application, "");
+ assertNull(foundHandler);
+
+ foundHandler = modelService.findHandler(application, null);
+ assertNull(foundHandler);
+ }
+
public void testBug314685() {
MApplication application = createApplication();
application.setContext(applicationContext);