Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2013-07-11 13:26:19 -0400
committerTom Schindl2013-07-11 13:26:19 -0400
commitcfd0f896572fabf1f8d94ab45e0846092a7bafbb (patch)
tree9d25b3b99b3e9c3dfac9dccd9bab27bdb9df1ab3
parent0b6386a34ba9dc7e598577e77c99408b15266c01 (diff)
downloadorg.eclipse.efxclipse-cfd0f896572fabf1f8d94ab45e0846092a7bafbb.tar.gz
org.eclipse.efxclipse-cfd0f896572fabf1f8d94ab45e0846092a7bafbb.tar.xz
org.eclipse.efxclipse-cfd0f896572fabf1f8d94ab45e0846092a7bafbb.zip
Bug 410158 - [kepler] add support for DynamicMenuContribution
-rwxr-xr-xbundles/runtime/org.eclipse.fx.ui.workbench.renderers.base/src/org/eclipse/fx/ui/workbench/renderers/base/BaseMenuRenderer.java84
1 files changed, 74 insertions, 10 deletions
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 6eb3b9270..7e43d36c2 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
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.fx.ui.workbench.renderers.base;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -17,13 +18,19 @@ import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.services.contributions.IContributionFactory;
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.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.core.log.Log;
+import org.eclipse.fx.core.log.Logger;
import org.eclipse.fx.ui.lifecycle.ELifecycleService;
import org.eclipse.fx.ui.lifecycle.annotations.PreClose;
import org.eclipse.fx.ui.lifecycle.annotations.PreShow;
@@ -31,11 +38,19 @@ 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;
+@SuppressWarnings("restriction")
public abstract class BaseMenuRenderer<N> extends BaseRenderer<MMenu, WMenu<N>> implements ChildrenHandler<MMenu, MMenuElement> {
@Inject
private ELifecycleService lifecycleService;
+ @Inject
+ private IContributionFactory contributionFactory;
+
+ @Log
+ @Inject
+ private Logger logger;
+
@PostConstruct
void init(IEventBroker eventBroker) {
EventProcessor.attachChildProcessor(eventBroker, this);
@@ -59,20 +74,66 @@ public abstract class BaseMenuRenderer<N> extends BaseRenderer<MMenu, WMenu<N>>
IEclipseContext context = getModelContext(element).createChild("lifecycle");
context.set(MMenu.class, element);
lifecycleService.validateAnnotation(PreClose.class, element, context);
+
+
+ for( MMenuElement e : element.getChildren().toArray(new MMenuElement[0]) ) {
+ if( e instanceof MDynamicMenuContribution ) {
+ MDynamicMenuContribution dc = (MDynamicMenuContribution) e;
+
+ Object contrib = dc.getObject();
+ if( contrib != null ) {
+ List<MMenuElement> list = new ArrayList<MMenuElement>();
+ context.set(List.class, list);
+ try {
+ ContextInjectionFactory.invoke(contrib, AboutToHide.class, context, null);
+ element.getChildren().removeAll(list);
+ } catch(Throwable t) {
+ logger.debug("Unable to process the AboutToHide", t);
+ }
+
+ }
+ }
+ }
+
context.dispose();
}
});
-// for (MApplicationElement m: element.getChildren()) {
-// if (!(m instanceof MDynamicMenuContribution)) continue;
-// MDynamicMenuContribution c = (MDynamicMenuContribution) m;
-// lifecycleService.registerLifecycleURI(element, c.getContributionURI());
-// }
}
void handleShowing(MMenu element) {
IEclipseContext context = getModelContext(element).createChild("lifecycle");
context.set(MMenu.class, element);
lifecycleService.validateAnnotation(PreShow.class, element, context);
+
+ // we iterate of the copy because it is modified in between
+ for( MMenuElement e : element.getChildren().toArray(new MMenuElement[0]) ) {
+ if( e instanceof MDynamicMenuContribution ) {
+ MDynamicMenuContribution dc = (MDynamicMenuContribution) e;
+ if( dc.getObject() == null && dc.getContributionURI() != null ) {
+ try {
+ //TODO On which context should we create the instance, would
+ dc.setObject(contributionFactory.create(dc.getContributionURI(), context));
+ } catch(Throwable t ) {
+ logger.debug("Unable to create contribution", t);
+ }
+ }
+
+ Object contrib = dc.getObject();
+ if( contrib != null ) {
+ List<MMenuElement> list = new ArrayList<MMenuElement>();
+ context.set(List.class, list);
+ try {
+ ContextInjectionFactory.invoke(contrib, AboutToShow.class, context, null);
+
+ int idx = element.getChildren().indexOf(e);
+ element.getChildren().addAll(idx, list);
+ } catch(Throwable t) {
+ logger.debug("Unable to process AboutToShow", t);
+ }
+
+ }
+ }
+ }
for (MMenuElement e : element.getChildren()) {
if (e.getRenderer() instanceof BaseItemRenderer) {
@@ -102,11 +163,14 @@ 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 dc = (MDynamicMenuContribution) element;
+ if( dc.getObject() != null ) {
+
+ }
+ }
+
if (element.isToBeRendered() && element.isVisible() && element.getWidget() != null) {
hideChild(parent, element);
}

Back to the top