diff options
author | vlorenzo | 2014-02-19 14:57:00 +0000 |
---|---|---|
committer | vlorenzo | 2014-02-19 14:59:11 +0000 |
commit | d1374f5b07a3f2e2cff017a2e1e27ac3a5b5e30c (patch) | |
tree | 64c897e2231b4fa87e4fc7f9256ef3d3e5012091 /plugins | |
parent | c95fad2fd31b01847c32354be5a23edd27e8be52 (diff) | |
download | org.eclipse.papyrus-d1374f5b07a3f2e2cff017a2e1e27ac3a5b5e30c.tar.gz org.eclipse.papyrus-d1374f5b07a3f2e2cff017a2e1e27ac3a5b5e30c.tar.xz org.eclipse.papyrus-d1374f5b07a3f2e2cff017a2e1e27ac3a5b5e30c.zip |
427129: Figures newly created via the palette should be snapped to grid
if "snap to grid" is activated
https://bugs.eclipse.org/bugs/show_bug.cgi?id=427129
FIX NPE on Snap Helper
Diffstat (limited to 'plugins')
2 files changed, 42 insertions, 40 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java index 87d508506f5..aa77b8fa7f1 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java @@ -86,24 +86,26 @@ public class XYLayoutWithConstrainedResizedEditPolicy extends XYLayoutEditPolicy double spacing = drep.getGridSpacing();
final double max_value = spacing * 20;
final SnapToHelper helper = (SnapToHelper)getHost().getAdapter(SnapToHelper.class);
- final LayoutHelper layoutHelper = new LayoutHelper();
- while(add < max_value) {//we define a max value to do test
- Rectangle LOCAL_BOUNDS = BOUNDS.getCopy();
- LOCAL_BOUNDS.translate(add, add);
- Rectangle tmp_rect = getBoundsOffest(req, LOCAL_BOUNDS, viewDescriptor);
- final PrecisionRectangle resultRect = new PrecisionRectangle(tmp_rect);
- resultRect.setWidth(-1);
- resultRect.setHeight(-1);
- PrecisionPoint res1 = new PrecisionPoint(tmp_rect.getLocation());
- helper.snapPoint(request, PositionConstants.NORTH_WEST, res1.getPreciseCopy(), res1);
- final Point pt = layoutHelper.validatePosition(getHostFigure(), resultRect.setLocation(res1));
- if(couldBeSnaped) {
- if(pt.equals(resultRect.getLocation())) {
- rect.setLocation(resultRect.getLocation());
- break;
- } else {
- add += spacing;
- continue;
+ if(helper != null) {
+ final LayoutHelper layoutHelper = new LayoutHelper();
+ while(add < max_value) {//we define a max value to do test
+ Rectangle LOCAL_BOUNDS = BOUNDS.getCopy();
+ LOCAL_BOUNDS.translate(add, add);
+ Rectangle tmp_rect = getBoundsOffest(req, LOCAL_BOUNDS, viewDescriptor);
+ final PrecisionRectangle resultRect = new PrecisionRectangle(tmp_rect);
+ resultRect.setWidth(-1);
+ resultRect.setHeight(-1);
+ PrecisionPoint res1 = new PrecisionPoint(tmp_rect.getLocation());
+ helper.snapPoint(request, PositionConstants.NORTH_WEST, res1.getPreciseCopy(), res1);
+ final Point pt = layoutHelper.validatePosition(getHostFigure(), resultRect.setLocation(res1));
+ if(couldBeSnaped) {
+ if(pt.equals(resultRect.getLocation())) {
+ rect.setLocation(resultRect.getLocation());
+ break;
+ } else {
+ add += spacing;
+ continue;
+ }
}
}
}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultXYLayoutEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultXYLayoutEditPolicy.java index 29bf93747f3..2ad1e4c7118 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultXYLayoutEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultXYLayoutEditPolicy.java @@ -40,8 +40,6 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.XYLayoutWithConstra */ public class DefaultXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEditPolicy { - protected double spacing = 80; - /** * Called in response to a <tt>REQ_CREATE</tt> request. Returns a command * to set each created element bounds and auto-size properties. @@ -64,33 +62,35 @@ public class DefaultXYLayoutEditPolicy extends XYLayoutWithConstrainedResizedEdi while(iter.hasNext()) { CreateViewRequest.ViewDescriptor viewDescriptor = (CreateViewRequest.ViewDescriptor)iter.next(); Rectangle rect = getBoundsOffest(req, BOUNDS, viewDescriptor); - + //see bug 427129: Figures newly created via the palette should be snapped to grid if "snap to grid" is activated if(couldBeSnaped) { //this code fix the bug in some case... int add = 0; DiagramRootEditPart drep = (DiagramRootEditPart)getHost().getRoot(); double spacing = drep.getGridSpacing(); - final double max_value = spacing*20; + final double max_value = spacing * 20; final SnapToHelper helper = (SnapToHelper)getHost().getAdapter(SnapToHelper.class); - final LayoutHelper layoutHelper = new LayoutHelper(); - while(add < max_value) {//we define a max value to do test - Rectangle LOCAL_BOUNDS = BOUNDS.getCopy(); - LOCAL_BOUNDS.translate(add, add); - Rectangle tmp_rect = getBoundsOffest(req, LOCAL_BOUNDS, viewDescriptor); - final PrecisionRectangle resultRect = new PrecisionRectangle(tmp_rect); - resultRect.setWidth(-1); - resultRect.setHeight(-1); - PrecisionPoint res1 = new PrecisionPoint(tmp_rect.getLocation()); - helper.snapPoint(request, PositionConstants.NORTH_WEST, res1.getPreciseCopy(), res1); - final Point pt = layoutHelper.validatePosition(getHostFigure(), resultRect.setLocation(res1)); - if(couldBeSnaped) { - if(pt.equals(resultRect.getLocation())) { - rect.setLocation(resultRect.getLocation()); - break; - } else { - add +=spacing; - continue; + if(helper != null) { + final LayoutHelper layoutHelper = new LayoutHelper(); + while(add < max_value) {//we define a max value to do test + Rectangle LOCAL_BOUNDS = BOUNDS.getCopy(); + LOCAL_BOUNDS.translate(add, add); + Rectangle tmp_rect = getBoundsOffest(req, LOCAL_BOUNDS, viewDescriptor); + final PrecisionRectangle resultRect = new PrecisionRectangle(tmp_rect); + resultRect.setWidth(-1); + resultRect.setHeight(-1); + PrecisionPoint res1 = new PrecisionPoint(tmp_rect.getLocation()); + helper.snapPoint(request, PositionConstants.NORTH_WEST, res1.getPreciseCopy(), res1); + final Point pt = layoutHelper.validatePosition(getHostFigure(), resultRect.setLocation(res1)); + if(couldBeSnaped) { + if(pt.equals(resultRect.getLocation())) { + rect.setLocation(resultRect.getLocation()); + break; + } else { + add += spacing; + continue; + } } } } |