int columnGroupCount = project.columnModel.columnGroups.size();
int columnCountChange = _columnNames.size() - (_removeOriginalColumn ? 1 : 0);
_oldColumnGroups = new ArrayList<ColumnGroup>(columnGroupCount);
for (int i = columnGroupCount - 1; i >= 0; i--) {
ColumnGroup columnGroup = project.columnModel.columnGroups.get(i);
_oldColumnGroups.add(columnGroup);
if (columnGroup.startColumnIndex <= _columnIndex) {
if (columnGroup.startColumnIndex + columnGroup.columnSpan > _columnIndex) {
// the column being split is in the middle of the group
if (columnGroup.keyColumnIndex == _columnIndex) {
if (_removeOriginalColumn) {
// the key column is being split and removed
project.columnModel.columnGroups.remove(i);
} else {
project.columnModel.columnGroups.set(i, new ColumnGroup(
columnGroup.startColumnIndex,
columnGroup.columnSpan + columnCountChange,
columnGroup.keyColumnIndex
));
}
} else {
project.columnModel.columnGroups.set(i, new ColumnGroup(
columnGroup.startColumnIndex,
columnGroup.columnSpan + columnCountChange,
columnGroup.keyColumnIndex < _columnIndex ?
columnGroup.keyColumnIndex :
(columnGroup.keyColumnIndex + columnCountChange)
));
}
}
} else {
// the new column precedes this whole group
project.columnModel.columnGroups.set(i, new ColumnGroup(
columnGroup.startColumnIndex + columnCountChange,
columnGroup.columnSpan,
columnGroup.keyColumnIndex + columnCountChange
));
}