Search in sources :

Example 16 with PositionCoordinate

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

the class ColumnSearchStrategyTest method shouldSearchAllBodyCellsForColumnInSelection.

@Test
public void shouldSearchAllBodyCellsForColumnInSelection() {
    ColumnSearchStrategy columnSearchStrategy = new ColumnSearchStrategy(new int[] { 2, 5, 8 }, this.configRegistry);
    columnSearchStrategy.setComparator(new CellValueAsStringComparator<>());
    columnSearchStrategy.setContextLayer(this.layer);
    PositionCoordinate cell = columnSearchStrategy.executeSearch("[2,2]");
    assertEquals(2, cell.getColumnPosition());
    assertEquals(2, cell.getRowPosition());
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 17 with PositionCoordinate

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

the class GridSearchStrategyTest method shouldFindAllCellsWithValue.

@Test
public void shouldFindAllCellsWithValue() {
    GridSearchStrategy gridStrategy = new GridSearchStrategy(this.configRegistry, true, ISearchDirection.SEARCH_BACKWARDS, true);
    gridStrategy.setComparator(new CellValueAsStringComparator<>());
    gridStrategy.setContextLayer(this.selectionLayer);
    gridStrategy.setCaseSensitive(true);
    gridStrategy.setWrapSearch(true);
    PositionCoordinate searchResult = gridStrategy.executeSearch("Body");
    assertEquals(0, searchResult.columnPosition);
    assertEquals(0, searchResult.rowPosition);
    // Simulate selecting the search result
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, searchResult.columnPosition, searchResult.rowPosition, false, false));
    searchResult = gridStrategy.executeSearch("Body");
    assertEquals(4, searchResult.columnPosition);
    assertEquals(4, searchResult.rowPosition);
    // Simulate selecting the search result
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, searchResult.columnPosition, searchResult.rowPosition, false, false));
    searchResult = gridStrategy.executeSearch("Body");
    assertEquals(3, searchResult.columnPosition);
    assertEquals(3, searchResult.rowPosition);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 18 with PositionCoordinate

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

the class SelectionSearchStrategyTest method shouldSearchSelectionBackwards.

@Test
public void shouldSearchSelectionBackwards() {
    // Select entire grid
    this.gridLayer.doCommand(new SelectAllCommand());
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getRowPosition());
    SelectionSearchStrategy selectionStrategy = new SelectionSearchStrategy(this.configRegistry);
    selectionStrategy.setWrapSearch(true);
    selectionStrategy.setComparator(new CellValueAsStringComparator<>());
    selectionStrategy.setContextLayer(this.selectionLayer);
    // the selection anchor is already in the first cell,
    // therefore the search result will return the second row in the first
    // column
    PositionCoordinate positionCoordinate = selectionStrategy.executeSearch(CELL_VALUE);
    assertEquals(0, positionCoordinate.columnPosition);
    assertEquals(1, positionCoordinate.rowPosition);
    // selection stays unchanged, only the selection anchor moves
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(1, this.selectionLayer.getSelectionAnchor().getRowPosition());
    // Should find last cell
    selectionStrategy = new SelectionSearchStrategy(this.configRegistry, ISearchDirection.SEARCH_BACKWARDS, true);
    selectionStrategy.setWrapSearch(true);
    selectionStrategy.setComparator(new CellValueAsStringComparator<>());
    selectionStrategy.setContextLayer(this.selectionLayer);
    // one backwards will find the first cell in the grid
    positionCoordinate = selectionStrategy.executeSearch(CELL_VALUE);
    assertEquals(0, positionCoordinate.columnPosition);
    assertEquals(0, positionCoordinate.rowPosition);
    // selection stays unchanged, only the selection anchor moves
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getRowPosition());
    // second backwards will find the last cell
    positionCoordinate = selectionStrategy.executeSearch(CELL_VALUE);
    assertEquals(9, positionCoordinate.columnPosition);
    assertEquals(4, positionCoordinate.rowPosition);
    // selection stays unchanged, only the selection anchor moves
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(9, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(4, this.selectionLayer.getSelectionAnchor().getRowPosition());
}
Also used : SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 19 with PositionCoordinate

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

the class SelectionSearchStrategyTest method shouldNotWrap.

@Test
public void shouldNotWrap() {
    this.gridLayer.doCommand(new SelectAllCommand());
    this.selectionLayer.moveSelectionAnchor(9, 4);
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(9, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(4, this.selectionLayer.getSelectionAnchor().getRowPosition());
    SelectionSearchStrategy selectionStrategy = new SelectionSearchStrategy(this.configRegistry);
    selectionStrategy.setComparator(new CellValueAsStringComparator<>());
    selectionStrategy.setContextLayer(this.selectionLayer);
    PositionCoordinate positionCoordinate = selectionStrategy.executeSearch(CELL_VALUE);
    assertNull(positionCoordinate);
}
Also used : SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 20 with PositionCoordinate

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

the class CellSelectionTest method shouldReturnTheCorrectCountOfSelectedCells.

/**
 * Selected cells are (col,row): (2,3),(4,1),(1,0),(9,9)
 */
@Test
public void shouldReturnTheCorrectCountOfSelectedCells() {
    this.selectionLayer.clear();
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 3, false, true));
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 4, 1, false, true));
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 1, 0, false, true));
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 9, 9, false, true));
    PositionCoordinate[] cells = this.selectionLayer.getSelectedCellPositions();
    Assert.assertEquals(4, cells.length);
    // (1, 0)
    Assert.assertEquals(1, cells[0].columnPosition);
    Assert.assertEquals(0, cells[0].rowPosition);
    // (2, 3)
    Assert.assertEquals(2, cells[1].columnPosition);
    Assert.assertEquals(3, cells[1].rowPosition);
    // (4, 1)
    Assert.assertEquals(4, cells[2].columnPosition);
    Assert.assertEquals(1, cells[2].rowPosition);
    // (9, 9)
    Assert.assertEquals(9, cells[3].columnPosition);
    Assert.assertEquals(9, cells[3].rowPosition);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

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