if (position.getType() != null
&& ITextRange.class.isAssignableFrom(position.getType())) {
range = (ITextRange) position.getDestinationObject();
}
ITextDocument textDocument = textTable.getTextDocument();
ITextContentService textContentService = textDocument
.getTextService().getTextContentService();
ITextTable newTable = textDocument.getTextTableService()
.constructTextTable(tablePropertyStore.getRows(),
tablePropertyStore.getColumns());
if (range != null) {
textContentService.insertTextContent(range, newTable);
} else {
textContentService.insertTextContentAfter(newTable, textTable);
}
String[] propertyKeysToCopy = null;
if (propertyKeysContainer != null) {
propertyKeysToCopy = propertyKeysContainer
.getPropertyKeys(ITextTableProperties.TYPE_ID);
} else {
// use default
propertyKeysToCopy = TextTableProperties
.getDefaultPropertyKeys();
}
if (propertyKeysToCopy != null) {
ITextTableProperties newTableProperties = newTable
.getProperties();
((IPropertyStore) tablePropertyStore).getProperties().copyTo(
propertyKeysToCopy, newTableProperties);
}
int rowArrayLength = cellCloneServices.length;
for (int rows = 0; rows < rowArrayLength; rows++) {
// set row height
newTable.getRow(rows).setHeight(
textTable.getRow(rows).getHeight());
newTable.getRow(rows).setAutoHeight(
textTable.getRow(rows).getAutoHeight());
int columnArrayLength = cellCloneServices[rows].length;
for (int columns = 0; columns < columnArrayLength; columns++) {
ICloneService cellClone = cellCloneServices[rows][columns];
ITextTableCell textTableCell = newTable.getCell(columns,
rows);
CloneDestinationPosition destinationCell = new CloneDestinationPosition(
textTableCell, textTableCell.getClass());
cellClone.cloneToPositionNoReturn(destinationCell,
adoptContent, propertyKeysContainer);
}
}
if (createSpace) {
IParagraph paragraph = textContentService
.constructNewParagraph();
textContentService.insertTextContentBefore(paragraph, newTable);
}
if (generateReturnValue)
return new ClonedObject(newTable, newTable.getClass());
else
return null;