Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 297816 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/papyrus/sysml/diagram/parametric/commands/switchrepresentation/SwitchConstraintPropertyRepresentationCommand.java (-3 / +4 lines)
Lines 18-24 Link Here
18
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.commands.Command;
19
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
19
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
20
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
20
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
21
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
22
import org.eclipse.gmf.runtime.notation.NotationFactory;
21
import org.eclipse.gmf.runtime.notation.NotationFactory;
23
import org.eclipse.gmf.runtime.notation.NotationPackage;
22
import org.eclipse.gmf.runtime.notation.NotationPackage;
24
import org.eclipse.gmf.runtime.notation.StringValueStyle;
23
import org.eclipse.gmf.runtime.notation.StringValueStyle;
Lines 73-80 Link Here
73
			structureCompartment.setVisible(true);
72
			structureCompartment.setVisible(true);
74
		}
73
		}
75
		else {
74
		else {
76
			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"));
75
			structureCompartment = ViewService.createNode((View)editPart.getModel(), SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID, new PreferencesHint("org.eclipse.papyrus.sysml.diagram.parametric"));
77
			structureCompartment.setElement(editPart.resolveSemanticElement());
76
			if (structureCompartment != null) {
77
				structureCompartment.setElement(editPart.resolveSemanticElement());
78
			}
78
		}
79
		}
79
		
80
		
80
		// add the << constraint >> tag
81
		// add the << constraint >> tag
(-)src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeDirectedEditHelperAdvice.java (-1 / +2 lines)
Lines 13-18 Link Here
13
import org.eclipse.uml2.uml.Association;
13
import org.eclipse.uml2.uml.Association;
14
import org.eclipse.uml2.uml.Classifier;
14
import org.eclipse.uml2.uml.Classifier;
15
import org.eclipse.uml2.uml.Property;
15
import org.eclipse.uml2.uml.Property;
16
import org.eclipse.uml2.uml.Type;
16
17
17
/** 
18
/** 
18
 * Edit helper advice for {@link Association} with "aggregation = composition" (used for creation purpose only).
19
 * Edit helper advice for {@link Association} with "aggregation = composition" (used for creation purpose only).
Lines 31-37 Link Here
31
	 * </pre>
32
	 * </pre>
32
	 */
33
	 */
33
	@Override
34
	@Override
34
	protected void addTargetInModel(Property targetEnd, Classifier owner, Classifier sourceType, Association association) {
35
	protected void addTargetInModel(Property targetEnd, Classifier owner, Type sourceType, Association association) {
35
		association.getOwnedEnds().add(targetEnd);
36
		association.getOwnedEnds().add(targetEnd);
36
	}
37
	}
37
}
38
}
(-)src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationCompositeEditHelperAdvice.java (-6 / +1 lines)
Lines 13-19 Link Here
13
import org.eclipse.uml2.uml.Association;
13
import org.eclipse.uml2.uml.Association;
14
import org.eclipse.uml2.uml.Classifier;
14
import org.eclipse.uml2.uml.Classifier;
15
import org.eclipse.uml2.uml.Property;
15
import org.eclipse.uml2.uml.Property;
16
import org.eclipse.uml2.uml.Type;
17
16
18
/** 
17
/** 
19
 * Edit helper advice for {@link Association} with "aggregation = composition" and navigable in one way (used for creation purpose only). 
18
 * Edit helper advice for {@link Association} with "aggregation = composition" and navigable in one way (used for creation purpose only). 
Lines 33-43 Link Here
33
	 * </pre>
32
	 * </pre>
34
	 */
33
	 */
35
	@Override
34
	@Override
36
	protected Property createSourceProperty(Type targetType) {
35
	protected void configureSourceProperty(Property sourceProperty) {	
37
			
38
		Property sourceProperty = super.createSourceProperty(targetType);
39
		sourceProperty.setIsComposite(true);
36
		sourceProperty.setIsComposite(true);
40
				
41
		return sourceProperty;
42
	}
37
	}
