Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemy Suen2010-01-29 17:35:54 +0000
committerRemy Suen2010-01-29 17:35:54 +0000
commit3730cf32fe4ca79a01f7723f1253a2046d5e54b1 (patch)
tree6ea5f4e39658ba6d2a284a3f17619337fa8e9021
parentd7decc4c3c936ab6c6981832fbfdfd2826d19451 (diff)
downloadeclipse.platform.ui-3730cf32fe4ca79a01f7723f1253a2046d5e54b1.tar.gz
eclipse.platform.ui-3730cf32fe4ca79a01f7723f1253a2046d5e54b1.tar.xz
eclipse.platform.ui-3730cf32fe4ca79a01f7723f1253a2046d5e54b1.zip
Bug 295003 [UI] Design and implement a EPartService API
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java7
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java62
2 files changed, 68 insertions, 1 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java
index 8625f2c5aca..f5fbb8fbaec 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java
@@ -315,13 +315,18 @@ public class PartServiceImpl implements EPartService {
rootContainer.getChildren().add(stack);
}
+ MPart activePart = getActivePart();
+ if (activePart == null) {
+ activate(part);
+ return part;
+ }
+
// 3) make it visible / active / re-layout
switch (partState) {
case ACTIVATE:
activate(part);
return part;
case VISIBLE:
- MPart activePart = getActivePart();
if (activePart.getParent() != part.getParent()) {
bringToTop(part);
}
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java
index 65162903552..3f9abd2e564 100644
--- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java
@@ -969,6 +969,37 @@ public class EPartServiceTest extends TestCase {
partService.isPartVisible(partB));
}
+ public void testShowPart_CREATE4() {
+ MApplication application = MApplicationFactory.eINSTANCE
+ .createApplication();
+ MWindow window = MApplicationFactory.eINSTANCE.createWindow();
+ application.getChildren().add(window);
+ MPartStack stack = MApplicationFactory.eINSTANCE.createPartStack();
+ stack.setId("stackId");
+ window.getChildren().add(stack);
+
+ MPartDescriptor partDescriptor = MApplicationFactory.eINSTANCE
+ .createPartDescriptor();
+ partDescriptor.setId("part");
+ partDescriptor.setCategory("stackId");
+ application.getDescriptors().add(partDescriptor);
+
+ application.setActiveChild(window);
+
+ initialize(applicationContext, application);
+
+ getEngine().createGui(window);
+
+ EPartService partService = (EPartService) window.getContext().get(
+ EPartService.class.getName());
+ MPart part = partService
+ .showPart("part", EPartService.PartState.CREATE);
+
+ assertEquals(1, stack.getChildren().size());
+ assertEquals(part, stack.getChildren().get(0));
+ assertEquals(part, partService.getActivePart());
+ }
+
public void testShowPart_VISIBLE() {
MApplication application = MApplicationFactory.eINSTANCE
.createApplication();
@@ -1117,6 +1148,37 @@ public class EPartServiceTest extends TestCase {
partService.isPartVisible(partB));
}
+ public void testShowPart_VISIBLE4() {
+ MApplication application = MApplicationFactory.eINSTANCE
+ .createApplication();
+ MWindow window = MApplicationFactory.eINSTANCE.createWindow();
+ application.getChildren().add(window);
+ MPartStack stack = MApplicationFactory.eINSTANCE.createPartStack();
+ stack.setId("stackId");
+ window.getChildren().add(stack);
+
+ MPartDescriptor partDescriptor = MApplicationFactory.eINSTANCE
+ .createPartDescriptor();
+ partDescriptor.setId("part");
+ partDescriptor.setCategory("stackId");
+ application.getDescriptors().add(partDescriptor);
+
+ application.setActiveChild(window);
+
+ initialize(applicationContext, application);
+
+ getEngine().createGui(window);
+
+ EPartService partService = (EPartService) window.getContext().get(
+ EPartService.class.getName());
+ MPart part = partService.showPart("part",
+ EPartService.PartState.VISIBLE);
+
+ assertEquals(1, stack.getChildren().size());
+ assertEquals(part, stack.getChildren().get(0));
+ assertEquals(part, partService.getActivePart());
+ }
+
public void testGetSaveableParts() {
MApplication application = createApplication(1, new String[1][0]);
MWindow window = application.getChildren().get(0);

Back to the top