|
Lines 16-21
Link Here
|
| 16 |
import java.util.ArrayList; |
16 |
import java.util.ArrayList; |
| 17 |
import java.util.Arrays; |
17 |
import java.util.Arrays; |
| 18 |
import java.util.List; |
18 |
import java.util.List; |
|
|
19 |
import java.util.Set; |
| 19 |
|
20 |
|
| 20 |
import org.eclipse.core.commands.ExecutionException; |
21 |
import org.eclipse.core.commands.ExecutionException; |
| 21 |
import org.eclipse.core.runtime.IAdaptable; |
22 |
import org.eclipse.core.runtime.IAdaptable; |
|
Lines 25-46
Link Here
|
| 25 |
import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
26 |
import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
| 26 |
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; |
27 |
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; |
| 27 |
import org.eclipse.gmf.runtime.common.core.command.ICommand; |
28 |
import org.eclipse.gmf.runtime.common.core.command.ICommand; |
|
|
29 |
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; |
| 28 |
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil; |
30 |
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil; |
| 29 |
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType; |
31 |
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType; |
| 30 |
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
32 |
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
| 31 |
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
33 |
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
| 32 |
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
34 |
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
| 33 |
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
35 |
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
|
|
36 |
import org.eclipse.gmf.runtime.notation.View; |
| 37 |
import org.eclipse.jface.dialogs.MessageDialogWithToggle; |
| 38 |
import org.eclipse.jface.preference.IPreferenceStore; |
| 34 |
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; |
39 |
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; |
| 35 |
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; |
40 |
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; |
| 36 |
import org.eclipse.papyrus.sysml.blocks.BlocksPackage; |
41 |
import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants; |
| 37 |
import org.eclipse.papyrus.sysml.constraints.ConstraintBlock; |
42 |
import org.eclipse.papyrus.sysml.constraints.ConstraintBlock; |
| 38 |
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty; |
43 |
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty; |
| 39 |
import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage; |
44 |
import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage; |
|
|
45 |
import org.eclipse.papyrus.sysml.service.types.Activator; |
| 40 |
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; |
46 |
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; |
|
|
47 |
import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil; |
| 41 |
import org.eclipse.papyrus.uml.service.types.utils.ElementUtil; |
48 |
import org.eclipse.papyrus.uml.service.types.utils.ElementUtil; |
| 42 |
import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper; |
49 |
import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper; |
| 43 |
import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants; |
50 |
import org.eclipse.swt.widgets.Display; |
| 44 |
import org.eclipse.uml2.uml.Association; |
51 |
import org.eclipse.uml2.uml.Association; |
| 45 |
import org.eclipse.uml2.uml.Element; |
52 |
import org.eclipse.uml2.uml.Element; |
| 46 |
import org.eclipse.uml2.uml.Port; |
53 |
import org.eclipse.uml2.uml.Port; |
|
Lines 71-80
Link Here
|
| 71 |
@SuppressWarnings("unchecked") |
78 |
@SuppressWarnings("unchecked") |
| 72 |
@Override |
79 |
@Override |
| 73 |
protected ICommand getBeforeSetCommand(SetRequest request) { |
80 |
protected ICommand getBeforeSetCommand(SetRequest request) { |
| 74 |
ICommand gmfCommand = super.getBeforeSetCommand(request); |
81 |
ICommand gmfCommand = super.getBeforeSetCommand(request); |
| 75 |
|
82 |
|
| 76 |
EObject elementToEdit = request.getElementToEdit(); |
83 |
EObject elementToEdit = request.getElementToEdit(); |
| 77 |
|
|
|
| 78 |
if((elementToEdit instanceof Property) && !(elementToEdit instanceof Port) && |
84 |
if((elementToEdit instanceof Property) && !(elementToEdit instanceof Port) && |
| 79 |
(request.getFeature() == UMLPackage.eINSTANCE.getTypedElement_Type()) && (request.getValue() instanceof Type)) { |
85 |
(request.getFeature() == UMLPackage.eINSTANCE.getTypedElement_Type()) && (request.getValue() instanceof Type)) { |
| 80 |
|
86 |
|
|
Lines 82-92
Link Here
|
| 82 |
|
88 |
|
| 83 |
// SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied |
89 |
// SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied |
| 84 |
if (request.getValue() instanceof org.eclipse.uml2.uml.Class) { |
90 |
if (request.getValue() instanceof org.eclipse.uml2.uml.Class) { |
| 85 |
ICommand stereotypeApplication = getConstraintPropertyStereotypeApplicationCommand(propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue()); |
91 |
ICommand stereotypeApplicationCommand = getConstraintPropertyStereotypeApplicationCommand(propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue(), request); |
| 86 |
gmfCommand = CompositeCommand.compose(gmfCommand, stereotypeApplication); |
92 |
gmfCommand = CompositeCommand.compose(gmfCommand, stereotypeApplicationCommand); |
| 87 |
} |
93 |
} |
| 88 |
|
94 |
|
| 89 |
// Exclude ConstraintParameter (simple property without stereotype owned by a ConstraintBlock) |
95 |
// Exclude ConstraintParameter (simple property without ConstraintProperty stereotype owned by a ConstraintBlock) |
| 90 |
if (propertyToEdit.eContainer() instanceof org.eclipse.uml2.uml.Class && UMLUtil.getStereotypeApplication((Element)propertyToEdit.eContainer(), ConstraintBlock.class) != null) { |
96 |
if (propertyToEdit.eContainer() instanceof org.eclipse.uml2.uml.Class && UMLUtil.getStereotypeApplication((Element)propertyToEdit.eContainer(), ConstraintBlock.class) != null) { |
| 91 |
if (UMLUtil.getStereotypeApplication(propertyToEdit, ConstraintProperty.class) == null) { |
97 |
if (UMLUtil.getStereotypeApplication(propertyToEdit, ConstraintProperty.class) == null) { |
| 92 |
return gmfCommand; |
98 |
return gmfCommand; |
|
Lines 230-249
Link Here
|
| 230 |
* |
236 |
* |
| 231 |
* @return the ConstraintProperty stereotype application command |
237 |
* @return the ConstraintProperty stereotype application command |
| 232 |
*/ |
238 |
*/ |
| 233 |
private ICommand getConstraintPropertyStereotypeApplicationCommand(final Property sourceProperty, final org.eclipse.uml2.uml.Class targetBlock) { |
239 |
private ICommand getConstraintPropertyStereotypeApplicationCommand(final Property sourceProperty, final org.eclipse.uml2.uml.Class targetBlock, final SetRequest request) { |
| 234 |
|
240 |
|
| 235 |
return new AbstractCommand("Apply/Remove ConstraintProperty Stereotype") { |
241 |
return new AbstractTransactionalCommand(request.getEditingDomain(), "Apply/Remove ConstraintProperty Stereotype", null) { |
| 236 |
|
242 |
|
| 237 |
@Override |
|
|
| 238 |
protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { |
| 239 |
return null; |
| 240 |
} |
| 241 |
|
| 242 |
@Override |
| 243 |
protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { |
| 244 |
return null; |
| 245 |
} |
| 246 |
|
| 247 |
@Override |
243 |
@Override |
| 248 |
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { |
244 |
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { |
| 249 |
// SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied |
245 |
// SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied |
|
Lines 251-256
Link Here
|
| 251 |
if (UMLUtil.getStereotypeApplication(targetBlock, ConstraintBlock.class) != null) { |
247 |
if (UMLUtil.getStereotypeApplication(targetBlock, ConstraintBlock.class) != null) { |
| 252 |
if (constraintPropertyApplication == null) { |
248 |
if (constraintPropertyApplication == null) { |
| 253 |
StereotypeApplicationHelper.INSTANCE.applyStereotype(sourceProperty, ConstraintsPackage.eINSTANCE.getConstraintProperty()); |
249 |
StereotypeApplicationHelper.INSTANCE.applyStereotype(sourceProperty, ConstraintsPackage.eINSTANCE.getConstraintProperty()); |
|
|
250 |
// Remove representations |
| 251 |
Set<View> memberViewsToDestroy = CrossReferencerUtil.getCrossReferencingViews(sourceProperty, null); |
| 252 |
if (memberViewsToDestroy.size() != 0) { |
| 253 |
final IPreferenceStore store = Activator.getDefault().getPreferenceStore(); |
| 254 |
final String DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY = "displayMessageForTypingActionPreferenceKey"; |
| 255 |
boolean contains = store.contains(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY); |
| 256 |
if(!contains) { |
| 257 |
store.setValue(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY, MessageDialogWithToggle.NEVER); |
| 258 |
store.setDefault(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY, MessageDialogWithToggle.NEVER); |
| 259 |
} |
| 260 |
final String hideValue = store.getString(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY); |
| 261 |
if(!hideValue.equals(MessageDialogWithToggle.ALWAYS)) { |
| 262 |
int size = memberViewsToDestroy.size(); |
| 263 |
MessageDialogWithToggle.openInformation(Display.getDefault().getActiveShell(), |
| 264 |
"Change Type Action", |
| 265 |
"WARNING! Typing a Property by a ConstraintBlock make this property become a ConstraintProperty. ConstraintProperty have a specific representation. " |
| 266 |
+ "\nSo all representations of this property will be removed from the model (" + size + " occurence" + ((size > 1) ? "s" : "") + ")." |
| 267 |
, "Don't show this dialog the next time", |
| 268 |
false, store, DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY); |
| 269 |
} |
| 270 |
|
| 271 |
} |
| 272 |
for (View view : memberViewsToDestroy) { |
| 273 |
final DestroyElementRequest destroyRequest = new DestroyElementRequest(request.getEditingDomain(), view, false); |
| 274 |
final IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(view); |
| 275 |
ICommand editCommand = commandProvider.getEditCommand(destroyRequest); |
| 276 |
editCommand.execute(progressMonitor, info); |
| 277 |
} |
| 254 |
} |
278 |
} |
| 255 |
} |
279 |
} |
| 256 |
else { |
280 |
else { |
|
Lines 263-269
Link Here
|
| 263 |
}; |
287 |
}; |
| 264 |
} |
288 |
} |
| 265 |
|
289 |
|
| 266 |
|
|
|
| 267 |
/** |
290 |
/** |
| 268 |
* Create a part association destroy command. |
291 |
* Create a part association destroy command. |
| 269 |
* |
292 |
* |