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;
}
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));
}
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]);
}
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];
}
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);
}
Aggregations