Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractAlignLabelCommand.java8
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AlignLabelCommand.java23
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusLabelEditPart.java8
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java172
4 files changed, 210 insertions, 1 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractAlignLabelCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractAlignLabelCommand.java
new file mode 100644
index 00000000000..577ea2cd271
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractAlignLabelCommand.java
@@ -0,0 +1,8 @@
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.gef.commands.Command;
+
+public class AbstractAlignLabelCommand extends Command {
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AlignLabelCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AlignLabelCommand.java
new file mode 100644
index 00000000000..e5dfcbc67ed
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AlignLabelCommand.java
@@ -0,0 +1,23 @@
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart;
+
+public class AlignLabelCommand extends AbstractAlignLabelCommand {
+
+ private Rectangle constraint;
+
+ private PapyrusLabelEditPart label;
+
+ @Override
+ public void execute() {
+ // TODO Auto-generated method stub
+ //super.execute();
+
+ System.out.println("____J'execute la commande");
+ }
+
+
+
+}
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 d4adfd85aeb..31e7775eb87 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
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2014 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,12 +8,14 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.LabelAlignmentEditPolicy;
public abstract class PapyrusLabelEditPart extends LabelEditPart {
@@ -27,5 +29,9 @@ public abstract class PapyrusLabelEditPart extends LabelEditPart {
super.createDefaultEditPolicies();
installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
+ installEditPolicy(LabelAlignmentEditPolicy.LABEL_ALIGNMENT_KEY, new LabelAlignmentEditPolicy());
+
}
}
+
+
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java
new file mode 100644
index 00000000000..be862e446d4
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java
@@ -0,0 +1,172 @@
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gef.editpolicies.AbstractEditPolicy;
+import org.eclipse.gef.requests.AlignmentRequest;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+
+/**
+ * This EditPolicy provides the command for the alignment. In the case of
+ * Label.
+ */
+public class LabelAlignmentEditPolicy extends AbstractEditPolicy{
+
+ /**
+ * the key for the Port Alignment EditPolicy
+ */
+ public static final String LABEL_ALIGNMENT_KEY = "Label Alignment"; //$NON-NLS-1$
+
+
+ /** Integer corresponding to the alignment type ( p.e. Left = 1, Bottom = 32) */
+ private int alignment ;
+
+ /** Current edit Part */
+ private GraphicalEditPart label ;
+
+ /** Reference rectangle on which the Label is aligned */
+ private Rectangle refBounds;
+
+ /** Bounds of the current label */
+ private Rectangle bounds;
+
+ /**
+ * Get Command associate to the corresponding Request
+ * Only REQ_ALIGN request return a Command
+ * @return Command to move the label in case of REQ_ALIGN, null if not.
+ * @param request Request for which a command is required.
+ */
+ public Command getCommand(Request request) {
+ Command cmd = null;
+ if (REQ_ALIGN.equals(request.getType())){
+ cmd = getAlignLabelCommand ((AlignmentRequest) request);
+ }
+ return cmd;
+ }
+
+ /**
+ * Get The alignment Command for the corresponding Alignment Request.
+ * This method transforms the alignment Request into a move request and return the move command associated to this new Request.
+ *
+ * @param request Alignment Request for which the Alignment Command is returned
+ * @return Alignment command
+ */
+ private Command getAlignLabelCommand(AlignmentRequest request) {
+
+ alignment = request.getAlignment();
+ // get the Alignment rectangle on which the selected edit part should be aligned.
+ refBounds = request.getAlignmentRectangle().getCopy();
+
+ label = (GraphicalEditPart) getHost();
+ bounds = getAbsolutePosition(label);
+
+ Point moveDelta = new Point(0, 0);
+
+ if (isAlignmentAllowed()){
+ switch (alignment ){
+ case PositionConstants.LEFT:
+ moveDelta.setX(refBounds.x - bounds.x );
+ break;
+ case PositionConstants.RIGHT:
+ moveDelta.setX(refBounds.getRight().x - bounds.getRight().x );
+ break;
+ case PositionConstants.TOP:
+ moveDelta.setY(refBounds.y - bounds.y );
+ break;
+ case PositionConstants.BOTTOM:
+ moveDelta.setY(refBounds.getBottom().y - bounds.getBottom().y );
+ break;
+ case PositionConstants.CENTER:
+ moveDelta.setX(refBounds.getTop().x - bounds.getTop().x );
+ break;
+ case PositionConstants.MIDDLE:
+ moveDelta.setY(refBounds.getLeft().y - bounds.getLeft().y );
+ break;
+ }
+
+
+ //build the Move request
+ ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE);
+
+ req.setEditParts(((ChangeBoundsRequest)request).getEditParts());
+ req.setMoveDelta(moveDelta);
+ req.setExtendedData(request.getExtendedData());
+
+ return getHost().getCommand(req);
+
+ }
+ else {
+ // if alignment not allowed return no command
+ return null;
+
+ }
+
+ }
+
+ /**
+ * Determine if the current edit part can be aligned.
+ *
+ * The label cannot be aligned if its connector target or source moves as well
+ * Because if the source/target moves, the connector moves as well and the label linked to the connector translates with the Edge
+ * Same if the Affixed node is selected.
+ */
+ private boolean isAlignmentAllowed() {
+ EditPart parent = label.getParent();
+ boolean isAllow = true;
+ if (parent instanceof AbstractConnectionEditPart){
+ // Label alignment is not allowed if it should moves at the same time as the connector
+ // That means if the Source or target of the connector is part of the selection
+ int sourceSelectionType = ((ConnectionEditPart)label.getParent()).getSource().getSelected();
+ int targetSelectionType = ((ConnectionEditPart)label.getParent()).getTarget().getSelected();
+
+ isAllow = !((sourceSelectionType == EditPart.SELECTED)||(targetSelectionType == EditPart.SELECTED)) ;
+
+ } else if (parent instanceof AbstractBorderItemEditPart) {
+ // if the label is an affixed label and if the affixed node is part of the selection, the label is not aligned
+ isAllow = !(parent.getSelected() == EditPart.SELECTED);
+ }
+
+ return isAllow;
+ }
+
+
+ /**
+ *
+ * A {@link Rectangle} with the absolute position from the {@link EditPart}
+ *
+ * @param ep
+ * the {@link EditPart} that we want the position
+ * @return a {@link Rectangle} with the absolute position from the {@link EditPart}
+ *
+ */
+ public static Rectangle getAbsolutePosition(EditPart ep) {
+ GraphicalEditPart part = (GraphicalEditPart)ep;
+ Rectangle rect = part.getFigure().getBounds().getCopy();
+ part.getFigure().translateToAbsolute(rect);
+ return rect;
+ }
+
+
+
+}

Back to the top