diff --git a/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/ActivityContainerEditPolicy.java b/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/ActivityContainerEditPolicy.java index bdaf6b56d..c80a78f22 100644 --- a/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/ActivityContainerEditPolicy.java +++ b/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/ActivityContainerEditPolicy.java @@ -12,17 +12,16 @@ *******************************************************************************/ package org.eclipse.gef.examples.flow.policies; -import java.util.List; - import org.eclipse.gef.EditPart; import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.CompoundCommand; import org.eclipse.gef.editpolicies.ContainerEditPolicy; +import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gef.requests.GroupRequest; + import org.eclipse.gef.examples.flow.model.Activity; import org.eclipse.gef.examples.flow.model.StructuredActivity; import org.eclipse.gef.examples.flow.model.commands.OrphanChildCommand; -import org.eclipse.gef.requests.CreateRequest; -import org.eclipse.gef.requests.GroupRequest; /** * ActivityContainerEditPolicy @@ -44,11 +43,10 @@ protected Command getCreateCommand(CreateRequest request) { */ @Override protected Command getOrphanChildrenCommand(GroupRequest request) { - List parts = request.getEditParts(); CompoundCommand result = new CompoundCommand(); - for (int i = 0; i < parts.size(); i++) { + for (EditPart child : request.getEditParts()) { OrphanChildCommand orphan = new OrphanChildCommand(); - orphan.setChild((Activity) ((EditPart) parts.get(i)).getModel()); + orphan.setChild((Activity) child.getModel()); orphan.setParent((StructuredActivity) getHost().getModel()); result.add(orphan); } diff --git a/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/ActivitySourceEditPolicy.java b/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/ActivitySourceEditPolicy.java index 06d925bac..786611b53 100644 --- a/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/ActivitySourceEditPolicy.java +++ b/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/ActivitySourceEditPolicy.java @@ -18,12 +18,13 @@ import org.eclipse.gef.commands.CompoundCommand; import org.eclipse.gef.editpolicies.AbstractEditPolicy; import org.eclipse.gef.editpolicies.ContainerEditPolicy; +import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gef.requests.GroupRequest; + import org.eclipse.gef.examples.flow.model.Activity; import org.eclipse.gef.examples.flow.model.StructuredActivity; import org.eclipse.gef.examples.flow.model.commands.AddAndAssignSourceCommand; import org.eclipse.gef.examples.flow.model.commands.CreateAndAssignSourceCommand; -import org.eclipse.gef.requests.CreateRequest; -import org.eclipse.gef.requests.GroupRequest; /** * @author Daniel Lee @@ -36,11 +37,11 @@ public class ActivitySourceEditPolicy extends ContainerEditPolicy { @Override protected Command getAddCommand(GroupRequest request) { CompoundCommand cmd = new CompoundCommand(); - for (int i = 0; i < request.getEditParts().size(); i++) { + for (EditPart ep : request.getEditParts()) { AddAndAssignSourceCommand add = new AddAndAssignSourceCommand(); add.setParent((StructuredActivity) getHost().getParent().getModel()); add.setSource((Activity) getHost().getModel()); - add.setChild(((Activity) ((EditPart) request.getEditParts().get(i)).getModel())); + add.setChild((Activity) ep.getModel()); cmd.add(add); } return cmd; @@ -63,12 +64,15 @@ protected Command getCreateCommand(CreateRequest request) { */ @Override public EditPart getTargetEditPart(Request request) { - if (REQ_CREATE.equals(request.getType())) + if (REQ_CREATE.equals(request.getType())) { return getHost(); - if (REQ_ADD.equals(request.getType())) + } + if (REQ_ADD.equals(request.getType())) { return getHost(); - if (REQ_MOVE.equals(request.getType())) + } + if (REQ_MOVE.equals(request.getType())) { return getHost(); + } return super.getTargetEditPart(request); } diff --git a/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/StructuredActivityLayoutEditPolicy.java b/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/StructuredActivityLayoutEditPolicy.java index 9cefa724d..71f438672 100644 --- a/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/StructuredActivityLayoutEditPolicy.java +++ b/org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/policies/StructuredActivityLayoutEditPolicy.java @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.gef.examples.flow.policies; -import java.util.List; - import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; @@ -21,13 +19,14 @@ import org.eclipse.gef.commands.CompoundCommand; import org.eclipse.gef.editpolicies.LayoutEditPolicy; import org.eclipse.gef.editpolicies.NonResizableEditPolicy; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.requests.CreateRequest; + import org.eclipse.gef.examples.flow.model.Activity; import org.eclipse.gef.examples.flow.model.StructuredActivity; import org.eclipse.gef.examples.flow.model.commands.AddCommand; import org.eclipse.gef.examples.flow.model.commands.CreateCommand; import org.eclipse.gef.examples.flow.parts.SimpleActivityPart; -import org.eclipse.gef.requests.ChangeBoundsRequest; -import org.eclipse.gef.requests.CreateRequest; /** * @author Daniel Lee @@ -47,20 +46,17 @@ protected Command createAddCommand(EditPart child) { */ @Override protected EditPolicy createChildEditPolicy(EditPart child) { - if (child instanceof SimpleActivityPart) + if (child instanceof SimpleActivityPart) { return new SimpleActivitySelectionEditPolicy(); + } return new NonResizableEditPolicy(); } @Override protected Command getAddCommand(Request req) { ChangeBoundsRequest request = (ChangeBoundsRequest) req; - List editParts = request.getEditParts(); CompoundCommand command = new CompoundCommand(); - for (int i = 0; i < editParts.size(); i++) { - EditPart child = (EditPart) editParts.get(i); - command.add(createAddCommand(child)); - } + request.getEditParts().forEach(child -> command.add(createAddCommand(child))); return command.unwrap(); } diff --git a/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicContainerEditPolicy.java b/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicContainerEditPolicy.java index 27d4725f2..6b7dfd580 100644 --- a/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicContainerEditPolicy.java +++ b/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicContainerEditPolicy.java @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.gef.examples.logicdesigner.edit; -import java.util.List; - import org.eclipse.gef.EditPart; import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.CompoundCommand; @@ -35,11 +33,10 @@ protected Command getCreateCommand(CreateRequest request) { @Override public Command getOrphanChildrenCommand(GroupRequest request) { - List parts = request.getEditParts(); CompoundCommand result = new CompoundCommand(LogicMessages.LogicContainerEditPolicy_OrphanCommandLabelText); - for (int i = 0; i < parts.size(); i++) { + for (EditPart child : request.getEditParts()) { OrphanChildCommand orphan = new OrphanChildCommand(); - orphan.setChild((LogicSubpart) ((EditPart) parts.get(i)).getModel()); + orphan.setChild((LogicSubpart) child.getModel()); orphan.setParent((LogicDiagram) getHost().getModel()); orphan.setLabel(LogicMessages.LogicElementEditPolicy_OrphanCommandLabelText); result.add(orphan); diff --git a/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicFlowEditPolicy.java b/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicFlowEditPolicy.java index cb22dc3f9..d1d65e2eb 100644 --- a/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicFlowEditPolicy.java +++ b/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicFlowEditPolicy.java @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.gef.examples.logicdesigner.edit; -import java.util.Iterator; - import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; import org.eclipse.gef.GraphicalEditPart; @@ -48,12 +46,10 @@ protected Command getCloneCommand(ChangeBoundsRequest request) { EditPart after = getInsertionReference(request); int index = getHost().getChildren().indexOf(after); - Iterator i = request.getEditParts().iterator(); - GraphicalEditPart currPart = null; - - while (i.hasNext()) { - currPart = (GraphicalEditPart) i.next(); - clone.addPart((LogicSubpart) currPart.getModel(), index++); + for (EditPart ep : request.getEditParts()) { + GraphicalEditPart currPart = (GraphicalEditPart) ep; + clone.addPart((LogicSubpart) currPart.getModel(), index); + index++; } return clone; @@ -85,8 +81,9 @@ protected Command createMoveChildCommand(EditPart child, EditPart after) { LogicDiagram parentModel = (LogicDiagram) getHost().getModel(); int oldIndex = getHost().getChildren().indexOf(child); int newIndex = getHost().getChildren().indexOf(after); - if (newIndex > oldIndex) + if (newIndex > oldIndex) { newIndex--; + } return new ReorderPartCommand(childModel, parentModel, newIndex); } diff --git a/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicTreeContainerEditPolicy.java b/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicTreeContainerEditPolicy.java index 3ebd39323..2abb6292e 100644 --- a/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicTreeContainerEditPolicy.java +++ b/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicTreeContainerEditPolicy.java @@ -45,8 +45,9 @@ protected Command createCreateCommand(LogicSubpart child, Rectangle r, int index cmd.setParent((LogicDiagram) getHost().getModel()); cmd.setChild(child); cmd.setLabel(label); - if (index >= 0) + if (index >= 0) { cmd.setIndex(index); + } return cmd; } @@ -54,14 +55,12 @@ protected Command createCreateCommand(LogicSubpart child, Rectangle r, int index protected Command getAddCommand(ChangeBoundsRequest request) { CompoundCommand command = new CompoundCommand(); command.setDebugLabel("Add in LogicTreeContainerEditPolicy");//$NON-NLS-1$ - List editparts = request.getEditParts(); int index = findIndexOfTreeItemAt(request.getLocation()); - for (int i = 0; i < editparts.size(); i++) { - EditPart child = (EditPart) editparts.get(i); - if (isAncestor(child, getHost())) + for (EditPart child : request.getEditParts()) { + if (isAncestor(child, getHost())) { command.add(UnexecutableCommand.INSTANCE); - else { + } else { LogicSubpart childModel = (LogicSubpart) child.getModel(); command.add(createCreateCommand(childModel, new Rectangle(new org.eclipse.draw2d.geometry.Point(), childModel.getSize()), index, @@ -81,18 +80,17 @@ protected Command getCreateCommand(CreateRequest request) { @Override protected Command getMoveChildrenCommand(ChangeBoundsRequest request) { CompoundCommand command = new CompoundCommand(); - List editparts = request.getEditParts(); List children = getHost().getChildren(); int newIndex = findIndexOfTreeItemAt(request.getLocation()); - for (int i = 0; i < editparts.size(); i++) { - EditPart child = (EditPart) editparts.get(i); + for (EditPart child : request.getEditParts()) { int tempIndex = newIndex; int oldIndex = children.indexOf(child); if (oldIndex == tempIndex || oldIndex + 1 == tempIndex) { command.add(UnexecutableCommand.INSTANCE); return command; - } else if (oldIndex <= tempIndex) { + } + if (oldIndex <= tempIndex) { tempIndex--; } command.add(new ReorderPartCommand((LogicSubpart) child.getModel(), (LogicDiagram) getHost().getModel(), @@ -102,10 +100,12 @@ protected Command getMoveChildrenCommand(ChangeBoundsRequest request) { } protected boolean isAncestor(EditPart source, EditPart target) { - if (source == target) + if (source == target) { return true; - if (target.getParent() != null) + } + if (target.getParent() != null) { return isAncestor(source, target.getParent()); + } return false; } diff --git a/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicXYLayoutEditPolicy.java b/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicXYLayoutEditPolicy.java index 2b0ae764c..d5a64effa 100644 --- a/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicXYLayoutEditPolicy.java +++ b/org.eclipse.gef.examples.logic/src/org/eclipse/gef/examples/logicdesigner/edit/LogicXYLayoutEditPolicy.java @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.gef.examples.logicdesigner.edit; -import java.util.Iterator; - import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; @@ -201,9 +199,8 @@ private static int getResizeDirections(Class modelClass) { } if (LogicLabel.class.equals(modelClass)) { return PositionConstants.EAST | PositionConstants.WEST; - } else { - return PositionConstants.NSEW; } + return PositionConstants.NSEW; } /* @@ -255,11 +252,8 @@ protected Command getCloneCommand(ChangeBoundsRequest request) { clone.setParent((LogicDiagram) getHost().getModel()); - Iterator i = request.getEditParts().iterator(); - GraphicalEditPart currPart = null; - - while (i.hasNext()) { - currPart = (GraphicalEditPart) i.next(); + for (EditPart ep : request.getEditParts()) { + GraphicalEditPart currPart = (GraphicalEditPart) ep; clone.addPart((LogicSubpart) currPart.getModel(), (Rectangle) getConstraintFor(request, currPart)); } diff --git a/org.eclipse.gef/src/org/eclipse/gef/SnapToGeometry.java b/org.eclipse.gef/src/org/eclipse/gef/SnapToGeometry.java index 1e450282d..209a830e9 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/SnapToGeometry.java +++ b/org.eclipse.gef/src/org/eclipse/gef/SnapToGeometry.java @@ -100,8 +100,9 @@ protected static class Entry { * @param location the location */ protected Entry(int type, int location) { - if (type < -1 || type > 1) + if (type < -1 || type > 1) { throw new IllegalArgumentException("Unrecognized snap type"); //$NON-NLS-1$ + } this.type = type; this.location = location; } @@ -201,7 +202,7 @@ protected void setThreshold(double newThreshold) { * @param exclusions the children to exclude * @return a list of parts which should be snapped to */ - protected List generateSnapPartsList(List exclusions) { + protected List generateSnapPartsList(List exclusions) { // Don't snap to any figure that is being dragged List children = new ArrayList<>(container.getChildren()); children.removeAll(exclusions); @@ -229,13 +230,16 @@ protected double getCorrectionFor(Entry[] entries, Map extendedData, boolean ver // far) there is no middle pixel so favor the left-most/top-most pixel // (which is what // populateRowsAndCols() does by using int precision). - if ((int) (near - far) % 2 != 0) + if ((int) (near - far) % 2 != 0) { total -= 1.0; + } double result = getCorrectionFor(entries, extendedData, vert, total / 2, 0); - if (result == getThreshold()) + if (result == getThreshold()) { result = getCorrectionFor(entries, extendedData, vert, near, -1); - if (result == getThreshold()) + } + if (result == getThreshold()) { result = getCorrectionFor(entries, extendedData, vert, far, 1); + } return result; } @@ -255,13 +259,13 @@ protected double getCorrectionFor(Entry[] entries, Map extendedData, boolean ver double result = getThreshold(); String property; - if (side == -1) + if (side == -1) { property = vert ? KEY_WEST_ANCHOR : KEY_NORTH_ANCHOR; - else + } else { property = vert ? KEY_EAST_ANCHOR : KEY_SOUTH_ANCHOR; + } - for (int i = 0; i < entries.length; i++) { - Entry entry = entries[i]; + for (Entry entry : entries) { double magnitude; if (entry.type == -1 && side != 0) { @@ -309,11 +313,11 @@ protected Rectangle getFigureBounds(GraphicalEditPart part) { * @since 3.0 * @param parts a List of EditParts */ - protected void populateRowsAndCols(List parts) { + protected void populateRowsAndCols(List parts) { rows = new Entry[parts.size() * 3]; cols = new Entry[parts.size() * 3]; for (int i = 0; i < parts.size(); i++) { - GraphicalEditPart child = (GraphicalEditPart) parts.get(i); + GraphicalEditPart child = parts.get(i); Rectangle bounds = getFigureBounds(child); cols[i * 3] = new Entry(-1, bounds.x); rows[i * 3] = new Entry(-1, bounds.y); @@ -341,15 +345,15 @@ public int snapRectangle(Request request, int snapOrientation, PrecisionRectangl boolean isClone = request.getType().equals(RequestConstants.REQ_CLONE); if (rows == null || cols == null || isClone != cachedCloneBool) { cachedCloneBool = isClone; - List exclusionSet = Collections.EMPTY_LIST; - if (!isClone && request instanceof GroupRequest) - exclusionSet = ((GroupRequest) request).getEditParts(); + List exclusionSet = Collections.emptyList(); + if (!isClone && request instanceof GroupRequest groupRequest) { + exclusionSet = groupRequest.getEditParts(); + } populateRowsAndCols(generateSnapPartsList(exclusionSet)); } if ((snapOrientation & HORIZONTAL) != 0) { - double xcorrect = getThreshold(); - xcorrect = getCorrectionFor(cols, request.getExtendedData(), true, baseRect.preciseX(), + double xcorrect = getCorrectionFor(cols, request.getExtendedData(), true, baseRect.preciseX(), baseRect.preciseRight()); if (xcorrect != getThreshold()) { snapOrientation &= ~HORIZONTAL; @@ -358,8 +362,7 @@ public int snapRectangle(Request request, int snapOrientation, PrecisionRectangl } if ((snapOrientation & VERTICAL) != 0) { - double ycorrect = getThreshold(); - ycorrect = getCorrectionFor(rows, request.getExtendedData(), false, baseRect.preciseY(), + double ycorrect = getCorrectionFor(rows, request.getExtendedData(), false, baseRect.preciseY(), baseRect.preciseBottom()); if (ycorrect != getThreshold()) { snapOrientation &= ~VERTICAL; diff --git a/org.eclipse.gef/src/org/eclipse/gef/SnapToGuides.java b/org.eclipse.gef/src/org/eclipse/gef/SnapToGuides.java index a400db8f9..0a3a18e1d 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/SnapToGuides.java +++ b/org.eclipse.gef/src/org/eclipse/gef/SnapToGuides.java @@ -160,13 +160,16 @@ protected double getCorrectionFor(int[] guides, double near, double far, Map ext double total = near + far; // If the width is even, there is no middle pixel so favor the left - // most pixel. - if ((int) (near - far) % 2 == 0) + if ((int) (near - far) % 2 == 0) { total -= 1.0; + } double result = getCorrectionFor(guides, total / 2, extendedData, isVertical, 0); - if (result == getThreshold()) + if (result == getThreshold()) { result = getCorrectionFor(guides, near, extendedData, isVertical, -1); - if (result == getThreshold()) + } + if (result == getThreshold()) { result = getCorrectionFor(guides, far, extendedData, isVertical, 1); + } return result; } @@ -190,13 +193,12 @@ protected double getCorrectionFor(int[] guides, double value, Map extendedData, double resultMag = getThreshold(); double result = getThreshold(); - for (int i = 0; i < guides.length; i++) { - int offset = guides[i]; + for (int offset : guides) { double magnitude; magnitude = Math.abs(value - offset); if (magnitude < resultMag) { - extendedData.put(vert ? KEY_VERTICAL_GUIDE : KEY_HORIZONTAL_GUIDE, Integer.valueOf(guides[i])); + extendedData.put(vert ? KEY_VERTICAL_GUIDE : KEY_HORIZONTAL_GUIDE, Integer.valueOf(offset)); extendedData.put(vert ? KEY_VERTICAL_ANCHOR : KEY_HORIZONTAL_ANCHOR, Integer.valueOf(side)); resultMag = magnitude; result = offset - value; @@ -215,10 +217,11 @@ protected int[] getHorizontalGuides() { if (horizontalGuides == null) { RulerProvider rProvider = ((RulerProvider) container.getViewer() .getProperty(RulerProvider.PROPERTY_VERTICAL_RULER)); - if (rProvider != null) + if (rProvider != null) { horizontalGuides = rProvider.getGuidePositions(); - else + } else { horizontalGuides = new int[0]; + } } return horizontalGuides; } @@ -233,10 +236,11 @@ protected int[] getVerticalGuides() { if (verticalGuides == null) { RulerProvider rProvider = ((RulerProvider) container.getViewer() .getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER)); - if (rProvider != null) + if (rProvider != null) { verticalGuides = rProvider.getGuidePositions(); - else + } else { verticalGuides = new int[0]; + } } return verticalGuides; } @@ -248,8 +252,9 @@ protected int[] getVerticalGuides() { @Override public int snapRectangle(Request request, int snapOrientation, PrecisionRectangle baseRect, PrecisionRectangle result) { - if (request instanceof GroupRequest && ((GroupRequest) request).getEditParts().size() > 1) + if (request instanceof GroupRequest groupReq && groupReq.getEditParts().size() > 1) { return snapOrientation; + } baseRect = baseRect.getPreciseCopy(); makeRelative(container.getContentPane(), baseRect); diff --git a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ConstrainedLayoutEditPolicy.java b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ConstrainedLayoutEditPolicy.java index c0b295297..1423ca8ba 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ConstrainedLayoutEditPolicy.java +++ b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/ConstrainedLayoutEditPolicy.java @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.gef.editpolicies; -import java.util.List; - import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PrecisionRectangle; @@ -89,6 +87,7 @@ protected Command createAddCommand(ChangeBoundsRequest request, EditPart child, * {@link #createAddCommand(ChangeBoundsRequest, EditPart, Object)} * instead. */ + @Deprecated protected Command createAddCommand(EditPart child, Object constraint) { return null; } @@ -135,6 +134,7 @@ protected Command createChangeConstraintCommand(ChangeBoundsRequest request, Edi * {@link #createChangeConstraintCommand(ChangeBoundsRequest, EditPart, Object)} * instead. */ + @Deprecated protected Command createChangeConstraintCommand(EditPart child, Object constraint) { return null; } @@ -161,13 +161,11 @@ protected EditPolicy createChildEditPolicy(EditPart child) { @Override protected Command getAddCommand(Request generic) { ChangeBoundsRequest request = (ChangeBoundsRequest) generic; - List editParts = request.getEditParts(); CompoundCommand command = new CompoundCommand(); command.setDebugLabel("Add in ConstrainedLayoutEditPolicy");//$NON-NLS-1$ - GraphicalEditPart child; - for (int i = 0; i < editParts.size(); i++) { - child = (GraphicalEditPart) editParts.get(i); + for (EditPart ep : request.getEditParts()) { + GraphicalEditPart child = (GraphicalEditPart) ep; command.add(createAddCommand(request, child, translateToModelConstraint(getConstraintFor(request, child)))); } return command.unwrap(); @@ -192,10 +190,12 @@ protected Command getAlignChildrenCommand(AlignmentRequest request) { */ @Override public Command getCommand(Request request) { - if (REQ_RESIZE_CHILDREN.equals(request.getType())) + if (REQ_RESIZE_CHILDREN.equals(request.getType())) { return getResizeChildrenCommand((ChangeBoundsRequest) request); - if (REQ_ALIGN_CHILDREN.equals(request.getType())) + } + if (REQ_ALIGN_CHILDREN.equals(request.getType())) { return getAlignChildrenCommand((AlignmentRequest) request); + } return super.getCommand(request); } @@ -314,6 +314,7 @@ protected Object getConstraintFor(CreateRequest request) { * clients. * @noreference This method is not intended to be referenced by clients. */ + @Deprecated protected Object getConstraintForClone(GraphicalEditPart part, ChangeBoundsRequest request) { // anyssen: The code executed herein was functionally the same // as that in getConstraintFor(ChangeBoundsRequest, GraphicalEditPart), @@ -355,15 +356,11 @@ protected Command getResizeChildrenCommand(ChangeBoundsRequest request) { */ protected Command getChangeConstraintCommand(ChangeBoundsRequest request) { CompoundCommand resize = new CompoundCommand(); - Command c; - GraphicalEditPart child; - List children = request.getEditParts(); - for (int i = 0; i < children.size(); i++) { - child = (GraphicalEditPart) children.get(i); - c = createChangeConstraintCommand(request, child, - translateToModelConstraint(getConstraintFor(request, child))); - resize.add(c); + for (EditPart ep : request.getEditParts()) { + GraphicalEditPart child = (GraphicalEditPart) ep; + resize.add(createChangeConstraintCommand(request, child, + translateToModelConstraint(getConstraintFor(request, child)))); } return resize.unwrap(); } diff --git a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/OrderedLayoutEditPolicy.java b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/OrderedLayoutEditPolicy.java index 07ee1c298..ecaa1a802 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/editpolicies/OrderedLayoutEditPolicy.java +++ b/org.eclipse.gef/src/org/eclipse/gef/editpolicies/OrderedLayoutEditPolicy.java @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.gef.editpolicies; -import java.util.List; - import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.OrderedLayout; @@ -91,12 +89,8 @@ protected EditPolicy createChildEditPolicy(EditPart child) { @Override protected Command getAddCommand(Request req) { ChangeBoundsRequest request = (ChangeBoundsRequest) req; - List editParts = request.getEditParts(); CompoundCommand command = new CompoundCommand(); - for (int i = 0; i < editParts.size(); i++) { - EditPart child = (EditPart) editParts.get(i); - command.add(createAddCommand(child, getInsertionReference(request))); - } + request.getEditParts().forEach(child -> command.add(createAddCommand(child, getInsertionReference(request)))); return command.unwrap(); } @@ -123,13 +117,9 @@ protected Command getAddCommand(Request req) { @Override protected Command getMoveChildrenCommand(Request request) { CompoundCommand command = new CompoundCommand(); - List editParts = ((ChangeBoundsRequest) request).getEditParts(); - EditPart insertionReference = getInsertionReference(request); - for (int i = 0; i < editParts.size(); i++) { - EditPart child = (EditPart) editParts.get(i); - command.add(createMoveChildCommand(child, insertionReference)); - } + ((ChangeBoundsRequest) request).getEditParts() + .forEach(child -> command.add(createMoveChildCommand(child, insertionReference))); return command.unwrap(); }