if (newStructuredDocumentRegion == null)
return null;
if (nextStructuredDocumentRegion == null)
return appendStructuredDocumentRegion(newStructuredDocumentRegion);
IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
if (flatNode == null)
return null; // error
if (flatNode == nextStructuredDocumentRegion) {
StructuredDocumentRegionContainer container = new StructuredDocumentRegionContainer();
container.appendStructuredDocumentRegion(newStructuredDocumentRegion);
container.appendStructuredDocumentRegion(flatNode);
setStructuredDocumentRegion(container);
return newStructuredDocumentRegion;
}
if (flatNode instanceof StructuredDocumentRegionContainer) {
StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
int count = container.getStructuredDocumentRegionCount();
for (int i = 0; i < count; i++) {
IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
if (content == nextStructuredDocumentRegion) {
container.insertStructuredDocumentRegion(newStructuredDocumentRegion, i);
return newStructuredDocumentRegion;
}
}