Search in sources :

Example 1 with Range

use of net.sourceforge.nattable.coordinate.Range in project translationstudio8 by heartsome.

the class CopyDataCommandHandler method assembleCopiedDataStructure.

protected LayerCell[][] assembleCopiedDataStructure() {
    final Set<Range> selectedRows = selectionLayer.getSelectedRows();
    final int rowOffset = columnHeaderLayer != null ? columnHeaderLayer.getRowCount() : 0;
    // Add offset to rows, remember they need to include the column header as a row
    final LayerCell[][] copiedCells = new LayerCell[selectionLayer.getSelectedRowCount() + rowOffset][1];
    if (columnHeaderLayer != null) {
        copiedCells[0] = assembleColumnHeaders(selectionLayer.getSelectedColumns());
    }
    for (Range range : selectedRows) {
        for (int rowPosition = range.start; rowPosition < range.end; rowPosition++) {
            copiedCells[(rowPosition - range.start) + rowOffset] = assembleBody(rowPosition);
        }
    }
    return copiedCells;
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Range(net.sourceforge.nattable.coordinate.Range)

Example 2 with Range

use of net.sourceforge.nattable.coordinate.Range in project translationstudio8 by heartsome.

the class AbstractColumnHideShowLayer method underlyingToLocalColumnPositions.

@Override
public Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges) {
    Collection<Range> localColumnPositionRanges = new ArrayList<Range>();
    for (Range underlyingColumnPositionRange : underlyingColumnPositionRanges) {
        int startColumnPosition = getAdjustedUnderlyingToLocalStartPosition(sourceUnderlyingLayer, underlyingColumnPositionRange.start, underlyingColumnPositionRange.end);
        int endColumnPosition = getAdjustedUnderlyingToLocalEndPosition(sourceUnderlyingLayer, underlyingColumnPositionRange.end, underlyingColumnPositionRange.start);
        // causes strange behaviour in Freeze- and other Layers were returned.
        if (startColumnPosition > -1) {
            localColumnPositionRanges.add(new Range(startColumnPosition, endColumnPosition));
        }
    }
    return localColumnPositionRanges;
}
Also used : ArrayList(java.util.ArrayList) Range(net.sourceforge.nattable.coordinate.Range)

Example 3 with Range

use of net.sourceforge.nattable.coordinate.Range 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 4 with Range

use of net.sourceforge.nattable.coordinate.Range 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 5 with Range

use of net.sourceforge.nattable.coordinate.Range in project translationstudio8 by heartsome.

the class ColumnReorderLayer method underlyingToLocalColumnPositions.

@Override
public Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges) {
    List<Integer> reorderedColumnPositions = new ArrayList<Integer>();
    for (Range underlyingColumnPositionRange : underlyingColumnPositionRanges) {
        for (int underlyingColumnPosition = underlyingColumnPositionRange.start; underlyingColumnPosition < underlyingColumnPositionRange.end; underlyingColumnPosition++) {
            int localColumnPosition = underlyingToLocalColumnPosition(sourceUnderlyingLayer, underlyingColumnPositionRange.start);
            reorderedColumnPositions.add(Integer.valueOf(localColumnPosition));
        }
    }
    Collections.sort(reorderedColumnPositions);
    return PositionUtil.getRanges(reorderedColumnPositions);
}
Also used : ArrayList(java.util.ArrayList) Range(net.sourceforge.nattable.coordinate.Range)

Aggregations

Range (net.sourceforge.nattable.coordinate.Range)25 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 StructuralDiff (net.sourceforge.nattable.layer.event.StructuralDiff)5 Serializable (java.io.Serializable)2 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)2 LinkedList (java.util.LinkedList)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 RowSelectionEvent (net.sourceforge.nattable.selection.event.RowSelectionEvent)1