use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class RowReorderLayer method handleLayerEvent.
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof IStructuralChangeEvent) {
IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
if (structuralChangeEvent.isVerticalStructureChanged()) {
Collection<StructuralDiff> structuralDiffs = structuralChangeEvent.getRowDiffs();
if (structuralDiffs == null) {
// Assume everything changed
populateIndexOrder();
} else {
// only react on ADD or DELETE and not on CHANGE
StructuralChangeEventHelper.handleRowDelete(structuralDiffs, this.underlyingLayer, this.rowIndexOrder, true);
StructuralChangeEventHelper.handleRowInsert(structuralDiffs, this.underlyingLayer, this.rowIndexOrder, true);
// update index-position mapping
refreshIndexPositionMapping();
}
invalidateCache();
}
}
super.handleLayerEvent(event);
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class RowReorderEvent method getRowDiffs.
@Override
public Collection<StructuralDiff> getRowDiffs() {
Collection<StructuralDiff> rowDiffs = new ArrayList<StructuralDiff>();
Collection<Range> beforeFromRowPositionRanges = getBeforeFromRowPositionRanges();
final int beforeToRowPosition = (this.reorderToTopEdge) ? this.beforeToRowPosition : (this.beforeToRowPosition + 1);
int afterAddRowPosition = beforeToRowPosition;
for (Range beforeFromRowPositionRange : beforeFromRowPositionRanges) {
if (beforeFromRowPositionRange.start < beforeToRowPosition) {
afterAddRowPosition -= Math.min(beforeFromRowPositionRange.end, beforeToRowPosition) - beforeFromRowPositionRange.start;
} else {
break;
}
}
int cumulativeAddSize = 0;
for (Range beforeFromRowPositionRange : beforeFromRowPositionRanges) {
cumulativeAddSize += beforeFromRowPositionRange.size();
}
int offset = 0;
for (Range beforeFromRowPositionRange : beforeFromRowPositionRanges) {
int afterDeleteRowPosition = beforeFromRowPositionRange.start - offset;
if (afterAddRowPosition < afterDeleteRowPosition) {
afterDeleteRowPosition += cumulativeAddSize;
}
rowDiffs.add(new StructuralDiff(DiffTypeEnum.DELETE, beforeFromRowPositionRange, new Range(afterDeleteRowPosition, afterDeleteRowPosition)));
offset += beforeFromRowPositionRange.size();
}
Range beforeAddRange = new Range(beforeToRowPosition, beforeToRowPosition);
offset = 0;
for (Range beforeFromRowPositionRange : beforeFromRowPositionRanges) {
int size = beforeFromRowPositionRange.size();
rowDiffs.add(new StructuralDiff(DiffTypeEnum.ADD, beforeAddRange, new Range(afterAddRowPosition + offset, afterAddRowPosition + offset + size)));
offset += size;
}
return rowDiffs;
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModel method handleLayerEvent.
@Override
public void handleLayerEvent(IStructuralChangeEvent event) {
// handling for deleting columns
if (event.isHorizontalStructureChanged()) {
Collection<StructuralDiff> diffs = event.getColumnDiffs();
if (diffs != null) {
// confusing indexes
for (StructuralDiff columnDiff : diffs) {
if (columnDiff.getDiffType() != null && columnDiff.getDiffType().equals(DiffTypeEnum.DELETE)) {
Range beforePositionRange = columnDiff.getBeforePositionRange();
for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
this.selections.deselectColumn(i);
// ask for further column selections that need to be
// modified
this.selections.updateColumnsForRemoval(i);
}
}
}
for (StructuralDiff columnDiff : diffs) {
if (columnDiff.getDiffType() != null && columnDiff.getDiffType().equals(DiffTypeEnum.ADD)) {
Range afterPositionRange = columnDiff.getAfterPositionRange();
for (int i = afterPositionRange.start; i < afterPositionRange.end; i++) {
// ask for column selections that need to be
// modified
this.selections.updateColumnsForAddition(i);
}
}
}
}
}
// handling for deleting rows
if (event.isVerticalStructureChanged()) {
// the change is already done and we don't know about indexes, so we
// need to check if the selected objects still exist
Collection<Serializable> keysToRemove = new ArrayList<Serializable>();
for (Selections.Row<T> row : this.selections.getRows()) {
int rowIndex = this.rowDataProvider.indexOfRowObject(row.getRowObject());
if (rowIndex == -1) {
keysToRemove.add(row.getId());
}
}
for (Serializable toRemove : keysToRemove) {
this.selections.deselectRow(toRemove);
}
}
}
Aggregations