Search in sources :

Example 11 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class RowSelectionTest method shouldNotIncludeDeselectedCellsWithCtrlModifier.

@Test
public void shouldNotIncludeDeselectedCellsWithCtrlModifier() {
    // test a previous bug where single deselected cells where added to the
    // selection with following modifier selections
    // start from a clear selection state
    this.selectionLayer.clear();
    // select a single cell
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 0, 2, false, false));
    // deselect the cell again
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 0, 2, false, true));
    // trigger selection of row 4 with ctrl
    this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 4, false, true));
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(4, this.selectionLayer.getSelectionAnchor().getRowPosition());
    assertFalse("[0, 2] is selected", this.selectionLayer.isCellPositionSelected(0, 2));
    assertTrue("row 4 not fully selected", this.selectionLayer.isRowPositionFullySelected(4));
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 12 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand 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 13 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class SelectionSearchStrategyTest method shouldOnlySearchWhatIsSelected.

@Test
public void shouldOnlySearchWhatIsSelected() {
    this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 1, 4, false, true));
    this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 2, 2, false, true));
    this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 3, 4, false, true));
    this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 5, 4, false, true));
    this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 6, 2, false, true));
    assertEquals(5, this.selectionLayer.getSelectedCellPositions().length);
    SelectionSearchStrategy selectionStrategy = new SelectionSearchStrategy(this.configRegistry);
    selectionStrategy.setWrapSearch(true);
    selectionStrategy.setComparator(new CellValueAsStringComparator<>());
    selectionStrategy.setContextLayer(this.selectionLayer);
    assertNull(selectionStrategy.executeSearch("[0,1]"));
    assertNotNull(selectionStrategy.executeSearch(CELL_VALUE));
    assertNotNull(selectionStrategy.executeSearch(CELL_VALUE));
    assertNull(selectionStrategy.executeSearch("[5,0]"));
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 14 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand 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)

Example 15 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class ColumnHeaderLayerSelectionTest method willSelectBodyCellAndShouldHaveColumnHeaderSelected.

@Test
public void willSelectBodyCellAndShouldHaveColumnHeaderSelected() {
    // Select body cell
    // The column position is a grid layer position
    this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 2, 2, false, false));
    // Get column header cell corresponding to the selected body cell
    ColumnHeaderLayer columnHeaderLayer = (ColumnHeaderLayer) this.gridLayer.getChildLayerByLayoutCoordinate(1, 0);
    // The column position is 1 because it takes into account the offset of
    // the row header
    ILayerCell cell = columnHeaderLayer.getCellByPosition(1, 0);
    // Assert the cell is in selected state
    assertEquals(DisplayMode.SELECT, cell.getDisplayMode());
}
Also used : ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Aggregations

SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)54 Test (org.junit.Test)50 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)14 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)4 SelectColumnCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand)4 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)3 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)2 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)2 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)2 DummySpanningBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 ShowAllColumnsCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand)2 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)2 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2