Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2013-07-10 16:16:28 -0400
committerTom Schindl2013-07-10 16:16:28 -0400
commit9b2b5959773b3b38f18069bd01354e98f2a66807 (patch)
treebfe1c77d1e526fbaf568eed031a168c2a155f2ae
parent366a3a6c6423c8edd6903ad03c6fd28560f7355d (diff)
downloadorg.eclipse.efxclipse-9b2b5959773b3b38f18069bd01354e98f2a66807.tar.gz
org.eclipse.efxclipse-9b2b5959773b3b38f18069bd01354e98f2a66807.tar.xz
org.eclipse.efxclipse-9b2b5959773b3b38f18069bd01354e98f2a66807.zip
Bug 410172 - [e4] add general lifecycle support for model elements
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.lifecycle/META-INF/MANIFEST.MF3
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/internal/lifecycle/LifecycleServiceImpl.java4
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/ELifecycleService.java3
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/LifecycleAddon.java42
-rwxr-xr-xbundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseMenuRenderer.java73
-rwxr-xr-xbundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseStackRenderer.java23
-rwxr-xr-xbundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseWorkbenchRendererFactory.java3
-rwxr-xr-xtestcases/org.eclipse.fx.testcases.e4/Application.e4xmi1
-rw-r--r--testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/handlers/ClosePerspectiveHandler.java2
-rw-r--r--testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/MenuLifecycle.java34
10 files changed, 125 insertions, 63 deletions
diff --git a/bundles/runtime/org.eclipse.fx.ui.lifecycle/META-INF/MANIFEST.MF b/bundles/runtime/org.eclipse.fx.ui.lifecycle/META-INF/MANIFEST.MF
index 63b15abec..795322649 100644
--- a/bundles/runtime/org.eclipse.fx.ui.lifecycle/META-INF/MANIFEST.MF
+++ b/bundles/runtime/org.eclipse.fx.ui.lifecycle/META-INF/MANIFEST.MF
@@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.e4.ui.model.workbench,
org.eclipse.e4.core.di,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.services,
- org.eclipse.e4.ui.workbench
+ org.eclipse.e4.ui.workbench,
+ org.eclipse.emf.ecore;bundle-version="2.9.0"
Export-Package: org.eclipse.fx.ui.lifecycle,
org.eclipse.fx.ui.lifecycle.annotations
Import-Package: javax.annotation;version="1.1.0",
diff --git a/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/internal/lifecycle/LifecycleServiceImpl.java b/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/internal/lifecycle/LifecycleServiceImpl.java
index d494a66da..54316919d 100644
--- a/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/internal/lifecycle/LifecycleServiceImpl.java
+++ b/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/internal/lifecycle/LifecycleServiceImpl.java
@@ -39,8 +39,8 @@ public class LifecycleServiceImpl implements ELifecycleService{
}
- public boolean validateAnnotation(Class annotationClass, MUIElement element) {
- return validateLifecycleAnnotation(annotationClass, getContextForParent(element), getModelContext(element), element);
+ public boolean validateAnnotation(Class annotationClass, MUIElement element, IEclipseContext context) {
+ return validateLifecycleAnnotation(annotationClass, getContextForParent(element), context, element);
}
private boolean validateLifecycleAnnotation(Class clazz, IEclipseContext parentContext,
diff --git a/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/ELifecycleService.java b/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/ELifecycleService.java
index cd1611b69..fd1afe872 100644
--- a/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/ELifecycleService.java
+++ b/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/ELifecycleService.java
@@ -2,6 +2,7 @@ package org.eclipse.fx.ui.lifecycle;
import java.lang.annotation.Annotation;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
public interface ELifecycleService {
@@ -10,6 +11,6 @@ public interface ELifecycleService {
public void unregisterLifecycleContribution(MUIElement element, Object contribution);
- public boolean validateAnnotation(Class<? extends Annotation> annotationClass, MUIElement element);
+ public boolean validateAnnotation(Class<? extends Annotation> annotationClass, MUIElement element, IEclipseContext context);
} \ No newline at end of file
diff --git a/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/LifecycleAddon.java b/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/LifecycleAddon.java
index caa269d7f..fc07466aa 100644
--- a/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/LifecycleAddon.java
+++ b/bundles/runtime/org.eclipse.fx.ui.lifecycle/src/org/eclipse/fx/ui/lifecycle/LifecycleAddon.java
@@ -6,12 +6,10 @@ import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.MApplicationElement;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
-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.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
//when we are ready to ditch the tag-based stuff we simply swap the addon
@@ -20,8 +18,8 @@ public class LifecycleAddon {
@Inject
MApplication app;
- @Inject
- EModelService modelService;
+// @Inject
+// EModelService modelService;
@Inject
ELifecycleService lifecycleService;
@@ -32,26 +30,18 @@ public class LifecycleAddon {
@PostConstruct
public void postConstruct(){
- //initial processing
- process(MPart.class, app);
- process(MWindow.class,app);
- process(MPerspective.class,app);
- //TODO - register an EH to watch for addition/removal of tags
-
- }
-
- private void process(Class<? extends MUIElement> clazz, MUIElement root) {
- List<? extends MUIElement> elements = modelService.findElements(root, null, clazz, null);
- for (MUIElement element : elements) {
- //build lifecycle uris set (because no duplicates allowed)
- List<String> tags = element.getTags();
- for (String tag: tags) {
- if (tag.startsWith(LIFECYCLE_TAG_PREFIX)) {
- lifecycleService.registerLifecycleURI(element,tag.substring(LIFECYCLE_TAG_PREFIX.length()));
+ TreeIterator<EObject> it = EcoreUtil.getAllContents((EObject)app, true);
+ while( it.hasNext() ) {
+ EObject e = it.next();
+ if( e instanceof MUIElement ) {
+ MUIElement element = (MUIElement) e;
+ List<String> tags = element.getTags();
+ for (String tag: tags) {
+ if (tag.startsWith(LIFECYCLE_TAG_PREFIX)) {
+ lifecycleService.registerLifecycleURI(element,tag.substring(LIFECYCLE_TAG_PREFIX.length()));
+ }
}
}
-
- }
+ }
}
-
} \ No newline at end of file
diff --git a/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseMenuRenderer.java b/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseMenuRenderer.java
index 1c60781cc..6eb3b9270 100755
--- a/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseMenuRenderer.java
+++ b/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseMenuRenderer.java
@@ -12,20 +12,21 @@ package org.eclipse.fx.ui.workbench.renderers.base;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
-import org.eclipse.e4.ui.di.AboutToHide;
-import org.eclipse.e4.ui.di.AboutToShow;
-import org.eclipse.e4.ui.model.application.MApplicationElement;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.menu.MDynamicMenuContribution;
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.fx.ui.lifecycle.ELifecycleService;
+import org.eclipse.fx.ui.lifecycle.annotations.PreClose;
+import org.eclipse.fx.ui.lifecycle.annotations.PreShow;
import org.eclipse.fx.ui.workbench.renderers.base.EventProcessor.ChildrenHandler;
import org.eclipse.fx.ui.workbench.renderers.base.widget.WMenu;
import org.eclipse.fx.ui.workbench.renderers.base.widget.WMenuElement;
@@ -55,22 +56,24 @@ public abstract class BaseMenuRenderer<N> extends BaseRenderer<MMenu, WMenu<N>>
@Override
public void run() {
- IEclipseContext modelContext = getModelContext(element);
- if (modelContext!=null) modelContext.set(MMenu.class, element);
- lifecycleService.validateAnnotation(AboutToHide.class, element);
+ IEclipseContext context = getModelContext(element).createChild("lifecycle");
+ context.set(MMenu.class, element);
+ lifecycleService.validateAnnotation(PreClose.class, element, context);
+ context.dispose();
}
});
- for (MApplicationElement m: element.getChildren()) {
- if (!(m instanceof MDynamicMenuContribution)) continue;
- MDynamicMenuContribution c = (MDynamicMenuContribution) m;
- lifecycleService.registerLifecycleURI(element, c.getContributionURI());
- }
+// for (MApplicationElement m: element.getChildren()) {
+// if (!(m instanceof MDynamicMenuContribution)) continue;
+// MDynamicMenuContribution c = (MDynamicMenuContribution) m;
+// lifecycleService.registerLifecycleURI(element, c.getContributionURI());
+// }
}
void handleShowing(MMenu element) {
- IEclipseContext modelContext = getModelContext(element);
- if (modelContext!=null) modelContext.set(MMenu.class, element);
- lifecycleService.validateAnnotation(AboutToShow.class, element);
+ IEclipseContext context = getModelContext(element).createChild("lifecycle");
+ context.set(MMenu.class, element);
+ lifecycleService.validateAnnotation(PreShow.class, element, context);
+
for (MMenuElement e : element.getChildren()) {
if (e.getRenderer() instanceof BaseItemRenderer) {
@SuppressWarnings("unchecked")
@@ -78,6 +81,8 @@ public abstract class BaseMenuRenderer<N> extends BaseRenderer<MMenu, WMenu<N>>
r.checkEnablement(e);
}
}
+
+ context.dispose();
}
@@ -97,11 +102,11 @@ public abstract class BaseMenuRenderer<N> extends BaseRenderer<MMenu, WMenu<N>>
Iterator<MMenuElement> iterator = elements.iterator();
while (iterator.hasNext()) {
MMenuElement element = iterator.next();
- if (element instanceof MDynamicMenuContribution) {
- MDynamicMenuContribution c = (MDynamicMenuContribution) element;
- lifecycleService.unregisterLifecycleContribution(element, c.getObject());
- continue;
- }
+// if (element instanceof MDynamicMenuContribution) {
+// MDynamicMenuContribution c = (MDynamicMenuContribution) element;
+// lifecycleService.unregisterLifecycleContribution(element, c.getObject());
+// continue;
+// }
if (element.isToBeRendered() && element.isVisible() && element.getWidget() != null) {
hideChild(parent, element);
}
@@ -112,11 +117,11 @@ public abstract class BaseMenuRenderer<N> extends BaseRenderer<MMenu, WMenu<N>>
Iterator<MMenuElement> iterator = elements.iterator();
while (iterator.hasNext()) {
MMenuElement element = iterator.next();
- if (element instanceof MDynamicMenuContribution) {
- MDynamicMenuContribution c = (MDynamicMenuContribution) element;
- lifecycleService.registerLifecycleURI(element, c.getContributionURI());
- continue;
- }
+// if (element instanceof MDynamicMenuContribution) {
+// MDynamicMenuContribution c = (MDynamicMenuContribution) element;
+// lifecycleService.registerLifecycleURI(element, c.getContributionURI());
+// continue;
+// }
if (element.isToBeRendered() && element.isVisible()) {
if (element.getWidget() == null) {
engineCreateWidget(element);
@@ -141,6 +146,26 @@ public abstract class BaseMenuRenderer<N> extends BaseRenderer<MMenu, WMenu<N>>
}
@Override
+ protected int getRenderedIndex(MUIElement parent, MUIElement element) {
+ EObject eElement = (EObject) element;
+
+ EObject container = eElement.eContainer();
+ @SuppressWarnings("unchecked")
+ List<MUIElement> list = (List<MUIElement>) container.eGet(eElement.eContainmentFeature());
+ int idx = 0;
+ for( MUIElement u : list ) {
+ if( u.isToBeRendered() && u.isVisible() && !(u instanceof MDynamicMenuContribution) ) {
+ if( u == element ) {
+ return idx;
+ }
+ idx++;
+ }
+ }
+ return -1;
+ }
+
+
+ @Override
public void hideChild(MMenu container, MUIElement changedObj) {
WMenu<N> menu = getWidget(container);
diff --git a/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseStackRenderer.java b/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseStackRenderer.java
index 165388247..2e2d2b376 100755
--- a/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseStackRenderer.java
+++ b/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseStackRenderer.java
@@ -350,16 +350,25 @@ public abstract class BaseStackRenderer<N, I, IC> extends BaseRenderer<MPartStac
IEclipseContext partContext = part.getContext();
IEclipseContext parentContext = getContextForParent(part);
// a part may not have a context if it hasn't been rendered
- IEclipseContext context = partContext == null ? parentContext : partContext;
+ IEclipseContext context = (partContext == null ? parentContext : partContext).createChild();
+ if( partContext == null ) {
+ context.set(MPart.class, part);
+ }
+
// Allow closes to be 'canceled'
EPartService partService = (EPartService) context.get(EPartService.class.getName());
- if (partService.savePart(part, true) && lifecycleService.validateAnnotation(PreClose.class, part)) {
- partService.hidePart(part);
- return true;
+
+ try {
+ if (partService.savePart(part, true) && lifecycleService.validateAnnotation(PreClose.class, part, context)) {
+ partService.hidePart(part);
+ return true;
+ }
+ // the user has canceled out of the save operation, so don't close the
+ // part
+ return false;
+ } finally {
+ context.dispose();
}
- // the user has canceled out of the save operation, so don't close the
- // part
- return false;
}
diff --git a/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseWorkbenchRendererFactory.java b/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseWorkbenchRendererFactory.java
index e65bb4519..92dba3513 100755
--- a/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseWorkbenchRendererFactory.java
+++ b/bundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseWorkbenchRendererFactory.java
@@ -28,6 +28,7 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicPackageImpl;
+import org.eclipse.e4.ui.model.application.ui.menu.MDynamicMenuContribution;
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
@@ -156,7 +157,7 @@ public abstract class BaseWorkbenchRendererFactory implements RendererFactory {
partRenderer = make(getPartRendererClass());
}
return (R) partRenderer;
- } else if( modelObject instanceof MMenuItem ) {
+ } else if( modelObject instanceof MMenuItem && ! (modelObject instanceof MDynamicMenuContribution) ) {
if( menuItemRenderer == null ) {
menuItemRenderer = make(getMenuItemRendererClass());
}
diff --git a/testcases/org.eclipse.fx.testcases.e4/Application.e4xmi b/testcases/org.eclipse.fx.testcases.e4/Application.e4xmi
index a8473b652..33018943f 100755
--- a/testcases/org.eclipse.fx.testcases.e4/Application.e4xmi
+++ b/testcases/org.eclipse.fx.testcases.e4/Application.e4xmi
@@ -94,6 +94,7 @@
</children>
<mainMenu xmi:id="_W8hHoORZEeGP-5z69KadAQ" elementId="org.eclipse.fx.testcases.e4.menu.0">
<children xsi:type="menu:Menu" xmi:id="_Xwuy0ORZEeGP-5z69KadAQ" elementId="org.eclipse.fx.testcases.e4.menu.1" label="M1">
+ <tags>EFX_LC:bundleclass://org.eclipse.fx.testcases.e4/org.eclipse.fx.testcases.e4.lifecycle.MenuLifecycle</tags>
<children xsi:type="menu:HandledMenuItem" xmi:id="_f6s64ORqEeGP-5z69KadAQ" elementId="org.eclipse.fx.testcases.e4.handledmenuitem.0" label="Push - HI 0" command="_FEZr8OUcEeGP-5z69KadAQ"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_lb8V4ORqEeGP-5z69KadAQ" elementId="org.eclipse.fx.testcases.e4.handledmenuitem.1" label="Check - HI 1" type="Check" command="_3PQSEOqiEeGrz8mV_3Gr5A"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_pBaAsORqEeGP-5z69KadAQ" elementId="org.eclipse.fx.testcases.e4.handledmenuitem.2" label="Radio - HI 2" type="Radio" command="_FEZr8OUcEeGP-5z69KadAQ"/>
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
index e72e85106..fce75d0ac 100644
--- 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
@@ -41,7 +41,7 @@ public class ClosePerspectiveHandler {
// AbstractRenderer renderer = (AbstractRenderer) activePerspective.getRenderer();
// if (renderer.validateLifecycleAnnotation(PreClose.class, null, renderer.getModelContext(activePerspective)
// , activePerspective))
- if (lifecycleService.validateAnnotation(PreClose.class, activePerspective))
+ if (lifecycleService.validateAnnotation(PreClose.class, activePerspective, activePerspective.getContext()))
modelService.removePerspectiveModel(activePerspective, window);//this one includes selecting the next active
}
diff --git a/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/MenuLifecycle.java b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/MenuLifecycle.java
new file mode 100644
index 000000000..98f6f2f62
--- /dev/null
+++ b/testcases/org.eclipse.fx.testcases.e4/src/org/eclipse/fx/testcases/e4/lifecycle/MenuLifecycle.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at 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:
+ * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.testcases.e4.lifecycle;
+
+import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.fx.ui.lifecycle.annotations.PreClose;
+import org.eclipse.fx.ui.lifecycle.annotations.PreShow;
+
+public class MenuLifecycle {
+
+ private MDirectMenuItem ds;
+
+ @PreClose
+ void closeingMenu(MMenu m) {
+ ds.getParent().getChildren().remove(ds);
+ }
+
+ @PreShow
+ void openingMenu(MMenu m, EModelService ms) {
+ ds = ms.createModelElement(MDirectMenuItem.class);
+ ds.setLabel("Dynamic Item");
+ m.getChildren().add(0,ds);
+ }
+}

Back to the top