43
}
38
}
(-)src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneDirectedEditHelperAdvice.java (-1 / +2 lines)
Lines 13-18 Link Here
13
import org.eclipse.uml2.uml.Association;
13
import org.eclipse.uml2.uml.Association;
14
import org.eclipse.uml2.uml.Classifier;
14
import org.eclipse.uml2.uml.Classifier;
15
import org.eclipse.uml2.uml.Property;
15
import org.eclipse.uml2.uml.Property;
16
import org.eclipse.uml2.uml.Type;
16
17
17
/** 
18
/** 
18
 * Edit helper advice for {@link Association} with "aggregation = none" and navigable in one way (used for creation purpose only). 
19
 * Edit helper advice for {@link Association} with "aggregation = none" and navigable in one way (used for creation purpose only). 
Lines 31-37 Link Here
31
	 * </pre>
32
	 * </pre>
32
	 */
33
	 */
33
	@Override
34
	@Override
34
	protected void addTargetInModel(Property targetEnd, Classifier owner, Classifier sourceType, Association association) {
35
	protected void addTargetInModel(Property targetEnd, Classifier owner, Type sourceType, Association association) {
35
		association.getOwnedEnds().add(targetEnd);
36
		association.getOwnedEnds().add(targetEnd);
36
	}
37
	}
37
}
38
}
(-)src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationNoneEditHelperAdvice.java (-44 / +91 lines)
Lines 13-34 Link Here
13
 *****************************************************************************/
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.service.types.helper.advice;
14
package org.eclipse.papyrus.sysml.service.types.helper.advice;
15
15
16
import java.util.List;
17
16
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.emf.transaction.TransactionalEditingDomain;
19
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
22
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
20
import org.eclipse.gmf.runtime.common.core.command.ICommand;
23
import org.eclipse.gmf.runtime.common.core.command.ICommand;
21
import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
24
import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
22
import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
25
import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
23
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
24
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
27
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
28
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
29
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
30
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
25
import org.eclipse.papyrus.sysml.service.types.Activator;
31
import org.eclipse.papyrus.sysml.service.types.Activator;
26
import org.eclipse.papyrus.uml.service.types.utils.ClassifierUtils;
32
import org.eclipse.papyrus.uml.service.types.utils.ClassifierUtils;
33
import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper;
27
import org.eclipse.uml2.uml.Association;
34
import org.eclipse.uml2.uml.Association;
28
import org.eclipse.uml2.uml.Classifier;
35
import org.eclipse.uml2.uml.Classifier;
36
import org.eclipse.uml2.uml.Element;
29
import org.eclipse.uml2.uml.Property;
37
import org.eclipse.uml2.uml.Property;
30
import org.eclipse.uml2.uml.Type;
38
import org.eclipse.uml2.uml.Type;
31
import org.eclipse.uml2.uml.UMLFactory;
39
import org.eclipse.uml2.uml.UMLFactory;
40
import org.eclipse.uml2.uml.UMLPackage;
32
41
33
/**
42
/**
34
 * Edit helper advice for {@link Association} with "aggregation = none" (used for creation purpose only).
43
 * Edit helper advice for {@link Association} with "aggregation = none" (used for creation purpose only).
Lines 66-104 Link Here
66
	}
75
	}
67
76
68
	/**
77
	/**
69
	 * Creates a new source {@link Property} from the targetType.
78
	 * Creates a new {@link Property} from the propertyType in the propertyContainer
70
	 * 
79
	 * 
71
	 * @param targetType
80
	 * @param propertyContainer
81
	 *        the container of the {@link Property}
82
	 * @param propertyType
72
	 *        the type of the {@link Property}
83
	 *        the type of the {@link Property}
73
	 * @return the new {@link Property}
84
	 * @return the new {@link Property}
74
	 */
85
	 * @throws ExecutionException 
