Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSopot Cela2013-07-10 12:35:16 -0400
committerTom Schindl2013-07-10 12:35:16 -0400
commitb8a74442c5fb0a62d04722cb9164299fa4445af2 (patch)
tree4dcea175b3de37b16b20643fcd46c8046e603376
parent1f3b7b9c7137c4f75e690056cd09e87b78e3a263 (diff)
downloadorg.eclipse.efxclipse-b8a74442c5fb0a62d04722cb9164299fa4445af2.tar.gz
org.eclipse.efxclipse-b8a74442c5fb0a62d04722cb9164299fa4445af2.tar.xz
org.eclipse.efxclipse-b8a74442c5fb0a62d04722cb9164299fa4445af2.zip
Bug 410172 - [e4] add general lifecycle support for model elements
Signed-off-by: Sopot Cela <sopotcela@gmail.com>
-rw-r--r--testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/contributions/DMContribution.java22
-rw-r--r--testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/ClosePerspectiveHandler.java49
-rw-r--r--testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/RegisterDynamicLifecycle.java16
-rw-r--r--testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/LifeCycle.java31
-rw-r--r--testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/SecondLifeCycle.java20
5 files changed, 138 insertions, 0 deletions
diff --git a/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/contributions/DMContribution.java b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/contributions/DMContribution.java
new file mode 100644
index 000000000..ba688513c
--- /dev/null
+++ b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/contributions/DMContribution.java
@@ -0,0 +1,22 @@
+package org.eclipse.fx.testcases.e4.contributions;
+
+import org.eclipse.e4.ui.di.AboutToHide;
+import org.eclipse.e4.ui.di.AboutToShow;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+
+public class DMContribution {
+
+
+ @AboutToShow
+ public void ats(MMenu menu){
+// menu.getChildren().remove(0); <--works
+ System.err.println(menu);
+ System.err.println("ATSH");
+ }
+
+ @AboutToHide
+ public void ath(){
+ System.err.println("ATH");
+ }
+
+} \ No newline at end of file
diff --git a/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/ClosePerspectiveHandler.java b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/ClosePerspectiveHandler.java
new file mode 100644
index 000000000..e72e85106
--- /dev/null
+++ b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/ClosePerspectiveHandler.java
@@ -0,0 +1,49 @@
+package org.eclipse.fx.testcases.e4.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
+import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.fx.ui.lifecycle.ELifecycleService;
+import org.eclipse.fx.ui.lifecycle.annotations.PreClose;
+import org.eclipse.fx.ui.workbench.base.rendering.AbstractRenderer;
+import org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer;
+
+public class ClosePerspectiveHandler {
+
+ @Execute
+ public void closePerspective(MWindow window, EModelService modelService, EPartService partService, ELifecycleService lifecycleService) {
+
+ MPerspectiveStack activeStack = (MPerspectiveStack) window
+ .getSelectedElement();
+ if (activeStack == null)
+ return;
+
+ // find the next perspective to activate, and the selected one
+ MPerspective activePerspective = activeStack.getSelectedElement();
+ List<MPart> partsInActive = modelService.findElements(window, null, MPart.class, null,
+ EModelService.IN_ACTIVE_PERSPECTIVE);
+ List<MPart> allParts = modelService.findElements(window, null, MPart.class, null,
+ EModelService.IN_ANY_PERSPECTIVE);
+ List<MPart> partsToRemove = new ArrayList<MPart>();
+ for (MPart p : partsInActive) {
+ if (!allParts.contains(p)) partsToRemove.add(p);
+ }
+ for (MPart p : partsToRemove) {
+ partService.hidePart(p, true);//don't care about saving here
+ }
+// AbstractRenderer renderer = (AbstractRenderer) activePerspective.getRenderer();
+// if (renderer.validateLifecycleAnnotation(PreClose.class, null, renderer.getModelContext(activePerspective)
+// , activePerspective))
+ if (lifecycleService.validateAnnotation(PreClose.class, activePerspective))
+ modelService.removePerspectiveModel(activePerspective, window);//this one includes selecting the next active
+
+ }
+
+} \ No newline at end of file
diff --git a/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/RegisterDynamicLifecycle.java b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/RegisterDynamicLifecycle.java
new file mode 100644
index 000000000..e7a0d9d11
--- /dev/null
+++ b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/RegisterDynamicLifecycle.java
@@ -0,0 +1,16 @@
+package org.eclipse.fx.testcases.e4.handlers;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.fx.ui.lifecycle.ELifecycleService;
+
+public class RegisterDynamicLifecycle {
+
+ @Execute
+ public void execute(ELifecycleService service, MPart part){
+ System.err.println(part.getLabel());
+ service.registerLifecycleURI(part, "bundleclass://org.eclipse.fx.testcases.e4/"+
+ "org.eclipse.fx.testcases.e4.lifecycle.SecondLifeCycle");
+ }
+
+} \ No newline at end of file
diff --git a/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/LifeCycle.java b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/LifeCycle.java
new file mode 100644
index 000000000..67bd19f53
--- /dev/null
+++ b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/LifeCycle.java
@@ -0,0 +1,31 @@
+package org.eclipse.fx.testcases.e4.lifecycle;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javafx.stage.Stage;
+
+import javax.annotation.PostConstruct;
+
+import org.eclipse.e4.core.services.contributions.IContributionFactory;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.MApplicationElement;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.fx.ui.dialogs.MessageDialog;
+import org.eclipse.fx.ui.lifecycle.LifecycleAddon;
+import org.eclipse.fx.ui.lifecycle.annotations.PreClose;
+import org.eclipse.fx.ui.workbench.renderers.base.widget.WWindow;
+
+public class LifeCycle {
+
+ @SuppressWarnings("rawtypes")
+ @PreClose
+ public boolean ph(MWindow win){
+ MessageDialog.openErrorDialog((Stage)((WWindow)win.getWidget()).getWidget(), "Sorry", "Sorry, no close.");
+ return false;
+ }
+
+ } \ No newline at end of file
diff --git a/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/SecondLifeCycle.java b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/SecondLifeCycle.java
new file mode 100644
index 000000000..cbc4e618f
--- /dev/null
+++ b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/SecondLifeCycle.java
@@ -0,0 +1,20 @@
+package org.eclipse.fx.testcases.e4.lifecycle;
+
+import javafx.stage.Stage;
+
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.fx.ui.dialogs.MessageDialog;
+import org.eclipse.fx.ui.lifecycle.annotations.PreClose;
+import org.eclipse.fx.ui.workbench.renderers.base.widget.WWindow;
+
+public class SecondLifeCycle {
+
+
+ @SuppressWarnings("rawtypes")
+ @PreClose
+ public boolean ph(MWindow win){
+ MessageDialog.openErrorDialog((Stage)((WWindow)win.getWidget()).getWidget(),
+ "Sorry again", "Sorry again, no close.");
+ return false;
+ }
+} \ No newline at end of file

Back to the top