use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class CellDisplayValueSearchUtil method getCellCoordinatesRowFirst.
static List<PositionCoordinate> getCellCoordinatesRowFirst(ILayer contextLayer, int startingColumnPosition, int startingRowPosition, int width, int height) {
List<PositionCoordinate> coordinates = new ArrayList<PositionCoordinate>(width * height);
for (int rowPosition = 0; rowPosition < height; rowPosition++) {
for (int columnPosition = 0; columnPosition < width; columnPosition++) {
PositionCoordinate coordinate = new PositionCoordinate(contextLayer, startingColumnPosition++, startingRowPosition);
coordinates.add(coordinate);
}
startingRowPosition++;
}
return coordinates;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class GridSearchStrategy method executeSearch.
@Override
public PositionCoordinate executeSearch(Object valueToMatch) throws PatternSyntaxException {
ILayer contextLayer = getContextLayer();
if (!(contextLayer instanceof SelectionLayer)) {
// $NON-NLS-1$
throw new RuntimeException("For the GridSearchStrategy to work it needs the selectionLayer to be passed as the contextLayer.");
}
SelectionLayer selectionLayer = (SelectionLayer) contextLayer;
PositionCoordinate selectionAnchor = selectionLayer.getSelectionAnchor();
// Pick start and end values depending on the direction of the search.
int direction = this.searchDirection.equals(ISearchDirection.SEARCH_FORWARD) ? 1 : -1;
boolean hadSelectionAnchor = selectionAnchor.columnPosition >= 0 && selectionAnchor.rowPosition >= 0;
if (!hadSelectionAnchor) {
selectionAnchor.columnPosition = 0;
selectionAnchor.rowPosition = 0;
}
// Pick a first and second dimension based on whether it's a column or
// row-first search.
int firstDimPosition;
int firstDimCount;
int secondDimPosition;
int secondDimCount;
if (this.columnFirst) {
firstDimPosition = selectionAnchor.columnPosition;
firstDimCount = selectionLayer.getColumnCount();
secondDimPosition = selectionAnchor.rowPosition;
secondDimCount = selectionLayer.getRowCount();
if (direction < 0) {
// If we are searching backwards we must accommodate spanned
// cells by starting the search from the right of the cell.
ILayerCell cellByPosition = selectionLayer.getCellByPosition(selectionAnchor.columnPosition, selectionAnchor.rowPosition);
firstDimPosition = selectionAnchor.columnPosition + cellByPosition.getColumnSpan() - 1;
}
} else {
firstDimPosition = selectionAnchor.rowPosition;
firstDimCount = selectionLayer.getRowCount();
secondDimPosition = selectionAnchor.columnPosition;
secondDimCount = selectionLayer.getColumnCount();
if (direction < 0) {
// If we are searching backwards we must accommodate spanned
// cells by starting the search from the bottom of the cell.
ILayerCell cellByPosition = selectionLayer.getCellByPosition(selectionAnchor.columnPosition, selectionAnchor.rowPosition);
firstDimPosition = selectionAnchor.rowPosition + cellByPosition.getRowSpan() - 1;
}
}
int firstDimStart;
int firstDimEnd;
int secondDimStart;
int secondDimEnd;
if (direction == 1) {
firstDimStart = 0;
firstDimEnd = firstDimCount;
secondDimStart = 0;
secondDimEnd = secondDimCount;
} else {
firstDimStart = firstDimCount - 1;
firstDimEnd = -1;
secondDimStart = secondDimCount - 1;
secondDimEnd = -1;
}
// Move to the next cell if a selection was active and it's not
// an incremental search.
final boolean startWithNextCell = hadSelectionAnchor && !isIncremental();
if (startWithNextCell) {
if (secondDimPosition + direction != secondDimEnd) {
// Increment the second dimension
secondDimPosition += direction;
} else {
// Wrap the second dimension
secondDimPosition = secondDimStart;
if (firstDimPosition + direction != firstDimEnd) {
// Increment the first dimension
firstDimPosition += direction;
} else if (this.wrapSearch) {
// Wrap the first dimension
firstDimPosition = firstDimStart;
} else {
// Fail outright because there's nothing to search
return null;
}
}
}
// Get a sequence of ranges for searching.
List<GridRectangle> gridRanges = getRanges(firstDimPosition, secondDimPosition, direction, firstDimStart, firstDimEnd, secondDimStart, secondDimEnd);
// Perform the search.
@SuppressWarnings("unchecked") Comparator<String> comparator = (Comparator<String>) getComparator();
return CellDisplayValueSearchUtil.findCell(getContextLayer(), this.configRegistry, gridRanges, valueToMatch, comparator, isCaseSensitive(), isWholeWord(), isRegex(), isColumnFirst(), isIncludeCollapsed());
}
use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class SelectionSearchStrategy method executeSearch.
@Override
public PositionCoordinate executeSearch(Object valueToMatch) throws PatternSyntaxException {
ILayer contextLayer = getContextLayer();
if (!(contextLayer instanceof SelectionLayer)) {
// $NON-NLS-1$
throw new RuntimeException("For the SelectionSearchStrategy to work it needs the selectionLayer to be passed as the contextLayer.");
}
SelectionLayer selectionLayer = (SelectionLayer) contextLayer;
@SuppressWarnings("unchecked") PositionCoordinate coordinate = CellDisplayValueSearchUtil.findCell(selectionLayer, this.configRegistry, getSelectedCells(selectionLayer), valueToMatch, (Comparator<String>) getComparator(), isCaseSensitive(), isWholeWord(), isRegex(), isIncludeCollapsed());
if (coordinate != null) {
selectionLayer.moveSelectionAnchor(coordinate.columnPosition, coordinate.rowPosition);
selectionLayer.doCommand(new VisualRefreshCommand());
}
return coordinate;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class SelectRegionCommand method convertToTargetLayer.
@Override
public boolean convertToTargetLayer(ILayer targetLayer) {
PositionCoordinate sourceCoordinate = new PositionCoordinate(this.sourceLayer, this.region.x, this.region.y);
PositionCoordinate targetCoordinate = LayerCommandUtil.convertPositionToTargetContext(sourceCoordinate, targetLayer);
if (targetCoordinate != null) {
this.sourceLayer = targetCoordinate.getLayer();
this.region.x = targetCoordinate.columnPosition;
this.region.y = targetCoordinate.rowPosition;
if (this.anchorColumnPosition >= 0) {
ColumnPositionCoordinate sourceColumn = new ColumnPositionCoordinate(this.sourceLayer, this.anchorColumnPosition);
ColumnPositionCoordinate targetColumn = LayerCommandUtil.convertColumnPositionToTargetContext(sourceColumn, targetLayer);
this.anchorColumnPosition = targetColumn.getColumnPosition();
}
if (this.anchorRowPosition >= 0) {
RowPositionCoordinate sourceRow = new RowPositionCoordinate(this.sourceLayer, this.anchorRowPosition);
RowPositionCoordinate targetRow = LayerCommandUtil.convertRowPositionToTargetContext(sourceRow, targetLayer);
this.anchorRowPosition = targetRow.getRowPosition();
}
return true;
}
return false;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class SelectionAnchorCellLabelKeyEventMatcher method matches.
@Override
public boolean matches(KeyEvent event) {
PositionCoordinate anchorPosition = this.selectionLayer.getSelectionAnchor();
if (anchorPosition.rowPosition != SelectionLayer.NO_SELECTION && anchorPosition.columnPosition != SelectionLayer.NO_SELECTION) {
int layerColumnPosition = LayerUtil.convertColumnPosition(this.selectionLayer, anchorPosition.columnPosition, this.layer);
int layerRowPosition = LayerUtil.convertRowPosition(this.selectionLayer, anchorPosition.rowPosition, this.layer);
LabelStack labels = this.layer.getConfigLabelsByPosition(layerColumnPosition, layerRowPosition);
boolean labelMatches = labels.hasLabel(this.labelToMatch);
if (this.aggregate != null) {
return labelMatches && this.aggregate.matches(event);
}
return labelMatches;
}
return false;
}
Aggregations