75
	protected Property createSourceProperty(Type targetType) {
86
	 */	
76
87
	protected Property createTargetProperty(Property targetProperty, Classifier propertyContainer, Type propertyType, Association association, TransactionalEditingDomain editingDomain, IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
77
		Property sourceProperty = UMLFactory.eINSTANCE.createProperty();
88
		addSourceInModel(targetProperty, propertyContainer, propertyType, association);
78
		sourceProperty.setType(targetType);
89
		setPropertyType(targetProperty, propertyType, editingDomain, progressMonitor, info);
79
		sourceProperty.setName(targetType.getName().toLowerCase());
90
		setPropertyName(targetProperty);
80
81
		return sourceProperty;
82
	}
83
84
	/**
85
	 * Creates a new target {@link Property} from the sourceType.
86
	 * 
87
	 * @param sourceType
88
	 *        the type of the {@link Property}
89
	 * @return the new {@link Property}
90
	 */
91
	protected Property createTargetProperty(Type sourceType) {
92
93
		Property targetProperty = UMLFactory.eINSTANCE.createProperty();
94
		targetProperty.setType(sourceType);
95
		targetProperty.setName(sourceType.getName().toLowerCase());
96
97
		return targetProperty;
91
		return targetProperty;
98
	}
92
	}
93
	
94
	protected Property createSourceProperty(Property sourceProperty, Classifier propertyContainer, Type propertyType, Association association, TransactionalEditingDomain editingDomain, IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
95
		addTargetInModel(sourceProperty, propertyContainer, propertyType, association);
96
		setPropertyType(sourceProperty, propertyType, editingDomain, progressMonitor, info);
97
		setPropertyName(sourceProperty);
98
		return sourceProperty;
99
	}
100
	
101
	protected void setPropertyType(Property property, Type propertyType, TransactionalEditingDomain editingDomain, IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
102
		// Set type using all AdviceHelper (use ServiceEdit instead of manually set)
103
		SetRequest request = new SetRequest(property, UMLPackage.eINSTANCE.getTypedElement_Type(), propertyType);
104
		request.setEditingDomain(editingDomain);	
105
		IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(property);
106
		ICommand editCommand = commandProvider.getEditCommand(request);
107
		editCommand.execute(progressMonitor, info);
108
	}
109
110
	private void setPropertyName(Property property) {
111
		String baseName = property.getType().getName().toLowerCase();
112
		Element owner = property.getOwner();
113
		if (owner instanceof Classifier) {
114
			List<Property> ownedAttributes = ClassifierUtils.getOwnedAttributes((Classifier)owner);
115
			String defaultNameWithIncrementFromBase = NamedElementHelper.getDefaultNameWithIncrementFromBase(
116
					property.getType().getName().toLowerCase(), ownedAttributes, "_");
117
			property.setName(defaultNameWithIncrementFromBase);
118
		}
119
		else {
120
			// default
121
			property.setName(baseName);
122
		}
123
	}
99
124
100
	/**
125
	/**
101
	 * Add the source {@link Property} in the correct container.
126
	 * This method has to be specialized by subclasses (AggregationKind)
127
	 * @param sourceProperty
128
	 * 			The property to configure
129
	 */
130
	protected void configureSourceProperty(Property sourceProperty)  {
131
		// do nothing
132
	}
133
134
	/**
135
	 * This method has to be specialized by subclasses (AggregationKind)
136
	 * @param sourceProperty
137
	 * 			The property to configure
138
	 */
139
	protected void configureTargetProperty(Property targetProperty) {
140
		// do nothing
141
	}
142
143
	/**
144
	 * This method has to be specialized by subclasses (owner)
102
	 * 
145
	 * 
103
	 * @param sourceEnd
146
	 * @param sourceEnd
104
	 *        the semantic end
147
	 *        the semantic end
Lines 110-125 Link Here
110
	 *        the association
153
	 *        the association
111
	 * @throws UnsupportedOperationException
154
	 * @throws UnsupportedOperationException
112
	 */
155
	 */
