summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2014-03-27 05:00:07 (EDT)
committerLaurent Wouters2014-03-27 09:18:33 (EDT)
commit6594cae513986631c6c4744678d8c90ac6b19c70 (patch)
treecb8cb0fdd8cd8c18970a44b196a88198bdc229a8
parentc8c5d8479159acb4a467694ec847840fb2fe64b7 (diff)
downloadorg.eclipse.papyrus-6594cae513986631c6c4744678d8c90ac6b19c70.zip
org.eclipse.papyrus-6594cae513986631c6c4744678d8c90ac6b19c70.tar.gz
org.eclipse.papyrus-6594cae513986631c6c4744678d8c90ac6b19c70.tar.bz2
#431139: [Diagram Creation] Issues with the Viewpoint-based Diagram Creation commands
Changed the auto-creation of diagram root element to use the edit service 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.java53
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java2
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java2
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java3
4 files changed, 53 insertions, 7 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 95cc745..d78e6f1 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
@@ -30,7 +30,6 @@ 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;
@@ -40,6 +39,10 @@ import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
@@ -54,6 +57,10 @@ import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.services.edit.Activator;
+import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.infra.viewpoints.configuration.ModelAutoCreate;
import org.eclipse.papyrus.infra.viewpoints.configuration.OwningRule;
import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
@@ -99,6 +106,10 @@ public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends Abst
private String name;
+ private IElementEditService service;
+
+ private IClientContext clientContext;
+
public Creator(ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name) {
this.modelSet = modelSet;
this.owner = owner;
@@ -112,11 +123,27 @@ public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends Abst
Resource notationResource = NotationUtils.getNotationResource(modelSet);
Resource diResource = DiModelUtils.getDiResource(modelSet);
- if(owner == null) {
+ if (owner == null) {
owner = getRootElement(modelResource);
attachModelToResource(owner, modelResource);
}
+ service = ElementEditServiceUtils.getCommandProvider(owner);
+ if (service == null) {
+ // Something isn't right ...
+ return null;
+ }
+
+ try {
+ clientContext = TypeContext.getContext();
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ if (clientContext == null) {
+ // Something isn't right ...
+ return null;
+ }
+
rule = PolicyChecker.getCurrent().getOwningRuleFor(prototype, owner);
if (rule == null) {
// Something isn't right ...
@@ -130,7 +157,7 @@ public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends Abst
EReference ref = auto.getFeature();
EClass type = auto.getCreationType();
if (ref.isMany()) {
- EObject temp = ((EPackage) type.eContainer()).getEFactoryInstance().create(type);
+ EObject temp = create(element, ref, type);
List list = (List) element.eGet(ref);
list.add(temp);
element = temp;
@@ -139,7 +166,7 @@ public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends Abst
if (temp != null) {
element = temp;
} else {
- temp = ((EPackage) type.eContainer()).getEFactoryInstance().create(type);
+ temp = create(element, ref, type);
element.eSet(ref, temp);
element = temp;
}
@@ -164,6 +191,24 @@ public abstract class AbstractPapyrusGmfCreateDiagramCommandHandler extends Abst
}
return diagram;
}
+
+ private EObject create(EObject origin, EReference reference, EClass type) {
+ IElementType itype = ElementTypeRegistry.getInstance().getElementType(type, clientContext);
+ CreateElementRequest request = new CreateElementRequest(origin, itype, reference);
+ ICommand command = service.getEditCommand(request);
+ IStatus status = null;
+ try {
+ status = command.execute(null, null);
+ } catch (ExecutionException e) {
+ return null;
+ }
+ if (!status.isOK())
+ return null;
+ CommandResult result = command.getCommandResult();
+ if (result == null)
+ return null;
+ return (EObject) result.getReturnValue();
+ }
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
index a85ef90..b5f7658 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
@@ -163,7 +163,7 @@ public class GMFModelElement extends EMFModelElement {
return new ModelContentProvider(diagram, getRoot(diagram.getElement())) {
@Override
protected boolean isValid(EObject selection, Diagram diagram, ViewPrototype prototype) {
- return PolicyChecker.getCurrent().canHaveNewView(diagram.getElement(), selection, prototype);
+ return (PolicyChecker.getCurrent().getOwningRuleFor(prototype, selection) != null);
}
};
}
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 0fce1c6..eeaaebb 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
@@ -462,7 +462,7 @@ public class PolicyChecker {
return false;
if (!matchesProfiles(prototype.configuration, profileHelper.getAppliedProfiles(element)))
return false;
- if (!matchesCreationRoot(prototype.configuration, element.eClass(), profileHelper.getAppliedStereotypes(element), getViewCountOn(element, prototype)))
+ if (!matchesCreationRoot(prototype.configuration, element, profileHelper.getAppliedStereotypes(element), getViewCountOn(element, prototype)))
return false;
return true;
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java
index a7e44e6..8e7cbb4 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java
@@ -54,6 +54,7 @@ import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
import org.eclipse.papyrus.views.modelexplorer.Activator;
import org.eclipse.papyrus.views.modelexplorer.commands.MoveOpenableCommand;
@@ -134,7 +135,7 @@ public class CommonDropAdapterAssistant extends org.eclipse.ui.navigator.CommonD
ViewPrototype proto = ViewPrototype.get(view);
// check if diagram can exist in new location
- if(!proto.isOwnerReassignable()) {
+ if (!proto.isOwnerReassignable() || PolicyChecker.getCurrent().getOwningRuleFor(proto, target) == null) {
// stop here with unexecutable command
return UnexecutableCommand.INSTANCE;
}