use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class SelectRegionCommandHandler method selectRegion.
protected void selectRegion(Rectangle region, boolean withShiftMask, boolean withControlMask, int anchorColumn, int anchorRow) {
Range changedRows = null;
if (SelectionUtils.noShiftOrControl(withShiftMask, withControlMask)) {
// no modifier
this.selectionLayer.clear(false);
this.selectionLayer.selectCell(region.x, region.y, false, false);
this.selectionLayer.selectRegion(region.x, region.y, region.width, region.height);
this.selectionLayer.moveSelectionAnchor(anchorColumn < 0 ? region.x : anchorColumn, anchorRow < 0 ? region.y : anchorRow);
changedRows = new Range(region.y, (region.height < Integer.MAX_VALUE) ? region.y + region.height : this.selectionLayer.getRowCount() - region.y);
} else if (SelectionUtils.bothShiftAndControl(withShiftMask, withControlMask) || SelectionUtils.isShiftOnly(withShiftMask, withControlMask)) {
// SHIFT or CTRL + SHIFT modifier enabled
changedRows = selectRegionWithShiftKey(region, anchorColumn, anchorRow);
} else if (SelectionUtils.isControlOnly(withShiftMask, withControlMask)) {
// CTRL modifier enabled
changedRows = selectRegionWithCtrlKey(region, anchorColumn, anchorRow);
}
// Set last selected position to the recently clicked cell
this.selectionLayer.setLastSelectedCell(region.x, region.y);
this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, changedRows, // position
-1, withShiftMask, withControlMask));
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class SelectRowCommandHandler method selectRowWithCtrlKey.
/**
* Performs selection operations with pressed CTRL modifier.
*
* @param columnPosition
* The column position of the {@link SelectRowsCommand}. Needed
* to move the selection anchor.
* @param rowPositions
* The row position of the {@link SelectRowsCommand}.
* @return The changed selection.
*/
private Range selectRowWithCtrlKey(int columnPosition, int rowPosition) {
Rectangle selectedRowRectangle = new Rectangle(0, rowPosition, Integer.MAX_VALUE, 1);
if (this.selectionLayer.isRowPositionFullySelected(rowPosition)) {
this.selectionLayer.clearSelection(selectedRowRectangle);
this.selectionLayer.setLastSelectedRegion(null);
// if there is still a row selected but no selection anchor, we
// need to set one for a consistent state
int[] selectedRows = this.selectionLayer.getFullySelectedRowPositions();
if (selectedRows.length > 0 && this.selectionLayer.getSelectionAnchor().rowPosition == SelectionLayer.NO_SELECTION) {
// determine row to move the anchor to
int toPos = selectedRows[0];
for (int i = 0; i < selectedRows.length; i++) {
if (selectedRows[i] < rowPosition) {
toPos = selectedRows[i];
} else {
break;
}
}
this.selectionLayer.moveSelectionAnchor(columnPosition, toPos);
}
} else {
if (this.selectionLayer.getLastSelectedRegion() != null) {
// Preserve last selected region
this.selectionLayer.selectRegion(this.selectionLayer.getLastSelectedRegion().x, this.selectionLayer.getLastSelectedRegion().y, this.selectionLayer.getLastSelectedRegion().width, this.selectionLayer.getLastSelectedRegion().height);
}
this.selectionLayer.selectRegion(0, rowPosition, Integer.MAX_VALUE, 1);
this.selectionLayer.moveSelectionAnchor(columnPosition, rowPosition);
}
return new Range(rowPosition, rowPosition + 1);
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class SelectRowCommandHandler method internalSelectRow.
/**
* Delegates the selection operations to execute regarding the state
* modifier keys.
*
* @param columnPosition
* The column position of the {@link SelectRowsCommand}.
* @param rowPositions
* The row position of the {@link SelectRowsCommand}.
* @param withShiftMask
* The shift mask information of the {@link SelectRowsCommand}.
* @param withControlMask
* The control mask information of the {@link SelectRowsCommand}.
* @return The changed selection.
*/
private Set<Range> internalSelectRow(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) {
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, Integer.MAX_VALUE, 1);
this.selectionLayer.moveSelectionAnchor(columnPosition, rowPosition);
changedRowRanges.add(new Range(rowPosition, rowPosition + 1));
} else if (bothShiftAndControl(withShiftMask, withControlMask)) {
changedRowRanges.add(selectRowWithShiftKey(columnPosition, rowPosition));
} else if (isShiftOnly(withShiftMask, withControlMask)) {
changedRowRanges.add(selectRowWithShiftKey(columnPosition, rowPosition));
} else if (isControlOnly(withShiftMask, withControlMask)) {
changedRowRanges.add(selectRowWithCtrlKey(columnPosition, rowPosition));
}
this.selectionLayer.setLastSelectedCell(columnPosition, rowPosition);
return changedRowRanges;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class SelectRowCommandHandler method selectRowWithShiftKey.
/**
* Performs selection operations with pressed SHIFT modifier.
*
* @param columnPosition
* The column position of the {@link SelectRowsCommand}. Needed
* to move the selection anchor.
* @param rowPositions
* The row position of the {@link SelectRowsCommand}.
* @return The changed selection.
*/
private Range selectRowWithShiftKey(int columnPosition, int rowPosition) {
int numOfRowsToInclude = 1;
int startRowPosition = rowPosition;
// This method selects the range based on the selection anchor and the
// clicked position. Therefore the selection prior adding the newly
// calculated selection needs to be cleared in advance.
Rectangle lastSelectedRegion = this.selectionLayer.getLastSelectedRegion();
if (lastSelectedRegion != null) {
this.selectionLayer.getSelectionModel().clearSelection(lastSelectedRegion);
} else {
this.selectionLayer.getSelectionModel().clearSelection();
}
// is no selection anchor active already
if (!this.selectionLayer.getSelectionModel().isMultipleSelectionAllowed() || this.selectionLayer.getSelectionAnchor().rowPosition == SelectionLayer.NO_SELECTION) {
this.selectionLayer.moveSelectionAnchor(columnPosition, rowPosition);
}
if (this.selectionLayer.getSelectionAnchor().rowPosition != SelectionLayer.NO_SELECTION) {
numOfRowsToInclude = Math.abs(this.selectionLayer.getSelectionAnchor().rowPosition - rowPosition) + 1;
if (this.selectionLayer.getSelectionAnchor().rowPosition < startRowPosition) {
startRowPosition = this.selectionLayer.getSelectionAnchor().rowPosition;
}
}
this.selectionLayer.selectRegion(0, startRowPosition, Integer.MAX_VALUE, numOfRowsToInclude);
return new Range(startRowPosition, startRowPosition + numOfRowsToInclude);
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class SelectRowCommandHandler method selectRows.
/**
* Performs row selection based on the given informations and fires a
* {@link RowSelectionEvent} for the changed selection.
*
* @param columnPosition
* The column position of the {@link SelectRowsCommand}.
* @param rowPositions
* The row position of the {@link SelectRowsCommand}.
* @param withShiftMask
* The shift mask information of the {@link SelectRowsCommand}.
* @param withControlMask
* The control mask information of the {@link SelectRowsCommand}.
* @param rowPositionToMoveIntoViewport
* Information which row should be moved to the viewport,
* transported by the {@link SelectRowsCommand}.
*/
protected void selectRows(int columnPosition, Collection<Integer> rowPositions, boolean withShiftMask, boolean withControlMask, int rowPositionToMoveIntoViewport) {
Set<Range> changedRowRanges = new HashSet<Range>();
for (int rowPosition : rowPositions) {
changedRowRanges.addAll(internalSelectRow(columnPosition, rowPosition, withShiftMask, withControlMask));
}
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));
}
Aggregations