Search in sources :

Example 1 with StructuralDiff

use of net.sourceforge.nattable.layer.event.StructuralDiff in project translationstudio8 by heartsome.

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
                columnIndexOrder.clear();
                populateIndexOrder();
            } else {
                for (StructuralDiff structuralDiff : structuralDiffs) {
                    switch(structuralDiff.getDiffType()) {
                        case ADD:
                            columnIndexOrder.clear();
                            populateIndexOrder();
                            break;
                        case DELETE:
                            columnIndexOrder.clear();
                            populateIndexOrder();
                            break;
                    }
                }
            }
            invalidateCache();
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(net.sourceforge.nattable.layer.event.IStructuralChangeEvent) StructuralDiff(net.sourceforge.nattable.layer.event.StructuralDiff)

Example 2 with StructuralDiff

use of net.sourceforge.nattable.layer.event.StructuralDiff in project translationstudio8 by heartsome.

the class ColumnReorderEvent method getColumnDiffs.

public Collection<StructuralDiff> getColumnDiffs() {
    Collection<StructuralDiff> columnDiffs = new ArrayList<StructuralDiff>();
    Collection<Range> beforeFromColumnPositionRanges = getBeforeFromColumnPositionRanges();
    int afterAddColumnPosition = beforeToColumnPosition;
    for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
        if (beforeFromColumnPositionRange.start < beforeToColumnPosition) {
            afterAddColumnPosition -= Math.min(beforeFromColumnPositionRange.end, beforeToColumnPosition) - beforeFromColumnPositionRange.start;
        } else {
            break;
        }
    }
    int cumulativeAddSize = 0;
    for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
        cumulativeAddSize += beforeFromColumnPositionRange.size();
    }
    int offset = 0;
    for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
        int afterDeleteColumnPosition = beforeFromColumnPositionRange.start - offset;
        if (afterAddColumnPosition < afterDeleteColumnPosition) {
            afterDeleteColumnPosition += cumulativeAddSize;
        }
        columnDiffs.add(new StructuralDiff(DiffTypeEnum.DELETE, beforeFromColumnPositionRange, new Range(afterDeleteColumnPosition, afterDeleteColumnPosition)));
        offset += beforeFromColumnPositionRange.size();
    }
    Range beforeAddRange = new Range(beforeToColumnPosition, beforeToColumnPosition);
    offset = 0;
    for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
        int size = beforeFromColumnPositionRange.size();
        columnDiffs.add(new StructuralDiff(DiffTypeEnum.ADD, beforeAddRange, new Range(afterAddColumnPosition + offset, afterAddColumnPosition + offset + size)));
        offset += size;
    }
    return columnDiffs;
}
Also used : ArrayList(java.util.ArrayList) StructuralDiff(net.sourceforge.nattable.layer.event.StructuralDiff) Range(net.sourceforge.nattable.coordinate.Range)

Example 3 with StructuralDiff

use of net.sourceforge.nattable.layer.event.StructuralDiff in project translationstudio8 by heartsome.

the class ShowColumnPositionsEvent method getColumnDiffs.

public Collection<StructuralDiff> getColumnDiffs() {
    Collection<StructuralDiff> columnDiffs = new ArrayList<StructuralDiff>();
    int offset = 0;
    for (Range range : getColumnPositionRanges()) {
        columnDiffs.add(new StructuralDiff(DiffTypeEnum.ADD, new Range(range.start - offset, range.start - offset), range));
        offset += range.size();
    }
    return columnDiffs;
}
Also used : ArrayList(java.util.ArrayList) StructuralDiff(net.sourceforge.nattable.layer.event.StructuralDiff) Range(net.sourceforge.nattable.coordinate.Range)

Example 4 with StructuralDiff

use of net.sourceforge.nattable.layer.event.StructuralDiff in project translationstudio8 by heartsome.

the class ViewportEventHandler method handleLayerEvent.

public void handleLayerEvent(IStructuralChangeEvent event) {
    if (event.isHorizontalStructureChanged()) {
        viewportLayer.invalidateHorizontalStructure();
    }
    if (event.isVerticalStructureChanged()) {
        viewportLayer.invalidateVerticalStructure();
    }
    Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
    if (columnDiffs != null) {
        int columnOffset = 0;
        int minimumOriginColumnPosition = viewportLayer.getMinimumOriginColumnPosition();
        for (StructuralDiff columnDiff : columnDiffs) {
            switch(columnDiff.getDiffType()) {
                case ADD:
                    Range afterPositionRange = columnDiff.getAfterPositionRange();
                    if (afterPositionRange.start < minimumOriginColumnPosition) {
                        columnOffset += afterPositionRange.size();
                    }
                    break;
                case DELETE:
                    Range beforePositionRange = columnDiff.getBeforePositionRange();
                    if (beforePositionRange.start < minimumOriginColumnPosition) {
                        columnOffset -= Math.min(beforePositionRange.end, minimumOriginColumnPosition + 1) - beforePositionRange.start;
                    }
                    break;
            }
        }
        viewportLayer.setMinimumOriginColumnPosition(minimumOriginColumnPosition + columnOffset);
    }
    Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
    if (rowDiffs != null) {
        int rowOffset = 0;
        int minimumOriginRowPosition = viewportLayer.getMinimumOriginRowPosition();
        for (StructuralDiff rowDiff : rowDiffs) {
            switch(rowDiff.getDiffType()) {
                case ADD:
                    Range afterPositionRange = rowDiff.getAfterPositionRange();
                    if (afterPositionRange.start < minimumOriginRowPosition) {
                        rowOffset += afterPositionRange.size();
                    }
                    break;
                case DELETE:
                    Range beforePositionRange = rowDiff.getBeforePositionRange();
                    if (beforePositionRange.start < minimumOriginRowPosition) {
                        rowOffset -= Math.min(beforePositionRange.end, minimumOriginRowPosition + 1) - beforePositionRange.start;
                    }
                    break;
            }
        }
        viewportLayer.setMinimumOriginRowPosition(minimumOriginRowPosition + rowOffset);
    }
}
Also used : StructuralDiff(net.sourceforge.nattable.layer.event.StructuralDiff) Range(net.sourceforge.nattable.coordinate.Range)

Example 5 with StructuralDiff

use of net.sourceforge.nattable.layer.event.StructuralDiff in project translationstudio8 by heartsome.

the class FreezeEventHandler method handleLayerEvent.

public void handleLayerEvent(IStructuralChangeEvent event) {
    PositionCoordinate topLeftPosition = freezeLayer.getTopLeftPosition();
    PositionCoordinate bottomRightPosition = 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(net.sourceforge.nattable.coordinate.PositionCoordinate) StructuralDiff(net.sourceforge.nattable.layer.event.StructuralDiff) Range(net.sourceforge.nattable.coordinate.Range)

Aggregations

StructuralDiff (net.sourceforge.nattable.layer.event.StructuralDiff)6 Range (net.sourceforge.nattable.coordinate.Range)5 ArrayList (java.util.ArrayList)3 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)1 IStructuralChangeEvent (net.sourceforge.nattable.layer.event.IStructuralChangeEvent)1