use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class ShowRowPositionsEvent method getRowDiffs.
@Override
public Collection<StructuralDiff> getRowDiffs() {
Collection<StructuralDiff> rowDiffs = new ArrayList<StructuralDiff>(getRowPositionRanges().size());
int offset = 0;
for (Range range : getRowPositionRanges()) {
rowDiffs.add(new StructuralDiff(DiffTypeEnum.ADD, new Range(range.start - offset, range.start - offset), range));
offset += range.size();
}
return rowDiffs;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class RowStructuralChangeEvent method getChangedPositionRectangles.
@Override
public Collection<Rectangle> getChangedPositionRectangles() {
Collection<Rectangle> changedPositionRectangles = new ArrayList<Rectangle>(getRowPositionRanges().size());
int columnCount = getLayer().getColumnCount();
int rowCount = getLayer().getRowCount();
for (Range range : getRowPositionRanges()) {
changedPositionRectangles.add(new Rectangle(0, range.start, columnCount, rowCount - range.start));
}
return changedPositionRectangles;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class RowVisualChangeEvent method getChangedPositionRectangles.
@Override
public Collection<Rectangle> getChangedPositionRectangles() {
Collection<Rectangle> changedPositionRectangles = new ArrayList<Rectangle>(this.rowPositionRanges.size());
int columnCount = this.layer.getColumnCount();
for (Range range : this.rowPositionRanges) {
changedPositionRectangles.add(new Rectangle(0, range.start, columnCount, range.end - range.start));
}
return changedPositionRectangles;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class StructuralChangeEventHelper method handleRowDelete.
/**
* Will check for events that indicate that rows have been deleted. In that
* case the given cached dataChanges need to be updated because the index of
* the rows might have changed. E.g. cell with row at index 3 is changed in
* the given layer, deleting row at index 1 will cause the row at index 3 to
* be moved to index 2. Without transforming the index regarding the delete
* event, the wrong cell at the incorrect row would be shown as changed.
*
* @param rowDiffs
* The collection of {@link StructuralDiff}s to handle.
* @param dataChanges
* The map that contains the data changes identified by a key
* that should be updated.
* @param keyHandler
* the {@link CellKeyHandler} that needs to be used to operate on
* the dataChanges correctly.
*
* @since 1.6
*/
public static <K, T> void handleRowDelete(Collection<StructuralDiff> rowDiffs, Map<K, T> dataChanges, CellKeyHandler<K> keyHandler) {
// for correct calculation the diffs need to be processed from lowest
// position to highest
List<StructuralDiff> diffs = new ArrayList<StructuralDiff>(rowDiffs);
Collections.sort(diffs, new Comparator<StructuralDiff>() {
@Override
public int compare(StructuralDiff o1, StructuralDiff o2) {
return o1.getBeforePositionRange().start - o2.getBeforePositionRange().start;
}
});
List<Integer> toRemove = new ArrayList<Integer>();
for (StructuralDiff rowDiff : diffs) {
if (rowDiff.getDiffType() != null && rowDiff.getDiffType().equals(DiffTypeEnum.DELETE)) {
Range beforePositionRange = rowDiff.getBeforePositionRange();
for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
int index = i;
if (index >= 0) {
toRemove.add(index);
}
}
}
}
// modify row indexes regarding the deleted rows
Map<K, T> modifiedRows = new HashMap<K, T>();
for (Map.Entry<K, T> entry : dataChanges.entrySet()) {
int columnIndex = keyHandler.getColumnIndex(entry.getKey());
int rowIndex = keyHandler.getRowIndex(entry.getKey());
if (!toRemove.contains(rowIndex)) {
// check number of removed indexes that are lower than the
// current one
int deletedBefore = 0;
for (Integer removed : toRemove) {
if (removed < rowIndex) {
deletedBefore++;
}
}
int modRow = rowIndex - deletedBefore;
if (modRow >= 0) {
modifiedRows.put(keyHandler.getKey(columnIndex, modRow), entry.getValue());
}
}
}
dataChanges.clear();
dataChanges.putAll(modifiedRows);
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class StructuralChangeEventHelper method handleRowInsert.
/**
* Will check for events that indicate that rows are added. In that case the
* given cached indexes need to be updated because the index of the rows
* might have changed. E.g. Row with index 3 is hidden in the given layer,
* adding a row at index 1 will cause the row at index 3 to be moved to
* index 4. Without transforming the index regarding the add event, the
* wrong row would be hidden.
*
* @param rowDiffs
* The collection of {@link StructuralDiff}s to handle
* @param underlyingLayer
* The underlying layer of the layer who caches the indexes.
* Needed to translate the transported row positions to indexes,
* because the conversion to the layer who caches the index is
* done before it is fired further in the layer stack
* @param cachedRowIndexes
* The collection of indexes that is cached by the layer that
* needs transformation
* @param addToCache
* Flag to configure if the added value should be added to the
* cache or not. This is necessary to differ whether
* cachedRowIndexes are a collection of all indexes that need to
* be updated (e.g. row reordering) or just a collection of
* indexes that are applied for a specific state (e.g. row hide
* state)
*/
public static void handleRowInsert(Collection<StructuralDiff> rowDiffs, ILayer underlyingLayer, Collection<Integer> cachedRowIndexes, boolean addToCache) {
for (StructuralDiff rowDiff : rowDiffs) {
if (rowDiff.getDiffType() != null && rowDiff.getDiffType().equals(DiffTypeEnum.ADD)) {
Range beforePositionRange = rowDiff.getBeforePositionRange();
List<Integer> modifiedRows = new ArrayList<Integer>();
int beforeIndex = underlyingLayer.getRowIndexByPosition(beforePositionRange.start);
for (Integer row : cachedRowIndexes) {
if (row >= beforeIndex) {
modifiedRows.add(row + 1);
} else {
modifiedRows.add(row);
}
}
if (addToCache) {
modifiedRows.add(beforeIndex, beforePositionRange.start);
}
cachedRowIndexes.clear();
cachedRowIndexes.addAll(modifiedRows);
}
}
}
Aggregations