Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2016-03-23 14:26:30 +0000
committerLaurent Redor2016-06-22 08:57:19 +0000
commit15a0b97ea0d09fd02ef8a738ccacefe03e3e6ca9 (patch)
tree57942842fec0037d3f036c366be3bed4a7dcc461
parent2d65d2279bda22f36ddd385cd59c6e9457ce1bea (diff)
downloadorg.eclipse.sirius-15a0b97ea0d09fd02ef8a738ccacefe03e3e6ca9.tar.gz
org.eclipse.sirius-15a0b97ea0d09fd02ef8a738ccacefe03e3e6ca9.tar.xz
org.eclipse.sirius-15a0b97ea0d09fd02ef8a738ccacefe03e3e6ca9.zip
[490360] Add "snap to shape" capability on border nodes
The standard "snap to shape" feature and the "snap to all shapes" (bug 463485) has been added to border nodes with this commit: * org.eclipse.sirius.ext.gef.editpolicies.SiriusSnapFeedbackPolicy has been deprecated in favor of org.eclipse.sirius.ext.gmf.runtime.editpolicies.SiriusSnapFeedbackPolicy. * SiriusSnapFeedbackPolicy has been added to AbstractDiagramBorderNodeEditPart and AbstractDiagramNodeEditPart to have correct feedback for snap of border nodes * Use the SiriusSnapToHelperUtil as SnapToHelper for AbstractDiagramBorderNodeEditPart * Update SiriusSnapToGeometry to allow the snap on the center of border nodes Bug: 490360 Change-Id: I2e41994dbb164a012556fdc855478ee90506ea3b Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java4
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramBorderNodeEditPart.java15
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramEdgeEditPart.java4
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNodeEditPart.java11
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java4
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToGeometry.java77
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToHelperUtil.java36
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ui/SiriusDragEditPartsTrackerEx.java5
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.html20
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile6
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html3
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile3
-rw-r--r--plugins/org.eclipse.sirius.ext.gef/src/org/eclipse/sirius/ext/gef/editpolicies/SiriusSnapFeedbackPolicy.java29
-rw-r--r--plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF6
-rw-r--r--plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editpolicies/SiriusSnapFeedbackPolicy.java279
15 files changed, 448 insertions, 54 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java
index 8127050fa4..2935d0d9dc 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES 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
@@ -74,8 +74,8 @@ import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuth
import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
-import org.eclipse.sirius.ext.gef.editpolicies.SiriusSnapFeedbackPolicy;
import org.eclipse.sirius.ext.gmf.runtime.diagram.ui.tools.RubberbandDragTracker;
+import org.eclipse.sirius.ext.gmf.runtime.editpolicies.SiriusSnapFeedbackPolicy;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import com.google.common.collect.Iterables;
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramBorderNodeEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramBorderNodeEditPart.java
index 4455aabfe5..b696edaf57 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramBorderNodeEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramBorderNodeEditPart.java
@@ -24,6 +24,7 @@ import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
+import org.eclipse.gef.SnapToHelper;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.editparts.ZoomManager;
@@ -39,6 +40,7 @@ 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.BorderedBorderItemEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
@@ -69,9 +71,11 @@ import org.eclipse.sirius.diagram.ui.tools.api.figure.FoldingToggleAwareClipping
import org.eclipse.sirius.diagram.ui.tools.api.figure.FoldingToggleImageFigure;
import org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils;
import org.eclipse.sirius.diagram.ui.tools.api.permission.EditPartAuthorityListener;
+import org.eclipse.sirius.diagram.ui.tools.internal.ruler.SiriusSnapToHelperUtil;
import org.eclipse.sirius.diagram.ui.tools.internal.ui.SiriusDragEditPartsTrackerEx;
import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority;
import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry;
+import org.eclipse.sirius.ext.gmf.runtime.editpolicies.SiriusSnapFeedbackPolicy;
import org.eclipse.swt.graphics.Image;
import com.google.common.collect.Iterables;
@@ -147,6 +151,9 @@ public abstract class AbstractDiagramBorderNodeEditPart extends BorderedBorderIt
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
AbstractDiagramNodeEditPartOperation.createDefaultEditPolicies(this);
+ // Add the Sirius feedback policy to have a the same lighter color for
+ // guides of snap features for border nodes on BorderNode
+ installEditPolicy(EditPolicyRoles.SNAP_FEEDBACK_ROLE, new SiriusSnapFeedbackPolicy());
}
@Override
@@ -476,4 +483,12 @@ public abstract class AbstractDiagramBorderNodeEditPart extends BorderedBorderIt
super.performDirectEditRequest(request);
}
}
+
+ @Override
+ public Object getAdapter(Class key) {
+ if (key == SnapToHelper.class) {
+ return SiriusSnapToHelperUtil.getSnapHelper(this);
+ }
+ return super.getAdapter(key);
+ }
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramEdgeEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramEdgeEditPart.java
index 532a7f685a..43753233d0 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramEdgeEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramEdgeEditPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2008, 2016 THALES GLOBAL SERVICES 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
@@ -63,7 +63,7 @@ import org.eclipse.sirius.diagram.ui.tools.api.requests.RequestConstants;
import org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.policies.SiriusConnectionEndPointEditPolicy;
import org.eclipse.sirius.diagram.ui.tools.internal.routers.SiriusBendpointConnectionRouter;
import org.eclipse.sirius.diagram.ui.tools.internal.ruler.SiriusSnapToHelperUtil;
-import org.eclipse.sirius.ext.gef.editpolicies.SiriusSnapFeedbackPolicy;
+import org.eclipse.sirius.ext.gmf.runtime.editpolicies.SiriusSnapFeedbackPolicy;
import org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription;
import org.eclipse.sirius.viewpoint.description.tool.PaneBasedSelectionWizardDescription;
import org.eclipse.sirius.viewpoint.description.tool.SelectionWizardDescription;
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNodeEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNodeEditPart.java
index 73b056e99f..194733bce7 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNodeEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNodeEditPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2008, 2016 THALES GLOBAL SERVICES 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
@@ -41,6 +41,7 @@ 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.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.NoteEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
@@ -74,6 +75,7 @@ import org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.styles.IStyleConfi
import org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.styles.StyleConfiguration;
import org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils;
import org.eclipse.sirius.diagram.ui.tools.internal.ui.NoCopyDragEditPartsTrackerEx;
+import org.eclipse.sirius.ext.gmf.runtime.editpolicies.SiriusSnapFeedbackPolicy;
import org.eclipse.swt.graphics.Color;
import com.google.common.collect.Iterables;
@@ -122,6 +124,9 @@ public abstract class AbstractDiagramNodeEditPart extends AbstractBorderedDiagra
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
AbstractDiagramNodeEditPartOperation.createDefaultEditPolicies(this);
+ // Add the Sirius feedback policy to have a the same lighter color for
+ // guides of snap features for border nodes on Node
+ installEditPolicy(EditPolicyRoles.SNAP_FEEDBACK_ROLE, new SiriusSnapFeedbackPolicy());
}
@Override
@@ -250,8 +255,8 @@ public abstract class AbstractDiagramNodeEditPart extends AbstractBorderedDiagra
break;
}
}
- final SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), Messages.IAbstractDiagramNodeEditPart_resizeCommandLabel, new EObjectAdapter(graphicalEditPart.getNotationView()),
- new Rectangle(position, dimension));
+ final SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), Messages.IAbstractDiagramNodeEditPart_resizeCommandLabel,
+ new EObjectAdapter(graphicalEditPart.getNotationView()), new Rectangle(position, dimension));
cmd = new ICommandProxy(setBoundsCommand);
}
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java
index 6c4ecd0549..62bc2888c4 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2009, 2016 THALES GLOBAL SERVICES 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
@@ -83,7 +83,7 @@ import org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.policies.Cont
import org.eclipse.sirius.diagram.ui.tools.internal.ruler.SiriusSnapToHelperUtil;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
-import org.eclipse.sirius.ext.gef.editpolicies.SiriusSnapFeedbackPolicy;
+import org.eclipse.sirius.ext.gmf.runtime.editpolicies.SiriusSnapFeedbackPolicy;
import org.eclipse.sirius.ui.tools.api.color.VisualBindingManager;
import org.eclipse.sirius.viewpoint.RGBValues;
import org.eclipse.sirius.viewpoint.description.style.LabelBorderStyleDescription;
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToGeometry.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToGeometry.java
index b59466f136..67772f85ab 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToGeometry.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToGeometry.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 THALES GLOBAL SERVICES.
+ * Copyright (c) 2015, 2016 THALES GLOBAL SERVICES.
* 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
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.internal.ruler;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -23,12 +22,15 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToGeometryEx;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractBorderedDiagramElementEditPart;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramBorderNodeEditPart;
+import org.eclipse.sirius.diagram.ui.edit.api.part.IStyleEditPart;
import org.eclipse.sirius.diagram.ui.graphical.edit.policies.SnapChangeBoundsRequest;
import org.eclipse.sirius.diagram.ui.internal.edit.policies.SnapBendpointRequest;
import org.eclipse.sirius.diagram.ui.tools.internal.ui.NoCopyDragEditPartsTrackerEx;
import org.eclipse.sirius.ext.gef.query.EditPartQuery;
import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
@@ -89,15 +91,34 @@ public class SiriusSnapToGeometry extends SnapToGeometryEx {
@Override
protected List generateSnapPartsList(List exclusions) {
if (!snapToAll) {
- return super.generateSnapPartsList(exclusions);
+ // Same code as super.generateSnapPartsList(exclusions); but with
+ // border nodes add to children list
+ // Don't snap to any figure that is being dragged
+ List children = Lists.newArrayList(container.getChildren());
+ // Add border nodes
+ Iterables.addAll(children, Iterables.filter(container.getParent().getChildren(), AbstractDiagramBorderNodeEditPart.class));
+ children.removeAll(exclusions);
+ // Remove IStyleEditPart from list of children
+ Iterable<Object> filteredChildren = Iterables.filter(children, Predicates.not(Predicates.instanceOf(IStyleEditPart.class)));
+
+ // Don't snap to hidden figures
+ List hiddenChildren = Lists.newArrayList();
+ for (Iterator iter = filteredChildren.iterator(); iter.hasNext(); /* */) {
+ GraphicalEditPart child = (GraphicalEditPart) iter.next();
+ if (!child.getFigure().isVisible()) {
+ hiddenChildren.add(child);
+ }
+ }
+ Iterables.removeAll(filteredChildren, hiddenChildren);
+ return Lists.newArrayList(filteredChildren);
} else {
// Get all potential snap targets
List<Class<?>> expectedClasses = Lists.newArrayList();
expectedClasses.add(AbstractBorderedDiagramElementEditPart.class);
expectedClasses.add(AbstractDiagramBorderNodeEditPart.class);
- List<EditPart> snapPartsList = new ArrayList<EditPart>(new EditPartQuery(container.getRoot()).getAllChildren(false, expectedClasses));
+ List<EditPart> snapPartsList = Lists.newArrayList(new EditPartQuery(container.getRoot()).getAllChildren(false, expectedClasses));
// Add children of elements that are being dragged
- List<EditPart> exclusionsWithChildren = new ArrayList<EditPart>();
+ List<EditPart> exclusionsWithChildren = Lists.newArrayList();
for (Object editPart : exclusions) {
if (editPart instanceof EditPart) {
exclusionsWithChildren.add((EditPart) editPart);
@@ -122,21 +143,39 @@ public class SiriusSnapToGeometry extends SnapToGeometryEx {
@Override
protected void populateRowsAndCols(List parts) {
- if (!snapToAll) {
- super.populateRowsAndCols(parts);
- } else {
- rows = new Entry[parts.size() * 3];
- cols = new Entry[parts.size() * 3];
- for (int i = 0; i < parts.size(); i++) {
- IGraphicalEditPart child = (IGraphicalEditPart) parts.get(i);
- Rectangle bounds = GraphicalHelper.getAbsoluteBounds(child);
+ // Only center is considered for border nodes (top/middle/bottom and
+ // left/center/right for others).
+ int nbOfBorderNodes = Iterables.size(Iterables.filter(parts, AbstractDiagramBorderNodeEditPart.class));
+ rows = new Entry[(parts.size() - nbOfBorderNodes) * 3 + nbOfBorderNodes];
+ cols = new Entry[(parts.size() - nbOfBorderNodes) * 3 + nbOfBorderNodes];
+ int currentIndex = 0;
+ for (int i = 0; i < parts.size(); i++) {
+ IGraphicalEditPart child = (IGraphicalEditPart) parts.get(i);
+ Rectangle bounds;
+ if (!snapToAll) {
+ if (child instanceof AbstractDiagramBorderNodeEditPart) {
+ // Handle specific case of Border Node
+ bounds = GraphicalHelper.getAbsoluteBounds(child);
+ makeRelative(container.getContentPane(), bounds);
+ } else {
+ // Same as in super.populateRowsAndCols(parts)
+ bounds = getFigureBounds(child);
+ }
+ } else {
+ bounds = GraphicalHelper.getAbsoluteBounds(child);
makeRelative(container.getContentPane(), bounds);
- cols[i * 3] = new SiriusEntry(-1, bounds.x);
- rows[i * 3] = new SiriusEntry(-1, bounds.y);
- cols[i * 3 + 1] = new SiriusEntry(0, bounds.x + (bounds.width - 1) / 2);
- rows[i * 3 + 1] = new SiriusEntry(0, bounds.y + (bounds.height - 1) / 2);
- cols[i * 3 + 2] = new SiriusEntry(1, bounds.right() - 1);
- rows[i * 3 + 2] = new SiriusEntry(1, bounds.bottom() - 1);
+ }
+ if (!(child instanceof AbstractDiagramBorderNodeEditPart)) {
+ // Only center is considered for border node
+ cols[currentIndex] = new SiriusEntry(-1, bounds.x);
+ rows[currentIndex++] = new SiriusEntry(-1, bounds.y);
+ }
+ cols[currentIndex] = new SiriusEntry(0, bounds.x + (bounds.width - 1) / 2);
+ rows[currentIndex++] = new SiriusEntry(0, bounds.y + (bounds.height - 1) / 2);
+ if (!(child instanceof AbstractDiagramBorderNodeEditPart)) {
+ // Only center is considered for border node
+ cols[currentIndex] = new SiriusEntry(1, bounds.right() - 1);
+ rows[currentIndex++] = new SiriusEntry(1, bounds.bottom() - 1);
}
}
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToHelperUtil.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToHelperUtil.java
index e9d07512e6..6911d9503f 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToHelperUtil.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToHelperUtil.java
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2007, 2015 IBM Corporation and others.
+ * Copyright (c) 2007, 2016 IBM Corporation 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
@@ -25,6 +25,7 @@ import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.CompoundSnapToHelperEx;
import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToGridEx;
import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToGuidesEx;
import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToHelperUtil;
+import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramNodeEditPart;
/**
* Utility class for the snapping behavior. This class adds the capability to
@@ -51,44 +52,57 @@ public class SiriusSnapToHelperUtil extends SnapToHelperUtil {
diagramEditPart = (GraphicalEditPart) diagramEditPart.getParent();
}
- if (diagramEditPart == null)
+ if (diagramEditPart == null) {
return null;
+ }
// for snap to geometry, attempt to locate a compartment as a parent
GraphicalEditPart parent = editPart;
- while (parent != null && !(parent instanceof ISurfaceEditPart)) {
- parent = (GraphicalEditPart) parent.getParent();
+ // If the editPart is an AbstractDiagramNodeEditPart, this means that
+ // element to snap is a border node of a DNode, this is an exception
+ // where we do not attempt to locate a compartment as a parent.
+ if (!(parent instanceof AbstractDiagramNodeEditPart)) {
+ while (parent != null && !(parent instanceof ISurfaceEditPart)) {
+ parent = (GraphicalEditPart) parent.getParent();
+ }
}
- if (parent == null)
+ if (parent == null) {
parent = diagramEditPart;
+ }
List<SnapToHelper> snapStrategies = new ArrayList<SnapToHelper>();
EditPartViewer viewer = diagramEditPart.getViewer();
Boolean val = (Boolean) editPart.getViewer().getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY);
- if (val != null && val.booleanValue())
+ if (val != null && val.booleanValue()) {
snapStrategies.add(new SnapToGuidesEx(diagramEditPart));
+ }
val = (Boolean) viewer.getProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED);
- if (val != null && val.booleanValue())
+ if (val != null && val.booleanValue()) {
snapStrategies.add(new SiriusSnapToGeometry(parent));
+ }
val = (Boolean) viewer.getProperty(SnapToGrid.PROPERTY_GRID_ENABLED);
- if (val != null && val.booleanValue())
+ if (val != null && val.booleanValue()) {
snapStrategies.add(new SnapToGridEx(diagramEditPart));
+ }
- if (snapStrategies.size() == 0)
+ if (snapStrategies.size() == 0) {
return null;
+ }
- if (snapStrategies.size() == 1)
+ if (snapStrategies.size() == 1) {
return snapStrategies.get(0);
+ }
SnapToHelper ss[] = new SnapToHelper[snapStrategies.size()];
- for (int i = 0; i < snapStrategies.size(); i++)
+ for (int i = 0; i < snapStrategies.size(); i++) {
ss[i] = snapStrategies.get(i);
+ }
return new CompoundSnapToHelperEx(ss);
}
// CHECKSTYLE:ON
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ui/SiriusDragEditPartsTrackerEx.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ui/SiriusDragEditPartsTrackerEx.java
index 1a23bc09f1..518cdeadab 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ui/SiriusDragEditPartsTrackerEx.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ui/SiriusDragEditPartsTrackerEx.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 THALES GLOBAL SERVICES.
+ * Copyright (c) 2009, 2016 THALES GLOBAL SERVICES.
* 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
@@ -20,7 +20,6 @@ import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.SharedCursors;
import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
import org.eclipse.sirius.ext.gmf.runtime.diagram.ui.tools.MoveInDiagramDragTracker;
import org.eclipse.swt.events.MouseEvent;
@@ -33,7 +32,7 @@ import org.eclipse.swt.events.MouseEvent;
*
* @author dlecan
*/
-public class SiriusDragEditPartsTrackerEx extends DragEditPartsTrackerEx implements MoveInDiagramDragTracker {
+public class SiriusDragEditPartsTrackerEx extends SnapToAllDragEditPartsTracker implements MoveInDiagramDragTracker {
/**
* The x margin used when moving bordered node to not have drag'n drop
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
index 1305ca1aa4..dd9c1d4551 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
@@ -90,6 +90,9 @@
</p>
<h2 id="sirius4.1.0">Changes in Sirius 4.1.0</h2>
<h3 id="UserVisibleChanges">User-Visible Changes</h3>
+ <p><span class="label label-success">Added</span> The
+ <a href="./user/diagrams/Diagrams.html#snap_to_shapes">snap to shape</a> feature is now available on border nodes.
+ </p>
<h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3>
<h3 id="DeveloperVisibleChanges">Developer-Visible Changes</h3>
<h4 id="Changesinorg.eclipse.sirius.diagram.ui">Changes in
@@ -99,6 +102,17 @@
<li><span class="label label-success">Added</span>
<code>org.eclipse.sirius.diagram.ui.business.api.query.NodeQuery.isDescendantOf(View)</code> has been added to know if a view is a descendant of another view.
</li>
+ </ul>
+ <h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime">Changes in
+ <code>org.eclipse.sirius.ext.gmf.runtime</code>
+ </h4>
+ <ul>
+ <li><span class="label label-success">Added</span> The class
+ <code>SiriusSnapFeedbackPolicy</code> has been copied from
+ <code>org.eclipse.sirius.ext.gef.editpolicies</code> to
+ <code>org.eclipse.sirius.ext.gmf.runtime.editpolicies</code>. The old class in plug-in
+ <code>org.eclipse.sirius.ext.gef</code> is deprecated and will be removed in the next version.
+ </li>
<li><span class="label label-success">Added</span>
<code>org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery.getAncestor(int...)</code> has been added to retrieve the first ancestor of the view, or itself, that has at least one of the visualID passed as parameter.
</li>
@@ -500,7 +514,7 @@
<code>org.eclipse.sirius.ext.emf.ui.properties.ExtensiblePropertySource.collector</code> field is now in protected visibility to be modifiable and accessible by subclass.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime">Changes in
+ <h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime2">Changes in
<code>org.eclipse.sirius.ext.gmf.runtime</code>
</h4>
<ul>
@@ -1118,7 +1132,7 @@
<code>org.eclipse.sirius.ext.jface.viewers.IToolTipProvider</code> has been copied from JFace 3.10 from Luna, so that we can use it with Juno and Kepler too.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime2">Changes in
+ <h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime3">Changes in
<code>org.eclipse.sirius.ext.gmf.runtime</code>
</h4>
<ul>
@@ -2405,7 +2419,7 @@
<code>EObject</code> from its container after a check by the permission authority that all changeable feature to modify can be edited.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime3">Changes in
+ <h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime4">Changes in
<code>org.eclipse.sirius.ext.gmf.runtime</code>
</h4>
<ul>
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
index 9b71ea861c..266560920a 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
@@ -8,6 +8,8 @@ h2(#sirius4.1.0). Changes in Sirius 4.1.0
h3. User-Visible Changes
+<span class="label label-success">Added</span> The "snap to shape":./user/diagrams/Diagrams.html#snap_to_shapes feature is now available on border nodes.
+
h3. Specifier-Visible Changes
h3. Developer-Visible Changes
@@ -17,6 +19,10 @@ h4. Changes in @org.eclipse.sirius.diagram.ui@
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.business.api.query.NodeQuery.isDescendantOf(View)@ has been added to know if a view is a descendant of another view.
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery.getAncestor(int...)@ has been added to retrieve the first ancestor of the view, or itself, that has at least one of the visualID passed as parameter.
+h4. Changes in @org.eclipse.sirius.ext.gmf.runtime@
+
+* <span class="label label-success">Added</span> The class @SiriusSnapFeedbackPolicy@ has been copied from @org.eclipse.sirius.ext.gef.editpolicies@ to @org.eclipse.sirius.ext.gmf.runtime.editpolicies@. The old class in plug-in @org.eclipse.sirius.ext.gef@ is deprecated and will be removed in the next version.
+
h2(#sirius4.0.0). Changes in Sirius 4.0.0
h3. User-Visible Changes
diff --git a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html
index 0c728fcf4c..1ff3cd8e4b 100644
--- a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html
+++ b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html
@@ -214,7 +214,8 @@
<p>Capability to allow edit parts to snap to the grid when editing (during creation, moving or resizing). It is also possible to have connection bendpoints snap to it. Grid snapping and visibility are two distinct properties, and it is possible to enable one without the other.</p>
<h5 id="snap_to_shapes">Snap to shapes</h5>
<p>The
- <em>Snap to shapes</em> feature allows you to quickly align parts being dragged or resized to other parts in the diagram or that share the same parent (e.g: edit parts inside a compartment can only snap to each other). The snap is effective on top, bottom, right, left and center of the figure. Feedback is shown in the form of a gray line when a part is being attached to another part. This feature is not enabled on border nodes.
+ <em>Snap to shapes</em> feature allows you to quickly align parts being dragged or resized to other parts in the diagram or that share the same parent (e.g: edit parts inside a compartment can only snap to each other). The snap is effective on top, bottom, right, left and center of the figure. Feedback is shown in the form of a gray line when a part is being attached to another part.
+ <br/>This drag part of this feature is also available on border nodes since Sirius 4.1.0. Note: For border nodes, the snap is effective only on the center of the figure. This is why the resize part is not handled for border nodes.
<br/>
<img border="0" src="images/snap_to_shape.png"/>
</p>
diff --git a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile
index 1c8b2cf72b..497d7aa5c9 100644
--- a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile
@@ -61,7 +61,8 @@ Capability to allow edit parts to snap to the grid when editing (during creation
h5(#snap_to_shapes). Snap to shapes
-The _Snap to shapes_ feature allows you to quickly align parts being dragged or resized to other parts in the diagram or that share the same parent (e.g: edit parts inside a compartment can only snap to each other). The snap is effective on top, bottom, right, left and center of the figure. Feedback is shown in the form of a gray line when a part is being attached to another part. This feature is not enabled on border nodes.
+The _Snap to shapes_ feature allows you to quickly align parts being dragged or resized to other parts in the diagram or that share the same parent (e.g: edit parts inside a compartment can only snap to each other). The snap is effective on top, bottom, right, left and center of the figure. Feedback is shown in the form of a gray line when a part is being attached to another part.
+This drag part of this feature is also available on border nodes since Sirius 4.1.0. Note: For border nodes, the snap is effective only on the center of the figure. This is why the resize part is not handled for border nodes.
!images/snap_to_shape.png!
By pressing the <kdb>F4</kdb> shortcut key, it is possible to temporarily enable the snap to all shapes currently visible on the diagram. Some screenshots of this feature are shown below.
diff --git a/plugins/org.eclipse.sirius.ext.gef/src/org/eclipse/sirius/ext/gef/editpolicies/SiriusSnapFeedbackPolicy.java b/plugins/org.eclipse.sirius.ext.gef/src/org/eclipse/sirius/ext/gef/editpolicies/SiriusSnapFeedbackPolicy.java
index 596858ebba..95dfa1b7bd 100644
--- a/plugins/org.eclipse.sirius.ext.gef/src/org/eclipse/sirius/ext/gef/editpolicies/SiriusSnapFeedbackPolicy.java
+++ b/plugins/org.eclipse.sirius.ext.gef/src/org/eclipse/sirius/ext/gef/editpolicies/SiriusSnapFeedbackPolicy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2014 IBM Corporation and others.
+ * Copyright (c) 2003, 2016 IBM Corporation 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
@@ -35,7 +35,11 @@ import org.eclipse.swt.widgets.Display;
* colors.
*
* @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a>
+ * @deprecated Use
+ * {@link org.eclipse.sirius.ext.gmf.runtime.editpolicies.SiriusSnapFeedbackPolicy}
+ * instead
*/
+@Deprecated
public class SiriusSnapFeedbackPolicy extends GraphicalEditPolicy {
/**
@@ -107,10 +111,12 @@ public class SiriusSnapFeedbackPolicy extends GraphicalEditPolicy {
/**
* @see org.eclipse.gef.EditPolicy#eraseTargetFeedback(org.eclipse.gef.Request)
*/
+ @Override
public void eraseTargetFeedback(Request request) {
for (int i = 0; i < guide.length; i++) {
- if (guide[i] != null)
+ if (guide[i] != null) {
removeFeedback(guide[i]);
+ }
guide[i] = null;
location[i] = null;
}
@@ -137,6 +143,7 @@ public class SiriusSnapFeedbackPolicy extends GraphicalEditPolicy {
/**
* @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
*/
+ @Override
protected void paintFigure(Graphics graphics) {
if (opacity != FRAMES) {
if (image != null) {
@@ -157,6 +164,7 @@ public class SiriusSnapFeedbackPolicy extends GraphicalEditPolicy {
count++;
}
Display.getCurrent().timerExec(100, new Runnable() {
+ @Override
public void run() {
opacity = Math.min(FRAMES, opacity + 1);
repaint();
@@ -164,15 +172,17 @@ public class SiriusSnapFeedbackPolicy extends GraphicalEditPolicy {
});
}
Rectangle r = getBounds();
- if (image != null)
+ if (image != null) {
graphics.drawImage(image, 0, 0, 1, 1, r.x, r.y, r.width, r.height);
- else
+ } else {
super.paintFigure(graphics);
+ }
}
/**
* @see org.eclipse.draw2d.Figure#removeNotify()
*/
+ @Override
public void removeNotify() {
if (image != null) {
image.dispose();
@@ -243,9 +253,16 @@ public class SiriusSnapFeedbackPolicy extends GraphicalEditPolicy {
/**
* @see org.eclipse.gef.EditPolicy#showTargetFeedback(org.eclipse.gef.Request)
*/
+ @Override
public void showTargetFeedback(Request req) {
- if (req.getType().equals(REQ_MOVE) || req.getType().equals(REQ_RESIZE) || req.getType().equals(REQ_CLONE) || req.getType().equals(REQ_ADD) || req.getType().equals(REQ_CREATE)) {
-
+ // The "drop" type is replaced by
+ // org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants.REQ_DROP
+ // in
+ // org.eclipse.sirius.ext.gmf.runtime.editpolicies.SiriusSnapFeedbackPolicy.
+ // This is why this class is now deprecated. It will be removed in
+ // future version.
+ if (req.getType().equals("drop") || req.getType().equals(REQ_MOVE) || req.getType().equals(REQ_RESIZE) || req.getType().equals(REQ_CLONE) || req.getType().equals(REQ_ADD)
+ || req.getType().equals(REQ_CREATE)) {
Integer value;
value = (Integer) req.getExtendedData().get(SnapToGeometry.KEY_WEST_ANCHOR);
highlightGuide(value, nsewColor, 0);
diff --git a/plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF
index 79c8de475d..badc3f2334 100644
--- a/plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF
@@ -14,9 +14,11 @@ Import-Package: com.google.common.base;version="10.0.1",
org.eclipse.emf.ecore,
org.eclipse.gef,
org.eclipse.gef.editparts,
+ org.eclipse.gef.editpolicies,
org.eclipse.gef.handles,
org.eclipse.gef.tools,
org.eclipse.gmf.runtime.diagram.ui.editparts,
+ org.eclipse.gmf.runtime.diagram.ui.requests,
org.eclipse.gmf.runtime.diagram.ui.util,
org.eclipse.gmf.runtime.draw2d.ui.figures,
org.eclipse.gmf.runtime.draw2d.ui.geometry,
@@ -25,7 +27,9 @@ Import-Package: com.google.common.base;version="10.0.1",
org.eclipse.sirius.ext.base;version="2.0.0",
org.eclipse.sirius.ext.draw2d.figure;version="2.0.0",
org.eclipse.swt.events,
+ org.eclipse.swt.graphics,
org.eclipse.swt.widgets
Export-Package: org.eclipse.sirius.ext.gmf.runtime.diagram.ui.tools;version="2.0.4",
org.eclipse.sirius.ext.gmf.runtime.draw2d.ui.geometry;version="2.0.0",
- org.eclipse.sirius.ext.gmf.runtime.editparts;version="3.0.0"
+ org.eclipse.sirius.ext.gmf.runtime.editparts;version="3.0.0",
+ org.eclipse.sirius.ext.gmf.runtime.editpolicies;version="4.0.0"
diff --git a/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editpolicies/SiriusSnapFeedbackPolicy.java b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editpolicies/SiriusSnapFeedbackPolicy.java
new file mode 100644
index 0000000000..e47e3ee8aa
--- /dev/null
+++ b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editpolicies/SiriusSnapFeedbackPolicy.java
@@ -0,0 +1,279 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2016 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * Laurent Redor (Obeo) <laurent.redor@obeo.fr> - Change feedback color
+ *******************************************************************************/
+package org.eclipse.sirius.ext.gmf.runtime.editpolicies;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.FigureUtilities;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.SnapToGeometry;
+import org.eclipse.gef.SnapToGuides;
+import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Specific feedback policy duplicated from
+ * {@link org.eclipse.gef.editpolicies.SnapFeedbackPolicy} to override guide
+ * colors.
+ *
+ * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a>
+ */
+public class SiriusSnapFeedbackPolicy extends GraphicalEditPolicy {
+
+ /**
+ * Color for guides of North, South, East or West side for snap to geometry.
+ * This is the original color used by GEF in
+ * {@link org.eclipse.gef.editpolicies.SnapFeedbackPolicy}.
+ */
+ public static final Color NSEW_GUIDE_ORIGINAL_COLOR = ColorConstants.blue;
+
+ /**
+ * Color for guides of North, South, East or West side for snap to geometry.
+ * Replace the blue color of
+ * {@link org.eclipse.gef.editpolicies.SnapFeedbackPolicy}.
+ */
+ public static final Color NSEW_GUIDE_COLOR = ColorConstants.lightGray;
+
+ /**
+ * Color for guides corresponding to Vertical guide or Horizontal guide.
+ * This is the original color used by GEF in
+ * {@link org.eclipse.gef.editpolicies.SnapFeedbackPolicy}.
+ */
+ public static final Color VERTICAL_HORIZONTAL_ORIGINAL_GUIDE_COLOR = new Color(null, 255, 175, 175);
+
+ /**
+ * Color for guides corresponding to Vertical guide or Horizontal guide.
+ * Replace the red color of
+ * {@link org.eclipse.gef.editpolicies.SnapFeedbackPolicy}.
+ */
+ public static final Color VERTICAL_HORIZONTAL_GUIDE_COLOR = new Color(null, 255, 175, 175);
+
+ /**
+ * Color for guides of North, South, East or West side for snap to geometry.
+ */
+ private Color nsewColor;
+
+ /**
+ * Color for guides corresponding to Vertical guide or Horizontal guide
+ */
+ private Color guideColor;
+
+ /**
+ * Default constructor that uses light gray and light red colors for
+ * feedback.
+ */
+ public SiriusSnapFeedbackPolicy() {
+ this(NSEW_GUIDE_COLOR, VERTICAL_HORIZONTAL_GUIDE_COLOR);
+ }
+
+ /**
+ * Constructor that allows to customize the colors to use for feedback.
+ *
+ * @param nsewColor
+ * Color for guides of North, South, East or West side for snap
+ * to geometry.
+ * @param guideColor
+ * Color for guides corresponding to Vertical guide or Horizontal
+ * guide.
+ */
+ public SiriusSnapFeedbackPolicy(Color nsewColor, Color guideColor) {
+ this.nsewColor = nsewColor;
+ this.guideColor = guideColor;
+ }
+
+ // CHECKSTYLE:OFF (Duplicated code)
+ IFigure guide[] = new IFigure[6];
+
+ Integer location[] = new Integer[6];
+
+ /**
+ * @see org.eclipse.gef.EditPolicy#eraseTargetFeedback(org.eclipse.gef.Request)
+ */
+ @Override
+ public void eraseTargetFeedback(Request request) {
+ for (int i = 0; i < guide.length; i++) {
+ if (guide[i] != null) {
+ removeFeedback(guide[i]);
+ }
+ guide[i] = null;
+ location[i] = null;
+ }
+ }
+
+ static class FadeIn extends Figure {
+ int opacity = 0;
+
+ static final int FRAMES = 6;
+
+ Image image;
+
+ static int count;
+
+ FadeIn(Color bg) {
+ setBackgroundColor(bg);
+ super.setOpaque(true);
+ }
+
+ private Color createMixedColor() {
+ return FigureUtilities.mixColors(getLocalBackgroundColor(), getParent().getBackgroundColor(), (double) opacity / FRAMES);
+ }
+
+ /**
+ * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
+ */
+ @Override
+ protected void paintFigure(Graphics graphics) {
+ if (opacity != FRAMES) {
+ if (image != null) {
+ image.dispose();
+ count--;
+ image = null;
+ }
+ if (opacity != FRAMES - 1) {
+ Display display = Display.getCurrent();
+ PaletteData pData = new PaletteData(0xFF, 0xFF00, 0xFF0000);
+ Color localBackgroundColor = createMixedColor();
+ int fillColor = pData.getPixel(localBackgroundColor.getRGB());
+ localBackgroundColor.dispose();
+ ImageData iData = new ImageData(1, 1, 24, pData);
+ iData.setPixel(0, 0, fillColor);
+ iData.setAlpha(0, 0, 255 * opacity / FRAMES);
+ image = new Image(display, iData);
+ count++;
+ }
+ Display.getCurrent().timerExec(100, new Runnable() {
+ @Override
+ public void run() {
+ opacity = Math.min(FRAMES, opacity + 1);
+ repaint();
+ }
+ });
+ }
+ Rectangle r = getBounds();
+ if (image != null) {
+ graphics.drawImage(image, 0, 0, 1, 1, r.x, r.y, r.width, r.height);
+ } else {
+ super.paintFigure(graphics);
+ }
+ }
+
+ /**
+ * @see org.eclipse.draw2d.Figure#removeNotify()
+ */
+ @Override
+ public void removeNotify() {
+ if (image != null) {
+ image.dispose();
+ count--;
+ image = null;
+ }
+ }
+ }
+
+ // Even offset indicates a vertical feedback line; odd, horizontal.
+ void highlightGuide(Integer pos, Color color, int offset) {
+ if (pos == null) {
+ if (guide[offset] != null) {
+ removeFeedback(guide[offset]);
+ guide[offset] = null;
+ }
+ location[offset] = pos;
+ return;
+ }
+
+ // pos is an integer relative to target's client area.
+ // translate pos to absolute, and then make it relative to fig.
+ int position = pos.intValue();
+ PrecisionPoint loc = new PrecisionPoint(position, position);
+ IFigure contentPane = ((GraphicalEditPart) getHost()).getContentPane();
+ contentPane.translateToParent(loc);
+ contentPane.translateToAbsolute(loc);
+
+ if (location[offset] == null || !location[offset].equals(pos)) {
+ location[offset] = pos;
+ if (guide[offset] != null) {
+ removeFeedback(guide[offset]);
+ guide[offset] = null;
+ }
+
+ IFigure fig = new FadeIn(color);
+ guide[offset] = fig;
+ addFeedback(fig);
+ fig.translateToRelative(loc);
+ position = offset % 2 == 0 ? (int) Math.round(loc.preciseX()) : (int) Math.round(loc.preciseY());
+ Rectangle figBounds = getFeedbackLayer().getBounds().getCopy();
+ if ((offset % 2) == 1) {
+ figBounds.height = 1;
+ figBounds.y = position;
+ } else {
+ figBounds.x = position;
+ figBounds.width = 1;
+ }
+ fig.setBounds(figBounds);
+ } else {
+ // The feedback layer could have grown (if auto-scrolling), so
+ // resize the fade-in
+ // line.
+ IFigure fig = guide[offset];
+ Rectangle figBounds = fig.getBounds().getCopy();
+ Rectangle feedbackBounds = getFeedbackLayer().getBounds();
+ if ((offset % 2) == 1) {
+ figBounds.x = feedbackBounds.x;
+ figBounds.width = feedbackBounds.width;
+ } else {
+ figBounds.y = feedbackBounds.y;
+ figBounds.height = feedbackBounds.height;
+ }
+ fig.setBounds(figBounds);
+ }
+ }
+
+ /**
+ * @see org.eclipse.gef.EditPolicy#showTargetFeedback(org.eclipse.gef.Request)
+ */
+ @Override
+ public void showTargetFeedback(Request req) {
+ if (req.getType().equals(RequestConstants.REQ_DROP) || req.getType().equals(REQ_MOVE) || req.getType().equals(REQ_RESIZE) || req.getType().equals(REQ_CLONE) || req.getType().equals(REQ_ADD)
+ || req.getType().equals(REQ_CREATE)) {
+ Integer value;
+ value = (Integer) req.getExtendedData().get(SnapToGeometry.KEY_WEST_ANCHOR);
+ highlightGuide(value, nsewColor, 0);
+
+ value = (Integer) req.getExtendedData().get(SnapToGeometry.KEY_NORTH_ANCHOR);
+ highlightGuide(value, nsewColor, 1);
+
+ value = (Integer) req.getExtendedData().get(SnapToGeometry.KEY_EAST_ANCHOR);
+ highlightGuide(value, nsewColor, 2);
+
+ value = (Integer) req.getExtendedData().get(SnapToGeometry.KEY_SOUTH_ANCHOR);
+ highlightGuide(value, nsewColor, 3);
+
+ value = (Integer) req.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
+ highlightGuide(value, guideColor, 4);
+
+ value = (Integer) req.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
+ highlightGuide(value, guideColor, 5);
+ }
+ }
+
+ // CHECKSTYLE:ON (Duplicated code)
+}

Back to the top