{
return;
}
Collections.sort(reportElements, new ElementPositionComparator());
final MassElementStyleUndoEntryBuilder builder = new MassElementStyleUndoEntryBuilder(reportElements);
final Element[] carrier = new Element[1];
final int lastElementIdx = reportElements.size() - 1;
final Element lastElement = reportElements.get(lastElementIdx);
final Element firstElement = reportElements.get(0);
final CachedLayoutData firstLayoutData = ModelUtility.getCachedLayoutData(firstElement);
final CachedLayoutData lastLayoutData = ModelUtility.getCachedLayoutData(lastElement);
final long height = (lastLayoutData.getY() + lastLayoutData.getHeight()) -
(firstLayoutData.getY() + firstLayoutData.getHeight());
final long incr = height / lastElementIdx;
long currentY = firstLayoutData.getY() + firstLayoutData.getHeight();
currentY += incr;//start from second element
for (int i = 1; i < lastElementIdx; i++)
{
final Element reportElement = reportElements.get(i);
final CachedLayoutData layoutData = ModelUtility.getCachedLayoutData(reportElement);
final long delta = currentY - layoutData.getHeight();
if (delta == 0)
{
continue;
}
carrier[0] = reportElement;
final Point2D.Double originPoint = new Point2D.Double(0, StrictGeomUtility.toExternalValue(layoutData.getY()));
final MoveDragOperation mop = new MoveDragOperation
(Arrays.asList(carrier), originPoint, EmptySnapModel.INSTANCE, EmptySnapModel.INSTANCE);
mop.update(new Point2D.Double(0, StrictGeomUtility.toExternalValue(delta)), 1);
mop.finish();
currentY += incr;
}
final MassElementStyleUndoEntry massElementStyleUndoEntry = builder.finish();
getActiveContext().getUndo().addChange(ActionMessages.getString("DistributeBottomAction.UndoName"), massElementStyleUndoEntry);
}