summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-05-21 04:54:55 (EDT)
committerBenoit Maggi2014-05-21 05:09:25 (EDT)
commit97cca5f2ec5afe7dda7e17194059f509fcccecc1 (patch)
tree03ed601f50c8dfe6da16608bfe40435c18a54cea
parentf398ed6ab77451c550ea42e705106f2729959407 (diff)
downloadorg.eclipse.papyrus-97cca5f2ec5afe7dda7e17194059f509fcccecc1.zip
org.eclipse.papyrus-97cca5f2ec5afe7dda7e17194059f509fcccecc1.tar.gz
org.eclipse.papyrus-97cca5f2ec5afe7dda7e17194059f509fcccecc1.tar.bz2
Bug 430548 - [Constraints] ConstraintLink not show on diagram after dragrefs/changes/78/26978/1
and drop from Model Explorer - add a strategy for the copy-paste of constraint Change-Id: Id50ece665fe0585575cee509598fe09f2bbf4cd4 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java5
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ConstraintPasteStrategy.java260
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java115
4 files changed, 381 insertions, 2 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java
index b005897..4904751 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java
@@ -106,7 +106,8 @@ public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
}
// Inform the clipboard of the element created (used by strategies)
- papyrusClipboard.addAllInternalToTargetCopy(transtypeCopier(copier));
+ Map<Object, EObject> transtypeCopier = transtypeCopier(copier);
+ papyrusClipboard.addAllInternalToTargetCopy(transtypeCopier);
List<EObject> semanticRootList = EcoreUtil.filterDescendants(semanticList);
MoveRequest moveRequest = new MoveRequest(container.getElement(), semanticRootList);
@@ -278,7 +279,7 @@ public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
Map<Object, EObject> map = new HashMap<Object, EObject>();
Set<Entry<EObject, EObject>> entrySet = copier.entrySet();
for(Entry<EObject, EObject> entry : entrySet) {
- map.put(entry.getValue(), entry.getValue());
+ map.put(entry.getKey(), entry.getValue());
}
return map;
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
index 9fccba4..e29e8ce 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
@@ -606,6 +606,9 @@
<strategy
strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.RenamePasteStrategy">
</strategy>
+ <strategy
+ strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.ConstraintPasteStrategy">
+ </strategy>
</extension>
<extension
point="org.eclipse.papyrus.infra.gmfdiag.common.copyStrategy">
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ConstraintPasteStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ConstraintPasteStrategy.java
new file mode 100644
index 0000000..63ae19f
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ConstraintPasteStrategy.java
@@ -0,0 +1,260 @@
+/*****************************************************************************
+ * 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.strategy.paste;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.RecordingCommand;
+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.View;
+import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
+import org.eclipse.papyrus.commands.wrappers.GMFtoGEFCommandWrapper;
+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.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.uml2.uml.Constraint;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Namespace;
+
+/**
+ * Offer a strategy for copying stereotypes.
+ */
+public class ConstraintPasteStrategy extends AbstractPasteStrategy implements IPasteStrategy {
+
+ /** The instance. */
+ private static IPasteStrategy instance = new ConstraintPasteStrategy();
+
+ /**
+ * 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 "ConstraintStrategy"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID()
+ */
+ public String getID() {
+ return Activator.ID + ".ConstraintStrategy"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription()
+ */
+ public String getDescription() {
+ return "Paste constraint elements and context links"; //$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("Reassociate constraint context");
+ Map<Object, ?> additionalDataMap = papyrusClipboard.getAdditionalDataForStrategy(getID());
+ 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 Constraint) {
+ ConstraintClipboard constraintClipboard = (ConstraintClipboard)additionalDataMap.get(object);
+ Namespace context = constraintClipboard.getConstraint().getContext();
+ if(checkContext(targetOwner, context)) {
+ RecordingCommand buildSemanticCommand = buildSemanticCommand(domain, (Constraint)target, context);
+ compoundCommand.append(buildSemanticCommand);
+ }
+
+ }
+ }
+
+ // An empty can't be executed
+ if(compoundCommand.getCommandList().isEmpty()) {
+ return null;
+ }
+ return compoundCommand;
+ }
+ return UnexecutableCommand.INSTANCE;
+
+ }
+
+ @Override
+ public Command getGraphicalCommand(EditingDomain domain, GraphicalEditPart targetEditPart, PapyrusClipboard<Object> papyrusClipboard) {
+ Set<Constraint> alreadyprocesed = new HashSet<Constraint>();
+ View targetView = (View)targetEditPart.getModel();
+ EObject targetOwner = (EObject)targetView.getElement();
+ org.eclipse.gef.commands.CompoundCommand compoundCommand = new org.eclipse.gef.commands.CompoundCommand("Reassociate constraint context");
+ Map<Object, ?> additionalDataMap = papyrusClipboard.getAdditionalDataForStrategy(getID());
+
+ for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
+ Object object = (Object)iterator.next();
+ // get target Element
+ EObject target = papyrusClipboard.getTragetCopyFromInternalClipboardCopy(object);
+
+ if(target instanceof View && ((View)target).getElement() instanceof Constraint) {
+ Constraint targetConstraint = (Constraint)((View)target).getElement();
+ if(!alreadyprocesed.contains(targetConstraint)) {
+ Object internalFromTarget = getInternalFromTarget(papyrusClipboard, targetConstraint);
+ ConstraintClipboard constraintClipboard = (ConstraintClipboard)additionalDataMap.get(internalFromTarget);
+ Namespace context = constraintClipboard.getConstraint().getContext();
+ if(checkContext(targetOwner, context)) {
+ RecordingCommand semanticCommand = buildSemanticCommand(domain, (Constraint)targetConstraint, context);
+ if(semanticCommand != null) {
+ compoundCommand.add(EMFtoGEFCommandWrapper.wrap(semanticCommand));
+ ShowConstraintContextLink command = new ShowConstraintContextLink((TransactionalEditingDomain)domain, targetEditPart, (View)target);
+ compoundCommand.add(GMFtoGEFCommandWrapper.wrap(command));
+ alreadyprocesed.add(targetConstraint);
+ }
+ }
+
+ }
+ }
+ }
+ // An empty can't be executed
+ if(compoundCommand.getChildren().length == 0) {
+ return null;
+ }
+ return compoundCommand;
+ }
+
+ protected RecordingCommand buildSemanticCommand(EditingDomain domain, final Constraint targetConstraint, final Namespace context) {
+ RecordingCommand command = new RecordingCommand((TransactionalEditingDomain)domain, "Set Context for constraint") {
+ @Override
+ protected void doExecute() {
+ targetConstraint.setContext(context);
+ }
+ };
+ return command;
+ }
+
+ /**
+ * Check if the target contains the context
+ * @param targetOwner
+ * @param context
+ * @return
+ */
+ protected boolean checkContext(EObject targetOwner, Namespace context) {
+ boolean contains = false;
+ if(targetOwner instanceof Namespace) {
+ Namespace targetNamespace = (Namespace)targetOwner;
+ contains = targetNamespace.getMembers().contains(context);
+ }
+ return contains;
+ }
+
+
+
+ /**
+ * Get the internal clipboard value from the target value
+ * @param papyrusClipboard
+ * @param target
+ * @return
+ */
+ protected Object getInternalFromTarget(PapyrusClipboard<Object> papyrusClipboard, EObject target) {
+ Map<Object, EObject> internalClipboardToTargetCopy = papyrusClipboard.getInternalClipboardToTargetCopy();
+ Set<Entry<Object, EObject>> entrySet = internalClipboardToTargetCopy.entrySet();
+ for(Entry<Object, EObject> entry : entrySet) {
+ if(entry.getValue().equals(target)) {
+ return entry.getKey();
+ }
+ }
+ 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, Collection<EObject> selection) {
+ Map<Object, IClipboardAdditionalData> mapCopyToConstraintData = new HashMap<Object, IClipboardAdditionalData>();
+ for(Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) {
+ EObject eObjectSource = (EObject)iterator.next();
+ if(eObjectSource instanceof Constraint) {
+ Constraint constraint = (Constraint) eObjectSource;
+ ConstraintClipboard constraintClipboard = new ConstraintClipboard(constraint);
+ Object copy = papyrusClipboard.getCopyFromSource(eObjectSource);
+ mapCopyToConstraintData.put(copy, constraintClipboard);
+ }
+ }
+ papyrusClipboard.pushAdditionalData(getID(), mapCopyToConstraintData);
+ }
+
+ /**
+ * This Class store the constraint with the context
+ */
+ protected class ConstraintClipboard implements IClipboardAdditionalData {
+
+ /** The stereotype. */
+ protected Constraint constraint;
+
+ /**
+ * @param stereotypes
+ */
+ public ConstraintClipboard(Constraint constraint) {
+ this.constraint = constraint;
+ }
+
+ /**
+ * @return
+ */
+ public Constraint getConstraint() {
+ return constraint;
+ }
+
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java
new file mode 100644
index 0000000..f19da88
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java
@@ -0,0 +1,115 @@
+/*****************************************************************************
+ * 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.strategy.paste;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+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.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.requests.ShowHideRelatedLinkRequest;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.requests.ShowHideRelatedLinkRequest.ShowHideKind;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil;
+import org.eclipse.uml2.uml.Constraint;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Namespace;
+
+
+/**
+ * Show the <<context>> link between a constraint and its context
+ *
+ * @author bmaggi
+ */
+public class ShowConstraintContextLink extends AbstractTransactionalCommand {
+
+ /** The diagram where the link will be displayed */
+ protected DiagramEditPart diagramEP;
+
+ /** The constraint */
+ protected Constraint constraint;
+
+ /**
+ * Show the <<context>> link between a constraint and its context
+ *
+ * @param domain
+ * @param targetEditPart
+ * @param constraintView
+ */
+ public ShowConstraintContextLink(TransactionalEditingDomain domain, GraphicalEditPart targetEditPart, View constraintView) {
+ super(domain, "Show Constraint Context Link", null);
+ this.diagramEP = DiagramEditPartsUtil.getDiagramEditPart(targetEditPart);
+ this.constraint = (Constraint)constraintView.getElement();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ if(diagramEP != null && getEditingDomain() != null) {
+ diagramEP.refresh();
+ Namespace context = constraint.getContext();
+ Collection<EditPart> allTopSemanticEditPart = DiagramEditPartsUtil.getAllTopSemanticEditPart(diagramEP);
+ EditPart constraintEditPart = getEditPart(constraint, allTopSemanticEditPart);
+ EditPart contextEditPart = getEditPart(context, allTopSemanticEditPart);
+
+ if(constraintEditPart != null && contextEditPart != null) {
+ Collection<EditPart> constraintAndContext = new ArrayList<EditPart>();
+ constraintAndContext.add(constraintEditPart);
+ constraintAndContext.add(contextEditPart);
+ final Request request = new ShowHideRelatedLinkRequest(constraintAndContext, ShowHideKind.SHOW_ALL_LINK_BETWEEN_SELECTED_ELEMENT);
+ final Command cmd = diagramEP.getCommand(request);
+ if(cmd != null) {
+ cmd.execute();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the correct edit of a specific namedElement from an editPartCollection
+ *
+ * @param namedElement
+ * @param editPartCollection
+ * @return
+ */
+ protected EditPart getEditPart(NamedElement namedElement, Collection<EditPart> editPartCollection) {
+ for(EditPart editPart : editPartCollection) {
+ Object model = editPart.getModel();
+ if(model instanceof View) {
+ View view = (View)model;
+ EObject element = view.getElement();
+ if(namedElement.equals(element)) {
+ return editPart;
+ }
+ }
+ }
+ return null;
+ }
+}