Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-09-29 09:13:53 +0000
committerRemi Schnekenburger2014-12-15 10:56:47 +0000
commit2cb215554c0990cca59d8efc543291ead02d6b4b (patch)
treefe187a9631629d5a165a1870e5a5ba45891bf258 /plugins
parent72e684176a5bd2cb885fae48c59eadb2715f0d85 (diff)
downloadorg.eclipse.papyrus-2cb215554c0990cca59d8efc543291ead02d6b4b.tar.gz
org.eclipse.papyrus-2cb215554c0990cca59d8efc543291ead02d6b4b.tar.xz
org.eclipse.papyrus-2cb215554c0990cca59d8efc543291ead02d6b4b.zip
Bug 445092 - Copy/paste copies profile-based stereotypes, but forgets
the profile parameters Change-Id: Iec665e9ac770d7b6ef408eb0d41b2139247994bd Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr> (cherry picked from commit da060f27a6d10b20ffd74410621fbe84c245de1d)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/RestoreStereotypeCompartmentCommand.java68
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java235
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DuplicateStereotypeCommand.java73
3 files changed, 268 insertions, 108 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/RestoreStereotypeCompartmentCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/RestoreStereotypeCompartmentCommand.java
new file mode 100644
index 00000000000..b91cfbb8e66
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/RestoreStereotypeCompartmentCommand.java
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.commands;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.BasicCompartment;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * A Command to restore a stereotype compartment with the good stereotype application
+ *
+ * @author Benoit Maggi
+ */
+public class RestoreStereotypeCompartmentCommand extends RecordingCommand {
+
+ protected BasicCompartment basicCompartment;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param element
+ * The UML Element on which the stereotype will be applied
+ * @param stereotype
+ * The stereotypes to apply
+ */
+ public RestoreStereotypeCompartmentCommand(TransactionalEditingDomain domain, BasicCompartment basicCompartment) {
+ super(domain);
+ this.basicCompartment = basicCompartment;
+ }
+
+ @Override
+ protected void doExecute() {
+ EObject element = basicCompartment.getElement();
+ Element baseElement = UMLUtil.getBaseElement(element);
+ if (baseElement != null) {
+ EObject eContainer = basicCompartment.eContainer();
+ if (eContainer instanceof View) {
+ View containerView = (View) eContainer;
+ EObject containerEObject = containerView.getElement();
+ if (containerEObject instanceof Element){
+ Element containerElement = (Element) containerEObject;
+ if (!baseElement.equals(containerEObject)) {
+ Stereotype stereotype = UMLUtil.getStereotype(element);
+ EObject containerStereotypeApplication = containerElement.getStereotypeApplication(stereotype);
+ basicCompartment.setElement(containerStereotypeApplication);
+ }
+ }
+
+ }
+ }
+
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
index 821549c2dc1..be79f194656 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* Copyright (c) 2014 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
@@ -25,24 +25,28 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.BasicCompartment;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
import org.eclipse.papyrus.infra.core.clipboard.IClipboardAdditionalData;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.AbstractPasteStrategy;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.DefaultPasteStrategy;
import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.commands.RestoreStereotypeCompartmentCommand;
import org.eclipse.papyrus.uml.diagram.common.preferences.IStereotypePasteStrategyPreferenceConstant;
import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
-import org.eclipse.papyrus.uml.tools.commands.ApplyStereotypeCommand;
+import org.eclipse.papyrus.uml.tools.commands.DuplicateStereotypeCommand;
import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.util.UMLUtil;
/**
* Offer a strategy for copying stereotypes.
@@ -64,88 +68,83 @@ public class StereotypePasteStrategy extends AbstractPasteStrategy implements IP
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel()
*/
- @Override
public String getLabel() {
return "StereotypeStrategy"; //$NON-NLS-1$
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID()
*/
- @Override
public String getID() {
return Activator.ID + ".StereotypeStrategy"; //".ClassifierToStructureCompDrop"; //$NON-NLS-1$
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription()
*/
- @Override
public String getDescription() {
return "Paste stereotype elements"; //$NON-NLS-1$
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
*/
@Override
public IPasteStrategy dependsOn() {
return DefaultPasteStrategy.getInstance();
- }
-
+ }
+
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getSemanticCommand(org.eclipse.emf.edit.domain.EditingDomain,
* org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
*/
@Override
public org.eclipse.emf.common.command.Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) {
-
- if (targetOwner instanceof Element) {
- CompoundCommand compoundCommand = new CompoundCommand("Copy all stereotypes"); //$NON-NLS-1$
-
- Map<Profile, List<ApplyStereotypeCommand>> missingProfiles = new HashMap<Profile, List<ApplyStereotypeCommand>>();
- Package targetPackage = ((Element) targetOwner).getNearestPackage();
-
+
+ if (targetOwner instanceof Element){
+ CompoundCommand compoundCommand = new CompoundCommand("Copy all stereotypes");
+
+ Map<Profile,List<DuplicateStereotypeCommand>> missingProfiles = new HashMap<Profile,List<DuplicateStereotypeCommand>>();
+ Package targetPackage = ((Element)targetOwner).getNearestPackage();
+
// 1. init all ApplyStereotypeCommand
- for (Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
- Object object = iterator.next();
+ for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
+ Object object = (Object)iterator.next();
// get target Element
EObject target = papyrusClipboard.getTragetCopyFromInternalClipboardCopy(object);
- if (target != null && target instanceof Element) {
+ if(target != null && target instanceof Element) {
// get affiliate StereotypeClipboard
Map<Object, ?> additionalDataMap = papyrusClipboard.getAdditionalDataForStrategy(getID());
Object additionnalData = additionalDataMap.get(object);
- if (additionnalData instanceof StereotypeClipboard) {
- StereotypeClipboard stereotypeClipboard = (StereotypeClipboard) additionnalData;
- Collection<Stereotype> stereotypes = stereotypeClipboard.getStereotypes();
- // Collection<Stereotype> stereotypeListInTargetContext = new ArrayList<Stereotype>();
- for (Stereotype stereotype : stereotypes) {
- // reload the stereotype in the new Contex-ResourceSet (Required because in org.eclipse.uml2.uml.internal.operations.PackageOperations
- // L960 in getProfileApplication the test is using == instead of equals)
- Stereotype stereotypeInTargetContext = EMFHelper.reloadIntoContext(stereotype, targetOwner);
-
+ if(additionnalData instanceof StereotypeClipboard) {
+ StereotypeClipboard stereotypeClipboard = (StereotypeClipboard)additionnalData;
+ Collection<EObject> stereotypeApplications = stereotypeClipboard.getstereotypeApplications();
+ for(EObject stereotypeApplication : stereotypeApplications) {
+ DuplicateStereotypeCommand applyStereotypeCommand = new DuplicateStereotypeCommand((TransactionalEditingDomain)domain, (Element)target, stereotypeApplication );
+
+ Stereotype stereotypeInTargetContext = applyStereotypeCommand.getStereotypeInTargetContext();
Profile profile = stereotypeInTargetContext.getProfile();
- ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand((Element) target, stereotypeInTargetContext, (TransactionalEditingDomain) domain);
- if (isProfileAppliedRecursive(targetPackage, profile)) {
+
+ if (isProfileAppliedRecursive(targetPackage, profile)){
compoundCommand.append(applyStereotypeCommand);
} else { // Profile is missing
- // Activator.getDefault().logWarning(profile.getName()+" is missing", null);
- List<ApplyStereotypeCommand> stereotypeListMissingProfiles = missingProfiles.get(profile);
- if (stereotypeListMissingProfiles != null && !stereotypeListMissingProfiles.isEmpty()) {
+ Activator.getDefault().logInfo(profile.getName()+" is missing", null);
+ List<DuplicateStereotypeCommand> stereotypeListMissingProfiles = missingProfiles.get(profile);
+ if (stereotypeListMissingProfiles!= null && !stereotypeListMissingProfiles.isEmpty()){
stereotypeListMissingProfiles.add(applyStereotypeCommand);
} else {
- stereotypeListMissingProfiles = new ArrayList<ApplyStereotypeCommand>();
+ stereotypeListMissingProfiles = new ArrayList<DuplicateStereotypeCommand>();
stereotypeListMissingProfiles.add(applyStereotypeCommand);
missingProfiles.put(profile, stereotypeListMissingProfiles);
}
@@ -154,56 +153,89 @@ public class StereotypePasteStrategy extends AbstractPasteStrategy implements IP
}
}
}
-
+
// 2. user preferences (Apply profiles, data...)
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
- String preferenceProfileStrategy = preferenceStore.getString(IStereotypePasteStrategyPreferenceConstant.PROFILE_STRATEGY);
-
- if (IStereotypePasteStrategyPreferenceConstant.ASK_POPUP.equals(preferenceProfileStrategy)) {// Ask user for instruction
- // TODO: 2. user choices (Apply profiles, data...)
- } else if (IStereotypePasteStrategyPreferenceConstant.IMPORT_MISSING_PROFILE.equals(preferenceProfileStrategy)) { // apply profile
- Set<Profile> keySet = missingProfiles.keySet();
- Package rootPackage = PackageUtil.getRootPackage((Element) targetOwner);
- ApplyProfileCommand applyProfileCommand = new ApplyProfileCommand(rootPackage, keySet, (TransactionalEditingDomain) domain);
+ String preferenceProfileStrategy = preferenceStore.getString(IStereotypePasteStrategyPreferenceConstant.PROFILE_STRATEGY);
+
+ if (IStereotypePasteStrategyPreferenceConstant.ASK_POPUP.equals(preferenceProfileStrategy)){// Ask user for instruction
+ // TODO: 2. user choices (Apply profiles, data...)
+ } else if (IStereotypePasteStrategyPreferenceConstant.IMPORT_MISSING_PROFILE.equals(preferenceProfileStrategy)){ // apply profile
+ Set<Profile> profiles = missingProfiles.keySet();
+ Package rootPackage = PackageUtil.getRootPackage((Element)targetOwner);
+ ApplyProfileCommand applyProfileCommand = new ApplyProfileCommand(rootPackage, profiles, (TransactionalEditingDomain)domain);
compoundCommand.append(applyProfileCommand);
- for (Profile profile : keySet) {
- List<ApplyStereotypeCommand> list = missingProfiles.get(profile);
- for (ApplyStereotypeCommand applyStereotypeCommand : list) {
+ for(Profile profile : profiles) {
+ List<DuplicateStereotypeCommand> list = missingProfiles.get(profile);
+ for(DuplicateStereotypeCommand applyStereotypeCommand : list) {
compoundCommand.append(applyStereotypeCommand);
}
}
}
-
-
- // An empty can't be executed
- if (compoundCommand.getCommandList().isEmpty()) {
+
+
+ // An empty can't be executed
+ if(compoundCommand.getCommandList().isEmpty()) {
return null;
}
- return compoundCommand;
+ return compoundCommand;
}
return UnexecutableCommand.INSTANCE;
}
+
+ @Override
+ public org.eclipse.gef.commands.Command getGraphicalCommand(EditingDomain domain, GraphicalEditPart targetEditPart, PapyrusClipboard<Object> papyrusClipboard) {
+ org.eclipse.gef.commands.CompoundCommand compoundCommand = new org.eclipse.gef.commands.CompoundCommand("Copy all stereotypes");
+
+ if (targetEditPart != null){
+ Object model = targetEditPart.getModel();
+ if (model instanceof View){
+ View view = (View)model;
+ EObject targetOwner = view.getElement();
+ org.eclipse.emf.common.command.Command semanticCommand = this.getSemanticCommand(domain, targetOwner, papyrusClipboard);
+ if (semanticCommand != null){
+ compoundCommand.add(EMFtoGEFCommandWrapper.wrap(semanticCommand));
+ }
+ }
+ }
+
+ for(Iterator<EObject> iterator = papyrusClipboard.getTarget().iterator(); iterator.hasNext();) {
+ EObject eObject = iterator.next();
+ if(eObject instanceof BasicCompartment) {
+ BasicCompartment basicCompartment = (BasicCompartment) eObject;
+ RestoreStereotypeCompartmentCommand refreshStereotypeCompartmentCommand = new RestoreStereotypeCompartmentCommand((TransactionalEditingDomain)domain,basicCompartment);
+ Command wrap = EMFtoGEFCommandWrapper.wrap(refreshStereotypeCompartmentCommand);
+ compoundCommand.add(wrap);
+ }
+ }
+
+ if(compoundCommand.getCommands().isEmpty()) {
+ return null;
+ }
+ return compoundCommand;
+ }
+
/**
* Checks recursively if a profile is applied .
*
* @param element
- * the element
+ * the element
* @param profile
- * the profile
+ * the profile
* @return true, if is profile applied recursive
*/
protected boolean isProfileAppliedRecursive(Element element, Profile profile) {
- if (element instanceof Package) {
- Package pkg = (Package) element;
+ if(element instanceof Package) {
+ Package pkg = (Package)element;
boolean profileApplied = pkg.isProfileApplied(profile);
- if (pkg instanceof Model) {
+ if(pkg instanceof Model) {
return profileApplied;
}
- if (!profileApplied) {
+ if(!profileApplied) {
return isProfileAppliedRecursive(element.getOwner(), profile);
} else {
return true;
@@ -218,24 +250,19 @@ public class StereotypePasteStrategy extends AbstractPasteStrategy implements IP
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#prepare(org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
*/
@Override
public void prepare(PapyrusClipboard<Object> papyrusClipboard, Collection<EObject> selection) {
Map<Object, IClipboardAdditionalData> mapCopyToStereotypeData = new HashMap<Object, IClipboardAdditionalData>();
- for (Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) {
- EObject eObjectSource = iterator.next();
- if (eObjectSource instanceof Element) {
- Element element = (Element) eObjectSource;
+ for(Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) {
+ EObject eObjectSource = (EObject)iterator.next();
+ if(eObjectSource instanceof Element) {
+ Element element = (Element)eObjectSource;
EList<EObject> stereotypeApplications = element.getStereotypeApplications();
- if (stereotypeApplications != null && !stereotypeApplications.isEmpty()) {
- List<Stereotype> stereotypeList = new ArrayList<Stereotype>();
- for (EObject stereotypeApplication : stereotypeApplications) {
- Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
- stereotypeList.add(stereotype);
- }
- StereotypeClipboard stereotypeClipboard = new StereotypeClipboard(stereotypeList);
+ if(stereotypeApplications != null && !stereotypeApplications.isEmpty()) {
+ StereotypeClipboard stereotypeClipboard = new StereotypeClipboard(stereotypeApplications);
Object copy = papyrusClipboard.getCopyFromSource(eObjectSource);
mapCopyToStereotypeData.put(copy, stereotypeClipboard);
}
@@ -245,30 +272,28 @@ public class StereotypePasteStrategy extends AbstractPasteStrategy implements IP
}
- // protected ICommand getOpenDialogCommand(final TransactionalEditingDomain domain, final Collection<EditPart> selectedEditPart, final Map<EditPart, Set<EObject>> availableLinks, final Collection<EObject> initialSelection, final Map<EObject,
- // LinkEndsMapper> linkMapping) {
+ // protected ICommand getOpenDialogCommand(final TransactionalEditingDomain domain, final Collection<EditPart> selectedEditPart, final Map<EditPart, Set<EObject>> availableLinks, final Collection<EObject> initialSelection, final Map<EObject, LinkEndsMapper> linkMapping) {
// final ICommand cmd = new AbstractTransactionalCommand(domain, "Open Show/HideDialogCommand", null) {//$NON-NLS-1$
//
- // @Override
- // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- // final ShowHideRelatedLinkSelectionDialog dialog = new ShowHideRelatedLinkSelectionDialog(Display.getDefault().getActiveShell(), new UMLLabelProvider(), new AbstractShowHideRelatedLinkEditPolicy.LinkContentProvider(availableLinks), availableLinks,
- // linkMapping);
+ // @Override
+ // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // final ShowHideRelatedLinkSelectionDialog dialog = new ShowHideRelatedLinkSelectionDialog(Display.getDefault().getActiveShell(), new UMLLabelProvider(), new AbstractShowHideRelatedLinkEditPolicy.LinkContentProvider(availableLinks), availableLinks, linkMapping);
// dialog.setTitle("Show/Hide Links");//$NON-NLS-1$
// dialog.setMessage("Choose the links to show.");//$NON-NLS-1$
- // dialog.setInput(selectedEditPart);
- // dialog.setInitialSelection(initialSelection);
- // dialog.setExpandedElements(selectedEditPart.toArray());
- // dialog.setContainerMode(true);
- // int status = dialog.open();
- // if(status == Window.CANCEL) {
- // return CommandResult.newCancelledCommandResult();
- // }
- // return CommandResult.newOKCommandResult(Arrays.asList(dialog.getResult()));
- // }
- // };
+ // dialog.setInput(selectedEditPart);
+ // dialog.setInitialSelection(initialSelection);
+ // dialog.setExpandedElements(selectedEditPart.toArray());
+ // dialog.setContainerMode(true);
+ // int status = dialog.open();
+ // if(status == Window.CANCEL) {
+ // return CommandResult.newCancelledCommandResult();
+ // }
+ // return CommandResult.newOKCommandResult(Arrays.asList(dialog.getResult()));
+ // }
+ // };
//
- // return cmd;
- // }
+ // return cmd;
+ // }
/**
@@ -276,23 +301,17 @@ public class StereotypePasteStrategy extends AbstractPasteStrategy implements IP
*/
protected class StereotypeClipboard implements IClipboardAdditionalData {
- /** The stereotype. */
- protected Collection<Stereotype> stereotypes;
-
- /**
- * @param stereotypes
- */
- public StereotypeClipboard(Collection<Stereotype> stereotypes) {
- this.stereotypes = stereotypes;
- }
+ /** The stereotype applications. */
+ protected Collection<EObject> stereotypeApplications;
+
+ public StereotypeClipboard(Collection<EObject> stereotypeApplications) {
+ this.stereotypeApplications = stereotypeApplications;
+ }
- /**
- * @return
- */
- public Collection<Stereotype> getStereotypes() {
- return stereotypes;
+ public Collection<EObject> getstereotypeApplications() {
+ return stereotypeApplications;
}
-
+
}
}
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
new file mode 100644
index 00000000000..cf413c1c481
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DuplicateStereotypeCommand.java
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.commands;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Extension;
+import org.eclipse.uml2.uml.Stereotype;
+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 {
+
+ protected Element element;
+
+ protected EObject stereotypeApplication;
+
+ protected Stereotype stereotypeInTargetContext;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param element
+ * The UML Element on which the stereotype will be applied
+ * @param stereotype
+ * The stereotypes to apply
+ */
+ public DuplicateStereotypeCommand(TransactionalEditingDomain domain, Element element, EObject stereotypeApplication) {
+ super(domain);
+ this.element = element;
+ this.stereotypeApplication = stereotypeApplication;
+ // reload the stereotype in the new Context-ResourceSet (Required because in org.eclipse.uml2.uml.internal.operations.PackageOperations
+ // L960 in getProfileApplication the test is using == instead of equals)
+ Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
+ Stereotype stereotypeInTargetContext = EMFHelper.reloadIntoContext(stereotype, element);
+ this.stereotypeInTargetContext = stereotypeInTargetContext;
+ }
+
+ public Stereotype getStereotypeInTargetContext() {
+ return stereotypeInTargetContext;
+ }
+
+ @Override
+ protected void doExecute() {
+ EObject applyStereotype = element.applyStereotype(stereotypeInTargetContext);
+ EList<EStructuralFeature> eStructuralFeatures = applyStereotype.eClass().getEStructuralFeatures();
+ for(EStructuralFeature eStructuralFeature : eStructuralFeatures) {
+ String name = eStructuralFeature.getName();
+ if(!name.startsWith(Extension.METACLASS_ROLE_PREFIX) && eStructuralFeature.isChangeable()) {
+ applyStereotype.eSet(eStructuralFeature, stereotypeApplication.eGet(eStructuralFeature));
+ }
+ }
+ }
+}

Back to the top