Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 153159 Details for
Bug 295003
[UI] Design and implement a EPartService API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
EPartService patch v1
bug295003-patch-v1.txt (text/plain), 19.00 KB, created by
Remy Suen
on 2009-11-26 07:22:50 EST
(
hide
)
Description:
EPartService patch v1
Filename:
MIME Type:
Creator:
Remy Suen
Created:
2009-11-26 07:22:50 EST
Size:
19.00 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.e4.ui.tests >Index: src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java >diff -N src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,367 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 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.application; >+ >+import java.util.Collection; >+ >+import junit.framework.TestCase; >+ >+import org.eclipse.e4.core.services.IContributionFactory; >+import org.eclipse.e4.core.services.IDisposable; >+import org.eclipse.e4.core.services.context.IEclipseContext; >+import org.eclipse.e4.ui.model.application.MApplication; >+import org.eclipse.e4.ui.model.application.MApplicationFactory; >+import org.eclipse.e4.ui.model.application.MPart; >+import org.eclipse.e4.ui.model.application.MPartStack; >+import org.eclipse.e4.ui.model.application.MWindow; >+import org.eclipse.e4.ui.workbench.swt.internal.E4Application; >+import org.eclipse.e4.workbench.modeling.EPartService; >+import org.eclipse.e4.workbench.ui.IPresentationEngine; >+ >+public class EPartServiceTest extends TestCase { >+ >+ private IEclipseContext applicationContext; >+ >+ private IPresentationEngine engine; >+ >+ @Override >+ protected void setUp() throws Exception { >+ applicationContext = E4Application.createDefaultContext(); >+ >+ IContributionFactory contributionFactory = (IContributionFactory) applicationContext >+ .get(IContributionFactory.class.getName()); >+ Object newEngine = contributionFactory.create(getEngineURI(), >+ applicationContext); >+ assertTrue(newEngine instanceof IPresentationEngine); >+ applicationContext.set(IPresentationEngine.class.getName(), newEngine); >+ >+ engine = (IPresentationEngine) newEngine; >+ >+ super.setUp(); >+ } >+ >+ protected String getEngineURI() { >+ return "platform:/plugin/org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.application.HeadlessContextPresentationEngine"; //$NON-NLS-1$ >+ } >+ >+ @Override >+ protected void tearDown() throws Exception { >+ super.tearDown(); >+ if (applicationContext instanceof IDisposable) { >+ ((IDisposable) applicationContext).dispose(); >+ } >+ } >+ >+ public void testFindPart_PartInWindow() { >+ MApplication application = createApplication("partId"); >+ >+ MWindow window = application.getChildren().get(0); >+ engine.createGui(window); >+ >+ EPartService partService = (EPartService) window.getContext().get( >+ EPartService.class.getName()); >+ MPart part = partService.findPart("partId"); >+ assertNotNull(part); >+ >+ MPartStack partStack = (MPartStack) window.getChildren().get(0); >+ assertEquals(partStack.getChildren().get(0), part); >+ >+ part = partService.findPart("invalidPartId"); >+ assertNull(part); >+ } >+ >+ public void testFindPart_PartNotInWindow() { >+ MApplication application = createApplication("partId"); >+ >+ MWindow window = application.getChildren().get(0); >+ engine.createGui(window); >+ >+ EPartService partService = (EPartService) window.getContext().get( >+ EPartService.class.getName()); >+ MPart part = partService.findPart("invalidPartId"); >+ assertNull(part); >+ } >+ >+ public void testFindPart_PartInAnotherWindow() { >+ MApplication application = createApplication( >+ new String[] { "partInWindow1" }, >+ new String[] { "partInWindow2" }); >+ >+ MWindow window1 = application.getChildren().get(0); >+ MWindow window2 = application.getChildren().get(1); >+ >+ engine.createGui(window1); >+ engine.createGui(window2); >+ >+ EPartService partService = (EPartService) window1.getContext().get( >+ EPartService.class.getName()); >+ MPart part = partService.findPart("partInWindow2"); >+ assertNull(part); >+ part = partService.findPart("partInWindow1"); >+ assertNotNull(part); >+ >+ MPartStack partStack = (MPartStack) window1.getChildren().get(0); >+ assertEquals(partStack.getChildren().get(0), part); >+ >+ partService = (EPartService) window2.getContext().get( >+ EPartService.class.getName()); >+ part = partService.findPart("partInWindow1"); >+ assertNull(part); >+ part = partService.findPart("partInWindow2"); >+ assertNotNull(part); >+ >+ partStack = (MPartStack) window2.getChildren().get(0); >+ assertEquals(partStack.getChildren().get(0), part); >+ } >+ >+ public void testBringToTop_PartOnTop() { >+ MApplication application = createApplication("partFront", "partBack"); >+ >+ MWindow window = application.getChildren().get(0); >+ MPartStack partStack = (MPartStack) window.getChildren().get(0); >+ MPart partFront = partStack.getChildren().get(0); >+ partStack.setActiveChild(partFront); >+ >+ engine.createGui(window); >+ >+ EPartService partService = (EPartService) window.getContext().get( >+ EPartService.class.getName()); >+ >+ partService.bringToTop(partFront); >+ assertEquals(partStack.getActiveChild(), partFront); >+ } >+ >+ public void testBringToTop_PartNotOnTop() { >+ MApplication application = createApplication("partFront", "partBack"); >+ >+ MWindow window = application.getChildren().get(0); >+ MPartStack partStack = (MPartStack) window.getChildren().get(0); >+ MPart partFront = partStack.getChildren().get(0); >+ MPart partBack = partStack.getChildren().get(1); >+ partStack.setActiveChild(partFront); >+ >+ engine.createGui(window); >+ >+ EPartService partService = (EPartService) window.getContext().get( >+ EPartService.class.getName()); >+ >+ partService.bringToTop(partBack); >+ assertEquals(partStack.getActiveChild(), partBack); >+ } >+ >+ public void testBringToTop_PartInAnotherWindow() { >+ MApplication application = createApplication(new String[] { >+ "partFrontA", "partBackA" }, new String[] { "partFrontB", >+ "partBackB" }); >+ >+ MWindow windowA = application.getChildren().get(0); >+ MPartStack partStackA = (MPartStack) windowA.getChildren().get(0); >+ MPart partFrontA = partStackA.getChildren().get(0); >+ MPart partBackA = partStackA.getChildren().get(1); >+ partStackA.setActiveChild(partFrontA); >+ >+ MWindow windowB = application.getChildren().get(1); >+ MPartStack partStackB = (MPartStack) windowB.getChildren().get(0); >+ MPart partFrontB = partStackB.getChildren().get(0); >+ MPart partBackB = partStackB.getChildren().get(1); >+ partStackB.setActiveChild(partFrontB); >+ >+ engine.createGui(windowA); >+ engine.createGui(windowB); >+ >+ EPartService partServiceA = (EPartService) windowA.getContext().get( >+ EPartService.class.getName()); >+ EPartService partServiceB = (EPartService) windowB.getContext().get( >+ EPartService.class.getName()); >+ >+ partServiceA.bringToTop(partBackB); >+ assertEquals(partStackA.getActiveChild(), partFrontA); >+ assertEquals(partStackB.getActiveChild(), partFrontB); >+ >+ partServiceB.bringToTop(partBackA); >+ assertEquals(partStackA.getActiveChild(), partFrontA); >+ assertEquals(partStackB.getActiveChild(), partFrontB); >+ >+ partServiceA.bringToTop(partBackA); >+ assertEquals(partStackA.getActiveChild(), partBackA); >+ assertEquals(partStackB.getActiveChild(), partFrontB); >+ >+ partServiceB.bringToTop(partBackB); >+ assertEquals(partStackA.getActiveChild(), partBackA); >+ assertEquals(partStackB.getActiveChild(), partBackB); >+ } >+ >+ public void testGetParts_Empty() { >+ MApplication application = createApplication(1, new String[1][0]); >+ MWindow window = application.getChildren().get(0); >+ >+ engine.createGui(window); >+ >+ EPartService partService = (EPartService) window.getContext().get( >+ EPartService.class.getName()); >+ Collection<MPart> parts = partService.getParts(); >+ assertNotNull(parts); >+ assertEquals(0, parts.size()); >+ } >+ >+ public void testGetParts_OneWindow() { >+ MApplication application = createApplication("partId", "partId2"); >+ MWindow window = application.getChildren().get(0); >+ MPartStack partStack = (MPartStack) window.getChildren().get(0); >+ >+ engine.createGui(window); >+ >+ EPartService partService = (EPartService) window.getContext().get( >+ EPartService.class.getName()); >+ Collection<MPart> parts = partService.getParts(); >+ assertNotNull(parts); >+ assertEquals(2, parts.size()); >+ assertTrue(parts.containsAll(partStack.getChildren())); >+ } >+ >+ public void testGetParts_TwoWindows() { >+ MApplication application = createApplication(new String[] { "partId", >+ "partId2" }, new String[] { "partIA", "partIdB", "partIdC" }); >+ >+ MWindow windowA = application.getChildren().get(0); >+ MWindow windowB = application.getChildren().get(1); >+ >+ engine.createGui(windowA); >+ engine.createGui(windowB); >+ >+ EPartService partServiceA = (EPartService) windowA.getContext().get( >+ EPartService.class.getName()); >+ EPartService partServiceB = (EPartService) windowB.getContext().get( >+ EPartService.class.getName()); >+ >+ MPartStack partStackA = (MPartStack) windowA.getChildren().get(0); >+ MPartStack partStackB = (MPartStack) windowB.getChildren().get(0); >+ >+ Collection<MPart> partsA = partServiceA.getParts(); >+ Collection<MPart> partsB = partServiceB.getParts(); >+ >+ assertNotNull(partsA); >+ assertEquals(2, partsA.size()); >+ assertTrue(partsA.containsAll(partStackA.getChildren())); >+ >+ assertNotNull(partsB); >+ assertEquals(3, partsB.size()); >+ assertTrue(partsB.containsAll(partStackB.getChildren())); >+ >+ for (MPart partA : partsA) { >+ assertFalse(partsB.contains(partA)); >+ } >+ } >+ >+ public void testIsVisible_ViewVisible() { >+ MApplication application = createApplication("partId"); >+ >+ MWindow window = application.getChildren().get(0); >+ MPartStack partStack = (MPartStack) window.getChildren().get(0); >+ MPart part = partStack.getChildren().get(0); >+ partStack.setActiveChild(part); >+ >+ engine.createGui(window); >+ >+ EPartService partService = (EPartService) window.getContext().get( >+ EPartService.class.getName()); >+ assertTrue(partService.isPartVisible(part)); >+ } >+ >+ public void testIsVisible_ViewNotVisible() { >+ MApplication application = createApplication("partId", "partId2"); >+ >+ MWindow window = application.getChildren().get(0); >+ MPartStack partStack = (MPartStack) window.getChildren().get(0); >+ partStack.setActiveChild(partStack.getChildren().get(0)); >+ >+ engine.createGui(window); >+ >+ MPart part = partStack.getChildren().get(1); >+ >+ EPartService partService = (EPartService) window.getContext().get( >+ EPartService.class.getName()); >+ assertFalse(partService.isPartVisible(part)); >+ } >+ >+ public void testIsVisible_ViewInAnotherWindow() { >+ MApplication application = createApplication(new String[] { >+ "partFrontA", "partBackA" }, new String[] { "partFrontB", >+ "partBackB" }); >+ >+ MWindow windowA = application.getChildren().get(0); >+ MPartStack partStackA = (MPartStack) windowA.getChildren().get(0); >+ MPart partFrontA = partStackA.getChildren().get(0); >+ MPart partBackA = partStackA.getChildren().get(1); >+ partStackA.setActiveChild(partFrontA); >+ >+ MWindow windowB = application.getChildren().get(1); >+ MPartStack partStackB = (MPartStack) windowB.getChildren().get(0); >+ MPart partFrontB = partStackB.getChildren().get(0); >+ MPart partBackB = partStackB.getChildren().get(1); >+ partStackB.setActiveChild(partFrontB); >+ >+ engine.createGui(windowA); >+ engine.createGui(windowB); >+ >+ EPartService partServiceA = (EPartService) windowA.getContext().get( >+ EPartService.class.getName()); >+ EPartService partServiceB = (EPartService) windowB.getContext().get( >+ EPartService.class.getName()); >+ >+ assertTrue(partServiceA.isPartVisible(partFrontA)); >+ assertFalse(partServiceA.isPartVisible(partBackA)); >+ assertFalse(partServiceA.isPartVisible(partFrontB)); >+ assertFalse(partServiceA.isPartVisible(partBackB)); >+ >+ assertFalse(partServiceB.isPartVisible(partFrontA)); >+ assertFalse(partServiceB.isPartVisible(partBackA)); >+ assertTrue(partServiceB.isPartVisible(partFrontB)); >+ assertFalse(partServiceB.isPartVisible(partBackB)); >+ } >+ >+ private MApplication createApplication(String partId) { >+ return createApplication(new String[] { partId }); >+ } >+ >+ private MApplication createApplication(String... partIds) { >+ return createApplication(new String[][] { partIds }); >+ } >+ >+ private MApplication createApplication(String[]... partIds) { >+ return createApplication(partIds.length, partIds); >+ } >+ >+ private MApplication createApplication(int windows, String[][] partIds) { >+ MApplication application = MApplicationFactory.eINSTANCE >+ .createApplication(); >+ >+ for (int i = 0; i < windows; i++) { >+ MWindow window = MApplicationFactory.eINSTANCE.createWindow(); >+ application.getChildren().add(window); >+ >+ MPartStack partStack = MApplicationFactory.eINSTANCE >+ .createPartStack(); >+ window.getChildren().add(partStack); >+ >+ for (int j = 0; j < partIds[i].length; j++) { >+ MPart part = MApplicationFactory.eINSTANCE.createPart(); >+ part.setId(partIds[i][j]); >+ partStack.getChildren().add(part); >+ } >+ } >+ >+ applicationContext.set(MApplication.class.getName(), application); >+ application.setContext(applicationContext); >+ >+ return application; >+ } >+} >#P org.eclipse.e4.ui.workbench >Index: src/org/eclipse/e4/workbench/modeling/EPartService.java >=================================================================== >RCS file: src/org/eclipse/e4/workbench/modeling/EPartService.java >diff -N src/org/eclipse/e4/workbench/modeling/EPartService.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/workbench/modeling/EPartService.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,34 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 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.workbench.modeling; >+ >+import java.util.Collection; >+import org.eclipse.e4.ui.model.application.MPart; >+ >+public interface EPartService { >+ >+ // public MPart activate(String id); >+ >+ // public void activate(MPart part); >+ >+ public void bringToTop(MPart part); >+ >+ public MPart findPart(String id); >+ >+ public Collection<MPart> getParts(); >+ >+ public boolean isPartVisible(MPart part); >+ >+ // public MPart showPart(String id); >+ // >+ // public MPart showPart(MPart part); >+ >+} >Index: src/org/eclipse/e4/workbench/ui/internal/EPartServiceImpl.java >=================================================================== >RCS file: src/org/eclipse/e4/workbench/ui/internal/EPartServiceImpl.java >diff -N src/org/eclipse/e4/workbench/ui/internal/EPartServiceImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/workbench/ui/internal/EPartServiceImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,115 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 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.workbench.ui.internal; >+ >+import java.util.ArrayList; >+import java.util.Collection; >+import javax.inject.Inject; >+import org.eclipse.e4.ui.model.application.MContext; >+import org.eclipse.e4.ui.model.application.MElementContainer; >+import org.eclipse.e4.ui.model.application.MPart; >+import org.eclipse.e4.ui.model.application.MUIElement; >+import org.eclipse.e4.workbench.modeling.EPartService; >+ >+public class EPartServiceImpl implements EPartService { >+ >+ @Inject >+ private MElementContainer<MUIElement> elementContainer; >+ >+ protected MContext getParentWithContext(MUIElement part) { >+ MElementContainer<MUIElement> parent = part.getParent(); >+ while (parent != null) { >+ if (parent instanceof MContext) { >+ if (((MContext) parent).getContext() != null) >+ return (MContext) parent; >+ } >+ parent = parent.getParent(); >+ } >+ return null; >+ } >+ >+ public void bringToTop(MPart part) { >+ if (isInContainer(part)) { >+ internalBringToTop(part); >+ } >+ } >+ >+ private void internalBringToTop(MPart part) { >+ MElementContainer<MUIElement> parent = part.getParent(); >+ if (parent.getActiveChild() != part) { >+ parent.setActiveChild(part); >+ } >+ } >+ >+ public MPart findPart(String id) { >+ return findPart(elementContainer, id); >+ } >+ >+ public Collection<MPart> getParts() { >+ return getParts(new ArrayList<MPart>(), elementContainer); >+ } >+ >+ private Collection<MPart> getParts(Collection<MPart> parts, >+ MElementContainer<?> elementContainer) { >+ for (Object child : elementContainer.getChildren()) { >+ if (child instanceof MPart) { >+ parts.add((MPart) child); >+ } else if (child instanceof MElementContainer<?>) { >+ getParts(parts, (MElementContainer<?>) child); >+ } >+ } >+ return parts; >+ } >+ >+ public boolean isPartVisible(MPart part) { >+ if (isInContainer(part)) { >+ MElementContainer<MUIElement> parent = part.getParent(); >+ return parent.getActiveChild() == part; >+ } >+ return false; >+ } >+ >+ private MPart findPart(MElementContainer<?> container, String id) { >+ for (Object object : container.getChildren()) { >+ if (object instanceof MPart) { >+ MPart part = (MPart) object; >+ if (id.equals(part.getId())) { >+ return part; >+ } >+ } else if (object instanceof MElementContainer<?>) { >+ MPart part = findPart((MElementContainer<?>) object, id); >+ if (part != null) { >+ return part; >+ } >+ } >+ } >+ >+ return null; >+ } >+ >+ private boolean isInContainer(MPart part) { >+ return isInContainer(elementContainer, part); >+ } >+ >+ private boolean isInContainer(MElementContainer<?> container, MPart part) { >+ for (Object object : container.getChildren()) { >+ if (object == part) { >+ return true; >+ } else if (object instanceof MElementContainer<?>) { >+ if (isInContainer((MElementContainer<?>) object, part)) { >+ return true; >+ } >+ } >+ } >+ >+ return false; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 295003
:
153159
|
153273
|
153815
|
155410
|
155599
|
155880
|
156933
|
157181
|
157513
|
157542