summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2014-03-26 11:36:34 (EDT)
committerLaurent Wouters2014-03-26 11:49:21 (EDT)
commit3235aacce0b5eea4beb6d7c67b07af14fef54885 (patch)
treeb972d67faffc238ada7ea3c5945c399d8e612b90
parent625aba3625623e9fd32a1ca4ea23b78ce10d455b (diff)
downloadorg.eclipse.papyrus-3235aacce0b5eea4beb6d7c67b07af14fef54885.zip
org.eclipse.papyrus-3235aacce0b5eea4beb6d7c67b07af14fef54885.tar.gz
org.eclipse.papyrus-3235aacce0b5eea4beb6d7c67b07af14fef54885.tar.bz2
Implemented the auto-creation of diagram root elements according to the owning rules
https://bugs.eclipse.org/bugs/show_bug.cgi?id=431139 Signed-off-by: Laurent Wouters <laurent.wouters@cea.fr>
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java87
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java21
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java16
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration/custom-src/org/eclipse/papyrus/infra/viewpoints/configuration/EReferencePropertyDescriptor.java19
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/builtin/default.configuration118
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java134
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java41
7 files changed, 263 insertions, 173 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
index 0b85523..95cc745 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/AbstractPapyrusGmfCreateDiagramCommandHandler.java
@@ -16,6 +16,7 @@
package org.eclipse.papyrus.infra.gmfdiag.common;
import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@@ -29,6 +30,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
@@ -49,12 +52,10 @@ import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
-import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule;
-import org.eclipse.papyrus.infra.viewpoints.configuration.ui.IModelElementValidator;
-import org.eclipse.papyrus.infra.viewpoints.configuration.ui.ModelElementSelectionDialog;
+import org.eclipse.papyrus.infra.viewpoints.configuration.ModelAutoCreate;
+import org.eclipse.papyrus.infra.viewpoints.configuration.OwningRule;
import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
import org.eclipse.papyrus.uml.tools.model.UmlUtils;
@@ -94,6 +95,8 @@ public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends Abst
private ViewPrototype prototype;
+ private OwningRule rule;
+
private String name;
public Creator(ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name) {
@@ -114,67 +117,41 @@ public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends Abst
attachModelToResource(owner, modelResource);
}
- if(!PolicyChecker.getCurrent().canOwnNewView(owner, prototype)) {
- ModelElementSelectionDialog dialog = new ModelElementSelectionDialog(Display.getCurrent().getActiveShell(), ServiceUtilsForResourceSet.getInstance().getServiceRegistry(modelSet), "Select an appropriate owner for the diagram:", getRootElement(modelResource), owner, new IModelElementValidator() {
-
- @Override
- public String isSelectable(EObject element) {
- if(PolicyChecker.getCurrent().canOwnNewView(owner, prototype)) {
- return null;
- }
- return "This element cannot own the diagram.";
- }
- });
- int result = dialog.open();
- if(result != Window.OK) {
- return null;
- }
- owner = dialog.getSelection();
+ rule = PolicyChecker.getCurrent().getOwningRuleFor(prototype, owner);
+ if (rule == null) {
+ // Something isn't right ...
+ return null;
}
- element = prototype.getRootFor(owner);
- if(!PolicyChecker.getCurrent().canHaveNewView(element, owner, prototype)) {
- StringBuilder builder = new StringBuilder("Select a root element for the diagram. Allowed types: ");
- if(prototype.getConfiguration() == null) {
- builder.append("<unknown>");
- } else if(prototype.getConfiguration().getModelRules().size() == 0) {
- builder.append("<unknown>");
- } else {
- boolean first = true;
- for(ModelRule rule : prototype.getConfiguration().getModelRules()) {
- EClass model = rule.getElement();
- if(model != null) {
- if(!first) {
- builder.append(", ");
- }
- first = false;
- builder.append(model.getName());
- }
- }
- }
- builder.append(".");
- ModelElementSelectionDialog dialog = new ModelElementSelectionDialog(Display.getCurrent().getActiveShell(), ServiceUtilsForResourceSet.getInstance().getServiceRegistry(modelSet), builder.toString(), getRootElement(modelResource), element, new IModelElementValidator() {
-
- @Override
- public String isSelectable(EObject element) {
- if(PolicyChecker.getCurrent().canHaveNewView(element, owner, prototype)) {
- return null;
+ element = owner;
+ if (rule.getNewModelPath() != null) {
+ // We have a path for the root auto-creation
+ for (ModelAutoCreate auto : rule.getNewModelPath()) {
+ EReference ref = auto.getFeature();
+ EClass type = auto.getCreationType();
+ if (ref.isMany()) {
+ EObject temp = ((EPackage) type.eContainer()).getEFactoryInstance().create(type);
+ List list = (List) element.eGet(ref);
+ list.add(temp);
+ element = temp;
+ } else {
+ EObject temp = (EObject) element.eGet(ref);
+ if (temp != null) {
+ element = temp;
+ } else {
+ temp = ((EPackage) type.eContainer()).getEFactoryInstance().create(type);
+ element.eSet(ref, temp);
+ element = temp;
}
- return "This element cannot be the root element of the diagram.";
}
- });
- int result = dialog.open();
- if(result != Window.OK) {
- return null;
}
- element = dialog.getSelection();
}
- if(name == null) {
+ if (name == null) {
name = openDiagramNameDialog(prototype.isNatural() ? getDefaultDiagramName() : "New" + prototype.getLabel().replace(" ", ""));
}
// canceled
- if(name == null) {
+ if (name == null) {
return null;
}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java
index ab883e3..9fd76e4 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java
@@ -20,6 +20,8 @@ import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
@@ -29,6 +31,8 @@ import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationPackage;
+import org.eclipse.papyrus.infra.viewpoints.configuration.EReferencePropertyDescriptor;
+import org.eclipse.papyrus.infra.viewpoints.configuration.ModelAutoCreate;
/**
* This is the item provider adapter for a {@link org.eclipse.papyrus.infra.viewpoints.configuration.ModelAutoCreate} object.
@@ -80,7 +84,7 @@ public class ModelAutoCreateItemProvider
*/
protected void addFeaturePropertyDescriptor(Object object) {
itemPropertyDescriptors.add
- (createItemPropertyDescriptor
+ (new EReferencePropertyDescriptor(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_ModelAutoCreate_feature_feature"),
@@ -91,7 +95,7 @@ public class ModelAutoCreateItemProvider
true,
null,
null,
- null));
+ null)));
}
/**
@@ -153,11 +157,20 @@ public class ModelAutoCreateItemProvider
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
- * @generated
*/
@Override
public String getText(Object object) {
- return getString("_UI_ModelAutoCreate_type");
+ ModelAutoCreate path = (ModelAutoCreate) object;
+ StringBuilder builder = new StringBuilder();
+ EClass origin = path.getOrigin();
+ EReference feature = path.getFeature();
+ EClass target = path.getCreationType();
+ builder.append(origin != null ? origin.getName() : "?");
+ builder.append(".");
+ builder.append(feature != null ? feature.getName() : "?");
+ builder.append(" => new ");
+ builder.append(target != null ? target.getName() : "?");
+ return builder.toString();
}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java
index 4dafa8b..6d9376d 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java
@@ -20,6 +20,8 @@ import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
@@ -157,10 +159,16 @@ public class PathElementItemProvider
@Override
public String getText(Object object) {
PathElement path = (PathElement) object;
- String data = "<undefined>";
- if (path.getFeature() != null && path.getOrigin() != null)
- data = path.getOrigin().getName() + "." + path.getFeature().getName() + " => " + path.getTarget().getName();
- return data;
+ StringBuilder builder = new StringBuilder();
+ EClass origin = path.getOrigin();
+ EReference feature = path.getFeature();
+ EClass target = path.getTarget();
+ builder.append(origin != null ? origin.getName() : "?");
+ builder.append(".");
+ builder.append(feature != null ? feature.getName() : "?");
+ builder.append(" => ");
+ builder.append(target != null ? target.getName() : "?");
+ return builder.toString();
}
/**
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration/custom-src/org/eclipse/papyrus/infra/viewpoints/configuration/EReferencePropertyDescriptor.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration/custom-src/org/eclipse/papyrus/infra/viewpoints/configuration/EReferencePropertyDescriptor.java
index 597cc2b..8ffc09b 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration/custom-src/org/eclipse/papyrus/infra/viewpoints/configuration/EReferencePropertyDescriptor.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration/custom-src/org/eclipse/papyrus/infra/viewpoints/configuration/EReferencePropertyDescriptor.java
@@ -33,10 +33,19 @@ public class EReferencePropertyDescriptor extends SurrogateItemPropertyDescripto
@Override
public Collection<?> getChoiceOfValues(Object object) {
- PathElement pe = (PathElement)object;
- EClass origin = pe.getOrigin();
- if (origin == null)
- return empty;
- return origin.getEAllReferences();
+ if (object instanceof PathElement) {
+ PathElement pe = (PathElement) object;
+ EClass origin = pe.getOrigin();
+ if (origin == null)
+ return empty;
+ return origin.getEAllReferences();
+ } else if (object instanceof ModelAutoCreate) {
+ ModelAutoCreate pe = (ModelAutoCreate) object;
+ EClass origin = pe.getOrigin();
+ if (origin == null)
+ return empty;
+ return origin.getEAllReferences();
+ }
+ return empty;
}
} \ No newline at end of file
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/builtin/default.configuration b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/builtin/default.configuration
index 89284ad..4751bf5 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/builtin/default.configuration
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/builtin/default.configuration
@@ -7,10 +7,10 @@
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
</modelRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
</owningRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
</owningRules>
<childRules>
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//Classifier"/>
@@ -60,10 +60,28 @@
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
</modelRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
</owningRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/classifierBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/ownedBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//Package/packagedElement"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
+ </newModelPath>
</owningRules>
<childRules/>
</modelKinds>
@@ -81,10 +99,28 @@
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
</modelRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
</owningRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/classifierBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/ownedBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//Package/packagedElement"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
+ </newModelPath>
</owningRules>
<childRules/>
</modelKinds>
@@ -102,10 +138,10 @@
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//Component"/>
</modelRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Component"/>
</owningRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Component"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
</owningRules>
<childRules>
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//Classifier"/>
@@ -197,10 +233,28 @@
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
</modelRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
</owningRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/classifierBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/ownedBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//Package/packagedElement"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Interaction"/>
+ </newModelPath>
</owningRules>
<childRules/>
</modelKinds>
@@ -209,10 +263,28 @@
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//StateMachine"/>
</modelRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//StateMachine"/>
</owningRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//StateMachine"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/classifierBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//StateMachine"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/ownedBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//StateMachine"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//Package/packagedElement"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//StateMachine"/>
+ </newModelPath>
</owningRules>
<childRules/>
</modelKinds>
@@ -239,10 +311,28 @@
<element href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
</modelRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
</owningRules>
<owningRules>
- <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/classifierBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//BehavioredClassifier/ownedBehavior"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
+ </newModelPath>
+ </owningRules>
+ <owningRules>
+ <element href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ <newModelPath>
+ <feature href="http://www.eclipse.org/uml2/5.0.0/UML#//Package/packagedElement"/>
+ <creationType href="http://www.eclipse.org/uml2/5.0.0/UML#//Activity"/>
+ </newModelPath>
</owningRules>
<childRules/>
</modelKinds>
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
index 18fbec7..0fce1c6 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
@@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -28,6 +29,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
@@ -37,6 +39,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.papyrus.infra.core.pluginexplorer.Plugin;
import org.eclipse.papyrus.infra.core.pluginexplorer.PluginEntry;
import org.eclipse.papyrus.infra.viewpoints.configuration.ChildRule;
+import org.eclipse.papyrus.infra.viewpoints.configuration.ModelAutoCreate;
import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule;
import org.eclipse.papyrus.infra.viewpoints.configuration.OwningRule;
import org.eclipse.papyrus.infra.viewpoints.configuration.PaletteRule;
@@ -441,24 +444,6 @@ public class PolicyChecker {
}
}
-
- /**
- * Determines whether the given element can own the given view
- *
- * @param element
- * The possible owner
- * @param prototype
- * The view prototype
- * @return <code>true</code> if the element can own the view
- */
- public boolean canOwnNewView(EObject element, ViewPrototype prototype) {
- if (prototype == null)
- return false;
- if (!matchesProfiles(prototype.configuration, profileHelper.getAppliedProfiles(element)))
- return false;
- return (matchesOwnerMultiplicity(prototype.configuration, element.eClass(), profileHelper.getAppliedStereotypes(element), getOwnedViewCount(element, prototype)));
- }
-
/**
* Determines whether the given element can be the root of a view owned by the given object
*
@@ -477,9 +462,7 @@ public class PolicyChecker {
return false;
if (!matchesProfiles(prototype.configuration, profileHelper.getAppliedProfiles(element)))
return false;
- if (!matchesOwnerMultiplicity(prototype.configuration, owner.eClass(), profileHelper.getAppliedStereotypes(owner), getOwnedViewCount(owner, prototype)))
- return false;
- if (!matchesRootMultiplicity(prototype.configuration, element.eClass(), profileHelper.getAppliedStereotypes(element), getViewCountOn(element, prototype)))
+ if (!matchesCreationRoot(prototype.configuration, element.eClass(), profileHelper.getAppliedStereotypes(element), getViewCountOn(element, prototype)))
return false;
return true;
}
@@ -626,18 +609,42 @@ public class PolicyChecker {
if (proto == null)
continue;
int count = getOwnedViewCount(element, proto);
- if (!matchesOwnerMultiplicity(view, element.eClass(), stereotypes, count))
- continue;
- count = getViewCountOn(element, proto);
- if (!matchesRootMultiplicity(view, element.eClass(), stereotypes, count))
+ OwningRule rule = matchesCreationOwner(view, element, stereotypes, count);
+ if (rule == null)
continue;
- result.add(proto);
+ if (rule.getNewModelPath() != null && !rule.getNewModelPath().isEmpty()) {
+ // Auto-created root => always OK
+ result.add(proto);
+ } else {
+ // We have to check if the owner can also be a root
+ count = getViewCountOn(element, proto);
+ if (matchesCreationRoot(view, element, stereotypes, count)) {
+ // The owner can also be the root => OK
+ result.add(proto);
+ }
+ }
}
}
return result;
}
/**
+ * Gets the owning rule relevant for the given view prototype and owner
+ *
+ * @param prototype
+ * The view prototype
+ * @param owner
+ * The view's owner
+ * @return The owning rule
+ */
+ public OwningRule getOwningRuleFor(ViewPrototype prototype, EObject owner) {
+ Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(owner);
+ int count = getOwnedViewCount(owner, prototype);
+ OwningRule rule = matchesCreationOwner(prototype.configuration, owner, stereotypes, count);
+ return rule;
+ }
+
+ /**
* Gets the number of views of a given type owned by a given object
*
* @param element
@@ -732,13 +739,13 @@ public class PolicyChecker {
if (owner != null) {
if (!matchesProfiles(view, profileHelper.getAppliedProfiles(owner)))
return false;
- if (!matchesOwner(view, owner.eClass(), profileHelper.getAppliedStereotypes(owner)))
+ if (!matchesExistingOwner(view, owner, profileHelper.getAppliedStereotypes(owner)))
return false;
}
if (root != null) {
if (!matchesProfiles(view, profileHelper.getAppliedProfiles(root)))
return false;
- if (!matchesRoot(view, root.eClass(), profileHelper.getAppliedStereotypes(root)))
+ if (!matchesExistingRoot(view, root, profileHelper.getAppliedStereotypes(root)))
return false;
}
return true;
@@ -775,11 +782,11 @@ public class PolicyChecker {
* The stereotypes applied on the owning element
* @return <code>true</code> if the prototype is matching
*/
- private boolean matchesOwner(PapyrusView view, EClass type, Collection<EClass> stereotypes) {
+ private boolean matchesExistingOwner(PapyrusView view, EObject owner, Collection<EClass> stereotypes) {
PapyrusView current = view;
while (current != null) {
for (OwningRule rule : current.getOwningRules()) {
- int result = allows(rule, type, stereotypes);
+ int result = allows(rule, owner.eClass(), stereotypes);
if (result == RESULT_DENY)
return false;
if (result == RESULT_PERMIT)
@@ -795,31 +802,33 @@ public class PolicyChecker {
*
* @param view
* The view to check against
- * @param type
- * The owning element's type
+ * @param owner
+ * The owning element
* @param stereotypes
* The stereotypes applied on the owning element
* @param count
* The current cardinality for the owning element
- * @return <code>true</code> if the prototype is matching
+ * @return The matching rule that allows the owner
*/
- private boolean matchesOwnerMultiplicity(PapyrusView view, EClass type, Collection<EClass> stereotypes, int count) {
+ private OwningRule matchesCreationOwner(PapyrusView view, EObject owner, Collection<EClass> stereotypes, int count) {
PapyrusView current = view;
while (current != null) {
for (OwningRule rule : current.getOwningRules()) {
- int allow = allows(rule, type, stereotypes);
+ int allow = allows(rule, owner.eClass(), stereotypes);
if (allow == RESULT_DENY)
- return false;
+ return null;
if (allow == RESULT_UNKNOWN)
continue;
int multiplicity = rule.getMultiplicity();
- if (multiplicity == -1)
- return true;
- return (count < multiplicity);
+ if (multiplicity == -1 || count < multiplicity) {
+ if (allows(rule, owner)) {
+ return rule;
+ }
+ }
}
current = current.getParent();
}
- return false;
+ return null;
}
/**
@@ -827,17 +836,17 @@ public class PolicyChecker {
*
* @param view
* The view to check against
- * @param type
- * The root element's type
+ * @param root
+ * The root element
* @param stereotypes
* The stereotypes applied on the root element
* @return <code>true</code> if the prototype is matching
*/
- private boolean matchesRoot(PapyrusView view, EClass type, Collection<EClass> stereotypes) {
+ private boolean matchesExistingRoot(PapyrusView view, EObject root, Collection<EClass> stereotypes) {
PapyrusView current = view;
while (current != null) {
for (ModelRule rule : current.getModelRules()) {
- int result = allows(rule, type, stereotypes);
+ int result = allows(rule, root.eClass(), stereotypes);
if (result == RESULT_DENY)
return false;
if (result == RESULT_PERMIT)
@@ -853,27 +862,26 @@ public class PolicyChecker {
*
* @param view
* The view to check against
- * @param type
- * The root element's type
+ * @param root
+ * The root element
* @param stereotypes
* The stereotypes applied on the root element
* @param count
* The current cardinality for the root element
* @return <code>true</code> if the prototype is matching
*/
- private boolean matchesRootMultiplicity(PapyrusView view, EClass type, Collection<EClass> stereotypes, int count) {
+ private boolean matchesCreationRoot(PapyrusView view, EObject root, Collection<EClass> stereotypes, int count) {
PapyrusView current = view;
while (current != null) {
for (ModelRule rule : current.getModelRules()) {
- int allow = allows(rule, type, stereotypes);
+ int allow = allows(rule, root.eClass(), stereotypes);
if (allow == RESULT_DENY)
return false;
if (allow == RESULT_UNKNOWN)
continue;
int multiplicity = (oneViewPerElem ? 1 : rule.getMultiplicity());
- if (multiplicity == -1)
+ if (multiplicity == -1 || count < multiplicity)
return true;
- return (count < multiplicity);
}
current = current.getParent();
}
@@ -906,6 +914,32 @@ public class PolicyChecker {
}
/**
+ * Checks whether the given owning rule will allow to derive an auto-created root
+ *
+ * @param rule
+ * The owning rule
+ * @param owner
+ * The owner
+ * @return <code>true</code> if it is possible
+ */
+ private boolean allows(OwningRule rule, EObject owner) {
+ List<ModelAutoCreate> list = rule.getNewModelPath();
+ if (list == null || list.isEmpty())
+ return true;
+ EObject current = owner;
+ for (ModelAutoCreate elem : list) {
+ EReference ref = elem.getFeature();
+ if (ref.isMany())
+ return true;
+ Object e = current.eGet(ref);
+ if (e == null)
+ return true;
+ current = (EObject) e;
+ }
+ return false;
+ }
+
+ /**
* Checks a root element's type against a rule
*
* @param rule
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
index 5ba6e8c..7f795b3 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
@@ -28,10 +28,8 @@ import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.papyrus.infra.viewpoints.configuration.Category;
import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule;
@@ -40,7 +38,6 @@ import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusSyncTable;
import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusTable;
import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView;
import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusViewpoint;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PathElement;
import org.eclipse.swt.graphics.Image;
@@ -322,44 +319,6 @@ public abstract class ViewPrototype {
}
/**
- * Gets the initial view's root from the owner
- *
- * @param owner
- * The initial view's owner
- * @return The initial root
- */
- public EObject getRootFor(EObject owner) {
- for (ModelRule rule : configuration.getModelRules()) {
- if (rule.getAutoSelectPath() != null && rule.getAutoSelectPath().size() > 0) {
- EObject result = traverse(owner, rule.getAutoSelectPath());
- if (result != null)
- return result;
- }
- }
- return owner;
- }
-
- private EObject traverse(EObject from, EList<PathElement> path) {
- EObject current = from;
- for (PathElement elem : path) {
- EReference feature = elem.getFeature();
- if (current.eIsSet(feature)) {
- Object temp = current.eGet(feature);
- if (temp instanceof EList) {
- current = ((EList<? extends EObject>) temp).get(0);
- } else if (temp instanceof EObject) {
- current = (EObject) temp;
- } else {
- return null;
- }
- } else {
- return null;
- }
- }
- return current;
- }
-
- /**
* Determines whether the instances of this prototype can change owners
*
* @return <code>true</code> if the owner is reassignable