113
	protected void addSourceInModel(final Property sourceEnd, Classifier owner, Classifier targetType, Association association) throws UnsupportedOperationException {
156
	protected void addSourceInModel(final Property sourceEnd, Classifier owner, Type targetType, Association association) throws UnsupportedOperationException {
114
		boolean added = ClassifierUtils.addOwnedAttribute(owner, sourceEnd);
157
		// set the container in order to allow Stereotype appliance
115
158
		boolean added = ClassifierUtils.addOwnedAttribute(owner, sourceEnd); 
116
		if(!added) {
159
		if(!added) {
117
			throw new UnsupportedOperationException("Cannot add a Property on Classifier " + owner.getQualifiedName());
160
			throw new UnsupportedOperationException("Cannot add a Property on Classifier " + owner.getQualifiedName());
118
		}
161
		}
119
	}
162
	}
120
163
121
	/**
164
	/**
122
	 * Add the source {@link Property} in the correct container.
165
	 * This method has to be specialized by subclasses (owner)
123
	 * 
166
	 * 
124
	 * @param targetEnd
167
	 * @param targetEnd
125
	 *        the semantic end
168
	 *        the semantic end
Lines 131-139 Link Here
131
	 *        the association
174
	 *        the association
132
	 * @throws UnsupportedOperationException
175
	 * @throws UnsupportedOperationException
133
	 */
176
	 */
134
	protected void addTargetInModel(Property targetEnd, Classifier owner, Classifier sourceType, Association association) {
177
	protected void addTargetInModel(Property targetEnd, Classifier owner, Type sourceType, Association association) {
135
		boolean added = ClassifierUtils.addOwnedAttribute(owner, targetEnd);
178
		// set the container in order to allow Stereotype appliance
136
179
		boolean added = ClassifierUtils.addOwnedAttribute(owner, targetEnd); 
137
		if(!added) {
180
		if(!added) {
138
			throw new UnsupportedOperationException("Cannot add a Property on Classifier " + owner.getQualifiedName());
181
			throw new UnsupportedOperationException("Cannot add a Property on Classifier " + owner.getQualifiedName());
139
		}
182
		}
Lines 162-179 Link Here
162
205
163
			protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
206
			protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
164
207
165
				// Create source and target ends
166
				Property sourceEnd = createSourceProperty(targetType);
167
				Property targetEnd = createTargetProperty(sourceType);
168
169
				// Add association ends references
170
				association.getMemberEnds().add(sourceEnd);
171
				association.getMemberEnds().add(targetEnd);
172
173
				// Add end properties in the model
174
				try {
208
				try {
175
					addSourceInModel(sourceEnd, sourceType, targetType, association);
209
					Property targetProperty = UMLFactory.eINSTANCE.createProperty();
176
					addTargetInModel(targetEnd, targetType, sourceType, association);
210
					Property sourceProperty = UMLFactory.eINSTANCE.createProperty();
211
212
					// TODO: problem with SysML. Link are inversed. A -> B => memberEnd={a, b} instead of {b, a}.
213
					// Problem seems to come from cached derivedFeature /endTypes
214
					// So we force to set memberEnd in this order before doing anything with the created properties
215
					association.getMemberEnds().add(targetProperty);
216
					association.getMemberEnds().add(sourceProperty);
217
218
					// Create source and target ends
219
					createTargetProperty(targetProperty, sourceType, targetType, association, request.getEditingDomain(), progressMonitor, info);
220
					configureSourceProperty(targetProperty);
221
					createSourceProperty(sourceProperty, targetType, sourceType, association, request.getEditingDomain(), progressMonitor, info);
222
					configureTargetProperty(sourceProperty);
223
	
177
				} catch (Exception e) {
224
				} catch (Exception e) {
178
					Activator.log.error(e);
225
					Activator.log.error(e);
179
					return CommandResult.newCancelledCommandResult();
226
					return CommandResult.newCancelledCommandResult();
(-)src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedDirectedEditHelperAdvice.java (-1 / +2 lines)
Lines 13-18 Link Here
13
import org.eclipse.uml2.uml.Association;
13
import org.eclipse.uml2.uml.Association;
14
import org.eclipse.uml2.uml.Classifier;
14
import org.eclipse.uml2.uml.Classifier;
15
import org.eclipse.uml2.uml.Property;
15
import org.eclipse.uml2.uml.Property;
16
import org.eclipse.uml2.uml.Type;
16
17
17
/** 
18
/** 
18
 * Edit helper advice for {@link Association} with "aggregation = shared" and navigable in one way (used for creation purpose only).
19
 * Edit helper advice for {@link Association} with "aggregation = shared" and navigable in one way (used for creation purpose only).
Lines 31-37 Link Here
31
	 * </pre>
32
	 * </pre>
32
	 */
33
	 */
33
	@Override
34
	@Override
34
	protected void addTargetInModel(Property targetEnd, Classifier owner, Classifier sourceType, Association association) {
35
	protected void addTargetInModel(Property targetEnd, Classifier owner, Type sourceType, Association association) {
35
		association.getOwnedEnds().add(targetEnd);
36
		association.getOwnedEnds().add(targetEnd);
36
	}
37
	}
37
}
38
}
(-)src/org/eclipse/papyrus/sysml/service/types/helper/advice/AssociationSharedEditHelperAdvice.java (-6 / +1 lines)
Lines 14-20 Link Here
14
import org.eclipse.uml2.uml.Association;
14
import org.eclipse.uml2.uml.Association;
15
import org.eclipse.uml2.uml.Classifier;
15
import org.eclipse.uml2.uml.Classifier;
16
import org.eclipse.uml2.uml.Property;
16
import org.eclipse.uml2.uml.Property;
17
import org.eclipse.uml2.uml.Type;
18
17
19
/** 
18
/** 
20
 * Edit helper advice for {@link Association} with "aggregation = shared" (used for creation purpose only).
19
 * Edit helper advice for {@link Association} with "aggregation = shared" (used for creation purpose only).
Lines 34-44 Link Here
34
	 * </pre>
33
	 * </pre>
35
	 */
34
	 */
36
	@Override
35
	@Override
37
	protected Property createSourceProperty(Type targetType) {
36
	protected void configureSourceProperty(Property sourceProperty) {
38
			
39
		Property sourceProperty = super.createSourceProperty(targetType);
40
		sourceProperty.setAggregation(AggregationKind.SHARED_LITERAL);
37
		sourceProperty.setAggregation(AggregationKind.SHARED_LITERAL);
41
		
42
		return sourceProperty;
43
	}
38
	}
44
}
39
}
(-)src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java (-14 / +19 lines)
Lines 104-112 Link Here
104
			// The edited property has to be related to a SysML association
