diff options
author | Mickael ADAM | 2014-10-14 07:15:39 +0000 |
---|---|---|
committer | Mickael ADAM | 2014-10-14 15:50:38 +0000 |
commit | d532bac9fd32e9f2778f01a9cf5c010003f9537b (patch) | |
tree | 458adcb497a426d27fba9f800bd1cf92172c7371 | |
parent | bb7807ff7375acee6f549dab705a241c5bb2be27 (diff) | |
download | org.eclipse.papyrus-d532bac9fd32e9f2778f01a9cf5c010003f9537b.tar.gz org.eclipse.papyrus-d532bac9fd32e9f2778f01a9cf5c010003f9537b.tar.xz org.eclipse.papyrus-d532bac9fd32e9f2778f01a9cf5c010003f9537b.zip |
445794: [All Diagram] Label Alignment/Justification is lost when the
name is edited instead of the diagram is closed
-Create PapyrusLinkLabelDragPolicy
-Fix the bug
to fix the bug I changed xtend to permit the override of
createEditPolicy for LinkLabelEditPart.
Code will be generated in the next commit
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=445794
Change-Id: Ic66d9d844543f1e66318e190dd8bd91ca6190a7b
Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
16 files changed, 1065 insertions, 828 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/diagram/editparts/LinkLabelEditPart.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/diagram/editparts/LinkLabelEditPart.xtend index 92a862615da..03513d7a8c8 100644 --- a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/diagram/editparts/LinkLabelEditPart.xtend +++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/diagram/editparts/LinkLabelEditPart.xtend @@ -11,14 +11,15 @@ * Alexander Shatalin (Borland) - initial API and implementation * Michael Golubev (Montages) - #386838 - migrate to Xtend2 */ -package aspects.diagram.editparts
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.gmf.codegen.gmfgen.GenLinkLabel
-import org.eclipse.papyrus.papyrusgmfgenextension.LabelVisibilityPreference
-import xpt.Common
-
+package aspects.diagram.editparts + +import com.google.inject.Inject +import com.google.inject.Singleton +import org.eclipse.gmf.codegen.gmfgen.GenLinkLabel +import org.eclipse.papyrus.papyrusgmfgenextension.LabelVisibilityPreference +import xpt.Common +import org.eclipse.gmf.codegen.gmfgen.CustomBehaviour + @Singleton class LinkLabelEditPart extends diagram.editparts.LinkLabelEditPart{ @Inject extension Common; @@ -50,4 +51,24 @@ import xpt.Common ''' override extendsList(GenLinkLabel it) '''extends org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart''' + + override createDefaultEditPolicies(GenLinkLabel it) ''' + /** + * @generated Papyrus Generation + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new «diagram.getTextSelectionEditPolicyQualifiedClassName()»()); + ««« BEGIN: PapyrusGenCode + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy()); + ««« END: PapyrusGenCode + ««« Get the added custom behavoir + «FOR CustomBehaviour:it.behaviour.filter(typeof (CustomBehaviour))» + installEditPolicy(«CustomBehaviour.key», new «CustomBehaviour.editPolicyQualifiedClassName»()); + «ENDFOR» + } + ''' + } diff --git a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/impl/diagram/editparts/TextAware.xtend b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/impl/diagram/editparts/TextAware.xtend index 98166be601d..753a66250a3 100644 --- a/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/impl/diagram/editparts/TextAware.xtend +++ b/plugins/developer/org.eclipse.papyrus.def/xtend/aspects/impl/diagram/editparts/TextAware.xtend @@ -570,7 +570,7 @@ override refreshLabel(GenCommonBase it , GenDiagram diagram )''' maskLabelPolicy = getEditPolicy(org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); } if (maskLabelPolicy == null) { - View view = (View)getModel(); + org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View)getModel(); if(view.isVisible()) { setLabelTextHelper(getFigure(), getLabelText()); setLabelIconHelper(getFigure(), getLabelIcon()); diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java index 287e0c5552e..0fb482deddb 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java @@ -43,7 +43,6 @@ import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; public abstract class PapyrusLabelEditPart extends LabelEditPart { - /** * Default Margin when not present in CSS */ @@ -157,6 +156,13 @@ public abstract class PapyrusLabelEditPart extends LabelEditPart { } /** + * @return the papyrusLabelLocator + */ + public PapyrusLabelLocator getPapyrusLabelLocator() { + return papyrusLabelLocator; + } + + /** * Sets the external label locator. * * @param offset diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusLinkLabelDragPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusLinkLabelDragPolicy.java new file mode 100644 index 00000000000..f0dc39eb51e --- /dev/null +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusLinkLabelDragPolicy.java @@ -0,0 +1,97 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST and others. + * + * 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: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.helper.PapyrusLabelHelper; + + +/** + * The Class PapyrusLinkLabelDragPolicy. + * + * @author Mickael ADAM + */ +public class PapyrusLinkLabelDragPolicy extends NonResizableLabelEditPolicy { + + /** + * @see org.eclipse.gef.editpolicies.NonResizableEditPolicy#createSelectionHandles() + * + * @return + */ + @Override + protected List<MoveHandle> createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + /** + * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy#getMoveCommand(org.eclipse.gef.requests.ChangeBoundsRequest) + * + * @param request + * @return + */ + @Override + protected Command getMoveCommand(ChangeBoundsRequest request) { + LabelEditPart editPart = (LabelEditPart) getHost(); + Point refPoint = editPart.getReferencePoint(); + + // translate the feedback figure + PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + getHostFigure().translateToAbsolute(rect); + rect.translate(request.getMoveDelta()); + rect.resize(request.getSizeDelta()); + getHostFigure().translateToRelative(rect); + + if (editPart instanceof PapyrusLabelEditPart) { + // translate according to the text alignments + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + rect.translate(-getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.CENTER: + break; + case PositionConstants.RIGHT: + rect.translate(getHostFigure().getBounds().width / 2, 0); + break; + default: + break; + } + } + + Point normalPoint = PapyrusLabelHelper.offsetFromRelativeCoordinate(getHostFigure(), rect, refPoint); + + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, + new EObjectAdapter((View) editPart.getModel()), normalPoint); + return new ICommandProxy(moveCommand); + } +} diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java index 74a3fb970c9..52e2be18b8b 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/RefreshTextAlignmentEditPolicy.java @@ -16,26 +16,30 @@ package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies; import org.eclipse.core.databinding.observable.ChangeEvent; import org.eclipse.core.databinding.observable.IChangeListener; import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.GraphicalEditPolicyEx; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStringStyleObservableValue; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; /** * this edit policy has in charge to refresh the edit part when text alignment change. */ public class RefreshTextAlignmentEditPolicy extends GraphicalEditPolicyEx implements IChangeListener { - /** The Constant TEXT_ALIGNMENT. */ - public static final String TEXT_ALIGNMENT = "textAlignment";//$NON-NLS-N$ - /** key for this edit policy. */ public final static String REFRESH_TEXT_ALIGNMENT_EDITPOLICY = "Refresh text alignment edit policy";//$NON-NLS-N$ /** The style observable. */ protected IObservableValue styleObservable; - protected IObservableValue positionObservable; + /** The view. */ + private View view; /** * @@ -44,14 +48,16 @@ public class RefreshTextAlignmentEditPolicy extends GraphicalEditPolicyEx implem @Override public void activate() { // retrieve the view and the element managed by the edit part - View view = (View) getHost().getModel(); + view = (View) getHost().getModel(); if (view == null) { return; } - // add style observable value - styleObservable = new CustomStringStyleObservableValue(view, EMFHelper.resolveEditingDomain(view), TEXT_ALIGNMENT); - styleObservable.addChangeListener(this); + if (getHost() instanceof PapyrusLabelEditPart) { + // add style observable value + styleObservable = new CustomStringStyleObservableValue(view, EMFHelper.resolveEditingDomain(view), PapyrusLabelEditPart.TEXT_ALIGNMENT); + styleObservable.addChangeListener(this); + } getHost().refresh(); } @@ -75,7 +81,33 @@ public class RefreshTextAlignmentEditPolicy extends GraphicalEditPolicyEx implem */ @Override public void handleChange(ChangeEvent event) { + + if (getHost() instanceof PapyrusLabelEditPart) { + // set the position to avoid that position move on text alignment change + PapyrusLabelEditPart editPart = (PapyrusLabelEditPart) getHost(); + + IFigure figure = editPart.getFigure(); + + ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE); + req.setEditParts(editPart); + req.setLocation(figure.getBounds().getLocation()); + Command command = editPart.getCommand(req); + if (command != null && command.canExecute()) { + TransactionUtil.getEditingDomain(view).getCommandStack().execute(GEFtoEMFCommandWrapper.wrap(command)); + } + + } + + // Save new location only on change + // final Point offset = newOffset; + // ChangeBoundsRequest req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); + // req.setEditParts(editPart); + // req.setLocation(offset); + // Command command = editPart.getCommand(req); + // if (command != null && command.canExecute() && !cachedIsConstrained) { + // TransactionUtil.getEditingDomain(view).getCommandStack().execute(GEFtoEMFCommandWrapper.wrap(command)); + // } + getHost().refresh(); } - } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java index f63c9d1de1f..18f22a38e20 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/locator/PapyrusLabelLocator.java @@ -23,16 +23,9 @@ import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; import org.eclipse.gmf.runtime.diagram.ui.internal.util.LabelViewConstants; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg; import org.eclipse.gmf.runtime.draw2d.ui.geometry.PointListUtilities; -import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.Activator; import org.eclipse.papyrus.infra.gmfdiag.common.helper.PapyrusLabelHelper; /** @@ -42,58 +35,27 @@ import org.eclipse.papyrus.infra.gmfdiag.common.helper.PapyrusLabelHelper; */ public class PapyrusLabelLocator extends AbstractLocator { - /** the parent figure of this locator. */ - protected IFigure parent; - /** The alignment. */ private int alignment; - /** The offset. */ - private Point offset; - /** The extent. */ private Dimension extent; - /** The cached string. */ - private String cachedString; - - /** The text alignment. */ - private int textAlignment = PositionConstants.MIDDLE; - - /** - * Gets the text alignment. - * - * @return the textAlignment - */ - public int getTextAlignment() { - return textAlignment; - } + /** The margin. */ + private Point margin = new Point(); - /** - * Sets the text alignment. - * - * @param textAlignment - * the textAlignment to set - */ - public void setTextAlignment(int textAlignment) { - this.textAlignment = textAlignment; - } + /** The offset. */ + private Point offset; - /** The cached bounds. */ - private Rectangle cachedBounds = new Rectangle(); + /** the parent figure of this locator. */ + protected IFigure parent; - /** The cached offset. */ - private Point cachedOffset; + /** The text alignment. */ + private int textAlignment = PositionConstants.MIDDLE; /** The view. */ private View view; - /** The cached segment. */ - private LineSeg cachedSegment; - - /** The margin. */ - private Point margin = new Point(); - /** * Constructor to create a an instance of <code>LabelLocator</code> which locates an IFigure offset relative to a calculated reference point. * @@ -127,6 +89,35 @@ public class PapyrusLabelLocator extends AbstractLocator { } /** + * Returns the alignment of ConnectionLocator. + * + * @return The alignment + * + */ + public int getAlignment() { + return alignment; + } + + /** + * Gets the location. + * + * @return the location + */ + @SuppressWarnings("restriction") + private int getLocation() { + switch (getAlignment()) { + case ConnectionLocator.SOURCE: + return LabelViewConstants.TARGET_LOCATION; + case ConnectionLocator.TARGET: + return LabelViewConstants.SOURCE_LOCATION; + case ConnectionLocator.MIDDLE: + return LabelViewConstants.MIDDLE_LOCATION; + default: + return LabelViewConstants.MIDDLE_LOCATION; + } + } + + /** * getter for the offset point. * * @return point @@ -136,13 +127,52 @@ public class PapyrusLabelLocator extends AbstractLocator { } /** - * setter for the offset point. + * Returns the <code>PointList</code> describing the label's parent. * - * @param offset - * the new offset + * @return pointList */ - public void setOffset(Point offset) { - this.offset = offset; + protected PointList getPointList() { + if (parent instanceof Connection) { + return ((Connection) parent).getPoints(); + } else { + PointList ptList = new PointList(); + ptList.addPoint(parent.getBounds().getLocation()); + return ptList; + } + } + + /** + * Returns the reference point for the locator. + * + * @return the reference point + */ + @Override + public Point getReferencePoint() { + if (parent instanceof Connection) { + PointList ptList = ((Connection) parent).getPoints(); + return PointListUtilities.calculatePointRelativeToLine(ptList, 0, getLocation(), true); + } else { + return parent.getBounds().getLocation(); + } + } + + /** + * Gets the size. + * + * @return the size + */ + public Dimension getSize() { + return extent.getCopy(); + } + + + /** + * Gets the text alignment. + * + * @return the textAlignment + */ + public int getTextAlignment() { + return textAlignment; } /** @@ -155,11 +185,9 @@ public class PapyrusLabelLocator extends AbstractLocator { @Override public void relocate(IFigure target) { - // The calculation of the location depends on the size of the shape so - // the size must be set first. + // The calculation of the location depends on the size of the shape so the size must be set first. Dimension size = new Dimension(); - if (extent != null) { PapyrusLabelLocator currentConstraint = (PapyrusLabelLocator) target.getParent().getLayoutManager().getConstraint(target); Dimension currentExtent = currentConstraint.getSize(); @@ -175,114 +203,27 @@ public class PapyrusLabelLocator extends AbstractLocator { target.setSize(new Dimension(target.getPreferredSize().width, target.getPreferredSize().height)); } - // Get the segment - PointList ptLst = PapyrusLabelHelper.getParentPointList(target); - int index = PointListUtilities.findNearestLineSegIndexOfPoint(ptLst, getReferencePoint()); - LineSeg segment = (LineSeg) PointListUtilities.getLineSegments(ptLst).get(index - 1); - Point location = null; - // If it's a rename - if (cachedString != null && !cachedString.equals(((WrappingLabel) target).getText())) { - location = cachedBounds.getLocation(); - int x; - int textWidth = ((IFigure) target.getChildren().get(0)).getBounds().width; - - // Set Location - switch (textAlignment) { - case PositionConstants.LEFT: - x = 0; - break; - case PositionConstants.RIGHT: - x = textWidth - cachedBounds.width + margin.x; - break; - case PositionConstants.CENTER: - x = (textWidth - cachedBounds.width + margin.x) / 2; - break; - default: - x = 0; - break; - } - location.translate(x, 0); - IFigure tmpTarget = target; - tmpTarget.translate(x, 0); - final Point viewLocation = PapyrusLabelHelper.offsetFromRelativeCoordinate(tmpTarget, cachedBounds, getReferencePoint()); - try { - TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(view); - org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.utils.TransactionHelper.run(domain, new Runnable() { - - @Override - public void run() { - // Add modelStylesheet to the resource without command - ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X(), Integer.valueOf(viewLocation.x)); - ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y(), Integer.valueOf(viewLocation.y)); - } - }); - } catch (Exception e) { - Activator.log.debug(e.toString()); - } - } else - // At the creation or It's a d&d move or // If it a move the connection - if (cachedBounds.height == 0 || !offset.equals(cachedOffset) || !segment.equals(cachedSegment)) { - location = PapyrusLabelHelper.relativeCoordinateFromOffset(target, getReferencePoint(), offset); - // cachedString = ((WrappingLabel) target).getText(); - } else { - // nothing change, in refresh case - location = cachedBounds.getLocation(); + // Calculate the position + location = PapyrusLabelHelper.relativeCoordinateFromOffset(target, getReferencePoint(), offset); + + // Translate the position according to the justification + switch (textAlignment) { + case PositionConstants.LEFT: + location.translate(target.getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + location.translate(-target.getBounds().width / 2, 0); + break; + case PositionConstants.CENTER: + break; + default: + break; } // Set the location target.setLocation(location); - - // cache actual values - cachedString = ((WrappingLabel) target).getText(); - cachedBounds = target.getBounds(); - cachedOffset = offset; - cachedSegment = segment; - } - - /** - * Returns the reference point for the locator. - * - * @return the reference point - */ - @Override - protected Point getReferencePoint() { - if (parent instanceof Connection) { - PointList ptList = ((Connection) parent).getPoints(); - return PointListUtilities.calculatePointRelativeToLine(ptList, 0, getLocation(), true); - } else { - return parent.getBounds().getLocation(); - } - } - - - /** - * Gets the location. - * - * @return the location - */ - private int getLocation() { - switch (getAlignment()) { - case ConnectionLocator.SOURCE: - return LabelViewConstants.TARGET_LOCATION; - case ConnectionLocator.TARGET: - return LabelViewConstants.SOURCE_LOCATION; - case ConnectionLocator.MIDDLE: - return LabelViewConstants.MIDDLE_LOCATION; - default: - return LabelViewConstants.MIDDLE_LOCATION; - } - } - - /** - * Returns the alignment of ConnectionLocator. - * - * @return The alignment - * - */ - public int getAlignment() { - return alignment; } /** @@ -297,47 +238,43 @@ public class PapyrusLabelLocator extends AbstractLocator { /** - * Gets the size. + * Sets the margin. * - * @return the size + * @param margin + * the margin to set */ - public Dimension getSize() { - return extent.getCopy(); + public void setMargin(Point margin) { + this.margin = margin; } /** - * Returns the <code>PointList</code> describing the label's parent. + * setter for the offset point. * - * @return pointList + * @param offset + * the new offset */ - protected PointList getPointList() { - if (parent instanceof Connection) { - return ((Connection) parent).getPoints(); - } else { - PointList ptList = new PointList(); - ptList.addPoint(parent.getBounds().getLocation()); - return ptList; - } + public void setOffset(Point offset) { + this.offset = offset; } /** - * Sets the view. + * Sets the text alignment. * - * @param view - * the new view + * @param textAlignment + * the textAlignment to set */ - public void setView(View view) { - this.view = view; + public void setTextAlignment(int textAlignment) { + this.textAlignment = textAlignment; } /** - * Sets the margin. + * Sets the view. * - * @param margin - * the margin to set + * @param view + * the new view */ - public void setMargin(Point margin) { - this.margin = margin; + public void setView(View view) { + this.view = view; } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ExternalLabelPrimaryDragRoleEditPolicy.java index 108eeff46c1..0b305132f46 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -16,6 +16,7 @@ package org.eclipse.papyrus.gmf.diagram.common.edit.policy; import java.util.Collections; import java.util.List; +import org.eclipse.draw2d.PositionConstants; import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.gef.GraphicalEditPart; @@ -30,6 +31,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPoli import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; /** * This policy provides the selection handles, feedback and move command for @@ -69,6 +71,22 @@ public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEdi rect.resize(request.getSizeDelta()); getHostFigure().translateToRelative(rect); + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedRect.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedRect.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect); return new ICommandProxy(moveCommand); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java index e7335fe616c..6505f7f2c24 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -1,69 +1,87 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.activity.edit.policies;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * This policy provides the selection handles, feedback and move command for
- * external node label.
- * The expected behavior is to provide an external label that can freely move and with a link feedback
- * towards its parent figure during the move.
- */
-public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy {
-
- @Override
- protected List<?> createSelectionHandles() {
- MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
- mh.setBorder(null);
- return Collections.singletonList(mh);
- }
-
- @Override
- protected Command getMoveCommand(ChangeBoundsRequest request) {
- LabelEditPart editPart = (LabelEditPart) getHost();
-
- // FeedBack - Port + Delta
- Rectangle updatedRect = new Rectangle();
- PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated());
- updatedRect = updatedRect.getTranslated(request.getMoveDelta());
-
- // translate the feedback figure
- PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- getHostFigure().translateToAbsolute(rect);
- rect.translate(request.getMoveDelta());
- rect.resize(request.getSizeDelta());
- getHostFigure().translateToRelative(rect);
-
- ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect);
- return new ICommandProxy(moveCommand);
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.activity.edit.policies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; + +/** + * This policy provides the selection handles, feedback and move command for + * external node label. + * The expected behavior is to provide an external label that can freely move and with a link feedback + * towards its parent figure during the move. + */ +public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy { + + @Override + protected List<?> createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + @Override + protected Command getMoveCommand(ChangeBoundsRequest request) { + LabelEditPart editPart = (LabelEditPart) getHost(); + + // FeedBack - Port + Delta + Rectangle updatedRect = new Rectangle(); + PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated()); + updatedRect = updatedRect.getTranslated(request.getMoveDelta()); + + // translate the feedback figure + PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + getHostFigure().translateToAbsolute(rect); + rect.translate(request.getMoveDelta()); + rect.resize(request.getSizeDelta()); + getHostFigure().translateToRelative(rect); + + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedRect.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedRect.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect); + return new ICommandProxy(moveCommand); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ExternalLabelPrimaryDragRoleEditPolicy.java index be1d93db781..e9dab4de935 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -1,66 +1,86 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.clazz.custom.policies;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * This policy provides the selection handles, feedback and move command for
- * external node label.
- * The expected behavior is to provide an external label that can freely move and with a link feedback
- * towards its parent figure during the move.
- */
-public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy {
-
- @Override
- protected List<MoveHandle> createSelectionHandles() {
- MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
- mh.setBorder(null);
- return Collections.singletonList(mh);
- }
-
- @Override
- protected Command getMoveCommand(ChangeBoundsRequest request) {
- LabelEditPart editPart = (LabelEditPart) getHost();
- // FeedBack - Port + Delta
- Rectangle updatedRect = new Rectangle();
- PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated());
- updatedRect = updatedRect.getTranslated(request.getMoveDelta());
- // translate the feedback figure
- PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- getHostFigure().translateToAbsolute(rect);
- rect.translate(request.getMoveDelta());
- rect.resize(request.getSizeDelta());
- getHostFigure().translateToRelative(rect);
- ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect);
- return new ICommandProxy(moveCommand);
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.clazz.custom.policies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; + +/** + * This policy provides the selection handles, feedback and move command for + * external node label. + * The expected behavior is to provide an external label that can freely move and with a link feedback + * towards its parent figure during the move. + */ +public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy { + + @Override + protected List<MoveHandle> createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + @Override + protected Command getMoveCommand(ChangeBoundsRequest request) { + LabelEditPart editPart = (LabelEditPart) getHost(); + // FeedBack - Port + Delta + Rectangle updatedRect = new Rectangle(); + PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated()); + updatedRect = updatedRect.getTranslated(request.getMoveDelta()); + // translate the feedback figure + PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + + getHostFigure().translateToAbsolute(rect); + rect.translate(request.getMoveDelta()); + rect.resize(request.getSizeDelta()); + getHostFigure().translateToRelative(rect); + + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedRect.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedRect.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect); + return new ICommandProxy(moveCommand); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/locator/ExternalLabelPositionLocator.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/locator/ExternalLabelPositionLocator.java index 6e8691e4699..2600026dc9c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/locator/ExternalLabelPositionLocator.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/locator/ExternalLabelPositionLocator.java @@ -21,16 +21,15 @@ import org.eclipse.draw2d.PositionConstants; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.gef.EditPart; -import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart; import org.eclipse.papyrus.infra.gmfdiag.common.locator.IPapyrusBorderItemLocator; -import org.eclipse.papyrus.uml.diagram.common.Activator; /** * This class is used to constrain the position of ExternalNodeLabel. The @@ -52,10 +51,7 @@ public class ExternalLabelPositionLocator implements IPapyrusBorderItemLocator { private Dimension offset = new Dimension(); /** The constrained. */ - private boolean constrained = false; - - /** The cached string. */ - private String cachedString; + private boolean isConstrained = false; /** The text alignment. */ private int textAlignment; @@ -75,8 +71,9 @@ public class ExternalLabelPositionLocator implements IPapyrusBorderItemLocator { this.editPart = editPart; } - /** The margin. */ - private Point margin = new Point(); + private boolean cachedIsConstrained = false; + + private Point margin; /** * Sets the view. @@ -138,7 +135,7 @@ public class ExternalLabelPositionLocator implements IPapyrusBorderItemLocator { */ @Override public boolean isConstrained() { - return constrained; + return isConstrained; } /** @@ -149,7 +146,7 @@ public class ExternalLabelPositionLocator implements IPapyrusBorderItemLocator { */ @Override public void setConstrained(boolean constrained) { - this.constrained = constrained; + this.isConstrained = constrained; } /** @@ -222,82 +219,72 @@ public class ExternalLabelPositionLocator implements IPapyrusBorderItemLocator { proposedBounds.setLocation(constraint.getLocation().translate(parentFigure.getBounds().getTopLeft())); proposedBounds.setSize(target.getPreferredSize()); - if (constrained) { + + if (isConstrained) { // TO_FIX if there is more than one label Point newconstraint; + Point newOffset; // Set the translation when alignment is auto switch (getPositionOnParent()) { case PositionConstants.WEST: // alignRight: newconstraint = new Point(-proposedBounds.width - offset.width, offset.height); + newOffset = new Point(newconstraint.x + proposedBounds.width, newconstraint.y); break; case PositionConstants.EAST: // alignLeft newconstraint = new Point(parentFigure.getBounds().width + offset.width, offset.height); + newOffset = new Point(newconstraint.x, newconstraint.y); break; case PositionConstants.NORTH: // alignLeft center to the north newconstraint = new Point(-proposedBounds.width / 2 + offset.width, -parentFigure.getBounds().height - offset.height); + newOffset = new Point(newconstraint.x, newconstraint.y); break; case PositionConstants.SOUTH: // alignLeft center to the south newconstraint = new Point(-proposedBounds.width / 2 + offset.width, parentFigure.getBounds().height + offset.height); + newOffset = new Point(newconstraint.x, newconstraint.y); break; default: - // the default is the like the EAST + // the default is like the EAST newconstraint = new Point(proposedBounds.width + offset.width, offset.height); + newOffset = new Point(newconstraint.x, newconstraint.y); break; } proposedBounds.setLocation(newconstraint.translate(parentFigure.getBounds().getTopLeft())); - } else - // If the label changed - if (cachedString != null && !cachedString.equals(((WrappingLabel) target).getText())) { - int x; - int textWidth = target.getBounds().width; + // Save new location only on change + final Point offset = newOffset; + ChangeBoundsRequest req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); + req.setEditParts(editPart); + req.setLocation(offset); + Command command = editPart.getCommand(req); + if (command != null && command.canExecute()) { + TransactionUtil.getEditingDomain(view).getCommandStack().execute(GEFtoEMFCommandWrapper.wrap(command)); + } + } else { + int x; // Set Location switch (textAlignment) { case PositionConstants.LEFT: x = 0; break; case PositionConstants.RIGHT: - x = textWidth - proposedBounds.width; + x = -proposedBounds.width; break; case PositionConstants.CENTER: - x = (textWidth - proposedBounds.width) / 2; + x = -proposedBounds.width / 2; break; default: x = 0; break; } - - Point offsettmp = constraint.getLocation(); - offsettmp.translate(x, 0); - final Point offset = offsettmp.getCopy(); - proposedBounds.translate(x, 0); - if (view != null) { - try { - TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(view); - org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.utils.TransactionHelper.run(domain, new Runnable() { - - @Override - public void run() { - // Set location to the resource without command - ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X(), Integer.valueOf(offset.x)); - ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y(), Integer.valueOf(offset.y)); - } - }); - } catch (Exception e) { - Activator.log.debug(e.toString()); - } - } } target.setBounds(proposedBounds); - if (target instanceof WrappingLabel){ - cachedString = ((WrappingLabel) target).getText(); - } + cachedIsConstrained = isConstrained; } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java index 07d187951a3..be098992960 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -1,70 +1,88 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- * Saadia DHOUIB (CEA LIST) saadia.dhouib@cea.fr - adapted from class diagram
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.communication.custom.edit.policies;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * This policy provides the selection handles, feedback and move command for
- * external node label. The expected behavior is to provide an external label
- * that can freely move and with a link feedback towards its parent figure
- * during the move.
- */
-public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy {
-
- @SuppressWarnings("rawtypes")
- @Override
- protected List createSelectionHandles() {
- MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
- mh.setBorder(null);
- return Collections.singletonList(mh);
- }
-
- @Override
- protected Command getMoveCommand(ChangeBoundsRequest request) {
- LabelEditPart editPart = (LabelEditPart) getHost();
-
- // FeedBack - Port + Delta
- Rectangle updatedRect = new Rectangle();
- PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated());
- updatedRect = updatedRect.getTranslated(request.getMoveDelta());
-
- // translate the feedback figure
- PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- getHostFigure().translateToAbsolute(rect);
- rect.translate(request.getMoveDelta());
- rect.resize(request.getSizeDelta());
- getHostFigure().translateToRelative(rect);
-
- ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect);
- return new ICommandProxy(moveCommand);
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * Saadia DHOUIB (CEA LIST) saadia.dhouib@cea.fr - adapted from class diagram + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.communication.custom.edit.policies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; + +/** + * This policy provides the selection handles, feedback and move command for + * external node label. The expected behavior is to provide an external label + * that can freely move and with a link feedback towards its parent figure + * during the move. + */ +public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy { + + @SuppressWarnings("rawtypes") + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + @Override + protected Command getMoveCommand(ChangeBoundsRequest request) { + LabelEditPart editPart = (LabelEditPart) getHost(); + + // FeedBack - Port + Delta + Rectangle updatedRect = new Rectangle(); + PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated()); + updatedRect = updatedRect.getTranslated(request.getMoveDelta()); + + // translate the feedback figure + PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + getHostFigure().translateToAbsolute(rect); + rect.translate(request.getMoveDelta()); + rect.resize(request.getSizeDelta()); + getHostFigure().translateToRelative(rect); + + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedRect.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedRect.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect); + return new ICommandProxy(moveCommand); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java index 37f3756df9f..7b0a53fd7cf 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -1,86 +1,103 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.component.custom.edit.policies;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-
-// TODO: Auto-generated Javadoc
-/**
- * This policy provides the selection handles, feedback and move command for
- * external node label.
- * The expected behavior is to provide an external label that can freely move and with a link feedback
- * towards its parent figure during the move.
- */
-public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy {
-
- /**
- * Creates the selection handles.
- *
- * @return the list
- * @see org.eclipse.gef.editpolicies.NonResizableEditPolicy#createSelectionHandles()
- */
-
- @Override
- protected List<?> createSelectionHandles() {
- MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
- mh.setBorder(null);
- return Collections.singletonList(mh);
- }
-
- /**
- * Gets the move command.
- *
- * @param request
- * the request
- * @return the move command
- * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy#getMoveCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
- */
-
- @Override
- protected Command getMoveCommand(ChangeBoundsRequest request) {
- LabelEditPart editPart = (LabelEditPart) getHost();
-
- // FeedBack - Port + Delta
- Rectangle updatedRect = new Rectangle();
- PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated());
- updatedRect = updatedRect.getTranslated(request.getMoveDelta());
-
- // translate the feedback figure
- PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- getHostFigure().translateToAbsolute(rect);
- rect.translate(request.getMoveDelta());
- rect.resize(request.getSizeDelta());
- getHostFigure().translateToRelative(rect);
-
- ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect);
- return new ICommandProxy(moveCommand);
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.component.custom.edit.policies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; + +/** + * This policy provides the selection handles, feedback and move command for + * external node label. + * The expected behavior is to provide an external label that can freely move and with a link feedback + * towards its parent figure during the move. + */ +public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy { + + /** + * Creates the selection handles. + * + * @return the list + * @see org.eclipse.gef.editpolicies.NonResizableEditPolicy#createSelectionHandles() + */ + + @Override + protected List<?> createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + /** + * Gets the move command. + * + * @param request + * the request + * @return the move command + * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy#getMoveCommand(org.eclipse.gef.requests.ChangeBoundsRequest) + */ + + @Override + protected Command getMoveCommand(ChangeBoundsRequest request) { + LabelEditPart editPart = (LabelEditPart) getHost(); + + // FeedBack - Port + Delta + Rectangle updatedRect = new Rectangle(); + PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated()); + updatedRect = updatedRect.getTranslated(request.getMoveDelta()); + + // translate the feedback figure + PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + getHostFigure().translateToAbsolute(rect); + rect.translate(request.getMoveDelta()); + rect.resize(request.getSizeDelta()); + getHostFigure().translateToRelative(rect); + + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedRect.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedRect.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect); + return new ICommandProxy(moveCommand); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java index ff196ca978a..7b2f1ff512f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -1,82 +1,92 @@ -/*****************************************************************************
- * Copyright (c) 2009-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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Manage BorderItemContainerFigure into the getMoveCommand
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.internal.figures.BorderItemContainerFigure;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * This policy provides the selection handles, feedback and move command for
- * external node label.
- * The expected behavior is to provide an external label that can freely move and with a link feedback
- * towards its parent figure during the move.
- */
-public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy {
-
- @Override
- protected List<?> createSelectionHandles() {
- MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
- mh.setBorder(null);
- return Collections.singletonList(mh);
- }
-
- @Override
- protected Command getMoveCommand(ChangeBoundsRequest request) {
- LabelEditPart editPart = (LabelEditPart) getHost();
-
- // FeedBack - Port + Delta
- Rectangle updatedRect = new Rectangle();
- PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- // in case of bordered item figure bounds is 1x1, real parent figure is then the grandParent
- if (getHostFigure().getParent() instanceof BorderItemContainerFigure){
- updatedRect = initialRect.getTranslated(getHostFigure().getParent().getParent().getBounds().getLocation().getNegated());
- }else{
- updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated());
- }
- updatedRect = updatedRect.getTranslated(request.getMoveDelta());
-
-
- // translate the feedback figure
- PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- getHostFigure().translateToAbsolute(rect);
- rect.translate(request.getMoveDelta());
- rect.resize(request.getSizeDelta());
- getHostFigure().translateToRelative(rect);
-
- ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect);
-
- return new ICommandProxy(moveCommand);
-
- }
-
-
-
-}
+/***************************************************************************** + * Copyright (c) 2009-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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Manage BorderItemContainerFigure into the getMoveCommand + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.internal.figures.BorderItemContainerFigure; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; + +/** + * This policy provides the selection handles, feedback and move command for + * external node label. + * The expected behavior is to provide an external label that can freely move and with a link feedback + * towards its parent figure during the move. + */ +public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy { + + @Override + protected List<?> createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + @Override + protected Command getMoveCommand(ChangeBoundsRequest request) { + LabelEditPart editPart = (LabelEditPart) getHost(); + + // FeedBack - Parent + Delta + Rectangle updatedRect = new Rectangle(); + PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + // in case of bordered item figure bounds is 1x1, real parent figure is then the grandParent + if (getHostFigure().getParent() instanceof BorderItemContainerFigure) { + updatedRect = initialRect.getTranslated(getHostFigure().getParent().getParent().getBounds().getLocation().getNegated()); + } else { + updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated()); + } + updatedRect = updatedRect.getTranslated(request.getMoveDelta()); + + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedRect.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedRect.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect); + + return new ICommandProxy(moveCommand); + + } + + + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java index 33b40b6cd65..6cbef7657e5 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -1,66 +1,85 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * This policy provides the selection handles, feedback and move command for
- * external node label.
- * The expected behavior is to provide an external label that can freely move and with a link feedback
- * towards its parent figure during the move.
- */
-public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy {
-
- @Override
- protected List<?> createSelectionHandles() {
- MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
- mh.setBorder(null);
- return Collections.singletonList(mh);
- }
-
- @Override
- protected Command getMoveCommand(ChangeBoundsRequest request) {
- LabelEditPart editPart = (LabelEditPart) getHost();
- // FeedBack - Port + Delta
- Rectangle updatedRect = new Rectangle();
- PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated());
- updatedRect = updatedRect.getTranslated(request.getMoveDelta());
- // translate the feedback figure
- PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- getHostFigure().translateToAbsolute(rect);
- rect.translate(request.getMoveDelta());
- rect.resize(request.getSizeDelta());
- getHostFigure().translateToRelative(rect);
- ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect);
- return new ICommandProxy(moveCommand);
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.sequence.edit.policies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; + +/** + * This policy provides the selection handles, feedback and move command for + * external node label. + * The expected behavior is to provide an external label that can freely move and with a link feedback + * towards its parent figure during the move. + */ +public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy { + + @Override + protected List<?> createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + @Override + protected Command getMoveCommand(ChangeBoundsRequest request) { + LabelEditPart editPart = (LabelEditPart) getHost(); + // FeedBack - Port + Delta + Rectangle updatedRect = new Rectangle(); + PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated()); + updatedRect = updatedRect.getTranslated(request.getMoveDelta()); + // translate the feedback figure + PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + getHostFigure().translateToAbsolute(rect); + rect.translate(request.getMoveDelta()); + rect.resize(request.getSizeDelta()); + getHostFigure().translateToRelative(rect); + + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedRect.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedRect.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect); + return new ICommandProxy(moveCommand); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.timing/custom-src/org/eclipse/papyrus/uml/diagram/timing/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.timing/custom-src/org/eclipse/papyrus/uml/diagram/timing/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java index e53dd438ab4..d400432f537 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.timing/custom-src/org/eclipse/papyrus/uml/diagram/timing/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.timing/custom-src/org/eclipse/papyrus/uml/diagram/timing/custom/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -1,78 +1,96 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- * Nicolas Bros (Mia-Software) - remove dead code, refresh on execute/undo/redo
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.timing.custom.edit.policies;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.FigureUtils;
-import org.eclipse.papyrus.uml.diagram.timing.custom.edit.commands.RefreshCommandForDo;
-import org.eclipse.papyrus.uml.diagram.timing.custom.edit.commands.RefreshCommandForUndo;
-
-/**
- * This policy provides the selection handles, feedback and move command for an external node label. The expected
- * behavior is to provide an external label that can freely move and with a link feedback towards its parent figure
- * during the move.
- *
- * @author nbros : I copied this class from
- * org.eclipse.papyrus.uml.diagram.clazz.custom.policies.ExternalLabelPrimaryDragRoleEditPolicy, removed dead
- * code, added a Refresh, and constrained the bounds within the containing compartment.
- */
-public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy {
-
- @Override
- protected List<?> createSelectionHandles() {
- final MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
- mh.setBorder(null);
- return Collections.singletonList(mh);
- }
-
- @Override
- protected Command getMoveCommand(final ChangeBoundsRequest request) {
- final LabelEditPart editPart = (LabelEditPart) getHost();
-
- final IFigure parentFigure = getHostFigure().getParent();
- final Rectangle parentBounds = parentFigure.getBounds();
-
- // First, start from the original bounds
- Rectangle updatedBounds = new Rectangle(getInitialFeedbackBounds());
- // Add the delta corresponding to the move
- updatedBounds = updatedBounds.getTranslated(FigureUtils.scaleByZoom(request.getMoveDelta(), parentFigure));
- // Constrain the bounds within the containing compartment if any
- updatedBounds = FigureUtils.constrainBoundsWithinContainingCompartment(updatedBounds, getHostFigure());
- // Then translate the bounds so that they are relative to the figure (BorderItemContainerFigure)
- // to which the label is attached
- updatedBounds = updatedBounds.getTranslated(parentBounds.getLocation().getNegated());
-
- final CompoundCommand compoundCommand = new CompoundCommand();
- compoundCommand.add(new RefreshCommandForUndo((GraphicalEditPart) editPart.getParent().getParent()));
- compoundCommand.add(new ICommandProxy(new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedBounds)));
- compoundCommand.add(new RefreshCommandForDo(editPart));
- return compoundCommand;
- }
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * Nicolas Bros (Mia-Software) - remove dead code, refresh on execute/undo/redo + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.timing.custom.edit.policies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.utils.FigureUtils; +import org.eclipse.papyrus.uml.diagram.timing.custom.edit.commands.RefreshCommandForDo; +import org.eclipse.papyrus.uml.diagram.timing.custom.edit.commands.RefreshCommandForUndo; + +/** + * This policy provides the selection handles, feedback and move command for an external node label. The expected + * behavior is to provide an external label that can freely move and with a link feedback towards its parent figure + * during the move. + * + * @author nbros : I copied this class from + * org.eclipse.papyrus.uml.diagram.clazz.custom.policies.ExternalLabelPrimaryDragRoleEditPolicy, removed dead + * code, added a Refresh, and constrained the bounds within the containing compartment. + */ +public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy { + + @Override + protected List<?> createSelectionHandles() { + final MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + @Override + protected Command getMoveCommand(final ChangeBoundsRequest request) { + final LabelEditPart editPart = (LabelEditPart) getHost(); + + final IFigure parentFigure = getHostFigure().getParent(); + final Rectangle parentBounds = parentFigure.getBounds(); + + // First, start from the original bounds + Rectangle updatedBounds = new Rectangle(getInitialFeedbackBounds()); + // Add the delta corresponding to the move + updatedBounds = updatedBounds.getTranslated(FigureUtils.scaleByZoom(request.getMoveDelta(), parentFigure)); + // Constrain the bounds within the containing compartment if any + updatedBounds = FigureUtils.constrainBoundsWithinContainingCompartment(updatedBounds, getHostFigure()); + // Then translate the bounds so that they are relative to the figure (BorderItemContainerFigure) + // to which the label is attached + updatedBounds = updatedBounds.getTranslated(parentBounds.getLocation().getNegated()); + + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedBounds.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedBounds.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + + final CompoundCommand compoundCommand = new CompoundCommand(); + compoundCommand.add(new RefreshCommandForUndo((GraphicalEditPart) editPart.getParent().getParent())); + compoundCommand.add(new ICommandProxy(new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedBounds))); + compoundCommand.add(new RefreshCommandForDo(editPart)); + return compoundCommand; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java index f5dc9cf2681..7652ae1dbfa 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.usecase/custom-src/org/eclipse/papyrus/uml/diagram/usecase/edit/policies/ExternalLabelPrimaryDragRoleEditPolicy.java @@ -1,66 +1,85 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.usecase.edit.policies;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * This policy provides the selection handles, feedback and move command for
- * external node label.
- * The expected behavior is to provide an external label that can freely move and with a link feedback
- * towards its parent figure during the move.
- */
-public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy {
-
- @Override
- protected List<?> createSelectionHandles() {
- MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost());
- mh.setBorder(null);
- return Collections.singletonList(mh);
- }
-
- @Override
- protected Command getMoveCommand(ChangeBoundsRequest request) {
- LabelEditPart editPart = (LabelEditPart) getHost();
- // FeedBack - Port + Delta
- Rectangle updatedRect = new Rectangle();
- PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated());
- updatedRect = updatedRect.getTranslated(request.getMoveDelta());
- // translate the feedback figure
- PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- getHostFigure().translateToAbsolute(rect);
- rect.translate(request.getMoveDelta());
- rect.resize(request.getSizeDelta());
- getHostFigure().translateToRelative(rect);
- ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect);
- return new ICommandProxy(moveCommand);
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.usecase.edit.policies; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.MoveHandle; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; + +/** + * This policy provides the selection handles, feedback and move command for + * external node label. + * The expected behavior is to provide an external label that can freely move and with a link feedback + * towards its parent figure during the move. + */ +public class ExternalLabelPrimaryDragRoleEditPolicy extends NonResizableLabelEditPolicy { + + @Override + protected List<?> createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + + @Override + protected Command getMoveCommand(ChangeBoundsRequest request) { + LabelEditPart editPart = (LabelEditPart) getHost(); + // FeedBack - Port + Delta + Rectangle updatedRect = new Rectangle(); + PrecisionRectangle initialRect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + updatedRect = initialRect.getTranslated(getHostFigure().getParent().getBounds().getLocation().getNegated()); + updatedRect = updatedRect.getTranslated(request.getMoveDelta()); + // translate the feedback figure + PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); + getHostFigure().translateToAbsolute(rect); + rect.translate(request.getMoveDelta()); + rect.resize(request.getSizeDelta()); + getHostFigure().translateToRelative(rect); + + // translate according to the text alignments + if (editPart instanceof PapyrusLabelEditPart) { + switch (((PapyrusLabelEditPart) editPart).getTextAlignment()) { + case PositionConstants.LEFT: + break; + case PositionConstants.CENTER: + updatedRect.translate(getHostFigure().getBounds().width / 2, 0); + break; + case PositionConstants.RIGHT: + updatedRect.translate(getHostFigure().getBounds().width, 0); + break; + default: + break; + } + } + + ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(), DiagramUIMessages.MoveLabelCommand_Label_Location, new EObjectAdapter((View) editPart.getModel()), updatedRect); + return new ICommandProxy(moveCommand); + } +} |