Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCéline Janssens2014-08-27 15:15:56 +0000
committerCéline Janssens2014-08-28 08:46:57 +0000
commit15322652cc079d206f5a886bafe9dc01c233ad27 (patch)
treead98d8517aff72a48b01e16772a2d49ed727f7c8 /plugins/infra
parent8cb2ca4a4ae589a3bd1988070416a1bd0e3d024a (diff)
downloadorg.eclipse.papyrus-15322652cc079d206f5a886bafe9dc01c233ad27.tar.gz
org.eclipse.papyrus-15322652cc079d206f5a886bafe9dc01c233ad27.tar.xz
org.eclipse.papyrus-15322652cc079d206f5a886bafe9dc01c233ad27.zip
442582: [All Diagrams] CustomAlignAction Refactor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=442582 New rules For the Alignment Change-Id: I408d686ca381c2fb54078350f63967460ea5d0c0 Signed-off-by: Céline Janssens <Celine.Janssens@all4tec.net>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java34
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java27
2 files changed, 60 insertions, 1 deletions
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
index be862e446d4..481aa72e222 100644
--- 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
@@ -13,6 +13,9 @@ package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
* Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
*
*****************************************************************************/
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
@@ -140,7 +143,14 @@ public class LabelAlignmentEditPolicy extends AbstractEditPolicy{
int sourceSelectionType = ((ConnectionEditPart)label.getParent()).getSource().getSelected();
int targetSelectionType = ((ConnectionEditPart)label.getParent()).getTarget().getSelected();
- isAllow = !((sourceSelectionType == EditPart.SELECTED)||(targetSelectionType == EditPart.SELECTED)) ;
+
+ boolean isRefDependent = isRefSibling(parent);
+
+ if (!isRefDependent) {
+ boolean isExtremitiesSelected = (sourceSelectionType == EditPart.SELECTED)||(targetSelectionType == EditPart.SELECTED);
+ isAllow = !isExtremitiesSelected;
+ }
+
} 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
@@ -150,6 +160,28 @@ public class LabelAlignmentEditPolicy extends AbstractEditPolicy{
return isAllow;
}
+ /**
+ * Define if the Label is sibling of the Reference object.
+ * @param parent Label's Parent
+ * @return true if the reference is a sibling of the Label
+ */
+ private boolean isRefSibling(EditPart parent) {
+
+ boolean isRefSibling = false;
+ if (parent instanceof AbstractConnectionEditPart){
+
+ List<?> children = parent.getChildren();
+ Iterator<?> iter = children.iterator();
+
+ while(iter.hasNext() && !isRefSibling ){
+ Object child = iter.next();
+ if (((EditPart)child).getSelected() == EditPart.SELECTED_PRIMARY){
+ isRefSibling = true;
+ }
+ }
+ }
+ return isRefSibling;
+ }
/**
*
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java
index acb9cc8ecc0..7320fe5b90c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java
@@ -20,8 +20,11 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.RootEditPart;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
@@ -224,4 +227,28 @@ public class DiagramEditPartsUtil {
}
return -1.0;
}
+
+ /**
+ * This Method return the Graphical container of an EditPart.
+ * Depending on the type of EditPart, the container can be the Direct Parent or the grand parent.
+ * @param currentEP
+ * @return
+ */
+ public static final EditPart getContainerEditPart(GraphicalEditPart currentEP) {
+
+ EditPart container;
+ EditPart parent = currentEP.getParent();
+ if (parent instanceof AbstractConnectionEditPart){
+ container = parent.getParent();
+ }else if (parent instanceof AbstractBorderItemEditPart){
+ container = parent.getParent().getParent();
+ }else if (currentEP instanceof AbstractBorderItemEditPart){
+ container = parent.getParent();
+ }else {
+ container = parent;
+ }
+
+ return container;
+ }
+
}

Back to the top