diff options
author | ytanguy | 2012-02-23 15:05:41 +0000 |
---|---|---|
committer | ytanguy | 2012-02-23 15:05:41 +0000 |
commit | 44ec0009add487beafc98b99b3b78f761b57f250 (patch) | |
tree | 693f2489e0eb3278c684082e2b643beee2e245e7 /plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service | |
parent | c929e2d8501806481527012d3eb1fb8ba4c5953a (diff) | |
download | org.eclipse.papyrus-44ec0009add487beafc98b99b3b78f761b57f250.tar.gz org.eclipse.papyrus-44ec0009add487beafc98b99b3b78f761b57f250.tar.xz org.eclipse.papyrus-44ec0009add487beafc98b99b3b78f761b57f250.zip |
ASSIGNED - bug 370854: [SysML Block Definition Diagram] Exception raised when drawing a directed composition from a block to another association
https://bugs.eclipse.org/bugs/show_bug.cgi?id=370854
ASSIGNED - bug 348651: [SysML Block Definition Diagram] Forbidden Association creation involving Actor is not detected before creation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=348651
Merged from branch 0.8
Diffstat (limited to 'plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service')
3 files changed, 182 insertions, 0 deletions
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/ActorEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/ActorEditHelperAdvice.java new file mode 100644 index 00000000000..219363b33e4 --- /dev/null +++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/ActorEditHelperAdvice.java @@ -0,0 +1,70 @@ +/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.service.types.helper.advice;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.uml2.uml.Actor;
+import org.eclipse.uml2.uml.Association;
+
+
+/**
+ * Advice to restrict {@link Association} creation in SysML
+ */
+public class ActorEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ /**
+ * {@inheritDoc}
+ *
+ * In case of {@link Association} creation, it should not be possible to have an {@link Actor} as source.
+ */
+ @Override
+ protected ICommand getBeforeCreateRelationshipCommand(CreateRelationshipRequest request) {
+ IElementType type = request.getElementType();
+ if(SysMLElementTypes.ASSOCIATION.equals(type)) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if(type != null) {
+ List<IElementType> superTypes = Arrays.asList(type.getAllSuperTypes());
+ if(superTypes.contains(SysMLElementTypes.ASSOCIATION)) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ }
+ return super.getBeforeCreateRelationshipCommand(request);
+ }
+
+ protected boolean hasSuperType(IElementType elementType, IElementType typeToTest) {
+ if(elementType == null || typeToTest == null) {
+ return false;
+ }
+
+ if(elementType.equals(typeToTest)) {
+ return true;
+ }
+
+ List<IElementType> superTypes = Arrays.asList(elementType.getAllSuperTypes());
+ if(superTypes.contains(typeToTest)) {
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationEditHelperAdvice.java index 6566a294bec..6522a1ddeff 100644 --- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationEditHelperAdvice.java +++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationEditHelperAdvice.java @@ -14,6 +14,7 @@ package org.eclipse.papyrus.sysml.service.types.helper.advice;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@@ -27,10 +28,13 @@ import org.eclipse.emf.ecore.EReference; import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
@@ -55,6 +59,31 @@ public class AssociationEditHelperAdvice extends AbstractEditHelperAdvice { * <pre>
* {@inheritDoc}
*
+ * avoid creation of association on another association
+ *
+ * </pre>
+ */
+ @Override
+ protected ICommand getBeforeCreateRelationshipCommand(CreateRelationshipRequest request) {
+ IElementType type = request.getElementType();
+ if(SysMLElementTypes.ASSOCIATION.equals(type)) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if(type != null) {
+ List<IElementType> superTypes = Arrays.asList(type.getAllSuperTypes());
+ if(superTypes.contains(SysMLElementTypes.ASSOCIATION)) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ }
+
+ return super.getBeforeCreateRelationshipCommand(request);
+ }
+
+ /**
+ * <pre>
+ * {@inheritDoc}
+ *
* Add a command to destroy {@link Association} when only 1 end remains.
*
* </pre>
@@ -168,6 +197,11 @@ public class AssociationEditHelperAdvice extends AbstractEditHelperAdvice { request.getParameters().put(RequestParameterConstants.ASSOCIATION_REFACTORED_ELEMENTS, currentlyRefactoredElements);
}
+ // not possible to have an association on another association, so reorient is forbidden here
+ if(request.getNewRelationshipEnd() instanceof Association) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
// Retrieve property ends of the Association (assumed to be binary)
Property semanticSource = association.getMemberEnds().get(0);
Property semanticTarget = association.getMemberEnds().get(1);
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PackageEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PackageEditHelperAdvice.java new file mode 100644 index 00000000000..4dac36c9f4a --- /dev/null +++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PackageEditHelperAdvice.java @@ -0,0 +1,78 @@ +/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.service.types.helper.advice;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.uml2.uml.Actor;
+import org.eclipse.uml2.uml.Association;
+
+
+/**
+ * Advice to restrict {@link Association} creation in SysML
+ */
+public class PackageEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ /**
+ * {@inheritDoc}
+ *
+ * In case of {@link Association} creation, it should not be possible to target an association as target end.
+ */
+ @Override
+ protected ICommand getBeforeCreateRelationshipCommand(CreateRelationshipRequest request) {
+ // test if the creation is for a SysML association
+
+ IElementType type = request.getElementType();
+ if(hasSuperType(type, SysMLElementTypes.ASSOCIATION)) {
+ // test source and target...
+ EObject target = request.getTarget();
+ if(target instanceof Association) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ if(target instanceof Actor) {
+ // association should be directed to the actor. In this case, the property is owned by the association, not by the actor
+ if(!(hasSuperType(type, SysMLElementTypes.ASSOCIATION_NONE_DIRECTED) || hasSuperType(type, SysMLElementTypes.ASSOCIATION_COMPOSITE_DIRECTED) || hasSuperType(type, SysMLElementTypes.ASSOCIATION_SHARED_DIRECTED))) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+ }
+
+ return super.getBeforeCreateRelationshipCommand(request);
+ }
+
+ protected boolean hasSuperType(IElementType elementType, IElementType typeToTest) {
+ if(elementType == null || typeToTest == null) {
+ return false;
+ }
+
+ if(elementType.equals(typeToTest)) {
+ return true;
+ }
+
+ List<IElementType> superTypes = Arrays.asList(elementType.getAllSuperTypes());
+ if(superTypes.contains(typeToTest)) {
+ return true;
+ }
+
+ return false;
+ }
+}
|