Search in sources :

Example 41 with PositionCoordinate

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;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ArrayList(java.util.ArrayList)

Example 42 with PositionCoordinate

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());
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Comparator(java.util.Comparator) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 43 with PositionCoordinate

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;
}
Also used : SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) VisualRefreshCommand(org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand)

Example 44 with PositionCoordinate

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;
}
Also used : ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate) ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)

Example 45 with PositionCoordinate

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;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Aggregations

PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)97 Test (org.junit.Test)55 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)10 Rectangle (org.eclipse.swt.graphics.Rectangle)9 SelectRegionCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand)7 ArrayList (java.util.ArrayList)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)5 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)5 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 ViewportSelectColumnGroupCommand (org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand)4 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)4 SelectAllCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand)4 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)3 HashSet (java.util.HashSet)2 Pattern (java.util.regex.Pattern)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 ColumnPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)2 RowPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)2 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2