Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2013-10-30 13:22:39 -0400
committerptessier2013-10-30 13:22:39 -0400
commitf51b14114fa4e8ef30e980187b06aa8ad87f9e9f (patch)
tree7421533818f0f2720711e573c67912222f0b841e /plugins
parent7666f7d51342ad09fc437aeddf59e5d121b91489 (diff)
downloadorg.eclipse.papyrus-f51b14114fa4e8ef30e980187b06aa8ad87f9e9f.tar.gz
org.eclipse.papyrus-f51b14114fa4e8ef30e980187b06aa8ad87f9e9f.tar.xz
org.eclipse.papyrus-f51b14114fa4e8ef30e980187b06aa8ad87f9e9f.zip
Applied Patch for R. Chevrel to :
-Allow not to create a Part/Reference/Value in diagram owned by a ConstraintBlock. - Suppress representation of Property which are re-typed by a ConstraintBlock (which become a ConstraintProperty which have special representation) - Enhanced Association creation in BDD with ConstraintBlock specific behavior in the context of 297816: [SysML Parametric Diagram] Papyrus shall provide a parametric diagram editor. https://bugs.eclipse.org/bugs/show_bug.cgi?id=297816
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectBlockPropertyTypeDialog.java22
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectTypeDialog.java21
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java7
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java18
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeDirectedEditHelperAdvice.java3
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeEditHelperAdvice.java7
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneDirectedEditHelperAdvice.java3
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneEditHelperAdvice.java125
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedDirectedEditHelperAdvice.java3
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedEditHelperAdvice.java7
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java98
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/ClassifierUtils.java63
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/NamedElementHelper.java24
13 files changed, 298 insertions, 103 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectBlockPropertyTypeDialog.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectBlockPropertyTypeDialog.java
index 28ba0f980b3..277b43c19c7 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectBlockPropertyTypeDialog.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectBlockPropertyTypeDialog.java
@@ -13,12 +13,18 @@
*****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.common.dialogs;
+import java.util.Arrays;
+import java.util.List;
+
import org.eclipse.papyrus.sysml.blocks.BlocksPackage;
import org.eclipse.papyrus.sysml.diagram.common.messages.Messages;
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.papyrus.sysml.util.SysmlResource;
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
/**
@@ -28,7 +34,21 @@ public class CreateOrSelectBlockPropertyTypeDialog extends CreateOrSelectTypeDia
/** Constructor */
public CreateOrSelectBlockPropertyTypeDialog(Shell shell, NamedElement owner) {
- super(shell, owner, SysMLElementTypes.BLOCK, UMLPackage.eINSTANCE.getTypedElement_Type(), BlocksPackage.eINSTANCE.getBlock(), UMLElementTypes.PACKAGE, UMLPackage.eINSTANCE.getPackage_PackagedElement(), null);
+ super(shell, owner, SysMLElementTypes.BLOCK, UMLPackage.eINSTANCE.getTypedElement_Type(), BlocksPackage.eINSTANCE.getBlock(), UMLElementTypes.PACKAGE, UMLPackage.eINSTANCE.getPackage_PackagedElement(), null, getConstraintBlockAsStereotype());
+ }
+
+ /**
+ * If we create a Part type by a ConstraintBlock, thisPart will become a ConstraintProperty and representation will immediately disappear.
+ * So we filter ConstraintBlock type => Only strict Block are allowed
+ * @return
+ */
+ @SuppressWarnings("deprecation")
+ private static List<?> getConstraintBlockAsStereotype() {
+ // We create a mock Stereotype to pass in the good code section of SemanticUMLContentProvider.isCompatibleMetaclass (bad gestion of static stereotypes)
+ Stereotype mockStereotype = UMLFactory.eINSTANCE.createStereotype();
+ // We use this stereotype with namespace instead of ConstraintsPackage.eINSTANCE.getConstraintBlock()
+ mockStereotype.setName(SysmlResource.CONSTRAINT_BLOCK_ID);
+ return Arrays.asList(mockStereotype);
}
/**
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectTypeDialog.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectTypeDialog.java
index 2b1e9e15ef0..18f6346160d 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectTypeDialog.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectTypeDialog.java
@@ -15,6 +15,8 @@
*****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.common.dialogs;
+import java.util.List;
+
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
@@ -101,6 +103,8 @@ public class CreateOrSelectTypeDialog extends FormDialog {
protected EClass containerEClass;
+ protected List<?> notWantedMetaclasses;
+
/**
* Create a new dialog to initialize an ActivityParameterNode.
*
@@ -121,6 +125,19 @@ public class CreateOrSelectTypeDialog extends FormDialog {
this.labelProvider = new UMLLabelProvider();
}
+ /**
+ * Create a new dialog to initialize an ActivityParameterNode.
+ * This dialog will filter certain Stereotypes
+ * @param shell
+ * parent shell
+ * @param owner
+ * the activity that owns the action
+ */
+ public CreateOrSelectTypeDialog(Shell shell, EObject defaultContainer, IElementType elementType, EStructuralFeature editedFeature, EClass elementEClass, IElementType containerType, EStructuralFeature containerFeature, EClass containerEClass, List<?> notWantedMetaclasses) {
+ this(shell, defaultContainer, elementType, editedFeature, elementEClass, containerType, containerFeature, containerEClass);
+ this.notWantedMetaclasses = notWantedMetaclasses;
+ }
+
protected String getDialogTitle() {
return Messages.CreateOrSelectTypeDialog_DialogTitle;
}
@@ -481,9 +498,11 @@ public class CreateOrSelectTypeDialog extends FormDialog {
dialog.setInput(EcoreUtil.getRootContainer(defaultContainer));
ServiceEditContentProvider provider = new ServiceEditContentProvider(elementType, editedFeature, EcoreUtil.getRootContainer(defaultContainer));
+ provider.setNotWantedMetaclasses(notWantedMetaclasses);
+
dialog.setContentProvider(provider);
dialog.setLabelProvider(labelProvider);
-
+
if(dialog.open() == Window.OK) {
Object result = dialog.getResult()[0];
if(result instanceof IAdaptable) {
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java
index a292903eefc..ac6a0167848 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java
@@ -18,7 +18,6 @@ import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.StringValueStyle;
@@ -73,8 +72,10 @@ public class SwitchConstraintPropertyRepresentationCommand extends Command {
structureCompartment.setVisible(true);
}
else {
- structureCompartment = ViewService.getInstance().createNode(null, (View)editPart.getModel(), SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID, ViewUtil.APPEND, true, new PreferencesHint("org.eclipse.papyrus.sysml.diagram.parametric"));
- structureCompartment.setElement(editPart.resolveSemanticElement());
+ structureCompartment = ViewService.createNode((View)editPart.getModel(), SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID, new PreferencesHint("org.eclipse.papyrus.sysml.diagram.parametric"));
+ if (structureCompartment != null) {
+ structureCompartment.setElement(editPart.resolveSemanticElement());
+ }
}
// add the << constraint >> tag
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java
index 99bae3ee3d9..1a8188dcda6 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java
@@ -22,6 +22,8 @@ import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.SpecializationType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
@@ -35,6 +37,9 @@ import org.eclipse.papyrus.sysml.diagram.parametric.commands.ReorientReferenceRe
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomBlockCompositeEditPartTN;
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart;
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policy.DiagramSemanticEditPolicy;
+import org.eclipse.papyrus.sysml.service.types.matcher.PartPropertyMatcher;
+import org.eclipse.papyrus.sysml.service.types.matcher.ReferencePropertyMatcher;
+import org.eclipse.papyrus.sysml.service.types.matcher.ValuePropertyMatcher;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ContextLinkEditPart;
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintParameterAffixedNodeEditPart;
import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart;
@@ -54,6 +59,19 @@ public class CustomParametricSemanticPolicy extends DiagramSemanticEditPolicy {
if (semanticOwner instanceof Class && org.eclipse.uml2.uml.util.UMLUtil.getStereotypeApplication(semanticOwner, ConstraintBlock.class) == null) {
return UnexecutableCommand.INSTANCE;
}
+ // Could not create Part/Reference/Value
+ if (request instanceof CreateElementRequest && ((CreateElementRequest)request).getElementType() instanceof SpecializationType) {
+ IElementMatcher matcher = ((SpecializationType)((CreateElementRequest)request).getElementType()).getMatcher();
+ if (matcher instanceof PartPropertyMatcher) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if (matcher instanceof ReferencePropertyMatcher) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if (matcher instanceof ValuePropertyMatcher) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
}
}
return super.getSemanticCommand(request);
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeDirectedEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeDirectedEditHelperAdvice.java
index 20281e55369..6fb4e8e68c3 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeDirectedEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeDirectedEditHelperAdvice.java
@@ -13,6 +13,7 @@ package org.eclipse.papyrus.sysml.service.types.helper.advice;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
/**
* Edit helper advice for {@link Association} with "aggregation = composition" (used for creation purpose only).
@@ -31,7 +32,7 @@ public class AssociationCompositeDirectedEditHelperAdvice extends AssociationCom
* </pre>
*/
@Override
- protected void addTargetInModel(Property targetEnd, Classifier owner, Classifier sourceType, Association association) {
+ protected void addTargetInModel(Property targetEnd, Classifier owner, Type sourceType, Association association) {
association.getOwnedEnds().add(targetEnd);
}
}
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeEditHelperAdvice.java
index 030d2d64b66..ae723f7dd76 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeEditHelperAdvice.java
@@ -13,7 +13,6 @@ package org.eclipse.papyrus.sysml.service.types.helper.advice;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
/**
* Edit helper advice for {@link Association} with "aggregation = composition" and navigable in one way (used for creation purpose only).
@@ -33,11 +32,7 @@ public class AssociationCompositeEditHelperAdvice extends AssociationNoneEditHel
* </pre>
*/
@Override
- protected Property createSourceProperty(Type targetType) {
-
- Property sourceProperty = super.createSourceProperty(targetType);
+ protected void configureSourceProperty(Property sourceProperty) {
sourceProperty.setIsComposite(true);
-
- return sourceProperty;
}
} \ No newline at end of file
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneDirectedEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneDirectedEditHelperAdvice.java
index 0fb14eebf3b..e9cd6d98115 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneDirectedEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneDirectedEditHelperAdvice.java
@@ -13,6 +13,7 @@ package org.eclipse.papyrus.sysml.service.types.helper.advice;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
/**
* Edit helper advice for {@link Association} with "aggregation = none" and navigable in one way (used for creation purpose only).
@@ -31,7 +32,7 @@ public class AssociationNoneDirectedEditHelperAdvice extends AssociationNoneEdit
* </pre>
*/
@Override
- protected void addTargetInModel(Property targetEnd, Classifier owner, Classifier sourceType, Association association) {
+ protected void addTargetInModel(Property targetEnd, Classifier owner, Type sourceType, Association association) {
association.getOwnedEnds().add(targetEnd);
}
}
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneEditHelperAdvice.java
index 025ba136d2e..0f69b4d04e0 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneEditHelperAdvice.java
@@ -13,22 +13,31 @@
*****************************************************************************/
package org.eclipse.papyrus.sysml.service.types.helper.advice;
+import java.util.List;
+
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
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.commands.ConfigureElementCommand;
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.SetRequest;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.sysml.service.types.Activator;
import org.eclipse.papyrus.uml.service.types.utils.ClassifierUtils;
+import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
/**
* Edit helper advice for {@link Association} with "aggregation = none" (used for creation purpose only).
@@ -66,39 +75,73 @@ public class AssociationNoneEditHelperAdvice extends AssociationEditHelperAdvice
}
/**
- * Creates a new source {@link Property} from the targetType.
+ * Creates a new {@link Property} from the propertyType in the propertyContainer
*
- * @param targetType
+ * @param propertyContainer
+ * the container of the {@link Property}
+ * @param propertyType
* the type of the {@link Property}
* @return the new {@link Property}
- */
- protected Property createSourceProperty(Type targetType) {
-
- Property sourceProperty = UMLFactory.eINSTANCE.createProperty();
- sourceProperty.setType(targetType);
- sourceProperty.setName(targetType.getName().toLowerCase());
-
+ * @throws ExecutionException
+ */
+ protected Property createTargetProperty(Property targetProperty, Classifier propertyContainer, Type propertyType, Association association, TransactionalEditingDomain editingDomain, IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ addSourceInModel(targetProperty, propertyContainer, propertyType, association);
+ setPropertyType(targetProperty, propertyType, editingDomain, progressMonitor, info);
+ setPropertyName(targetProperty);
+ return targetProperty;
+ }
+
+ protected Property createSourceProperty(Property sourceProperty, Classifier propertyContainer, Type propertyType, Association association, TransactionalEditingDomain editingDomain, IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ addTargetInModel(sourceProperty, propertyContainer, propertyType, association);
+ setPropertyType(sourceProperty, propertyType, editingDomain, progressMonitor, info);
+ setPropertyName(sourceProperty);
return sourceProperty;
}
+
+ protected void setPropertyType(Property property, Type propertyType, TransactionalEditingDomain editingDomain, IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ // Set type using all AdviceHelper (use ServiceEdit instead of manually set)
+ SetRequest request = new SetRequest(property, UMLPackage.eINSTANCE.getTypedElement_Type(), propertyType);
+ request.setEditingDomain(editingDomain);
+ IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(property);
+ ICommand editCommand = commandProvider.getEditCommand(request);
+ editCommand.execute(progressMonitor, info);
+ }
+
+ private void setPropertyName(Property property) {
+ String baseName = property.getType().getName().toLowerCase();
+ Element owner = property.getOwner();
+ if (owner instanceof Classifier) {
+ List<Property> ownedAttributes = ClassifierUtils.getOwnedAttributes((Classifier)owner);
+ String defaultNameWithIncrementFromBase = NamedElementHelper.getDefaultNameWithIncrementFromBase(
+ property.getType().getName().toLowerCase(), ownedAttributes, "_");
+ property.setName(defaultNameWithIncrementFromBase);
+ }
+ else {
+ // default
+ property.setName(baseName);
+ }
+ }
/**
- * Creates a new target {@link Property} from the sourceType.
- *
- * @param sourceType
- * the type of the {@link Property}
- * @return the new {@link Property}
+ * This method has to be specialized by subclasses (AggregationKind)
+ * @param sourceProperty
+ * The property to configure
*/
- protected Property createTargetProperty(Type sourceType) {
-
- Property targetProperty = UMLFactory.eINSTANCE.createProperty();
- targetProperty.setType(sourceType);
- targetProperty.setName(sourceType.getName().toLowerCase());
+ protected void configureSourceProperty(Property sourceProperty) {
+ // do nothing
+ }
- return targetProperty;
+ /**
+ * This method has to be specialized by subclasses (AggregationKind)
+ * @param sourceProperty
+ * The property to configure
+ */
+ protected void configureTargetProperty(Property targetProperty) {
+ // do nothing
}
/**
- * Add the source {@link Property} in the correct container.
+ * This method has to be specialized by subclasses (owner)
*
* @param sourceEnd
* the semantic end
@@ -110,16 +153,16 @@ public class AssociationNoneEditHelperAdvice extends AssociationEditHelperAdvice
* the association
* @throws UnsupportedOperationException
*/
- protected void addSourceInModel(final Property sourceEnd, Classifier owner, Classifier targetType, Association association) throws UnsupportedOperationException {
- boolean added = ClassifierUtils.addOwnedAttribute(owner, sourceEnd);
-
+ protected void addSourceInModel(final Property sourceEnd, Classifier owner, Type targetType, Association association) throws UnsupportedOperationException {
+ // set the container in order to allow Stereotype appliance
+ boolean added = ClassifierUtils.addOwnedAttribute(owner, sourceEnd);
if(!added) {
throw new UnsupportedOperationException("Cannot add a Property on Classifier " + owner.getQualifiedName());
}
}
/**
- * Add the source {@link Property} in the correct container.
+ * This method has to be specialized by subclasses (owner)
*
* @param targetEnd
* the semantic end
@@ -131,9 +174,9 @@ public class AssociationNoneEditHelperAdvice extends AssociationEditHelperAdvice
* the association
* @throws UnsupportedOperationException
*/
- protected void addTargetInModel(Property targetEnd, Classifier owner, Classifier sourceType, Association association) {
- boolean added = ClassifierUtils.addOwnedAttribute(owner, targetEnd);
-
+ protected void addTargetInModel(Property targetEnd, Classifier owner, Type sourceType, Association association) {
+ // set the container in order to allow Stereotype appliance
+ boolean added = ClassifierUtils.addOwnedAttribute(owner, targetEnd);
if(!added) {
throw new UnsupportedOperationException("Cannot add a Property on Classifier " + owner.getQualifiedName());
}
@@ -162,18 +205,22 @@ public class AssociationNoneEditHelperAdvice extends AssociationEditHelperAdvice
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- // Create source and target ends
- Property sourceEnd = createSourceProperty(targetType);
- Property targetEnd = createTargetProperty(sourceType);
-
- // Add association ends references
- association.getMemberEnds().add(sourceEnd);
- association.getMemberEnds().add(targetEnd);
-
- // Add end properties in the model
try {
- addSourceInModel(sourceEnd, sourceType, targetType, association);
- addTargetInModel(targetEnd, targetType, sourceType, association);
+ Property targetProperty = UMLFactory.eINSTANCE.createProperty();
+ Property sourceProperty = UMLFactory.eINSTANCE.createProperty();
+
+ // TODO: problem with SysML. Link are inversed. A -> B => memberEnd={a, b} instead of {b, a}.
+ // Problem seems to come from cached derivedFeature /endTypes
+ // So we force to set memberEnd in this order before doing anything with the created properties
+ association.getMemberEnds().add(targetProperty);
+ association.getMemberEnds().add(sourceProperty);
+
+ // Create source and target ends
+ createTargetProperty(targetProperty, sourceType, targetType, association, request.getEditingDomain(), progressMonitor, info);
+ configureSourceProperty(targetProperty);
+ createSourceProperty(sourceProperty, targetType, sourceType, association, request.getEditingDomain(), progressMonitor, info);
+ configureTargetProperty(sourceProperty);
+
} catch (Exception e) {
Activator.log.error(e);
return CommandResult.newCancelledCommandResult();
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedDirectedEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedDirectedEditHelperAdvice.java
index f724ef0aa42..b2a121d4ee9 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedDirectedEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedDirectedEditHelperAdvice.java
@@ -13,6 +13,7 @@ package org.eclipse.papyrus.sysml.service.types.helper.advice;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
/**
* Edit helper advice for {@link Association} with "aggregation = shared" and navigable in one way (used for creation purpose only).
@@ -31,7 +32,7 @@ public class AssociationSharedDirectedEditHelperAdvice extends AssociationShared
* </pre>
*/
@Override
- protected void addTargetInModel(Property targetEnd, Classifier owner, Classifier sourceType, Association association) {
+ protected void addTargetInModel(Property targetEnd, Classifier owner, Type sourceType, Association association) {
association.getOwnedEnds().add(targetEnd);
}
}
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedEditHelperAdvice.java
index 828a487555d..76afbbc68cf 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedEditHelperAdvice.java
@@ -14,7 +14,6 @@ import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
/**
* Edit helper advice for {@link Association} with "aggregation = shared" (used for creation purpose only).
@@ -34,11 +33,7 @@ public class AssociationSharedEditHelperAdvice extends AssociationNoneEditHelper
* </pre>
*/
@Override
- protected Property createSourceProperty(Type targetType) {
-
- Property sourceProperty = super.createSourceProperty(targetType);
+ protected void configureSourceProperty(Property sourceProperty) {
sourceProperty.setAggregation(AggregationKind.SHARED_LITERAL);
-
- return sourceProperty;
}
} \ No newline at end of file
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java
index b9cb070659e..fd24bbb36cf 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java
@@ -16,6 +16,7 @@ package org.eclipse.papyrus.sysml.service.types.helper.advice;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
@@ -25,22 +26,28 @@ import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
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.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.sysml.blocks.BlocksPackage;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage;
+import org.eclipse.papyrus.sysml.service.types.Activator;
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil;
import org.eclipse.papyrus.uml.service.types.utils.ElementUtil;
import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper;
-import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Port;
@@ -71,10 +78,9 @@ public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
@SuppressWarnings("unchecked")
@Override
protected ICommand getBeforeSetCommand(SetRequest request) {
- ICommand gmfCommand = super.getBeforeSetCommand(request);
+ ICommand gmfCommand = super.getBeforeSetCommand(request);
EObject elementToEdit = request.getElementToEdit();
-
if((elementToEdit instanceof Property) && !(elementToEdit instanceof Port) &&
(request.getFeature() == UMLPackage.eINSTANCE.getTypedElement_Type()) && (request.getValue() instanceof Type)) {
@@ -82,11 +88,11 @@ public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
// SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied
if (request.getValue() instanceof org.eclipse.uml2.uml.Class) {
- ICommand stereotypeApplication = getConstraintPropertyStereotypeApplicationCommand(propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue());
- gmfCommand = CompositeCommand.compose(gmfCommand, stereotypeApplication);
+ ICommand stereotypeApplicationCommand = getConstraintPropertyStereotypeApplicationCommand(propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue(), request);
+ gmfCommand = CompositeCommand.compose(gmfCommand, stereotypeApplicationCommand);
}
- // Exclude ConstraintParameter (simple property without stereotype owned by a ConstraintBlock)
+ // Exclude ConstraintParameter (simple property without ConstraintProperty stereotype owned by a ConstraintBlock)
if (propertyToEdit.eContainer() instanceof org.eclipse.uml2.uml.Class && UMLUtil.getStereotypeApplication((Element)propertyToEdit.eContainer(), ConstraintBlock.class) != null) {
if (UMLUtil.getStereotypeApplication(propertyToEdit, ConstraintProperty.class) == null) {
return gmfCommand;
@@ -98,9 +104,12 @@ public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
// The edited property has to be related to a SysML association
if((relatedAssociation == null) || !(ElementUtil.hasNature(relatedAssociation, SysMLElementTypes.SYSML_NATURE))) {
- // If no association exist and the new type is a Block, add the association
+ // If no association exist and the new type is a Block
+ // (not a ConstraintBlock => a property typed by a ConstraintBlock is a ConstraintProperty, not a Part neither a Reference),
+ // add the association
if ((relatedAssociation == null)
&& ((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue())
+ && !((ISpecializationType) SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type) request.getValue())
&& ((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches(propertyToEdit.eContainer())) {
ICommand addAssociationCommand = getCreatePartAssociationCommand((org.eclipse.uml2.uml.Class)propertyToEdit.eContainer(), propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue());
@@ -126,7 +135,7 @@ public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
// If the new type is not a block, destroy related association
// This must be done only if the setting of the property type is not part of an association re-orient (hence after the previous code-block),
// otherwise there is no legitimate reason to destroy the existing association while re-orienting it.
- if (!((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue())) {
+ if (!((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue()) && propertyToEdit.getType() != null) {
ICommand destroyCommand = getDestroyPartAssociationCommand(relatedAssociation, propertyToEdit);
gmfCommand = CompositeCommand.compose(gmfCommand, destroyCommand);
@@ -159,18 +168,20 @@ public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
Association relatedAssociation = setProperty.getAssociation(); // Should not be null, test before calling method.
- // Re-orient the related association (do not use edit service to avoid infinite loop here)
- int direction = ReorientRelationshipRequest.REORIENT_TARGET;
- if(setProperty == associationToRefactor.getMemberEnds().get(1)) {
- direction = ReorientRelationshipRequest.REORIENT_SOURCE;
- }
-
- ReorientRelationshipRequest reorientRequest = new ReorientRelationshipRequest(relatedAssociation, (Type)request.getValue(), setProperty.eContainer(), direction);
- reorientRequest.addParameters(request.getParameters());
-
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(relatedAssociation);
- if(provider != null) {
- return provider.getEditCommand(reorientRequest);
+ if (associationToRefactor.getMemberEnds().size() >= 2) {
+ // Re-orient the related association (do not use edit service to avoid infinite loop here)
+ int direction = ReorientRelationshipRequest.REORIENT_TARGET;
+ if(setProperty == associationToRefactor.getMemberEnds().get(1)) {
+ direction = ReorientRelationshipRequest.REORIENT_SOURCE;
+ }
+
+ ReorientRelationshipRequest reorientRequest = new ReorientRelationshipRequest(relatedAssociation, (Type)request.getValue(), setProperty.eContainer(), direction);
+ reorientRequest.addParameters(request.getParameters());
+
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(relatedAssociation);
+ if(provider != null) {
+ return provider.getEditCommand(reorientRequest);
+ }
}
return null;
@@ -230,20 +241,10 @@ public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
*
* @return the ConstraintProperty stereotype application command
*/
- private ICommand getConstraintPropertyStereotypeApplicationCommand(final Property sourceProperty, final org.eclipse.uml2.uml.Class targetBlock) {
+ private ICommand getConstraintPropertyStereotypeApplicationCommand(final Property sourceProperty, final org.eclipse.uml2.uml.Class targetBlock, final SetRequest request) {
- return new AbstractCommand("Apply/Remove ConstraintProperty Stereotype") {
-
- @Override
- protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- return null;
- }
-
- @Override
- protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- return null;
- }
-
+ return new AbstractTransactionalCommand(request.getEditingDomain(), "Apply/Remove ConstraintProperty Stereotype", null) {
+
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
// SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied
@@ -251,6 +252,34 @@ public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
if (UMLUtil.getStereotypeApplication(targetBlock, ConstraintBlock.class) != null) {
if (constraintPropertyApplication == null) {
StereotypeApplicationHelper.INSTANCE.applyStereotype(sourceProperty, ConstraintsPackage.eINSTANCE.getConstraintProperty());
+ // Remove representations
+ Set<View> memberViewsToDestroy = CrossReferencerUtil.getCrossReferencingViews(sourceProperty, null);
+ if (memberViewsToDestroy.size() != 0) {
+ final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ final String DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY = "displayMessageForTypingActionPreferenceKey";
+ boolean contains = store.contains(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
+ if(!contains) {
+ store.setValue(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY, MessageDialogWithToggle.NEVER);
+ store.setDefault(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY, MessageDialogWithToggle.NEVER);
+ }
+ final String hideValue = store.getString(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
+ if(!hideValue.equals(MessageDialogWithToggle.ALWAYS)) {
+ int size = memberViewsToDestroy.size();
+ MessageDialogWithToggle.openInformation(Display.getDefault().getActiveShell(),
+ "Change Type Action",
+ "WARNING! Typing a Property by a ConstraintBlock make this property become a ConstraintProperty. ConstraintProperty have a specific representation. "
+ + "\nSo all representations of this property will be removed from the model (" + size + " occurence" + ((size > 1) ? "s" : "") + ")."
+ , "Don't show this dialog the next time",
+ false, store, DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
+ }
+
+ }
+ for (View view : memberViewsToDestroy) {
+ final DestroyElementRequest destroyRequest = new DestroyElementRequest(request.getEditingDomain(), view, false);
+ final IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(view);
+ ICommand editCommand = commandProvider.getEditCommand(destroyRequest);
+ editCommand.execute(progressMonitor, info);
+ }
}
}
else {
@@ -263,7 +292,6 @@ public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
};
}
-
/**
* Create a part association destroy command.
*
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/ClassifierUtils.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/ClassifierUtils.java
index 1ccdcebb614..a6c5e363374 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/ClassifierUtils.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/ClassifierUtils.java
@@ -14,6 +14,9 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.service.types.utils;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.uml2.uml.Artifact;
import org.eclipse.uml2.uml.Class;
@@ -45,6 +48,20 @@ public class ClassifierUtils {
}
/**
+ * This method provides a switch to ease the addition of a new Property in a Classifier.
+ *
+ * @param classifier
+ * the parent classifier.
+ * @param property
+ * the contained property.
+ * @return false if the addition fails.
+ */
+ public static List<Property> getOwnedAttributes(Classifier classifier) {
+ GetOwnedAttributesSwitch classifierSwitch = new GetOwnedAttributesSwitch();
+ return classifierSwitch.doSwitch(classifier);
+ }
+
+ /**
* Switch implementation for Property addition.
*/
private static class AddOwnedAttributeSwitch extends UMLSwitch<Boolean> {
@@ -98,4 +115,50 @@ public class ClassifierUtils {
return Boolean.FALSE;
}
};
+
+ /**
+ * Switch implementation for Property addition.
+ */
+ private static class GetOwnedAttributesSwitch extends UMLSwitch<List<Property>> {
+
+ public GetOwnedAttributesSwitch() {
+ super();
+ }
+
+ @Override
+ public List<Property> caseArtifact(Artifact object) {
+ return object.getOwnedAttributes();
+ }
+
+ @Override
+ public List<Property> caseDataType(DataType object) {
+ return object.getOwnedAttributes();
+ }
+
+ @Override
+ public List<Property> caseInterface(Interface object) {
+ return object.getOwnedAttributes();
+ }
+
+ @Override
+ public List<Property> caseSignal(Signal object) {
+ return object.getOwnedAttributes();
+ }
+
+ @Override
+ public List<Property> caseStructuredClassifier(StructuredClassifier object) {
+ return object.getOwnedAttributes();
+ }
+
+ @Override
+ public List<Property> caseClass(Class object) {
+ return object.getOwnedAttributes();
+ }
+
+ @Override
+ public List<Property> defaultCase(EObject object) {
+ return new ArrayList<Property>();
+ }
+ };
+
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/NamedElementHelper.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/NamedElementHelper.java
index b728c97c4f2..b32eb5875a4 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/NamedElementHelper.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/NamedElementHelper.java
@@ -115,15 +115,21 @@ public class NamedElementHelper {
this.baseString = baseString;
}
- @SuppressWarnings("rawtypes")
- public static String getDefaultNameWithIncrementFromBase(String base, Collection contents) {
- return getDefaultNameWithIncrementFromBase(base, contents, null);
+ public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents) {
+ return getDefaultNameWithIncrementFromBase(base, contents, null, "");
+ }
+
+ public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents, String separator) {
+ return getDefaultNameWithIncrementFromBase(base, contents, null, separator);
}
- @SuppressWarnings("rawtypes")
- public static String getDefaultNameWithIncrementFromBase(String base, Collection contents, EObject elementToRename) {
- // Not change the name if elementToRename already present in the contents collection
- if (contents.contains(elementToRename)) {
+ public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents, EObject elementToRename) {
+ return getDefaultNameWithIncrementFromBase(base, contents, elementToRename, "");
+ }
+
+ public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents, EObject elementToRename, String separator) {
+ // Not change the name if elementToRename already present in the contents collection and already have a name
+ if (contents.contains(elementToRename) && EMFCoreUtil.getName(elementToRename) != null) {
if (elementToRename instanceof ENamedElement) {
return ((ENamedElement)elementToRename).getName();
}
@@ -136,7 +142,7 @@ public class NamedElementHelper {
if("property".equalsIgnoreCase(base)) {
base = "Attribute";
}
- int nextNumber = 1;
+ int nextNumber = 0;
for(Object o : contents) {
if(o instanceof EObject && o != elementToRename) {
@@ -157,6 +163,6 @@ public class NamedElementHelper {
}
}
- return base + nextNumber;
+ return nextNumber > 0 ? base + separator + nextNumber : base;
}
}

Back to the top