ShapeFactoryPart factoryPart = (ShapeFactoryPart)toMovePart.parent();
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);
}
}