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());
}
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);
}
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());
}
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);
}
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);
}
Aggregations