@Override protected Command createMoveChildCommand(EditPart child, EditPart after) { if (!(child instanceof ShapeEditPart)) { return null; } ShapeEditPart toMove = (ShapeEditPart) child; ShapePart toMovePart = (ShapePart) (((ShapeModel) toMove.getModel()).getSapphirePart()); ShapeFactoryPart factoryPart = (ShapeFactoryPart) toMovePart.getParentPart(); List<ShapePart> childShapes = factoryPart.getChildren(); if (!(after instanceof ShapeEditPart)) { return new MoveShapeInFactoryCommand(factoryPart, toMovePart, -1); } else { ShapeEditPart afterShape = (ShapeEditPart) after; ShapePart afterShapePart = (ShapePart) (((ShapeModel) afterShape.getModel()).getSapphirePart()); int oldIndex = childShapes.indexOf(toMovePart); int newIndex = childShapes.indexOf(afterShapePart); // subtract self from the index if (newIndex > oldIndex) { newIndex--; } return new MoveShapeInFactoryCommand(factoryPart, toMovePart, newIndex); } }