}
}
private UndoEntry handleInsertElement(final Element insertElement)
{
final Section parent = insertElement.getParentSection();
if (parent == null)
{
throw new IllegalStateException("Assert Failed: A newly inserted section must have a parent."); // NON-NLS
}
final int position = ModelUtility.findIndexOf(parent, insertElement);
if (position == -1)
{
if (insertElement instanceof SubReport && parent instanceof RootLevelBand)
{
final SubReport subReport = (SubReport) insertElement;
final RootLevelBand arb = (RootLevelBand) parent;
final int subreportPosition = ModelUtility.findSubreportIndexOf(arb, subReport);
if (subreportPosition == -1)
{
throw new IllegalStateException
("Assert Failed: A newly inserted section must have a position within its parent.");
}
else
{
return new BandedSubreportEditUndoEntry(parent.getObjectID(), arb.getSubReportCount(), null, subReport);
}
}
else
{
throw new IllegalStateException("A newly inserted section must have a position within its parent.");
}
}
else
{
return new ElementEditUndoEntry(parent.getObjectID(), position, null, insertElement);
}
}