Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf')
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/Activator.java67
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/action/CreateChildAction.java73
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/action/ExtendedTypeAction.java73
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/AbstractCustomFillElement.java38
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/CustomFillElement.java27
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillElement.java22
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenu.java54
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuAction.java49
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuContainer.java37
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuGroup.java77
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuRoot.java38
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillNewChild.java225
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillSeparator.java34
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillerFactory.java77
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/MyCustomFiller.java28
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/AbstractFillPolicy.java48
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/FilterFillPolicy.java26
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/NewChildFillPolicy.java62
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyManager.java35
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java78
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/ReplaceFillPolicy.java37
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/DisabledContributionItem.java58
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/MenuConstraintEngine.java35
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/NewchildManager.java102
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/util/MenuHelper.java35
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/util/Util.java38
26 files changed, 1473 insertions, 0 deletions
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/Activator.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/Activator.java
new file mode 100644
index 00000000000..5341d9da478
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/Activator.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.emf.newchild"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/action/CreateChildAction.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/action/CreateChildAction.java
new file mode 100644
index 00000000000..d477dea90b8
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/action/CreateChildAction.java
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.action;
+
+import java.net.URL;
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.edit.command.CommandActionDelegate;
+import org.eclipse.emf.edit.command.CommandParameter;
+import org.eclipse.emf.edit.command.CreateChildCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.ui.action.StaticSelectionCommandAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+
+public class CreateChildAction extends StaticSelectionCommandAction {
+
+ private EObject parent;
+
+ private EReference createIn;
+
+ private EClass createAs;
+
+ private EditingDomain domain;
+
+ public CreateChildAction(EditingDomain domain, EObject parent, EReference createIn, EClass createAs) {
+ super(domain);
+ this.domain = domain;
+ this.parent = parent;
+ this.createIn = createIn;
+ this.createAs = createAs;
+ }
+
+ @Override
+ protected Command createActionCommand(EditingDomain editingDomain, Collection<?> collection) {
+ EObject createdEObject = createAs.getEPackage().getEFactoryInstance().create(createAs);
+
+ CommandParameter creationParameter = new CommandParameter(parent, createIn, createdEObject);
+
+ Command createInFeature = CreateChildCommand.create(domain, parent, creationParameter, collection);
+
+ // super.setText(createInFeature.getLabel());
+ super.setDescription(createInFeature.getDescription());
+ if(createInFeature instanceof CommandActionDelegate) {
+
+ Object image = ((CommandActionDelegate)createInFeature).getImage();
+ if(image instanceof URL) {
+ ImageDescriptor descriptor = ImageDescriptor.createFromURL((URL)image);
+ super.setImageDescriptor(descriptor);
+ }
+ }
+
+ return createInFeature;
+ }
+
+ @Override
+ public String getText() {
+ return createAs.getName();
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/action/ExtendedTypeAction.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/action/ExtendedTypeAction.java
new file mode 100644
index 00000000000..120edaadde0
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/action/ExtendedTypeAction.java
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.action;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.extendedtypes.ExtendedEditHelperAdvice;
+import org.eclipse.papyrus.infra.extendedtypes.ExtendedElementTypeConfiguration;
+import org.eclipse.papyrus.infra.extendedtypes.ExtendedSemanticTypeDescriptor;
+import org.eclipse.papyrus.infra.extendedtypes.ExtendedTypesRegistry;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+
+
+public class ExtendedTypeAction extends Action {
+
+ private IElementType elementType;
+
+ private EObject parent;
+
+ private EditingDomain domain;
+
+ private ExtendedSemanticTypeDescriptor descriptor;
+
+ public static ExtendedEditHelperAdvice advice = new ExtendedEditHelperAdvice();
+
+ public ExtendedTypeAction(EObject parent, ExtendedElementTypeConfiguration elementTypeConfiguration, EditingDomain domain) {
+ this.elementType = ExtendedTypesRegistry.getInstance().getType(elementTypeConfiguration.getId());
+ // this.descriptor = new ExtendedSemanticTypeDescriptor(elementTypeConfiguration);
+ // this.elementType = ExtendedHintedTypeFactory.getInstance().createSpecializationType(descriptor);
+ this.parent = parent;
+ this.domain = domain;
+
+ configureAction();
+ }
+
+ protected void configureAction() {
+ setText(descriptor.getName());
+ setImageDescriptor(ImageDescriptor.createFromURL(descriptor.getIconURL()));
+ }
+
+ @Override
+ public void run() {
+ CreateElementRequest request = new CreateElementRequest((TransactionalEditingDomain)domain, parent, elementType);
+
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(parent);
+
+ if(provider != null) {
+ ICommand createGMFCommand = provider.getEditCommand(request);
+
+ Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
+
+ domain.getCommandStack().execute(emfCommand);
+ }
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/AbstractCustomFillElement.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/AbstractCustomFillElement.java
new file mode 100644
index 00000000000..bf5c1c5325e
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/AbstractCustomFillElement.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.CustomFiller;
+
+/**
+ * A base implementation for CustomFillElement
+ *
+ * @author Camille Letavernier
+ */
+public abstract class AbstractCustomFillElement implements CustomFillElement {
+
+ protected FillMenuGroup group;
+
+ protected CustomFiller filler;
+
+ public void setMenuItem(CustomFiller filler) {
+ this.filler = filler;
+ }
+
+ public void setParentGroup(FillMenuGroup group) {
+ this.group = group;
+ }
+
+ public abstract void fill(IMenuManager menuManager);
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/CustomFillElement.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/CustomFillElement.java
new file mode 100644
index 00000000000..0f0a4a824c3
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/CustomFillElement.java
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.papyrus.infra.emf.newchild.CustomFiller;
+
+/**
+ * An interface for Custom menu filler
+ *
+ * @author Camille Letavernier
+ */
+public interface CustomFillElement extends FillElement {
+
+ public void setMenuItem(CustomFiller filler);
+
+ public void setParentGroup(FillMenuGroup group);
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillElement.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillElement.java
new file mode 100644
index 00000000000..e91f761f5f9
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillElement.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.jface.action.IMenuManager;
+
+
+
+public interface FillElement {
+
+ public void fill(IMenuManager menuManager);
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenu.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenu.java
new file mode 100644
index 00000000000..02d5dd465ad
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenu.java
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.papyrus.infra.emf.newchild.Menu;
+import org.eclipse.papyrus.infra.emf.newchild.runtime.NewchildManager;
+import org.eclipse.papyrus.infra.emf.newchild.util.MenuHelper;
+import org.eclipse.papyrus.infra.emf.newchild.util.Util;
+
+
+public class FillMenu extends FillMenuContainer {
+
+ protected Menu menu;
+
+ protected FillMenuGroup parentGroup;
+
+ protected IMenuManager subMenu;
+
+ public FillMenu(FillMenuGroup parentGroup, Menu menu, Object selectedObject) {
+ super(menu, selectedObject);
+ this.menu = menu;
+ this.parentGroup = parentGroup;
+ }
+
+ @Override
+ public void fill(IMenuManager menuManager) {
+ IMenuManager subMenuManager = getSubMenu(menuManager);
+ super.fill(subMenuManager);
+ }
+
+ protected IMenuManager getSubMenu(IMenuManager fromMenu) {
+ if(subMenu == null) {
+ subMenu = new MenuManager(menu.getName(), Util.getImage(menu), menu.getId());
+ MenuHelper.add(parentGroup, fromMenu, subMenu);
+
+ Separator separator = new Separator();
+ separator.setId(NewchildManager.TOP);
+ subMenu.add(separator);
+ }
+ return subMenu;
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuAction.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuAction.java
new file mode 100644
index 00000000000..6356c504748
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuAction.java
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.MenuAction;
+import org.eclipse.papyrus.infra.emf.newchild.action.ExtendedTypeAction;
+import org.eclipse.papyrus.infra.emf.newchild.util.MenuHelper;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+
+
+public class FillMenuAction implements FillElement {
+
+ private FillMenuGroup parentGroup;
+
+ private MenuAction menuAction;
+
+ private EObject selectedEObject;
+
+ private EditingDomain domain;
+
+ public FillMenuAction(FillMenuGroup parentGroup, MenuAction menuAction, Object selectedObject){
+ this.parentGroup = parentGroup;
+ this.menuAction = menuAction;
+ this.selectedEObject = EMFHelper.getEObject(selectedObject);
+ if(selectedEObject == null) {
+ throw new IllegalArgumentException("ExtendedTypes can only be used on EMF EObject");
+ }
+
+ domain = AdapterFactoryEditingDomain.getEditingDomainFor(selectedEObject);
+ }
+
+ public void fill(IMenuManager menuManager) {
+ MenuHelper.add(parentGroup, menuManager, new ExtendedTypeAction(selectedEObject, menuAction.getElementType(), domain));
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuContainer.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuContainer.java
new file mode 100644
index 00000000000..cabcb331c3b
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuContainer.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.MenuContainer;
+import org.eclipse.papyrus.infra.emf.newchild.MenuItem;
+
+
+public class FillMenuContainer implements FillElement {
+
+ protected MenuContainer container;
+
+ protected Object selectedObject;
+
+ public FillMenuContainer(MenuContainer container, Object selectedObject) {
+ this.container = container;
+ this.selectedObject = selectedObject;
+ }
+
+ public void fill(IMenuManager menuManager) {
+ for(MenuItem menuItem : container.getSubmenus()) {
+ FillElement filler = FillerFactory.instance.getFiller(menuItem, selectedObject);
+ filler.fill(menuManager);
+ }
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuGroup.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuGroup.java
new file mode 100644
index 00000000000..30dfdf1de79
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuGroup.java
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.papyrus.infra.emf.newchild.MenuGroup;
+import org.eclipse.papyrus.infra.emf.newchild.MenuItem;
+import org.eclipse.papyrus.infra.emf.newchild.runtime.NewchildManager;
+
+
+public class FillMenuGroup extends FillMenuContainer {
+
+ private static String TOP_SEP = "TMP_GROUP#TOP"; //$NON-NLS-1$
+
+ private static String END_SEP = "TMP_GROUP#END"; //$NON-NLS-1$
+
+ protected MenuGroup group;
+
+ protected String groupId = TOP_SEP;
+
+ public FillMenuGroup(MenuGroup group, Object selectedObject) {
+ super(group, selectedObject);
+ this.group = group;
+ }
+
+ @Override
+ public void fill(IMenuManager manager) {
+
+ Separator tmpSeparator = new Separator(groupId);
+
+ if(manager.find(group.getBefore()) != null) {
+ manager.insertBefore(group.getBefore(), tmpSeparator);
+ } else if(manager.find(group.getAfter()) != null) {
+ manager.insertAfter(group.getAfter(), tmpSeparator);
+ } else if(group.getAbsolutePosition() != null) {
+ switch(group.getAbsolutePosition()) {
+ case TOP:
+ if(manager.find(NewchildManager.TOP) != null) {
+ manager.insertAfter(NewchildManager.TOP, tmpSeparator);
+ break;
+ }
+ case BOTTOM:
+ default:
+ manager.add(tmpSeparator);
+ break;
+ }
+ }
+
+ Separator endSeparator = new Separator(END_SEP);
+ manager.insertAfter(TOP_SEP, endSeparator);
+
+ for(MenuItem menuItem : container.getSubmenus()) {
+ FillElement filler = FillerFactory.instance.getFiller(this, menuItem, selectedObject);
+ if(filler != null) {
+ filler.fill(manager);
+ }
+ }
+
+ manager.remove(tmpSeparator);
+ manager.remove(endSeparator);
+ }
+
+ public String getGroupId() {
+ return groupId;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuRoot.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuRoot.java
new file mode 100644
index 00000000000..5332eda969f
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillMenuRoot.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.MenuGroup;
+import org.eclipse.papyrus.infra.emf.newchild.MenuRoot;
+
+
+public class FillMenuRoot extends FillMenuContainer {
+
+ protected MenuRoot root;
+
+ public FillMenuRoot(MenuRoot root, Object selectedObject) {
+ super(root, selectedObject);
+
+ this.root = root;
+ }
+
+ @Override
+ public void fill(IMenuManager menuManager) {
+ super.fill(menuManager);
+
+ for(MenuGroup group : root.getGroups()) {
+ FillerFactory.instance.getFiller(group, selectedObject).fill(menuManager);
+ }
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillNewChild.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillNewChild.java
new file mode 100644
index 00000000000..3cad806dd37
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillNewChild.java
@@ -0,0 +1,225 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import java.io.IOException;
+import java.text.Collator;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.emf.newchild.Activator;
+import org.eclipse.papyrus.infra.emf.newchild.MenuGroup;
+import org.eclipse.papyrus.infra.emf.newchild.NewchildConfiguration;
+import org.eclipse.papyrus.infra.emf.newchild.action.CreateChildAction;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.CreateIn;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.Layout;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewChildPolicySet;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewEMFChildMenu;
+import org.eclipse.papyrus.infra.emf.newchild.policies.NewChildFillPolicy;
+import org.eclipse.papyrus.infra.emf.newchild.policies.PolicyManager;
+import org.eclipse.papyrus.infra.emf.newchild.policies.PolicyMatcher;
+import org.eclipse.papyrus.infra.emf.newchild.runtime.DisabledContributionItem;
+import org.eclipse.papyrus.infra.emf.newchild.util.MenuHelper;
+import org.eclipse.papyrus.infra.emf.newchild.util.Util;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+
+
+
+public class FillNewChild extends FillMenu implements FillElement {
+
+ protected EObject selectedEObject;
+
+ protected NewEMFChildMenu menu;
+
+ //private static PolicyManager policyManager;
+
+ private PolicyManager policyManager;
+
+ public FillNewChild(FillMenuGroup parentGroup, NewEMFChildMenu menu, Object selectedObject) {
+ super(parentGroup, menu, selectedObject);
+ this.menu = menu;
+ this.selectedEObject = EMFHelper.getEObject(selectedObject);
+
+ //TODO : Extract that to a static instance, and load with extension point
+ policyManager = new PolicyManager();
+ try {
+ NewchildConfiguration configuration = (NewchildConfiguration)EMFHelper.loadEMFModel(null, URI.createPlatformPluginURI("org.eclipse.papyrus.infra.emf.newchild/Model/NewchildConfiguration.xmi", true));
+ policyManager.addConfiguration(configuration);
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ }
+ }
+
+ @Override
+ public void fill(IMenuManager menuManager) {
+ EObject parentEObject = selectedEObject;
+ if(menu.getCreateIn() == CreateIn.PARENT) {
+ if(selectedEObject != null) {
+ parentEObject = selectedEObject.eContainer();
+ }
+ }
+
+ if(parentEObject == null) {
+ return;
+ }
+
+ if(EMFHelper.isReadOnly(parentEObject)) {
+ DisabledContributionItem disabledItem = new DisabledContributionItem(menu.getName(), Util.getImage(menu), menu.getId());
+ disabledItem.setMenuStyle(true);
+ MenuHelper.add(parentGroup, menuManager, disabledItem);
+ return;
+ }
+
+ IMenuManager createChildMenu = getSubMenu(menuManager);
+
+ Map<EStructuralFeature, List<EClass>> instantiableClasses = new LinkedHashMap<EStructuralFeature, List<EClass>>();
+
+ List<EStructuralFeature> features = new LinkedList<EStructuralFeature>(parentEObject.eClass().getEAllStructuralFeatures());
+ Collections.sort(features, new Comparator<EStructuralFeature>() {
+
+ public int compare(EStructuralFeature feature1, EStructuralFeature feature2) {
+ if(feature1 == null) {
+ if(feature2 == null) {
+ return 0;
+ }
+ return -1;
+ }
+
+ return Collator.getInstance().compare(feature1.getName(), feature2.getName());
+ }
+
+ });
+
+ for(EStructuralFeature feature : features) {
+ if(feature instanceof EReference && ((EReference)feature).isContainment()) {
+ EClass type = (EClass)feature.getEType();
+ List<EClass> eClasses = EMFHelper.getSubclassesOf(type, true);
+ Collections.sort(eClasses, new Comparator<EClass>() {
+
+ public int compare(EClass class1, EClass class2) {
+ if(class1 == null) {
+ if(class2 == null) {
+ return 0;
+ }
+ return -1;
+ }
+
+ return Collator.getInstance().compare(class1.getName(), class2.getName());
+ }
+
+ });
+
+ instantiableClasses.put(feature, eClasses);
+ }
+ }
+
+ Layout layout = getLayout(instantiableClasses);
+
+ Set<NewChildPolicySet> policySets = policyManager.getDisplayUnits(new StructuredSelection(parentEObject));
+ PolicyMatcher matcher = new PolicyMatcher();
+ matcher.setPolicies(policySets);
+
+ if(layout == Layout.FLAT) {
+ for(EStructuralFeature feature : instantiableClasses.keySet()) {
+ for(EClass eClass : instantiableClasses.get(feature)) {
+ addActionToMenu(matcher, createChildMenu, parentEObject, eClass, feature);
+ }
+ }
+ } else { //Hierarchical
+ for(EStructuralFeature feature : instantiableClasses.keySet()) {
+ IMenuManager subMenu = new MenuManager(feature.getName());
+ createChildMenu.add(subMenu);
+
+ for(EClass eClass : instantiableClasses.get(feature)) {
+ addActionToMenu(matcher, subMenu, parentEObject, eClass, feature);
+ }
+ }
+ }
+
+ super.fill(menuManager);
+
+ for(MenuGroup group : menu.getGroups()) {
+ FillerFactory.instance.getFiller(group, selectedObject).fill(createChildMenu);
+ }
+ }
+
+ protected void addActionToMenu(PolicyMatcher matcher, IMenuManager menu, EObject parentEObject, EClass eClass, EStructuralFeature feature) {
+ eClass = (EClass)eClass.getEPackage().getEClassifier(eClass.getName()); //Loads the EClass from the static resourceSet
+
+ List<NewChildFillPolicy> matchingPolicies = matcher.getMatchingPolicies(eClass, feature);
+ if(matchingPolicies.isEmpty()) {
+ addCreateActionToMenu(menu, parentEObject, eClass, (EReference)feature);
+ } else {
+ for(NewChildFillPolicy policy : matchingPolicies) {
+ policy.fill(menu, parentEObject, eClass, feature, parentEObject);
+ }
+ }
+ }
+
+ @Override
+ protected IMenuManager getSubMenu(IMenuManager menuManager) {
+ return super.getSubMenu(menuManager);
+ }
+
+ private Layout getLayout(Map<EStructuralFeature, List<EClass>> instantiableClasses) {
+ if(menu.getLayout() != Layout.AUTO) {
+ return menu.getLayout();
+ }
+
+ if(instantiableClasses.size() < 2) {
+ return Layout.FLAT;
+ }
+
+ if(instantiableClasses.size() > 5) {
+ return Layout.HIERARCHICAL;
+ }
+
+ for(List<EClass> eClasses : instantiableClasses.values()) {
+ if(eClasses.size() > 5) {
+ return Layout.HIERARCHICAL;
+ }
+ }
+
+ return Layout.FLAT;
+ }
+
+ private void addCreateActionToMenu(IMenuManager menuManager, EObject parent, EClass createAs, EReference createIn) {
+ menuManager.add(getCreateChildAction(parent, createAs, createIn));
+ }
+
+ private Action getCreateChildAction(EObject parent, EClass createAs, EReference createIn) {
+ EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(parent);
+ CreateChildAction action = new CreateChildAction(domain, parent, createIn, createAs);
+ IStructuredSelection selection = new StructuredSelection(parent);
+ action.configureAction(selection);
+ action.setId(createIn.getName() + "#" + createAs.getName());
+ return action;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillSeparator.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillSeparator.java
new file mode 100644
index 00000000000..d8237a935e6
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillSeparator.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.Separator;
+import org.eclipse.papyrus.infra.emf.newchild.util.MenuHelper;
+
+
+public class FillSeparator implements FillElement {
+
+ protected Separator separator;
+
+ protected FillMenuGroup group;
+
+ public FillSeparator(FillMenuGroup parentGroup, Separator separator) {
+ this.separator = separator;
+ this.group = parentGroup;
+ }
+
+ public void fill(IMenuManager menuManager) {
+ MenuHelper.add(group, menuManager, new org.eclipse.jface.action.Separator());
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillerFactory.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillerFactory.java
new file mode 100644
index 00000000000..084c2187ebe
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/FillerFactory.java
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.papyrus.infra.emf.newchild.Activator;
+import org.eclipse.papyrus.infra.emf.newchild.CustomFiller;
+import org.eclipse.papyrus.infra.emf.newchild.Menu;
+import org.eclipse.papyrus.infra.emf.newchild.MenuAction;
+import org.eclipse.papyrus.infra.emf.newchild.MenuContainer;
+import org.eclipse.papyrus.infra.emf.newchild.MenuGroup;
+import org.eclipse.papyrus.infra.emf.newchild.MenuItem;
+import org.eclipse.papyrus.infra.emf.newchild.MenuRoot;
+import org.eclipse.papyrus.infra.emf.newchild.Separator;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewEMFChildMenu;
+import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+
+
+public class FillerFactory {
+
+ public static FillerFactory instance = new FillerFactory();
+
+ public FillElement getFiller(FillMenuGroup parentGroup, MenuItem menuItem, Object selectedObject) {
+ if(menuItem instanceof NewEMFChildMenu) {
+ return new FillNewChild(parentGroup, (NewEMFChildMenu)menuItem, selectedObject);
+ }
+
+ if(menuItem instanceof Separator) {
+ return new FillSeparator(parentGroup, (Separator)menuItem);
+ }
+
+ if(menuItem instanceof Menu) {
+ return new FillMenu(parentGroup, (Menu)menuItem, selectedObject);
+ }
+
+ if(menuItem instanceof MenuAction) {
+ return new FillMenuAction(parentGroup, (MenuAction)menuItem, selectedObject);
+ }
+
+ if(menuItem instanceof CustomFiller) {
+ String className = ((CustomFiller)menuItem).getClassName();
+ CustomFillElement filler = ClassLoaderHelper.newInstance(className, CustomFillElement.class);
+ filler.setParentGroup(parentGroup);
+ filler.setMenuItem((CustomFiller)menuItem);
+ return filler;
+ }
+
+ Activator.log.warn("Unknown MenuItem type : " + menuItem.eClass().getName());
+ return null;
+ }
+
+ public FillElement getFiller(MenuItem menuItem, Object selectedObject) {
+ return getFiller(null, menuItem, selectedObject);
+ }
+
+ public FillElement getFiller(MenuContainer container, Object selectedObject) {
+ if(container instanceof MenuGroup) {
+ return new FillMenuGroup((MenuGroup)container, selectedObject);
+ } else if(container instanceof MenuRoot) {
+ return new FillMenuRoot((MenuRoot)container, selectedObject);
+ }
+
+ return null;
+ }
+
+ private FillerFactory() {
+
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/MyCustomFiller.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/MyCustomFiller.java
new file mode 100644
index 00000000000..bc0fe9a475e
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/menu/MyCustomFiller.java
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.menu;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.runtime.DisabledContributionItem;
+import org.eclipse.papyrus.infra.emf.newchild.util.MenuHelper;
+
+
+public class MyCustomFiller extends AbstractCustomFillElement {
+
+ @Override
+ public void fill(IMenuManager menuManager) {
+ DisabledContributionItem item = new DisabledContributionItem("MyCustomFiller", null, null);
+ item.setMenuStyle(true);
+ MenuHelper.add(group, menuManager, item);
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/AbstractFillPolicy.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/AbstractFillPolicy.java
new file mode 100644
index 00000000000..3dddbc0bf68
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/AbstractFillPolicy.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.policies;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewChildPolicy;
+
+
+public abstract class AbstractFillPolicy implements NewChildFillPolicy {
+
+ protected NewChildPolicy policy;
+
+ protected Collection<EClass> eClasses;
+
+ public Collection<EClass> getEClasses() {
+ if(eClasses == null) {
+ eClasses = new HashSet<EClass>();
+ for(EClass eClass : policy.getEClasses()) {
+ EPackage staticPackage = EPackage.Registry.INSTANCE.getEPackage(eClass.getEPackage().getNsURI());
+ eClass = (EClass)staticPackage.getEClassifier(eClass.getName());
+ eClasses.add(eClass);
+ }
+ }
+ return eClasses;
+ }
+
+ public Collection<String> getRoles() {
+ return policy.getRoles();
+ }
+
+ public void setPolicy(NewChildPolicy policy) {
+ this.policy = policy;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/FilterFillPolicy.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/FilterFillPolicy.java
new file mode 100644
index 00000000000..cce63c79631
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/FilterFillPolicy.java
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.policies;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.jface.action.IMenuManager;
+
+
+public class FilterFillPolicy extends AbstractFillPolicy {
+
+ public void fill(IMenuManager manager, EObject parentEObject, EClass eClass, EStructuralFeature role, EObject selectedEObject) {
+ return;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/NewChildFillPolicy.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/NewChildFillPolicy.java
new file mode 100644
index 00000000000..9a6a9f6839e
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/NewChildFillPolicy.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.policies;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.CustomPolicy;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.FilterPolicy;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewChildPolicy;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.ReplacePolicy;
+import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+
+
+public interface NewChildFillPolicy {
+
+ public void setPolicy(NewChildPolicy policy);
+
+ public Collection<EClass> getEClasses();
+
+ public Collection<String> getRoles();
+
+ public void fill(IMenuManager manager, EObject parentEObject, EClass eClass, EStructuralFeature role, EObject selectedEObject);
+
+ public class Factory {
+
+ public static Factory instance = new Factory();
+
+ private Factory() {
+ }
+
+ public NewChildFillPolicy getPolicy(NewChildPolicy policy) {
+ NewChildFillPolicy result = null;
+ if(policy instanceof ReplacePolicy) {
+ result = new ReplaceFillPolicy();
+ } else if(policy instanceof FilterPolicy) {
+ result = new FilterFillPolicy();
+ } else if(policy instanceof CustomPolicy) {
+ String className = ((CustomPolicy)policy).getClassName();
+ return ClassLoaderHelper.newInstance(className, NewChildFillPolicy.class);
+ }
+
+ if(result != null) {
+ result.setPolicy(policy);
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyManager.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyManager.java
new file mode 100644
index 00000000000..136d4370cc2
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyManager.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.policies;
+
+import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
+import org.eclipse.papyrus.infra.constraints.runtime.DefaultConstraintEngine;
+import org.eclipse.papyrus.infra.emf.newchild.NewchildConfiguration;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewChildPolicySet;
+
+
+public class PolicyManager extends DefaultConstraintEngine<NewChildPolicySet> {
+
+ @Override
+ public void refresh() {
+ //TODO
+ }
+
+ public void addConfiguration(NewchildConfiguration configuration) {
+ for(NewChildPolicySet policy : configuration.getNewChildPolicies()) {
+ for(ConstraintDescriptor descriptor : policy.getConstraints()) {
+ addConstraint(descriptor);
+ }
+ }
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java
new file mode 100644
index 00000000000..4e3c9d20116
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.policies;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewChildPolicy;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewChildPolicySet;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+
+
+public class PolicyMatcher {
+
+ private List<NewChildFillPolicy> fillPolicies;
+
+ public void setPolicies(Collection<NewChildPolicySet> policySets) {
+ this.fillPolicies = new LinkedList<NewChildFillPolicy>();
+ for(NewChildPolicySet policySet : policySets) {
+ for(NewChildPolicy policy : policySet.getPolicies()) {
+ NewChildFillPolicy fillPolicy = NewChildFillPolicy.Factory.instance.getPolicy(policy);
+ fillPolicies.add(fillPolicy);
+ }
+ }
+ }
+
+ public List<NewChildFillPolicy> getMatchingPolicies(EClass eClass, EStructuralFeature role){
+ List<NewChildFillPolicy> matchedPolicies = new LinkedList<NewChildFillPolicy>();
+
+ for (NewChildFillPolicy policy : fillPolicies){
+ if(matches(policy, eClass, role)) {
+ matchedPolicies.add(policy);
+ }
+ }
+
+ return matchedPolicies;
+ }
+
+ private boolean matches(NewChildFillPolicy policy, EClass eClass, EStructuralFeature role) {
+ Collection<EClass> eClasses = policy.getEClasses();
+ Collection<String> roles = policy.getRoles();
+
+ if(eClasses.isEmpty() && roles.isEmpty()) {
+ return true;
+ }
+
+ if(roles.contains(role.getName()) && (eClasses.isEmpty() || isContained(eClass, eClasses))) {
+ return true;
+ }
+
+ if((roles.isEmpty() || roles.contains(role)) && isContained(eClass, eClasses)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean isContained(EClass eClass, Collection<EClass> eClasses) {
+ for(EClass classToCheck : eClasses) {
+ if(EMFHelper.isSubclass(eClass, classToCheck)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/ReplaceFillPolicy.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/ReplaceFillPolicy.java
new file mode 100644
index 00000000000..2b4089c5868
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/ReplaceFillPolicy.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.policies;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.MenuItem;
+import org.eclipse.papyrus.infra.emf.newchild.menu.FillElement;
+import org.eclipse.papyrus.infra.emf.newchild.menu.FillerFactory;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.ReplacePolicy;
+
+
+public class ReplaceFillPolicy extends AbstractFillPolicy {
+
+ public void fill(IMenuManager menuManager, EObject parentEObject, EClass eClass, EStructuralFeature role, EObject selectedEObject) {
+ for(MenuItem menuItem : getPolicy().getReplaceWith()) {
+ FillElement filler = FillerFactory.instance.getFiller(menuItem, selectedEObject);
+ filler.fill(menuManager);
+ }
+ }
+
+ public ReplacePolicy getPolicy() {
+ return (ReplacePolicy)policy;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/DisabledContributionItem.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/DisabledContributionItem.java
new file mode 100644
index 00000000000..684846ae5ef
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/DisabledContributionItem.java
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.runtime;
+
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+
+
+public class DisabledContributionItem extends ContributionItem {
+
+ protected String text;
+
+ protected ImageDescriptor image;
+
+ protected boolean menuStyle = false;
+
+ public DisabledContributionItem(String text, ImageDescriptor image, String id) {
+ this.text = text;
+ this.image = image;
+ setId(id);
+ }
+
+ public void setMenuStyle(boolean menuStyle) {
+ this.menuStyle = menuStyle;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public void fill(Menu parent, int index) {
+ MenuItem item = new MenuItem(parent, SWT.CASCADE, index);
+ item.setText(text);
+ item.setEnabled(false);
+
+ if(image != null) {
+ item.setImage(image.createImage());
+ }
+
+ if(menuStyle) {
+ item.setMenu(new Menu(item));
+ }
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/MenuConstraintEngine.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/MenuConstraintEngine.java
new file mode 100644
index 00000000000..a2c4bd502a8
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/MenuConstraintEngine.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.runtime;
+
+import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
+import org.eclipse.papyrus.infra.constraints.runtime.DefaultConstraintEngine;
+import org.eclipse.papyrus.infra.emf.newchild.MenuRoot;
+import org.eclipse.papyrus.infra.emf.newchild.NewchildConfiguration;
+
+
+public class MenuConstraintEngine extends DefaultConstraintEngine<MenuRoot> {
+
+ public void addConfiguration(NewchildConfiguration configuration) {
+ for(MenuRoot root : configuration.getRoots()) {
+ for(ConstraintDescriptor descriptor : root.getConstraints()) {
+ addConstraint(descriptor);
+ }
+ }
+ }
+
+ @Override
+ public void refresh() {
+ constraints.clear();
+ //Find all active Configurations
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/NewchildManager.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/NewchildManager.java
new file mode 100644
index 00000000000..2b9e2d949cd
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/runtime/NewchildManager.java
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.runtime;
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.newchild.Activator;
+import org.eclipse.papyrus.infra.emf.newchild.MenuRoot;
+import org.eclipse.papyrus.infra.emf.newchild.NewchildConfiguration;
+import org.eclipse.papyrus.infra.emf.newchild.menu.FillElement;
+import org.eclipse.papyrus.infra.emf.newchild.menu.FillerFactory;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+
+/**
+ * A singleton manager for customizable "New child" menu.
+ *
+ * The custom menus are defined via {@link NewchildConfiguration}, which
+ * may be registered either with an extension point, programatically, or
+ * locally (In the preferences).
+ *
+ * Once set up, the manager simply takes a IMenuManager and a ISelection,
+ * and fills the menu according to the available {@link NewchildConfiguration}.
+ *
+ * USAGE : NewchildManager.instance.fillMenu(IMenuManager, IStructuredSelection)
+ *
+ * See the org.eclipse.papyrus.infra.emf.newchild.configuration extension point.
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class NewchildManager {
+
+ /**
+ * The ID of the menu's top element.
+ */
+ public static final String TOP = "top"; //$NON-NLS-1$
+
+ /**
+ * The singleton NewchildManager instance
+ */
+ public static NewchildManager instance = new NewchildManager();
+
+ /**
+ * The default {@link #ConstraintEngine} for this manager
+ */
+ public MenuConstraintEngine constraintEngine;
+
+ private NewchildManager() {
+ }
+
+ /**
+ * Fills the menuManager with a custom menu
+ *
+ * The menu will be retrieved via registered {@link NewchildConfiguration}s,
+ * depending on the given selection.
+ *
+ * The menu manager should have an IContributionItem with the {@link #TOP} id ;
+ * otherwise, the absolute position "top" won't work properly.
+ *
+ * @param menuManager
+ * @param selection
+ */
+ public void fillMenu(IMenuManager menuManager, IStructuredSelection selection) {
+ constraintEngine = new MenuConstraintEngine();
+ try {
+ //TODO : Load that from extension point
+ NewchildConfiguration configuration = (NewchildConfiguration)EMFHelper.loadEMFModel(null, URI.createPlatformPluginURI("org.eclipse.papyrus.infra.emf.newchild/Model/NewchildConfiguration.xmi", true));
+ constraintEngine.addConfiguration(configuration);
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ }
+
+ Set<MenuRoot> roots = findRootsFor(selection);
+ if(roots.isEmpty()) {
+ return;
+ }
+
+ for(MenuRoot root : roots) {
+ Object selectedObject = selection.getFirstElement();
+ FillElement filler = FillerFactory.instance.getFiller(root, selectedObject);
+ filler.fill(menuManager);
+ }
+ }
+
+ private Set<MenuRoot> findRootsFor(IStructuredSelection selection) {
+ Set<MenuRoot> roots = constraintEngine.getDisplayUnits(selection);
+ return roots;
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/util/MenuHelper.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/util/MenuHelper.java
new file mode 100644
index 00000000000..f435fb14b08
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/util/MenuHelper.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.util;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.infra.emf.newchild.menu.FillMenuGroup;
+
+
+public class MenuHelper {
+
+ public static void add(FillMenuGroup group, IMenuManager manager, IContributionItem item) {
+ if(group == null) {
+ manager.add(item);
+ } else {
+ manager.appendToGroup(group.getGroupId(), item);
+ }
+ }
+
+ public static void add(FillMenuGroup group, IMenuManager manager, Action action) {
+ add(group, manager, new ActionContributionItem(action));
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/util/Util.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/util/Util.java
new file mode 100644
index 00000000000..34368aca544
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/util/Util.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.infra.emf.newchild.Activator;
+import org.eclipse.papyrus.infra.emf.newchild.Menu;
+
+
+public class Util {
+
+ public static ImageDescriptor getImage(Menu menu) {
+ if(menu.getIcon() != null && !menu.getIcon().equals("")) {
+ String iconPath = menu.getIcon();
+ URI uri = URI.createPlatformPluginURI(iconPath, false);
+ try {
+ return ImageDescriptor.createFromURL(new URL(uri.toString()));
+ } catch (MalformedURLException ex) {
+ Activator.log.error(ex);
+ }
+ }
+
+ return null;
+ }
+}

Back to the top