Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/org.eclipse.papyrus.newchild/src/org/eclipse')
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/Activator.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/CreateChildAction.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/ExtendedTypeAction.java82
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/AbstractCustomFillElement.java16
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/CustomFillElement.java14
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillElement.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenu.java35
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuAction.java49
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuContainer.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuGroup.java56
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuRoot.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillNewChild.java100
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillSeparator.java16
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillerFactory.java25
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/MyCustomFiller.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/AbstractFillPolicy.java48
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/FilterFillPolicy.java26
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/NewChildFillPolicy.java75
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/PolicyManager.java35
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/PolicyMatcher.java78
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/ReplaceFillPolicy.java37
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/DisabledContributionItem.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/MenuConstraintEngine.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/NewchildManager.java83
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/EMFHelper.java11
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/MenuHelper.java40
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/Util.java11
27 files changed, 840 insertions, 85 deletions
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/Activator.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/Activator.java
index 29647bc0eee..7597fde8701 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/Activator.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/Activator.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild;
import org.eclipse.papyrus.log.LogHelper;
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/CreateChildAction.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/CreateChildAction.java
index de5c68ed6b4..aa5d0870b03 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/CreateChildAction.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/CreateChildAction.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild.action;
import java.net.URL;
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/ExtendedTypeAction.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/ExtendedTypeAction.java
new file mode 100644
index 00000000000..e98c1c9bd2c
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/action/ExtendedTypeAction.java
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * 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.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.commands.CreateElementCommand;
+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.core.utils.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.extendedtypes.ExtendedElementTypeConfiguration;
+import org.eclipse.papyrus.extendedtypes.gmf.ExtendedEditHelperAdvice;
+import org.eclipse.papyrus.extendedtypes.gmf.ExtendedSemanticTypeDescriptor;
+import org.eclipse.papyrus.extendedtypes.gmf.types.ExtendedHintedTypeFactory;
+
+
+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.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);
+ // ICommand beforeCommand = advice.getBeforeEditCommand(request);
+ ICommand command = new CreateElementCommand(request);
+ // baseCommand.getCommandResult().getReturnValue();
+ // ConfigureRequest configure = new ConfigureRequest(parent, elementType);
+ // ICommand afterCommand = advice.getAfterEditCommand(configure);
+ // CompositeCommand command = new CompositeCommand(getText());
+ //
+ // if(beforeCommand != null) {
+ // command.add(beforeCommand);
+ // }
+ // if (baseCommand != null){
+ // command.add(baseCommand);
+ // }
+ // if(afterCommand != null) {
+ // command.add(afterCommand);
+ // }
+
+ Command emfCommand = new GMFtoEMFCommandWrapper(command);
+
+ System.out.println(emfCommand.canExecute());
+ domain.getCommandStack().execute(emfCommand);
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/AbstractCustomFillElement.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/AbstractCustomFillElement.java
index 663d9125cbf..2f069cf178a 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/AbstractCustomFillElement.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/AbstractCustomFillElement.java
@@ -1,8 +1,18 @@
+/*****************************************************************************
+ * 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.newchild.menu;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.papyrus.newchild.CustomFiller;
-import org.eclipse.papyrus.newchild.MenuGroup;
/**
* A base implementation for CustomFillElement
@@ -11,7 +21,7 @@ import org.eclipse.papyrus.newchild.MenuGroup;
*/
public abstract class AbstractCustomFillElement implements CustomFillElement {
- protected MenuGroup group;
+ protected FillMenuGroup group;
protected CustomFiller filler;
@@ -19,7 +29,7 @@ public abstract class AbstractCustomFillElement implements CustomFillElement {
this.filler = filler;
}
- public void setParentGroup(MenuGroup group) {
+ public void setParentGroup(FillMenuGroup group) {
this.group = group;
}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/CustomFillElement.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/CustomFillElement.java
index 51b36414815..1c98925d089 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/CustomFillElement.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/CustomFillElement.java
@@ -1,7 +1,17 @@
+/*****************************************************************************
+ * 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.newchild.menu;
import org.eclipse.papyrus.newchild.CustomFiller;
-import org.eclipse.papyrus.newchild.MenuGroup;
/**
* An interface for Custom menu filler
@@ -12,6 +22,6 @@ public interface CustomFillElement extends FillElement {
public void setMenuItem(CustomFiller filler);
- public void setParentGroup(MenuGroup group);
+ public void setParentGroup(FillMenuGroup group);
}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillElement.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillElement.java
index 4f74722334c..ec15646452b 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillElement.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillElement.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild.menu;
import org.eclipse.jface.action.IMenuManager;
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenu.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenu.java
index 22e5bce7e3d..7305434b257 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenu.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenu.java
@@ -1,9 +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.newchild.menu;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
import org.eclipse.papyrus.newchild.Menu;
-import org.eclipse.papyrus.newchild.MenuGroup;
+import org.eclipse.papyrus.newchild.runtime.NewchildManager;
+import org.eclipse.papyrus.newchild.util.MenuHelper;
import org.eclipse.papyrus.newchild.util.Util;
@@ -11,9 +24,11 @@ public class FillMenu extends FillMenuContainer {
protected Menu menu;
- protected MenuGroup parentGroup;
+ protected FillMenuGroup parentGroup;
- public FillMenu(MenuGroup parentGroup, Menu menu, Object selectedObject) {
+ protected IMenuManager subMenu;
+
+ public FillMenu(FillMenuGroup parentGroup, Menu menu, Object selectedObject) {
super(menu, selectedObject);
this.menu = menu;
this.parentGroup = parentGroup;
@@ -21,7 +36,19 @@ public class FillMenu extends FillMenuContainer {
@Override
public void fill(IMenuManager menuManager) {
- MenuManager subMenuManager = new MenuManager(menu.getName(), Util.getImage(menu), menu.getId());
+ 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/newchild/menu/FillMenuAction.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuAction.java
new file mode 100644
index 00000000000..aa6d9517ee5
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/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.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.newchild.MenuAction;
+import org.eclipse.papyrus.newchild.action.ExtendedTypeAction;
+import org.eclipse.papyrus.newchild.util.EMFHelper;
+import org.eclipse.papyrus.newchild.util.MenuHelper;
+
+
+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/newchild/menu/FillMenuContainer.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuContainer.java
index 1dc29186261..99a9be5c3da 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuContainer.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuContainer.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild.menu;
import org.eclipse.jface.action.IMenuManager;
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuGroup.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuGroup.java
index fc6b4240c60..1f289befeda 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuGroup.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuGroup.java
@@ -1,27 +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.newchild.menu;
import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
import org.eclipse.papyrus.newchild.MenuGroup;
import org.eclipse.papyrus.newchild.MenuItem;
+import org.eclipse.papyrus.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 menuManager) {
+ 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(group, menuItem, selectedObject);
+ FillElement filler = FillerFactory.instance.getFiller(this, menuItem, selectedObject);
if(filler != null) {
- filler.fill(menuManager);
+ 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/newchild/menu/FillMenuRoot.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuRoot.java
index 87a0633c3f0..5b70900bdd2 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuRoot.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillMenuRoot.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild.menu;
import org.eclipse.jface.action.IMenuManager;
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillNewChild.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillNewChild.java
index 0a670081ea5..38553681be1 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillNewChild.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillNewChild.java
@@ -1,9 +1,23 @@
+/*****************************************************************************
+ * 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.newchild.menu;
+import java.io.IOException;
import java.util.HashMap;
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;
@@ -15,11 +29,17 @@ 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.newchild.ElementPosition;
+import org.eclipse.papyrus.newchild.Activator;
import org.eclipse.papyrus.newchild.MenuGroup;
-import org.eclipse.papyrus.newchild.NewChildKind;
-import org.eclipse.papyrus.newchild.NewChildMenu;
+import org.eclipse.papyrus.newchild.NewchildConfiguration;
import org.eclipse.papyrus.newchild.action.CreateChildAction;
+import org.eclipse.papyrus.newchild.ncpolicy.CreateIn;
+import org.eclipse.papyrus.newchild.ncpolicy.Layout;
+import org.eclipse.papyrus.newchild.ncpolicy.NewChildPolicySet;
+import org.eclipse.papyrus.newchild.ncpolicy.NewEMFChildMenu;
+import org.eclipse.papyrus.newchild.policies.NewChildFillPolicy;
+import org.eclipse.papyrus.newchild.policies.PolicyManager;
+import org.eclipse.papyrus.newchild.policies.PolicyMatcher;
import org.eclipse.papyrus.newchild.runtime.DisabledContributionItem;
import org.eclipse.papyrus.newchild.util.EMFHelper;
import org.eclipse.papyrus.newchild.util.MenuHelper;
@@ -31,19 +51,31 @@ public class FillNewChild extends FillMenu implements FillElement {
protected EObject selectedEObject;
- protected NewChildMenu menu;
+ protected NewEMFChildMenu menu;
- public FillNewChild(MenuGroup parentGroup, NewChildMenu menu, Object selectedObject) {
+ //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.createPlatformResourceURI("org.eclipse.papyrus.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.getPosition() == ElementPosition.SIBLING) {
+ if(menu.getCreateIn() == CreateIn.PARENT) {
if(selectedEObject != null) {
parentEObject = selectedEObject.eContainer();
}
@@ -60,8 +92,7 @@ public class FillNewChild extends FillMenu implements FillElement {
return;
}
- MenuManager createChildMenu = new MenuManager(menu.getName(), Util.getImage(menu), menu.getId());
- MenuHelper.add(parentGroup, menuManager, createChildMenu);
+ IMenuManager createChildMenu = getSubMenu(menuManager);
Map<EStructuralFeature, List<EClass>> instantiableClasses = new HashMap<EStructuralFeature, List<EClass>>();
@@ -72,12 +103,16 @@ public class FillNewChild extends FillMenu implements FillElement {
}
}
- NewChildKind kind = getKind(instantiableClasses);
+ Layout layout = getLayout(instantiableClasses);
- if(kind == NewChildKind.FLAT) {
+ 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)) {
- addCreateActionToMenu(createChildMenu, parentEObject, eClass, (EReference)feature);
+ addActionToMenu(matcher, createChildMenu, parentEObject, eClass, feature);
}
}
} else { //Hierarchical
@@ -86,32 +121,56 @@ public class FillNewChild extends FillMenu implements FillElement {
createChildMenu.add(subMenu);
for(EClass eClass : instantiableClasses.get(feature)) {
- addCreateActionToMenu(subMenu, parentEObject, eClass, (EReference)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 NewChildKind getKind(Map<EStructuralFeature, List<EClass>> instantiableClasses) {
- if(menu.getKind() != NewChildKind.AUTO) {
- return menu.getKind();
+ private Layout getLayout(Map<EStructuralFeature, List<EClass>> instantiableClasses) {
+ if(menu.getLayout() != Layout.AUTO) {
+ return menu.getLayout();
}
if(instantiableClasses.size() < 2) {
- return NewChildKind.FLAT;
+ return Layout.FLAT;
}
if(instantiableClasses.size() > 5) {
- return NewChildKind.HIERARCHICAL;
+ return Layout.HIERARCHICAL;
}
for(List<EClass> eClasses : instantiableClasses.values()) {
if(eClasses.size() > 5) {
- return NewChildKind.HIERARCHICAL;
+ return Layout.HIERARCHICAL;
}
}
- return NewChildKind.FLAT;
+ return Layout.FLAT;
}
private void addCreateActionToMenu(IMenuManager menuManager, EObject parent, EClass createAs, EReference createIn) {
@@ -123,6 +182,7 @@ public class FillNewChild extends FillMenu implements FillElement {
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/newchild/menu/FillSeparator.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillSeparator.java
index 95725dc79d2..b4dc0ac2b66 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillSeparator.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillSeparator.java
@@ -1,7 +1,17 @@
+/*****************************************************************************
+ * 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.newchild.menu;
import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.papyrus.newchild.MenuGroup;
import org.eclipse.papyrus.newchild.Separator;
import org.eclipse.papyrus.newchild.util.MenuHelper;
@@ -10,9 +20,9 @@ public class FillSeparator implements FillElement {
protected Separator separator;
- protected MenuGroup group;
+ protected FillMenuGroup group;
- public FillSeparator(MenuGroup parentGroup, Separator separator) {
+ public FillSeparator(FillMenuGroup parentGroup, Separator separator) {
this.separator = separator;
this.group = parentGroup;
}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillerFactory.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillerFactory.java
index 432615d994f..3d17df0c8c1 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillerFactory.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/FillerFactory.java
@@ -1,23 +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.newchild.menu;
import org.eclipse.papyrus.extendedtypes.Activator;
import org.eclipse.papyrus.newchild.CustomFiller;
import org.eclipse.papyrus.newchild.Menu;
+import org.eclipse.papyrus.newchild.MenuAction;
import org.eclipse.papyrus.newchild.MenuContainer;
import org.eclipse.papyrus.newchild.MenuGroup;
import org.eclipse.papyrus.newchild.MenuItem;
import org.eclipse.papyrus.newchild.MenuRoot;
-import org.eclipse.papyrus.newchild.NewChildMenu;
import org.eclipse.papyrus.newchild.Separator;
+import org.eclipse.papyrus.newchild.ncpolicy.NewEMFChildMenu;
public class FillerFactory {
public static FillerFactory instance = new FillerFactory();
- public FillElement getFiller(MenuGroup parentGroup, MenuItem menuItem, Object selectedObject) {
- if(menuItem instanceof NewChildMenu) {
- return new FillNewChild(parentGroup, (NewChildMenu)menuItem, selectedObject);
+ public FillElement getFiller(FillMenuGroup parentGroup, MenuItem menuItem, Object selectedObject) {
+ if(menuItem instanceof NewEMFChildMenu) {
+ return new FillNewChild(parentGroup, (NewEMFChildMenu)menuItem, selectedObject);
}
if(menuItem instanceof Separator) {
@@ -28,6 +40,10 @@ public class FillerFactory {
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();
if (className != null){
@@ -51,6 +67,7 @@ public class FillerFactory {
}
}
+ Activator.log.warn("Unknown MenuItem type : " + menuItem.eClass().getName());
return null;
}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/MyCustomFiller.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/MyCustomFiller.java
index b6c9698d612..a94b97430b2 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/MyCustomFiller.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/menu/MyCustomFiller.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild.menu;
import org.eclipse.jface.action.IMenuManager;
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/AbstractFillPolicy.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/AbstractFillPolicy.java
new file mode 100644
index 00000000000..3577e468ef3
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/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.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.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/newchild/policies/FilterFillPolicy.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/FilterFillPolicy.java
new file mode 100644
index 00000000000..487e05f7b32
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/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.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/newchild/policies/NewChildFillPolicy.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/NewChildFillPolicy.java
new file mode 100644
index 00000000000..c5179df201f
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/NewChildFillPolicy.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * 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.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.newchild.Activator;
+import org.eclipse.papyrus.newchild.ncpolicy.CustomPolicy;
+import org.eclipse.papyrus.newchild.ncpolicy.FilterPolicy;
+import org.eclipse.papyrus.newchild.ncpolicy.NewChildPolicy;
+import org.eclipse.papyrus.newchild.ncpolicy.ReplacePolicy;
+
+
+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();
+ try {
+ return Class.forName(className).asSubclass(NewChildFillPolicy.class).newInstance();
+ } catch (InstantiationException ex) {
+ Activator.log.error(ex);
+ } catch (IllegalAccessException ex) {
+ Activator.log.error(ex);
+ } catch (ClassNotFoundException ex) {
+ Activator.log.error(ex);
+ } catch (ClassCastException ex) {
+ String message = "The CustomPolicy must implement " + NewChildFillPolicy.class.getName() + ". ";
+ message += "Class : " + className;
+ Activator.log.error(message, ex);
+ Activator.log.error(ex);
+ }
+ }
+
+ if(result != null) {
+ result.setPolicy(policy);
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/PolicyManager.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/PolicyManager.java
new file mode 100644
index 00000000000..989f7dd5c27
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/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.newchild.policies;
+
+import org.eclipse.papyrus.constraints.ConstraintDescriptor;
+import org.eclipse.papyrus.constraints.runtime.DefaultConstraintEngine;
+import org.eclipse.papyrus.newchild.NewchildConfiguration;
+import org.eclipse.papyrus.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/newchild/policies/PolicyMatcher.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/PolicyMatcher.java
new file mode 100644
index 00000000000..1ecbe03ffa4
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/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.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.newchild.ncpolicy.NewChildPolicy;
+import org.eclipse.papyrus.newchild.ncpolicy.NewChildPolicySet;
+import org.eclipse.papyrus.newchild.util.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/newchild/policies/ReplaceFillPolicy.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/policies/ReplaceFillPolicy.java
new file mode 100644
index 00000000000..d3fb1baa3fe
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/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.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.newchild.MenuItem;
+import org.eclipse.papyrus.newchild.menu.FillElement;
+import org.eclipse.papyrus.newchild.menu.FillerFactory;
+import org.eclipse.papyrus.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/newchild/runtime/DisabledContributionItem.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/DisabledContributionItem.java
index 90bd808693b..7e16e180096 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/DisabledContributionItem.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/DisabledContributionItem.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild.runtime;
import org.eclipse.jface.action.ContributionItem;
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/MenuConstraintEngine.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/MenuConstraintEngine.java
index 8b459fc5f58..39493bdfd97 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/MenuConstraintEngine.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/MenuConstraintEngine.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild.runtime;
import org.eclipse.papyrus.constraints.ConstraintDescriptor;
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/NewchildManager.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/NewchildManager.java
index 522aac7efa3..2874be4bc63 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/NewchildManager.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/runtime/NewchildManager.java
@@ -1,14 +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.newchild.runtime;
import java.io.IOException;
-import java.util.Collections;
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.constraints.ConstraintDescriptor;
-import org.eclipse.papyrus.constraints.runtime.ConstraintEngine;
import org.eclipse.papyrus.newchild.Activator;
import org.eclipse.papyrus.newchild.MenuRoot;
import org.eclipse.papyrus.newchild.NewchildConfiguration;
@@ -16,16 +24,65 @@ import org.eclipse.papyrus.newchild.menu.FillElement;
import org.eclipse.papyrus.newchild.menu.FillerFactory;
import org.eclipse.papyrus.newchild.util.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.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.createPlatformResourceURI("org.eclipse.papyrus.newchild/Model/NewchildConfiguration.xmi", true));
+ constraintEngine.addConfiguration(configuration);
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ }
+
Set<MenuRoot> roots = findRootsFor(selection);
if(roots.isEmpty()) {
return;
@@ -39,21 +96,7 @@ public class NewchildManager {
}
private Set<MenuRoot> findRootsFor(IStructuredSelection selection) {
- try {
- NewchildConfiguration configuration = (NewchildConfiguration)EMFHelper.loadEMFModel(null, URI.createPlatformPluginURI("org.eclipse.papyrus.newchild/Model/NewchildConfiguration.xmi", true));
- ConstraintEngine<MenuRoot> constraintEngine = new MenuConstraintEngine();
- for(MenuRoot root : configuration.getRoots()) {
- for (ConstraintDescriptor descriptor : root.getConstraints()){
- constraintEngine.addConstraint(descriptor);
- }
- }
-
- Set<MenuRoot> roots = constraintEngine.getDisplayUnits(selection);
- return roots;
- } catch (IOException ex) {
- Activator.log.error(ex);
- }
-
- return Collections.EMPTY_SET;
+ Set<MenuRoot> roots = constraintEngine.getDisplayUnits(selection);
+ return roots;
}
}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/EMFHelper.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/EMFHelper.java
index 1c43ccc2458..54460af8316 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/EMFHelper.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/EMFHelper.java
@@ -118,16 +118,15 @@ public class EMFHelper {
return true;
}
+ if(eClass == fromClass) {
+ return true;
+ }
+
List<EClass> superTypes = eClass.getEAllSuperTypes();
if(superTypes.contains(fromClass)) {
return true;
- } else {
- for(EClass superClass : superTypes) {
- if(isSubclass(superClass, fromClass)) {
- return true;
- }
- }
}
+
return false;
}
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/MenuHelper.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/MenuHelper.java
index df4dca52001..108da1a31a5 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/MenuHelper.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/MenuHelper.java
@@ -1,35 +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.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.newchild.MenuGroup;
-import org.eclipse.papyrus.newchild.runtime.NewchildManager;
+import org.eclipse.papyrus.newchild.menu.FillMenuGroup;
public class MenuHelper {
- public static void add(MenuGroup group, IMenuManager manager, IContributionItem item) {
+ public static void add(FillMenuGroup group, IMenuManager manager, IContributionItem item) {
if(group == null) {
manager.add(item);
- } else if(manager.find(group.getBefore()) != null) {
- manager.insertBefore(group.getBefore(), item);
- } else if(manager.find(group.getAfter()) != null) {
- manager.insertAfter(group.getAfter(), item);
- } else if(group.getAbsolutePosition() != null) {
- switch(group.getAbsolutePosition()) {
- case TOP:
- if(manager.find(NewchildManager.TOP) != null) {
- manager.insertBefore(NewchildManager.TOP, item);
- break;
- }
- case BOTTOM:
- default:
- manager.add(item);
- break;
- }
} else {
- manager.add(item);
+ 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/newchild/util/Util.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/Util.java
index b24ede6e09a..77f9b6c81b1 100644
--- a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/Util.java
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/newchild/util/Util.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * 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.newchild.util;
import java.net.MalformedURLException;

Back to the top