Search in sources :

Example 36 with PositionCoordinate

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

the class SelectionUtils method getBottomRightCellInSelection.

/**
 * Returns the bottom right cell of a selected region. Will only return an
 * ILayerCell if the selected region is consecutive. Otherwise
 * <code>null</code> will be returned.
 *
 * @param selectionLayer
 *            The {@link SelectionLayer} needed to determine the selection.
 *
 * @return The bottom right cell of a selected region or <code>null</code>
 *         if the selected region is not consecutive.
 *
 * @since 1.4
 */
public static ILayerCell getBottomRightCellInSelection(SelectionLayer selectionLayer) {
    if (hasConsecutiveSelection(selectionLayer)) {
        int column = -1;
        int row = -1;
        for (PositionCoordinate coord : selectionLayer.getSelectedCellPositions()) {
            column = Math.max(column, coord.columnPosition);
            row = Math.max(row, coord.rowPosition);
        }
        return selectionLayer.getCellByPosition(column, row);
    }
    return null;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 37 with PositionCoordinate

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

the class CellDisplayValueSearchUtil method findCell.

/**
 * Finds the first matching cell in a list of grid cell rectangles.
 *
 * @param layer
 * @param configRegistry
 * @param cellRectangles
 * @param valueToMatch
 * @param comparator
 * @param caseSensitive
 * @param wholeWord
 * @param regex
 * @param includeCollapsed
 *            TODO currently ignored
 * @return
 * @throws PatternSyntaxException
 */
static PositionCoordinate findCell(final ILayer layer, final IConfigRegistry configRegistry, final List<GridRectangle> cellRectangles, final Object valueToMatch, final Comparator<String> comparator, final boolean caseSensitive, final boolean wholeWord, final boolean regex, final boolean columnFirst, final boolean includeCollapsed) throws PatternSyntaxException {
    String stringValue = caseSensitive ? valueToMatch.toString() : valueToMatch.toString().toLowerCase();
    Pattern pattern = regex ? Pattern.compile(stringValue) : null;
    for (GridRectangle cellRectangle : cellRectangles) {
        int direction = cellRectangle.firstDim.size() > 0 || cellRectangle.secondDim.size() > 0 ? 1 : -1;
        for (int i = cellRectangle.firstDim.start; Math.abs(cellRectangle.firstDim.end - i) > 0; i += direction) {
            PositionCoordinate result = findCell(layer, configRegistry, i, cellRectangle.secondDim.start, cellRectangle.secondDim.end, direction, pattern, stringValue, comparator, caseSensitive, wholeWord, regex, columnFirst, includeCollapsed);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) GridRectangle(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy.GridRectangle)

Example 38 with PositionCoordinate

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

the class CellDisplayValueSearchUtil method findCell.

/**
 * Finds the first matching cell in a table slice.
 *
 * @param layer
 * @param configRegistry
 * @param firstDimIndex
 * @param secondDimStart
 * @param secondDimEnd
 * @param direction
 * @param pattern
 * @param stringValue
 * @param comparator
 * @param caseSensitive
 * @param wholeWord
 * @param regex
 * @param columnFirst
 * @param includeCollapsed
 * @return
 * @throws PatternSyntaxException
 */
private static PositionCoordinate findCell(ILayer layer, IConfigRegistry configRegistry, int firstDimIndex, int secondDimStart, int secondDimEnd, int direction, Pattern pattern, String stringValue, Comparator<String> comparator, boolean caseSensitive, boolean wholeWord, boolean regex, final boolean columnFirst, boolean includeCollapsed) throws PatternSyntaxException {
    int columnPosition;
    int rowPosition;
    if (columnFirst) {
        columnPosition = firstDimIndex;
        rowPosition = secondDimStart;
    } else {
        columnPosition = secondDimStart;
        rowPosition = firstDimIndex;
    }
    for (int i = secondDimStart; direction * (secondDimEnd - i) > 0; i += direction) {
        ILayerCell cellByPosition = layer.getCellByPosition(columnPosition, rowPosition);
        PositionCoordinate searchAnchor = getSearchAnchor(cellByPosition, direction);
        // Thus we skip the compare and proceed to the next position.
        if (searchAnchor.columnPosition == columnPosition && searchAnchor.rowPosition == rowPosition) {
            if (compare(layer, configRegistry, pattern, stringValue, comparator, caseSensitive, wholeWord, regex, columnPosition, rowPosition)) {
                return new PositionCoordinate(layer, columnPosition, rowPosition);
            }
        }
        if (columnFirst) {
            rowPosition += direction;
        } else {
            columnPosition += direction;
        }
    }
    return null;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 39 with PositionCoordinate

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

the class CellDisplayValueSearchUtil method getCellCoordinates.

static List<PositionCoordinate> getCellCoordinates(ILayer contextLayer, int startingColumnPosition, int startingRowPosition, int width, int height) {
    List<PositionCoordinate> coordinates = new ArrayList<PositionCoordinate>(width * height);
    for (int columnPosition = 0; columnPosition < width; columnPosition++) {
        for (int rowPosition = 0; rowPosition < height; rowPosition++) {
            PositionCoordinate coordinate = new PositionCoordinate(contextLayer, startingColumnPosition, startingRowPosition++);
            coordinates.add(coordinate);
        }
        startingColumnPosition++;
    }
    return coordinates;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ArrayList(java.util.ArrayList)

Example 40 with PositionCoordinate

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

the class CellDisplayValueSearchUtil method getDescendingCellCoordinates.

static List<PositionCoordinate> getDescendingCellCoordinates(ILayer contextLayer, int startingColumnPosition, int startingRowPosition, int width, int height) {
    List<PositionCoordinate> coordinates = new ArrayList<PositionCoordinate>(width * height);
    for (int columnPosition = width; columnPosition >= 0 && startingColumnPosition >= 0; columnPosition--) {
        for (int rowPosition = height; rowPosition >= 0 && startingRowPosition >= 0; rowPosition--) {
            PositionCoordinate coordinate = new PositionCoordinate(contextLayer, startingColumnPosition, startingRowPosition--);
            coordinates.add(coordinate);
        }
        startingColumnPosition--;
    }
    return coordinates;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ArrayList(java.util.ArrayList)

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