diff options
author | Benoit Maggi | 2014-02-28 12:23:37 +0000 |
---|---|---|
committer | Vincent Lorenzo | 2014-03-18 14:00:40 +0000 |
commit | ab2f48a1904a94c25bd910354920ee5717148820 (patch) | |
tree | 64715b3cd41279e9dacf2fcc258662f80c1f0b52 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common | |
parent | 38987f2559764e1f12b9c9edc60213665502c78a (diff) | |
download | org.eclipse.papyrus-ab2f48a1904a94c25bd910354920ee5717148820.tar.gz org.eclipse.papyrus-ab2f48a1904a94c25bd910354920ee5717148820.tar.xz org.eclipse.papyrus-ab2f48a1904a94c25bd910354920ee5717148820.zip |
[Usability] Papyrus shall provide a copy/paste/cut feature
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Conflicts:
plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common')
6 files changed, 282 insertions, 7 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF index 1c01988f0fe..afd4ff85fbf 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF @@ -35,6 +35,7 @@ Export-Package: org.eclipse.papyrus.uml.diagram.common, org.eclipse.papyrus.uml.diagram.common.service, org.eclipse.papyrus.uml.diagram.common.service.palette, org.eclipse.papyrus.uml.diagram.common.sheet, + org.eclipse.papyrus.uml.diagram.common.strategy.paste, org.eclipse.papyrus.uml.diagram.common.ui.dialogs, org.eclipse.papyrus.uml.diagram.common.ui.helper, org.eclipse.papyrus.uml.diagram.common.util, @@ -93,6 +94,7 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.0.0", org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)", org.eclipse.core.databinding;bundle-version="1.4.1", org.eclipse.gmf.tooling.runtime, + org.eclipse.papyrus.uml.commands;bundle-version="1.0.0", org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0", org.eclipse.papyrus.infra.core.pluginexplorer;bundle-version="1.0.0", org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0" diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java index 229325fd876..2e418cfe32c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/GraphicalCommandHandler.java @@ -38,7 +38,9 @@ import org.eclipse.ui.handlers.HandlerUtil; * calculates the visibility and enablement based on command executability - * executes the command in Papyrus command stack * + * @deprecated Since February 2014 use org.eclipse.papyrus.infra.gmfdiag.menu.handlers.AbstractGraphicalCommandHandler */ +@Deprecated public abstract class GraphicalCommandHandler extends AbstractHandler { protected abstract Command getCommand(); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java index 64747a64393..8558ec04c50 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelCommandHandler.java @@ -25,7 +25,9 @@ import org.eclipse.ui.handlers.HandlerUtil; * * @see org.eclipse.core.commands.IHandler * @see org.eclipse.core.commands.AbstractHandler + * @deprecated unused and with the text "Hello, Eclipse world" */ +@Deprecated public class PasteWithModelCommandHandler extends AbstractHandler { /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java index dc73f950d09..ab22bb3e145 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java @@ -35,7 +35,9 @@ import org.eclipse.ui.handlers.HandlerUtil; * * @see org.eclipse.core.commands.IHandler * @see org.eclipse.core.commands.AbstractHandler + * @Deprecated seems unused, use org.eclipse.papyrus.uml.diagram.menu.handlers.PasteWithModelHandler */ +@Deprecated // seems unused, use org.eclipse.papyrus.uml.diagram.menu.handlers.PasteWithModelHandler public class PasteWithModelHandler extends AbstractHandler { /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java index b22ddaf2c3e..f5a3f73c80c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ImportResourcePasteStrategy.java @@ -8,60 +8,157 @@ * * Contributors: * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation + * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.strategy.paste; import java.util.Map; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.gef.EditPart; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.commands.wrappers.GMFtoGEFCommandWrapper; +import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.DefaultDiagramPasteCommand; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.DefaultPasteCommand; import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy; import org.eclipse.papyrus.uml.diagram.common.Activator; import org.eclipse.swt.graphics.Image; + /** - * + * The Class ImportResourcePasteStrategy. */ public class ImportResourcePasteStrategy implements IPasteStrategy { + + /** The instance. */ + private static IPasteStrategy instance = new ImportResourcePasteStrategy(); + + /** + * Gets the single instance of ImportResourcePasteStrategy. + * + * @return single instance of ImportResourcePasteStrategy + */ + public static IPasteStrategy getInstance() { + return instance; + } + + + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel() + */ public String getLabel() { return "ImportResourcePasteStrategy"; //$NON-NLS-1$ } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID() + */ public String getID() { - return Activator.ID + ".ImportResourcePasteStrategy"; //".ClassifierToStructureCompDrop"; //$NON-NLS-1$ + return Activator.ID + ".ImportResourcePasteStrategy"; //$NON-NLS-1$ } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription() + */ public String getDescription() { return "Import required ressources for paste."; //$NON-NLS-1$ } + /** + * Gets the category id. + * + * @return the category id + */ public String getCategoryID() { return "org.eclipse.papyrus.strategy.paste"; //$NON-NLS-1$ } + /** + * Gets the category label. + * + * @return the category label + */ public String getCategoryLabel() { return "Paste all copied elements"; //$NON-NLS-1$ - } - + } + + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getImage() + */ public Image getImage() { return null; } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getPriority() + */ public int getPriority() { return 0; } + /** + * Sets the options. + * + * @param options the options + */ public void setOptions(Map<String, Object> options) { //Nothing } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getCommand(org.eclipse.gef.Request, org.eclipse.gef.EditPart) + */ @Override public Command getCommand(Request request, EditPart targetEditPart) { // TODO Auto-generated method stub return null; } + /* (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) { + // TODO : deport to Default Copy + + DefaultPasteCommand pasteElementCommand = new DefaultPasteCommand(domain, targetOwner, papyrusClipboard); + return pasteElementCommand; + } + + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn() + */ + @Override + public IPasteStrategy dependsOn() { + // TODO Auto-generated method stub + return null; + } + + /* (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) { + // TODO Auto-generated method stub + } + + + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getGraphicalCommand(org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard) + */ + @Override + public Command getGraphicalCommand(EditingDomain domain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart targetEditPart, PapyrusClipboard<Object> papyrusClipboard) { + CompoundCommand compoundCommand = new CompoundCommand("Semantic And Graphical paste"); //$NON-NLS-1$ + DefaultDiagramPasteCommand defaultDiagramPasteCommand = new DefaultDiagramPasteCommand(targetEditPart.getEditingDomain(), "DefaultGraphicalPasteWithModel", papyrusClipboard, (View)targetEditPart.getModel()); + GMFtoGEFCommandWrapper gmFtoGEFCommandWrapper = new GMFtoGEFCommandWrapper(defaultDiagramPasteCommand); + compoundCommand.add(gmFtoGEFCommandWrapper); + return compoundCommand; + } } 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 780129ea349..f5322faed53 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 @@ -11,59 +11,229 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.strategy.paste; +import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import org.eclipse.emf.common.command.CompoundCommand; +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.EditPart; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; +import org.eclipse.papyrus.infra.core.clipboard.IClipboardAdditionalData; +import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard; import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy; -import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.TransactionalPasteStrategy; import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.tools.commands.ApplyStereotypeCommand; import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.uml2.uml.util.UMLUtil; /** - * + * Offer a strategy for copying stereotypes. */ public class StereotypePasteStrategy implements IPasteStrategy { + /** The instance. */ + private static IPasteStrategy instance = new StereotypePasteStrategy(); + + /** + * Gets the single instance of StereotypePasteStrategy. + * + * @return single instance of StereotypePasteStrategy + */ + public static IPasteStrategy getInstance(){ + return instance; + } + + + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel() + */ public String getLabel() { return "StereotypeStrategy"; //$NON-NLS-1$ } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID() + */ public String getID() { return Activator.ID + ".StereotypeStrategy"; //".ClassifierToStructureCompDrop"; //$NON-NLS-1$ } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription() + */ public String getDescription() { return "Paste stereotype elements"; //$NON-NLS-1$ } + /** + * Gets the category id. + * + * @return the category id + */ public String getCategoryID() { return "org.eclipse.papyrus.strategy.paste"; //$NON-NLS-1$ } + /** + * Gets the category label. + * + * @return the category label + */ public String getCategoryLabel() { return "Paste all copied elements"; //$NON-NLS-1$ } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getImage() + */ + @Deprecated public Image getImage() { return null; } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getPriority() + */ + @Deprecated public int getPriority() { - return 0; + return 1; } + /** + * Sets the options. + * + * @param options the options + */ public void setOptions(Map<String, Object> options) { //Nothing } + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getCommand(org.eclipse.gef.Request, org.eclipse.gef.EditPart) + */ @Override public Command getCommand(Request request, EditPart targetEditPart) { // TODO Auto-generated method stub return null; } + /* (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> p) { + CompoundCommand compoundCommand = new CompoundCommand("Copy all stereotypes"); //$NON-NLS-1$ + for (Iterator<Object> iterator = p.iterator(); iterator.hasNext();) { + Object object = (Object) iterator.next(); + // get target Element + EObject target= p.getTragetCopyFromInternalClipboardCopy(object); + if (target != null && target instanceof Element){ + // get affiliate StereotypeClipboard + Map<Object, ?> additionalDataMap = p.getAdditionalDataForStrategy(getID()); + Object additionnalData = additionalDataMap.get(object); + if (additionnalData instanceof StereotypeClipboard){ + StereotypeClipboard stereotypeClipboard = (StereotypeClipboard) additionnalData; + Stereotype stereotype = stereotypeClipboard.getStereotype(); + if (stereotype != null) { + // append command to apply stereotype + ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand((Element)target, stereotype, (TransactionalEditingDomain) domain); + compoundCommand.append(applyStereotypeCommand); + } + } + } + } + // An empty can't be executed + if (compoundCommand.getCommandList().isEmpty()) { + return null; + } + return compoundCommand; + } + + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getGraphicalCommand(org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard) + */ + @Override + public Command getGraphicalCommand( + EditingDomain domain, + org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart targetOwner, + PapyrusClipboard<Object> papyrusClipboard) { + // TODO Auto-generated method stub + return null; + } + + + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn() + */ + @Override + public IPasteStrategy dependsOn() { + // TODO Auto-generated method stub + return ImportResourcePasteStrategy.getInstance(); + } + + + /* (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) { + 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(); + Map<Object,IClipboardAdditionalData> hashMap = new HashMap<Object,IClipboardAdditionalData>(); + for (EObject stereotypeApplication : stereotypeApplications) { // TODO : manage many stereotypes + Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication); + StereotypeClipboard stereotypeClipboard = new StereotypeClipboard(stereotype); + Object copy = papyrusClipboard.getCopyFromSource(eObjectSource); + hashMap.put(copy, stereotypeClipboard); + } + papyrusClipboard.pushAdditionalData(getID(), hashMap); + } + } + } + + + + // TODO : remove no internal class + /** + * The Class StereotypeClipboard. + */ + private class StereotypeClipboard implements IClipboardAdditionalData{ + + /** The stereotype. */ + private Stereotype stereotype; + + /** + * Gets the stereotype. + * + * @return the stereotype + */ + public Stereotype getStereotype() { + return stereotype; + } + + /** + * Instantiates a new stereotype clipboard. + * + * @param pStereotype the stereotype + */ + public StereotypeClipboard(Stereotype pStereotype) { + stereotype = pStereotype; + } + + } + + + } |