diff options
author | atischenko | 2014-11-05 22:25:19 +0000 |
---|---|---|
committer | Remi Schnekenburger | 2014-11-06 07:36:16 +0000 |
commit | 8237c87ab58c3811e6e056effabd24203f815d10 (patch) | |
tree | efaf7611761cd9c6e6a98701856b27b05120e1e0 | |
parent | 67651950285dd9b8efaa39d67482f9e2c9a98d03 (diff) | |
download | org.eclipse.papyrus-8237c87ab58c3811e6e056effabd24203f815d10.tar.gz org.eclipse.papyrus-8237c87ab58c3811e6e056effabd24203f815d10.tar.xz org.eclipse.papyrus-8237c87ab58c3811e6e056effabd24203f815d10.zip |
Bug 409484 - [All diagrams] Incorrectly populated Diagram after
drag-and-drop.
Fixed
1. Dropping dependencies with multiple supplier nodes
2. Dropping dependencies with single supplier nodes
cherry-picked from master Iabd7a01fbf4f16f37f71de31a2718454e79e6866
Change-Id: I1235926b24daa37ab31c15d9ac4dab96ea13e29b
Signed-off-by: atischenko <ticher777@gmail.com>
3 files changed, 131 insertions, 45 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/MultiDependencyHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/MultiDependencyHelper.java index 6727c38eb94..dfd66a5b194 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/MultiDependencyHelper.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/MultiDependencyHelper.java @@ -56,6 +56,7 @@ import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.DependencyNodeEditPart; import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.common.commands.DeleteLinkDuringCreationCommand;
import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.helper.ElementHelper;
import org.eclipse.uml2.uml.Dependency;
import org.eclipse.uml2.uml.NamedElement;
@@ -68,6 +69,8 @@ import org.eclipse.uml2.uml.UMLPackage; @SuppressWarnings("restriction")
public class MultiDependencyHelper extends ElementHelper {
+ private final CommonDiagramDragDropEditPolicy.CompositeCommandRegistryHelper myVirtualNodesRegistry;
+
/**
* Instantiates a new multi dependency helper.
*
@@ -75,8 +78,13 @@ public class MultiDependencyHelper extends ElementHelper { * the edit domain
*/
public MultiDependencyHelper(TransactionalEditingDomain editDomain) {
+ this(editDomain, new CommonDiagramDragDropEditPolicy.CompositeCommandRegistryHelper());
+ }
+
+ public MultiDependencyHelper(TransactionalEditingDomain editDomain, CommonDiagramDragDropEditPolicy.CompositeCommandRegistryHelper virtualNodesRegistry) {
super();
this.editDomain = editDomain;
+ myVirtualNodesRegistry = virtualNodesRegistry;
}
private CompoundCommand constructDependencyEnd(CompoundCommand command, DependencyDiamonViewCreateCommand nodeCreation, Collection<NamedElement> dependencyEnd, Dependency dependency, EditPartViewer viewer, PreferencesHint diagramPreferencesHint,
@@ -107,35 +115,29 @@ public class MultiDependencyHelper extends ElementHelper { }
// descriptor for the branch
ConnectionViewDescriptor viewBranchDescriptor = new ConnectionViewDescriptor(UMLElementTypes.Dependency_4018, ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), diagramPreferencesHint);
+ IAdaptable nodeCreationAdapter = (IAdaptable) nodeCreation.getCommandResult().getReturnValue();
// the editpart exist -> only creation of the branch
if (sourceEditPart != null) {
CustomDeferredCreateConnectionViewCommand aBranchCommand = null;
if (constructSource) {
- aBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), new SemanticAdapter(null, sourceEditPart.getModel()), (IAdaptable) nodeCreation
- .getCommandResult().getReturnValue(), sourceEditPart.getViewer(), ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint(), viewBranchDescriptor, null);
+ aBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), new SemanticAdapter(null, sourceEditPart.getModel()), nodeCreationAdapter,
+ sourceEditPart.getViewer(), ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint(), viewBranchDescriptor, null);
} else {
- aBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), (IAdaptable) nodeCreation.getCommandResult().getReturnValue(), new SemanticAdapter(null,
+ aBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), nodeCreationAdapter, new SemanticAdapter(null,
sourceEditPart.getModel()), sourceEditPart.getViewer(), ((IGraphicalEditPart) sourceEditPart).getDiagramPreferencesHint(), viewBranchDescriptor, null);
}
aBranchCommand.setElement(dependency);
command.add(new ICommandProxy(aBranchCommand));
} else {// the editpart does not exist
- // creation of the node
- IAdaptable elementAdapter = new EObjectAdapter(currentEnd);
- ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, null, ViewUtil.APPEND, false, diagramPreferencesHint);
- // get the command and execute it.
- CreateCommand nodeCreationCommand = new CreateCommand(getEditingDomain(), descriptor, containerView);
- command.add(new ICommandProxy(nodeCreationCommand));
- SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x + 200, location.y + index * 100));
- command.add(new ICommandProxy(setBoundsCommand));
+ IAdaptable currentEndAdapter = findOrCreateEndAdapter(currentEnd, command, containerView, diagramPreferencesHint, location, index);
// Creation of the branch
CustomDeferredCreateConnectionViewCommand aBranchCommand = null;
if (constructSource) {
- aBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue(),
- (IAdaptable) nodeCreation.getCommandResult().getReturnValue(), viewer, diagramPreferencesHint, viewBranchDescriptor, null);
+ aBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), currentEndAdapter,
+ nodeCreationAdapter, viewer, diagramPreferencesHint, viewBranchDescriptor, null);
} else {
- aBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), (IAdaptable) nodeCreation.getCommandResult().getReturnValue(),
- (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue(), viewer, diagramPreferencesHint, viewBranchDescriptor, null);
+ aBranchCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.Dependency_4018).getSemanticHint(), nodeCreationAdapter,
+ currentEndAdapter, viewer, diagramPreferencesHint, viewBranchDescriptor, null);
}
aBranchCommand.setElement(dependency);
command.add(new ICommandProxy(aBranchCommand));
@@ -145,6 +147,24 @@ public class MultiDependencyHelper extends ElementHelper { return command;
}
+ private IAdaptable findOrCreateEndAdapter(NamedElement currentEnd, CompoundCommand command, View containerView, PreferencesHint diagramPreferencesHint, Point location, int index) {
+ IAdaptable currentEndAdapter = myVirtualNodesRegistry.findAdapter(currentEnd);
+ if (currentEndAdapter != null) {
+ return currentEndAdapter;
+ }
+ // creation of the node
+ IAdaptable elementAdapter = new EObjectAdapter(currentEnd);
+ ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, null, ViewUtil.APPEND, false, diagramPreferencesHint);
+ // get the command and execute it.
+ CreateCommand nodeCreationCommand = new CreateCommand(getEditingDomain(), descriptor, containerView);
+ command.add(new ICommandProxy(nodeCreationCommand));
+ SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x + 200, location.y + index * 100));
+ command.add(new ICommandProxy(setBoundsCommand));
+ currentEndAdapter = (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue();
+ myVirtualNodesRegistry.registerAdapter(currentEnd, currentEndAdapter);
+ return currentEndAdapter;
+ }
+
public Command dropMutliDependency(Dependency dependency, EditPartViewer viewer, PreferencesHint diagramPreferencesHint, Point location, View containerView) {
CompoundCommand command = new CompoundCommand();
// 0. Obtain list of property to display
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java index 2d30e45c44a..0be2e671fd8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java @@ -282,7 +282,7 @@ public class ClassDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPol return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Association"), source, target, 4008, dropRequest.getLocation(), semanticLink));
}
if (sources.size() > 1 || targets.size() > 1) {
- MultiDependencyHelper dependencyHelper = new MultiDependencyHelper(getEditingDomain());
+ MultiDependencyHelper dependencyHelper = new MultiDependencyHelper(getEditingDomain(), getCompositeCommandRegistry());
return dependencyHelper.dropMutliDependency((Dependency) semanticLink, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
}
return UnexecutableCommand.INSTANCE;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java index da4726e565e..763ea00acfa 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java @@ -17,8 +17,10 @@ package org.eclipse.papyrus.uml.diagram.common.editpolicies; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.core.commands.operations.IUndoableOperation; @@ -70,6 +72,8 @@ import org.eclipse.uml2.uml.Element; */ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEditPolicy { + private CompositeCommandRegistryHelper myCompositeCommandRegistryHelper; + /** The specific drop. */ private Set<Integer> specificDrop = null; @@ -116,6 +120,16 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi protected abstract Set<Integer> getDroppableElementVisualId(); /** + * Gets composite command adapters + */ + protected CompositeCommandRegistryHelper getCompositeCommandRegistry() { + if (myCompositeCommandRegistryHelper == null) { + myCompositeCommandRegistryHelper = new CompositeCommandRegistryHelper(); + } + return myCompositeCommandRegistryHelper; + } + + /** * {@inheritedDoc} */ @Override @@ -148,39 +162,17 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi * @return the composite command */ public CompositeCommand dropBinaryLink(CompositeCommand cc, Element source, Element target, int linkVISUALID, Point absoluteLocation, Element semanticLink) { - // look for editpart - GraphicalEditPart sourceEditPart = (GraphicalEditPart) lookForEditPart(source); - GraphicalEditPart targetEditPart = (GraphicalEditPart) lookForEditPart(target); + IAdaptable sourceAdapter = findAdapter(cc, source, getLinkSourceDropLocation(absoluteLocation, source, target)); + IAdaptable targetAdapter = findAdapter(cc, target, getLinkTargetDropLocation(absoluteLocation, source, target)); // descriptor of the link CreateConnectionViewRequest.ConnectionViewDescriptor linkdescriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(getUMLElementType(linkVISUALID), ((IHintedType) getUMLElementType(linkVISUALID)).getSemanticHint(), getDiagramPreferencesHint()); - - IAdaptable sourceAdapter = null; - IAdaptable targetAdapter = null; - if (sourceEditPart == null) { - ICommand createCommand = getDefaultDropNodeCommand(getLinkSourceDropLocation(absoluteLocation, source, target), source); - cc.add(createCommand); - - sourceAdapter = (IAdaptable) createCommand.getCommandResult().getReturnValue(); - } else { - sourceAdapter = new SemanticAdapter(null, sourceEditPart.getModel()); - } - if (targetEditPart == null) { - ICommand createCommand = getDefaultDropNodeCommand(getLinkTargetDropLocation(absoluteLocation, source, target), target); - cc.add(createCommand); - - targetAdapter = (IAdaptable) createCommand.getCommandResult().getReturnValue(); - } else { - targetAdapter = new SemanticAdapter(null, targetEditPart.getModel()); - } - CommonDeferredCreateConnectionViewCommand aLinkCommand = new CommonDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) getUMLElementType(linkVISUALID)).getSemanticHint(), sourceAdapter, targetAdapter, getViewer(), getDiagramPreferencesHint(), linkdescriptor, null); aLinkCommand.setElement(semanticLink); cc.compose(aLinkCommand); return cc; - } /** @@ -237,17 +229,17 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi /* * when it's the first action after the opening of Papyrus, the * viewService is not loaded! see bug 302555 - * + * * Duration test for 100000 creations of DropCommand : Here 2 solutions * : - call ViewServiceUtil.forceLoad(); for each drop -> ~2500ms - * + * * - test if the command cc can be executed at the end of the method, * and if not : - call ViewServiceUtil.forceLoad(); - and return * getDropObjectsCommand(getDropObjectsCommand) -> ~4700ms - * + * * - for information : without call ViewServiceUtil.forceLoad(); -> * ~1600ms - * + * * It's better don't test if the command is executable! */ ViewServiceUtil.forceLoad(); @@ -265,7 +257,7 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi EObject droppedObject = (EObject) iter.next(); cc.add(getDropObjectCommand(dropRequest, droppedObject)); } - + getCompositeCommandRegistry().clear(); return new ICommandProxy(cc); } @@ -693,4 +685,78 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi protected boolean isEditPartTypeSuitableForEClass(Class<? extends GraphicalEditPart> editPartClass, EClass eClass) { return true; } + + /** + * the method provides command to create the binary link into the diagram. + * Find source/target adapter + * If the source and the target views do not exist, these views will be + * created. + * + * @see dropBinaryLink(CompositeCommand cc, Element source, Element target, int linkVISUALID + * , Point absoluteLocation, Element semanticLink) + * + * @param cc + * the composite command that will contain the set of command to + * create the binary link + * @param source + * source/target link node + * @param point + * source/target node location + */ + private IAdaptable findAdapter(CompositeCommand cc, Element source, Point dropLocation) { + IAdaptable result = getCompositeCommandRegistry().findAdapter(source); + if (result != null) { + return result; + } + GraphicalEditPart editPart = (GraphicalEditPart) lookForEditPart(source); + if (editPart == null) { + ICommand createCommand = getDefaultDropNodeCommand(dropLocation, source); + cc.add(createCommand); + result = (IAdaptable) createCommand.getCommandResult().getReturnValue(); + getCompositeCommandRegistry().registerAdapter(source, result); + return result; + } else { + return new SemanticAdapter(null, editPart.getModel()); + } + } + + /** + * Composite command items registry before adding to the diagram view + * + * @see CommonDiagramDragDropEditPolicy.findAdapter(CompositeCommand cc, Element source, Point dropLocation) + * @see MultiDependencyHelper.findOrCreateEndAdapter(CompositeCommand cc, Element source, Point dropLocation) + * @author + */ + public static class CompositeCommandRegistryHelper { + + private final Map<Element, IAdaptable> myElement2Adapter; + + /** + * public constructor + */ + public CompositeCommandRegistryHelper() { + myElement2Adapter = new HashMap<Element, IAdaptable>(); + } + + /** + * {@inheritDoc} + */ + public void clear() { + myElement2Adapter.clear(); + } + + /** + * {@inheritDoc} + */ + public IAdaptable findAdapter(Element element) { + return myElement2Adapter.get(element); + } + + /** + * {@inheritDoc} + */ + public void registerAdapter(Element element, IAdaptable adapter) { + myElement2Adapter.put(element, adapter); + } + } } |