use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class RowSelectionModel method handleLayerEvent.
@Override
public void handleLayerEvent(IStructuralChangeEvent event) {
// 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 (Map.Entry<Serializable, R> entry : this.selectedRows.entrySet()) {
int rowIndex = this.rowDataProvider.indexOfRowObject(entry.getValue());
if (rowIndex == -1) {
keysToRemove.add(entry.getKey());
}
}
this.selectionsLock.readLock().lock();
try {
for (Serializable toRemove : keysToRemove) {
this.selectedRows.remove(toRemove);
}
} finally {
this.selectionsLock.readLock().unlock();
}
// change for all deleted rows
if (!keysToRemove.isEmpty()) {
Collection<Integer> rowPositions = new HashSet<Integer>();
Collection<StructuralDiff> diffs = event.getRowDiffs();
if (diffs != null) {
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++) {
rowPositions.add(i);
}
}
}
}
// if there is no diff in the event we assume everything has
// changed, in such a case we are not able to fire an
// appropriate event the layer stack upwards since it will be
// stopped while converting it to the target layer
// for the RowSelectionProvider this is sufficient because it
// registers itself as a listener to the SelectionLayer and
// therefore gets informed about the selection change
this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, rowPositions, -1, false, false));
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class ViewportEventHandler method handleLayerEvent.
@Override
public void handleLayerEvent(IStructuralChangeEvent event) {
IUniqueIndexLayer scrollableLayer = this.viewportLayer.getScrollableLayer();
if (event.isHorizontalStructureChanged()) {
this.viewportLayer.invalidateHorizontalStructure();
int columnOffset = 0;
int minimumOriginColumnPosition = this.viewportLayer.getMinimumOriginColumnPosition();
Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
if (columnDiffs != null) {
if (minimumOriginColumnPosition < 0) {
// this is for handling of hide/show behaviour
// the value can only be -1 in case the column for which the
// minimum origin was set before
// was hidden, so we try to determine the correct value now
// if it is shown again
minimumOriginColumnPosition = scrollableLayer.getColumnPositionByX(this.viewportLayer.getMinimumOrigin().getX());
}
for (StructuralDiff columnDiff : columnDiffs) {
switch(columnDiff.getDiffType()) {
case ADD:
Range afterPositionRange = columnDiff.getAfterPositionRange();
if (minimumOriginColumnPosition > 0) {
for (int i = afterPositionRange.start; i < afterPositionRange.end; i++) {
if (i < minimumOriginColumnPosition) {
minimumOriginColumnPosition++;
}
}
}
break;
case DELETE:
Range beforePositionRange = columnDiff.getBeforePositionRange();
if (minimumOriginColumnPosition > 0) {
for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
if (i < minimumOriginColumnPosition) {
columnOffset -= 1;
}
}
}
break;
}
}
}
int minimumOriginColumn = minimumOriginColumnPosition + columnOffset;
// of the calculated value
if (this.viewportLayer.getMinColumnPosition() >= 0) {
minimumOriginColumn = this.viewportLayer.getMinColumnPosition();
}
// if the new origin is out of range (e.g. the last column in the
// viewport is moved
// to the frozen region, the minimum origin need to be updated in
// another way
int startX = scrollableLayer.getStartXOfColumnPosition(minimumOriginColumn);
if (startX < 0 && minimumOriginColumnPosition > 0) {
int columnCount = scrollableLayer.getColumnCount();
if (columnCount == 0) {
// special case when all columns are hidden
startX = 0;
} else {
startX = scrollableLayer.getStartXOfColumnPosition(columnCount - 1) + scrollableLayer.getColumnWidthByPosition(columnCount - 1);
}
}
this.viewportLayer.setMinimumOriginX(startX);
}
if (event.isVerticalStructureChanged()) {
this.viewportLayer.invalidateVerticalStructure();
int rowOffset = 0;
int minimumOriginRowPosition = this.viewportLayer.getMinimumOriginRowPosition();
Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
if (rowDiffs != null) {
if (minimumOriginRowPosition < 0) {
// this is for handling of hide/show behaviour
// the value can only be -1 in case the row for which the
// minimum origin was set before
// was hidden, so we try to determine the correct value now
// if it is shown again
minimumOriginRowPosition = scrollableLayer.getRowPositionByY(this.viewportLayer.getMinimumOrigin().getY());
}
for (StructuralDiff rowDiff : rowDiffs) {
switch(rowDiff.getDiffType()) {
case ADD:
Range afterPositionRange = rowDiff.getAfterPositionRange();
if (minimumOriginRowPosition > 0) {
for (int i = afterPositionRange.start; i < afterPositionRange.end; i++) {
if (i < minimumOriginRowPosition) {
minimumOriginRowPosition++;
}
}
}
break;
case DELETE:
Range beforePositionRange = rowDiff.getBeforePositionRange();
if (minimumOriginRowPosition > 0) {
for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
if (i < minimumOriginRowPosition) {
rowOffset -= 1;
}
}
}
break;
}
}
}
int minimumOriginRow = minimumOriginRowPosition + rowOffset;
// the calculated value
if (this.viewportLayer.getMinRowPosition() >= 0) {
minimumOriginRow = this.viewportLayer.getMinRowPosition();
}
// if the new origin is out of range (e.g. the last row in the
// viewport is moved
// to the frozen region, the minimum origin need to be updated in
// another way
int startY = scrollableLayer.getStartYOfRowPosition(minimumOriginRow);
if (startY < 0 && minimumOriginRowPosition > 0) {
int rowCount = scrollableLayer.getRowCount();
if (rowCount == 0) {
// special case when all rows are hidden
startY = 0;
} else {
startY = scrollableLayer.getStartYOfRowPosition(rowCount - 1) + scrollableLayer.getRowHeightByPosition(rowCount - 1);
}
}
this.viewportLayer.setMinimumOriginY(startY);
}
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class ResizeEventDiffTest method testColumnDiffs.
@Test
public void testColumnDiffs() {
Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
Assert.assertNotNull(columnDiffs);
Assert.assertEquals(1, columnDiffs.size());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.CHANGE, new Range(2, 3), new Range(2, 3)), columnDiffs.iterator().next());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class ShowColumnPositionsEventDiffTest method testConvertToLocal.
/**
* + + + before: 0 1 3 5 6 8 9 10 11 12 after: 0 1 2 3 4 5 6 7 8 9 + + + + +
*/
@Test
public void testConvertToLocal() {
this.event.convertToLocal(this.hideShowLayer);
Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
Assert.assertNotNull(columnDiffs);
Assert.assertEquals(3, columnDiffs.size());
Iterator<StructuralDiff> iterator = columnDiffs.iterator();
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(2, 2), new Range(2, 3)), iterator.next());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(3, 3), new Range(4, 5)), iterator.next());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(5, 5), new Range(7, 10)), iterator.next());
this.event.convertToLocal(this.viewportLayer);
columnDiffs = this.event.getColumnDiffs();
Assert.assertNotNull(columnDiffs);
Assert.assertEquals(3, columnDiffs.size());
iterator = columnDiffs.iterator();
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(0, 0), new Range(0, 1)), iterator.next());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(1, 1), new Range(2, 3)), iterator.next());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(3, 3), new Range(5, 8)), iterator.next());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class MultiColumnReorderEventDiffTest method testReorderLeftConvertToLocal.
/**
* + - - - before: 0 1 2 3 4 5 6 7 8 9 10 after: 0 1 7 8 9 2 3 4 5 6 10 + +
* + -
*/
@Test
public void testReorderLeftConvertToLocal() {
this.event = new ColumnReorderEvent(this.dataLayer, Arrays.asList(new Integer[] { 7, 8, 9 }), 2, 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(5, 8), new Range(8, 8)), iterator.next());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(0, 0), new Range(0, 3)), iterator.next());
}
Aggregations