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-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectBlockPropertyTypeDialog.java (-1 / +21 lines)
Lines 13-24 Link Here
13
 *****************************************************************************/
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.common.dialogs;
14
package org.eclipse.papyrus.sysml.diagram.common.dialogs;
15
15
16
import java.util.Arrays;
17
import java.util.List;
18
16
import org.eclipse.papyrus.sysml.blocks.BlocksPackage;
19
import org.eclipse.papyrus.sysml.blocks.BlocksPackage;
17
import org.eclipse.papyrus.sysml.diagram.common.messages.Messages;
20
import org.eclipse.papyrus.sysml.diagram.common.messages.Messages;
18
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
21
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
22
import org.eclipse.papyrus.sysml.util.SysmlResource;
19
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
23
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
20
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.uml2.uml.NamedElement;
25
import org.eclipse.uml2.uml.NamedElement;
26
import org.eclipse.uml2.uml.Stereotype;
27
import org.eclipse.uml2.uml.UMLFactory;
22
import org.eclipse.uml2.uml.UMLPackage;
28
import org.eclipse.uml2.uml.UMLPackage;
23
29
24
/**
30
/**
Lines 28-34 Link Here
28
34
29
	/** Constructor */
35
	/** Constructor */
30
	public CreateOrSelectBlockPropertyTypeDialog(Shell shell, NamedElement owner) {
36
	public CreateOrSelectBlockPropertyTypeDialog(Shell shell, NamedElement owner) {
31
		super(shell, owner, SysMLElementTypes.BLOCK, UMLPackage.eINSTANCE.getTypedElement_Type(), BlocksPackage.eINSTANCE.getBlock(), UMLElementTypes.PACKAGE, UMLPackage.eINSTANCE.getPackage_PackagedElement(), null);
37
		super(shell, owner, SysMLElementTypes.BLOCK, UMLPackage.eINSTANCE.getTypedElement_Type(), BlocksPackage.eINSTANCE.getBlock(), UMLElementTypes.PACKAGE, UMLPackage.eINSTANCE.getPackage_PackagedElement(), null, getConstraintBlockAsStereotype());
38
	}
39
	
40
	/**
41
	 * If we create a Part type by a ConstraintBlock, thisPart will become a ConstraintProperty and representation will immediately disappear.
42
	 * So we filter ConstraintBlock type => Only strict Block are allowed 
43
	 * @return
44
	 */
45
	@SuppressWarnings("deprecation")
46
	private static List<?> getConstraintBlockAsStereotype() {
47
		// We create a mock Stereotype to pass in the good code section of SemanticUMLContentProvider.isCompatibleMetaclass (bad gestion of static stereotypes)
48
		Stereotype mockStereotype = UMLFactory.eINSTANCE.createStereotype();
49
		// We use this stereotype with namespace instead of ConstraintsPackage.eINSTANCE.getConstraintBlock()
50
		mockStereotype.setName(SysmlResource.CONSTRAINT_BLOCK_ID);
51
		return Arrays.asList(mockStereotype);
32
	}
52
	}
33
53
34
	/**
54
	/**
(-)src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectTypeDialog.java (-1 / +20 lines)
Lines 15-20 Link Here
15
 *****************************************************************************/
15
 *****************************************************************************/
16
package org.eclipse.papyrus.sysml.diagram.common.dialogs;
16
package org.eclipse.papyrus.sysml.diagram.common.dialogs;
17
17
18
import java.util.List;
19
18
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.emf.ecore.EClass;
21
import org.eclipse.emf.ecore.EClass;
20
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.emf.ecore.EObject;
Lines 101-106 Link Here
101
103
102
	protected EClass containerEClass;
104
	protected EClass containerEClass;
103
105
106
	protected List<?> notWantedMetaclasses;
107
104
	/**
108
	/**
105
	 * Create a new dialog to initialize an ActivityParameterNode.
109
	 * Create a new dialog to initialize an ActivityParameterNode.
106
	 * 
110
	 * 
Lines 119-124 Link Here
119
		this.containerFeature = containerFeature;
123
		this.containerFeature = containerFeature;
120
		this.containerEClass = containerEClass;
124
		this.containerEClass = containerEClass;
121
		this.labelProvider = new UMLLabelProvider();
125
		this.labelProvider = new UMLLabelProvider();
126
	}
127
128
	/**
129
	 * Create a new dialog to initialize an ActivityParameterNode.
130
	 * This dialog will filter certain Stereotypes
131
	 * @param shell
132
	 *        parent shell
133
	 * @param owner
134
	 *        the activity that owns the action
135
	 */
136
	public CreateOrSelectTypeDialog(Shell shell, EObject defaultContainer, IElementType elementType, EStructuralFeature editedFeature, EClass elementEClass, IElementType containerType, EStructuralFeature containerFeature, EClass containerEClass, List<?> notWantedMetaclasses) {
137
		this(shell, defaultContainer, elementType, editedFeature, elementEClass, containerType, containerFeature, containerEClass);
138
		this.notWantedMetaclasses = notWantedMetaclasses;
122
	}
139
	}
123
140
124
	protected String getDialogTitle() {
141
	protected String getDialogTitle() {
Lines 481-489 Link Here
481
		dialog.setInput(EcoreUtil.getRootContainer(defaultContainer));
498
		dialog.setInput(EcoreUtil.getRootContainer(defaultContainer));
482
499
483
		ServiceEditContentProvider provider = new ServiceEditContentProvider(elementType, editedFeature, EcoreUtil.getRootContainer(defaultContainer));
500
		ServiceEditContentProvider provider = new ServiceEditContentProvider(elementType, editedFeature, EcoreUtil.getRootContainer(defaultContainer));
501
		provider.setNotWantedMetaclasses(notWantedMetaclasses);
502
484
		dialog.setContentProvider(provider);
503
		dialog.setContentProvider(provider);
485
		dialog.setLabelProvider(labelProvider);
504
		dialog.setLabelProvider(labelProvider);
486
505
		
487
		if(dialog.open() == Window.OK) {
506
		if(dialog.open() == Window.OK) {
488
			Object result = dialog.getResult()[0];
507
			Object result = dialog.getResult()[0];
489
			if(result instanceof IAdaptable) {
508
			if(result instanceof IAdaptable) {
(-)src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java (-21 / +44 lines)
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
	 * 

Return to bug 297816