diff options
author | Vincent Lorenzo | 2014-02-28 10:02:25 +0000 |
---|---|---|
committer | Vincent Lorenzo | 2014-02-28 12:32:17 +0000 |
commit | e474787bb7eb9cc760471002282ca52a0c5a9f7c (patch) | |
tree | 4aea3b8447399fa8f4f2428a32c9345e1545aff7 /plugins/sysml | |
parent | 0371c3178a303bc31b4aa7e2590c8f2e352e6849 (diff) | |
download | org.eclipse.papyrus-e474787bb7eb9cc760471002282ca52a0c5a9f7c.tar.gz org.eclipse.papyrus-e474787bb7eb9cc760471002282ca52a0c5a9f7c.tar.xz org.eclipse.papyrus-e474787bb7eb9cc760471002282ca52a0c5a9f7c.zip |
427129: Figures newly created via the palette should be snapped to grid
if "snap to grid" is activated
https://bugs.eclipse.org/bugs/show_bug.cgi?id=427129
Fix the bug for the port in IDB and BDD
Diffstat (limited to 'plugins/sysml')
-rw-r--r-- | plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/edit/policy/StructuredClassifierCreationEditPolicy.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/edit/policy/StructuredClassifierCreationEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/edit/policy/StructuredClassifierCreationEditPolicy.java index 258fa384432..ded500e86c8 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/edit/policy/StructuredClassifierCreationEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/edit/policy/StructuredClassifierCreationEditPolicy.java @@ -13,6 +13,7 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.edit.policy; +import java.util.Collections; import java.util.Iterator; import org.eclipse.draw2d.IFigure; @@ -22,6 +23,7 @@ import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.SnapToHelper; import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.UnexecutableCommand; import org.eclipse.gef.requests.ChangeBoundsRequest; @@ -37,6 +39,7 @@ import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescrip import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.gmf.diagram.common.commands.CreateViewCommand; +import org.eclipse.papyrus.infra.gmfdiag.common.snap.NodeSnapHelper; import org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator; /** @@ -121,11 +124,23 @@ public class StructuredClassifierCreationEditPolicy extends CreationEditPolicy { PortPositionLocator locator = new PortPositionLocator(getHostFigure(), PositionConstants.NONE); Rectangle proposedBounds = new Rectangle(requestedLocation, new Dimension(20, 20)); Rectangle preferredBounds = locator.getPreferredLocation(proposedBounds); - + + if(request.isSnapToEnabled()) { //request for snap port at the creation + //we find the best location with snap + Point wantedPoint = preferredBounds.getLocation(); + getHostFigure().translateToAbsolute(wantedPoint); + Rectangle portBounds = new Rectangle(wantedPoint, new Dimension(20, 20)); + NodeSnapHelper helper = new NodeSnapHelper((SnapToHelper)getHost().getAdapter(SnapToHelper.class), portBounds, false, false, true); + final ChangeBoundsRequest tmpRequest = new ChangeBoundsRequest("move"); //$NON-NLS-1$ + tmpRequest.setEditParts(Collections.emptyList()); + tmpRequest.setSnapToEnabled(true); + tmpRequest.setLocation(portBounds.getLocation()); + helper.snapPoint(tmpRequest); + preferredBounds.translate(tmpRequest.getMoveDelta()); + } // Convert the calculated preferred bounds as relative to parent location Rectangle creationBounds = preferredBounds.getTranslated(parentLoc.getNegated()); setBoundsCommand = new SetBoundsCommand(editingDomain, DiagramUIMessages.SetLocationCommand_Label_Resize, descriptor, creationBounds); - return setBoundsCommand; } |