Search in sources :

Example 46 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class SelectRowGroupCommandHandler method internalSelectRow.

private Set<Range> internalSelectRow(int columnPosition, int rowPosition, int rowCount, boolean withShiftMask, boolean withControlMask, boolean moveAnchorToTopOfGroup) {
    Set<Range> changedRowRanges = new HashSet<Range>();
    if (noShiftOrControl(withShiftMask, withControlMask)) {
        changedRowRanges.addAll(this.selectionLayer.getSelectedRowPositions());
        this.selectionLayer.clear(false);
        this.selectionLayer.selectCell(0, rowPosition, withShiftMask, withControlMask);
        this.selectionLayer.selectRegion(0, rowPosition, this.selectionLayer.getColumnCount(), rowCount);
        changedRowRanges.add(new Range(rowPosition, rowPosition + rowCount));
    } else if (isControlOnly(withShiftMask, withControlMask)) {
        changedRowRanges.add(selectRowWithCtrlKey(columnPosition, rowPosition, rowCount));
    } else if (isShiftOnly(withShiftMask, withControlMask)) {
        changedRowRanges.add(selectRowWithShiftKey(columnPosition, rowPosition, rowCount));
    }
    if (moveAnchorToTopOfGroup) {
        this.selectionLayer.moveSelectionAnchor(columnPosition, rowPosition);
    }
    this.selectionLayer.getLastSelectedCellPosition().columnPosition = this.selectionLayer.getColumnCount() - 1;
    this.selectionLayer.getLastSelectedCellPosition().rowPosition = rowPosition;
    return changedRowRanges;
}
Also used : Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) HashSet(java.util.HashSet)

Example 47 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class SelectRowGroupCommandHandler method selectRows.

protected void selectRows(int columnPosition, List<Integer> rowPositions, boolean withShiftMask, boolean withControlMask, int rowPositionToMoveIntoViewport, boolean moveAnchorToTopOfGroup) {
    Set<Range> changedRowRanges = new HashSet<Range>();
    if (rowPositions.size() > 0) {
        changedRowRanges.addAll(internalSelectRow(columnPosition, rowPositions.get(0), rowPositions.size(), withShiftMask, withControlMask, moveAnchorToTopOfGroup));
    }
    Set<Integer> changedRows = new HashSet<Integer>();
    for (Range range : changedRowRanges) {
        for (int i = range.start; i < range.end; i++) {
            changedRows.add(Integer.valueOf(i));
        }
    }
    this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, changedRows, rowPositionToMoveIntoViewport, withShiftMask, withControlMask));
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) HashSet(java.util.HashSet)

Example 48 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class SelectionLayer method getSelectedCellPositions.

public PositionCoordinate[] getSelectedCellPositions() {
    int[] selectedColumnPositions = getSelectedColumnPositions();
    Set<Range> selectedRowPositions = getSelectedRowPositions();
    List<PositionCoordinate> selectedCells = new LinkedList<PositionCoordinate>();
    for (int columnPositionIndex = 0; columnPositionIndex < selectedColumnPositions.length; columnPositionIndex++) {
        final int columnPosition = selectedColumnPositions[columnPositionIndex];
        for (Range rowIndexRange : selectedRowPositions) {
            for (int rowPositionIndex = rowIndexRange.start; rowPositionIndex < rowIndexRange.end; rowPositionIndex++) {
                if (this.selectionModel.isCellPositionSelected(columnPosition, rowPositionIndex)) {
                    selectedCells.add(new PositionCoordinate(this, columnPosition, rowPositionIndex));
                }
            }
        }
    }
    return selectedCells.toArray(new PositionCoordinate[0]);
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) LinkedList(java.util.LinkedList) Point(org.eclipse.swt.graphics.Point)

Example 49 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class SelectionModel method getFullySelectedRowPositions.

@Override
public int[] getFullySelectedRowPositions(int rowWidth) {
    final Set<Range> selectedRows = getSelectedRowPositions();
    int[] fullySelectedRows = new int[getSelectedRowCount()];
    int index = 0;
    for (Range rowRange : selectedRows) {
        for (int i = rowRange.start; i < rowRange.end; i++) {
            if (isRowPositionFullySelected(i, rowWidth)) {
                fullySelectedRows[index++] = i;
            }
        }
    }
    return index > 0 ? ArrayUtil.subarray(fullySelectedRows, 0, index) : new int[0];
}
Also used : Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 50 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class SelectionModel method internalGetSelectedColumnPositions.

/**
 * @since 1.5
 */
protected Set<Range> internalGetSelectedColumnPositions() {
    Set<Range> selectedColumnsRange = new HashSet<Range>();
    this.selectionsLock.readLock().lock();
    int columnCount = this.selectionLayer.getColumnCount();
    try {
        for (Rectangle r : this.selections) {
            if (r.x < columnCount) {
                int width = (r.x + r.width <= columnCount) ? r.width : columnCount - r.x;
                selectedColumnsRange.add(new Range(r.x, r.x + width));
            }
        }
    } finally {
        this.selectionsLock.readLock().unlock();
    }
    ArrayList<Range> ranges = new ArrayList<Range>(selectedColumnsRange);
    Range.sortByStart(ranges);
    List<Range> uniqueRanges = new ArrayList<Range>(ranges.size());
    // Adjust for overlaps - between consecutive selections
    for (int i = 0; i < ranges.size(); i++) {
        if (i > 0) {
            Range previousRange = ranges.get(i - 1);
            Range currentRange = ranges.get(i);
            if (previousRange.overlap(currentRange) || (previousRange.end == currentRange.start)) {
                int largerRangeEnd = (previousRange.end > currentRange.end) ? previousRange.end : currentRange.end;
                uniqueRanges.get(uniqueRanges.size() - 1).end = largerRangeEnd;
                ranges.get(i).end = largerRangeEnd;
            } else {
                uniqueRanges.add(ranges.get(i));
            }
        } else {
            uniqueRanges.add(ranges.get(i));
        }
    }
    return new HashSet<Range>(uniqueRanges);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) HashSet(java.util.HashSet)

Aggregations

Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)115 Test (org.junit.Test)54 ArrayList (java.util.ArrayList)40 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)23 HashSet (java.util.HashSet)12 Rectangle (org.eclipse.swt.graphics.Rectangle)12 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)9 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)9 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)6 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)6 ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)6 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)5 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 Point (org.eclipse.swt.graphics.Point)5 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4