Search in sources :

Example 21 with StructuralDiff

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());
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 22 with StructuralDiff

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;
    }
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 23 with StructuralDiff

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;
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 24 with StructuralDiff

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;
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 25 with StructuralDiff

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);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)

Aggregations

StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)28 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)23 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 IStructuralChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent)5 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)4 Serializable (java.io.Serializable)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)1 DataUpdateEvent (org.eclipse.nebula.widgets.nattable.edit.event.DataUpdateEvent)1 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)1