use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class MultiColumnReorderEventDiffTest method testReorderRightConvertToLocal.
/**
* - - - + before: 0 1 2 3 4 5 6 7 8 after: 0 1 5 6 2 3 4 7 8 - + + +
*/
@Test
public void testReorderRightConvertToLocal() {
this.event = new ColumnReorderEvent(this.dataLayer, Arrays.asList(new Integer[] { 2, 3, 4 }), 7, true);
this.event.convertToLocal(this.viewportLayer);
Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
Assert.assertNotNull(columnDiffs);
Assert.assertEquals(2, columnDiffs.size());
Iterator<StructuralDiff> iterator = columnDiffs.iterator();
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.DELETE, new Range(0, 3), new Range(0, 0)), iterator.next());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(5, 5), new Range(2, 5)), iterator.next());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class FreezeEventHandler method handleLayerEvent.
@Override
public void handleLayerEvent(IStructuralChangeEvent event) {
PositionCoordinate topLeftPosition = this.freezeLayer.getTopLeftPosition();
PositionCoordinate bottomRightPosition = this.freezeLayer.getBottomRightPosition();
Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
if (columnDiffs != null) {
int leftOffset = 0;
int rightOffset = 0;
for (StructuralDiff columnDiff : columnDiffs) {
switch(columnDiff.getDiffType()) {
case ADD:
Range afterPositionRange = columnDiff.getAfterPositionRange();
if (afterPositionRange.start < topLeftPosition.columnPosition) {
leftOffset += afterPositionRange.size();
}
if (afterPositionRange.start <= bottomRightPosition.columnPosition) {
rightOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = columnDiff.getBeforePositionRange();
if (beforePositionRange.start < topLeftPosition.columnPosition) {
leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.columnPosition + 1) - beforePositionRange.start;
}
if (beforePositionRange.start <= bottomRightPosition.columnPosition) {
rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.columnPosition + 1) - beforePositionRange.start;
}
break;
}
}
topLeftPosition.columnPosition += leftOffset;
bottomRightPosition.columnPosition += rightOffset;
}
Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
if (rowDiffs != null) {
int leftOffset = 0;
int rightOffset = 0;
for (StructuralDiff rowDiff : rowDiffs) {
switch(rowDiff.getDiffType()) {
case ADD:
Range afterPositionRange = rowDiff.getAfterPositionRange();
if (afterPositionRange.start < topLeftPosition.rowPosition) {
leftOffset += afterPositionRange.size();
}
if (afterPositionRange.start <= bottomRightPosition.rowPosition) {
rightOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = rowDiff.getBeforePositionRange();
if (beforePositionRange.start < topLeftPosition.rowPosition) {
leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.rowPosition + 1) - beforePositionRange.start;
}
if (beforePositionRange.start <= bottomRightPosition.rowPosition) {
rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.rowPosition + 1) - beforePositionRange.start;
}
break;
}
}
topLeftPosition.rowPosition += leftOffset;
bottomRightPosition.rowPosition += rightOffset;
}
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class HideColumnPositionsEvent method getColumnDiffs.
@Override
public Collection<StructuralDiff> getColumnDiffs() {
Collection<StructuralDiff> columnDiffs = new ArrayList<StructuralDiff>(getColumnPositionRanges().size());
for (Range range : getColumnPositionRanges()) {
StructuralDiff diff = new StructuralDiff(DiffTypeEnum.DELETE, range, new Range(range.start, range.start));
columnDiffs.add(diff);
}
return columnDiffs;
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff 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.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class ColumnReorderLayer method handleLayerEvent.
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof IStructuralChangeEvent) {
IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
if (structuralChangeEvent.isHorizontalStructureChanged()) {
Collection<StructuralDiff> structuralDiffs = structuralChangeEvent.getColumnDiffs();
if (structuralDiffs == null) {
// Assume everything changed
populateIndexOrder();
} else {
// only react on ADD or DELETE and not on CHANGE
StructuralChangeEventHelper.handleColumnDelete(structuralDiffs, this.underlyingLayer, this.columnIndexOrder, true);
StructuralChangeEventHelper.handleColumnInsert(structuralDiffs, this.underlyingLayer, this.columnIndexOrder, true);
// update index-position mapping
refreshIndexPositionMapping();
}
invalidateCache();
}
}
super.handleLayerEvent(event);
}
Aggregations