104
			// The edited property has to be related to a SysML association
105
			if((relatedAssociation == null) || !(ElementUtil.hasNature(relatedAssociation, SysMLElementTypes.SYSML_NATURE))) {
105
			if((relatedAssociation == null) || !(ElementUtil.hasNature(relatedAssociation, SysMLElementTypes.SYSML_NATURE))) {
106
				
106
				
107
				// If no association exist and the new type is a Block, add the association
107
				// If no association exist and the new type is a Block 
108
				// (not a ConstraintBlock => a property typed by a ConstraintBlock is a ConstraintProperty, not a Part neither a Reference),
109
				// add the association
108
				if ((relatedAssociation == null) 
110
				if ((relatedAssociation == null) 
109
					&& ((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue())
111
					&& ((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue())
112
					&& !((ISpecializationType) SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type) request.getValue())
110
					&& ((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches(propertyToEdit.eContainer())) {
113
					&& ((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches(propertyToEdit.eContainer())) {
111
					
114
					
112
					ICommand addAssociationCommand = getCreatePartAssociationCommand((org.eclipse.uml2.uml.Class)propertyToEdit.eContainer(), propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue());
115
					ICommand addAssociationCommand = getCreatePartAssociationCommand((org.eclipse.uml2.uml.Class)propertyToEdit.eContainer(), propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue());
Lines 132-138 Link Here
132
			// If the new type is not a block, destroy related association
135
			// If the new type is not a block, destroy related association
133
			// 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),
136
			// 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),
134
			// otherwise there is no legitimate reason to destroy the existing association while re-orienting it.
137
			// otherwise there is no legitimate reason to destroy the existing association while re-orienting it.
135
			if (!((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue())) {
138
 			if (!((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue()) && propertyToEdit.getType() != null) {
136
				ICommand destroyCommand = getDestroyPartAssociationCommand(relatedAssociation, propertyToEdit);
139
				ICommand destroyCommand = getDestroyPartAssociationCommand(relatedAssociation, propertyToEdit);
137
				gmfCommand = CompositeCommand.compose(gmfCommand, destroyCommand);
140
				gmfCommand = CompositeCommand.compose(gmfCommand, destroyCommand);
138
				
141
				
Lines 165-182 Link Here
165
168
166
		Association relatedAssociation = setProperty.getAssociation(); // Should not be null, test before calling method.
169
		Association relatedAssociation = setProperty.getAssociation(); // Should not be null, test before calling method.
167
170
168
		// Re-orient the related association (do not use edit service to avoid infinite loop here)
171
		if (associationToRefactor.getMemberEnds().size() >= 2) {
169
		int direction = ReorientRelationshipRequest.REORIENT_TARGET;
172
			// Re-orient the related association (do not use edit service to avoid infinite loop here)
170
		if(setProperty == associationToRefactor.getMemberEnds().get(1)) {
173
			int direction = ReorientRelationshipRequest.REORIENT_TARGET;
171
			direction = ReorientRelationshipRequest.REORIENT_SOURCE;
174
			if(setProperty == associationToRefactor.getMemberEnds().get(1)) {
172
		}
175
				direction = ReorientRelationshipRequest.REORIENT_SOURCE;
173
176
			}
174
		ReorientRelationshipRequest reorientRequest = new ReorientRelationshipRequest(relatedAssociation, (Type)request.getValue(), setProperty.eContainer(), direction);
177
	
175
		reorientRequest.addParameters(request.getParameters());
178
			ReorientRelationshipRequest reorientRequest = new ReorientRelationshipRequest(relatedAssociation, (Type)request.getValue(), setProperty.eContainer(), direction);
176
179
			reorientRequest.addParameters(request.getParameters());
177
		IElementEditService provider = ElementEditServiceUtils.getCommandProvider(relatedAssociation);
180
	
178
		if(provider != null) {
181
			IElementEditService provider = ElementEditServiceUtils.getCommandProvider(relatedAssociation);
179
			return provider.getEditCommand(reorientRequest);
182
			if(provider != null) {
183
				return provider.getEditCommand(reorientRequest);
184
			}
180
		}
185
		}
181
186
182
		return null;
187
		return null;
(-)src/org/eclipse/papyrus/uml/service/types/utils/ClassifierUtils.java (+63 lines)
Lines 14-19 Link Here
14
 *****************************************************************************/
14
 *****************************************************************************/
15
package org.eclipse.papyrus.uml.service.types.utils;
15
package org.eclipse.papyrus.uml.service.types.utils;
16
16
17
import java.util.ArrayList;
18
import java.util.List;
19
17
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.uml2.uml.Artifact;
21
import org.eclipse.uml2.uml.Artifact;
19
import org.eclipse.uml2.uml.Class;
22
import org.eclipse.uml2.uml.Class;
Lines 41-46 Link Here
41
	 */
44
	 */
42
	public static boolean addOwnedAttribute(Classifier classifier, Property property) {
45
	public static boolean addOwnedAttribute(Classifier classifier, Property property) {
43
		AddOwnedAttributeSwitch classifierSwitch = new AddOwnedAttributeSwitch(property);
46
		AddOwnedAttributeSwitch classifierSwitch = new AddOwnedAttributeSwitch(property);
47
		return classifierSwitch.doSwitch(classifier);
48
	}
49
50
	/**
51
	 * This method provides a switch to ease the addition of a new Property in a Classifier.
52
	 * 
53
	 * @param classifier
54
	 *        the parent classifier.
55
	 * @param property
56
	 *        the contained property.
57
	 * @return false if the addition fails.
58
	 */
59
	public static List<Property> getOwnedAttributes(Classifier classifier) {
60
		GetOwnedAttributesSwitch classifierSwitch = new GetOwnedAttributesSwitch();
44
		return classifierSwitch.doSwitch(classifier);
61
		return classifierSwitch.doSwitch(classifier);
45
	}
62
	}
46
63
Lines 98-101 Link Here
98
			return Boolean.FALSE;
115
			return Boolean.FALSE;
99
		}
116
		}
100
	};
117
	};
118
119
	/**
120
	 * Switch implementation for Property addition.
121
	 */
122
	private static class GetOwnedAttributesSwitch extends UMLSwitch<List<Property>> {
123
124
		public GetOwnedAttributesSwitch() {
125
			super();
126
		}
127
128
		@Override
129
		public List<Property> caseArtifact(Artifact object) {
130
			return object.getOwnedAttributes();
131
		}
132
133
		@Override
134
		public List<Property> caseDataType(DataType object) {
135
			return object.getOwnedAttributes();
136
		}
137
138
		@Override
139
		public List<Property> caseInterface(Interface object) {
140
			return object.getOwnedAttributes();
141
		}
142
143
		@Override
144
		public List<Property> caseSignal(Signal object) {
145
			return object.getOwnedAttributes();
146
		}
147
148
		@Override
149
		public List<Property> caseStructuredClassifier(StructuredClassifier object) {
150
			return object.getOwnedAttributes();
151
		}
152
153
		@Override
154
		public List<Property> caseClass(Class object) {
155
			return object.getOwnedAttributes();
156
		}
157
158
		@Override
159
		public List<Property> defaultCase(EObject object) {
160
			return new ArrayList<Property>();
161
		}
162
	};
163
101
}
164
}
(-)src/org/eclipse/papyrus/uml/service/types/utils/NamedElementHelper.java (-9 / +15 lines)
Lines 115-129 Link Here
115
		this.baseString = baseString;
115
		this.baseString = baseString;
116
	}
116
	}
117
117
118
	@SuppressWarnings("rawtypes")
118
	public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents) {
119
	public static String getDefaultNameWithIncrementFromBase(String base, Collection contents) {
119
		return getDefaultNameWithIncrementFromBase(base, contents, null, "");
120
		return getDefaultNameWithIncrementFromBase(base, contents, null);
120
	}
121
122
	public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents, String separator) {
123
		return getDefaultNameWithIncrementFromBase(base, contents, null, separator);
121
	}
124
	}
122
	
125
	
123
	@SuppressWarnings("rawtypes")
126
	public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents, EObject elementToRename) {
124
	public static String getDefaultNameWithIncrementFromBase(String base, Collection contents, EObject elementToRename) {
127
		return getDefaultNameWithIncrementFromBase(base, contents, elementToRename, "");
125
		// Not change the name if elementToRename already present in the contents collection
128
	}
126
		if (contents.contains(elementToRename)) {
129
130
	public static String getDefaultNameWithIncrementFromBase(String base, Collection<?> contents, EObject elementToRename, String separator) {
131
		// Not change the name if elementToRename already present in the contents collection and already have a name
132
		if (contents.contains(elementToRename) && EMFCoreUtil.getName(elementToRename) != null) {
127
			if (elementToRename instanceof ENamedElement) {
133
			if (elementToRename instanceof ENamedElement) {
128
				return ((ENamedElement)elementToRename).getName();
134
				return ((ENamedElement)elementToRename).getName();
129
			}
135
			}
Lines 136-142 Link Here
136
		if("property".equalsIgnoreCase(base)) {
142
		if("property".equalsIgnoreCase(base)) {
137
			base = "Attribute";
143
			base = "Attribute";
138
		}
144
		}
139
		int nextNumber = 1;
145
		int nextNumber = 0;
140
146
141
		for(Object o : contents) {
147
		for(Object o : contents) {
142
			if(o instanceof EObject && o != elementToRename) {
148
			if(o instanceof EObject && o != elementToRename) {
Lines 157-162 Link Here
157
			}
163
			}
158
		}
164
		}
159
165
160
		return base + nextNumber;
166
		return nextNumber > 0 ? base + separator + nextNumber : base;
161
	}
167
	}
162
}
168
}

Return to bug 297816