diff options
author | Thanh Liem PHAN | 2017-02-21 14:54:59 +0000 |
---|---|---|
committer | Patrick Tessier | 2017-02-22 09:50:13 +0000 |
commit | b041625e79aeb0c6eac308bab315652c72636e26 (patch) | |
tree | 7cf3d5e7f91a85987b6df64faca192950d4abb2b | |
parent | fd468a9f97b61ebded39d1b74d6e4bae645ddc26 (diff) | |
download | org.eclipse.papyrus-b041625e79aeb0c6eac308bab315652c72636e26.tar.gz org.eclipse.papyrus-b041625e79aeb0c6eac308bab315652c72636e26.tar.xz org.eclipse.papyrus-b041625e79aeb0c6eac308bab315652c72636e26.zip |
Bug 511045: [Core] required stereotype extension prevent copy paste
https://bugs.eclipse.org/bugs/show_bug.cgi?id=51104
- Check the stereotype application on the element before applying the
stereotype
Change-Id: Ied91ba4bbeae74a580c372b8116fa9bcada6cbf4
Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
(cherry picked from commit 0742574025577a584bd8703277f5bf3977949861)
-rw-r--r-- | plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DuplicateStereotypeCommand.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DuplicateStereotypeCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DuplicateStereotypeCommand.java index 307dcb58b36..60c3deb4a58 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DuplicateStereotypeCommand.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DuplicateStereotypeCommand.java @@ -1,6 +1,6 @@ /***************************************************************************** - * Copyright (c) 2014 CEA LIST. - * + * Copyright (c) 2014, 2017 CEA LIST. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Contributors: * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation * Gaabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - bug 438511 + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - bug 511045 *****************************************************************************/ package org.eclipse.papyrus.uml.tools.commands; @@ -25,7 +26,7 @@ import org.eclipse.uml2.uml.util.UMLUtil; /** * A Command to apply a Stereotype and its data to an UML Element - * + * * @author Benoit Maggi */ public class DuplicateStereotypeCommand extends RecordingCommand { @@ -37,9 +38,9 @@ public class DuplicateStereotypeCommand extends RecordingCommand { protected Stereotype stereotypeInTargetContext; /** - * + * * Constructor. - * + * * @param element * The UML Element on which the stereotype will be applied * @param stereotype @@ -62,7 +63,14 @@ public class DuplicateStereotypeCommand extends RecordingCommand { @Override protected void doExecute() { - EObject applyStereotype = element.applyStereotype(stereotypeInTargetContext); + // Retrieve the stereotype application for the element + EObject applyStereotype = element.getStereotypeApplication(stereotypeInTargetContext); + // If the stereotype is not applied yet + if (null == applyStereotype) { + // Then apply it safely without triggering the exception when applying an already applied stereotype (bug 511045) + applyStereotype = element.applyStereotype(stereotypeInTargetContext); + } + EList<EStructuralFeature> eStructuralFeatures = applyStereotype.eClass().getEAllStructuralFeatures(); for (EStructuralFeature eStructuralFeature : eStructuralFeatures) { String name = eStructuralFeature.getName(); |