Search in sources :

Example 36 with SelectCellCommand

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

the class HierarchicalTreeLayerTest method testGetDisplayModeByPosition.

@Test
public void testGetDisplayModeByPosition() {
    // first test that all cells in a row are NORMAL
    for (int i = 0; i < this.treeLayer.getColumnCount(); i++) {
        assertEquals(DisplayMode.NORMAL, this.treeLayer.getDisplayModeByPosition(i, 0));
    }
    // select a cell
    this.treeLayer.doCommand(new SelectCellCommand(this.treeLayer, 5, 0, false, false));
    // test that all cells despite the selected one are NORMAL
    boolean selectedFound = false;
    for (int i = 0; i < this.treeLayer.getColumnCount(); i++) {
        if (i != 5) {
            assertEquals(DisplayMode.NORMAL, this.treeLayer.getDisplayModeByPosition(i, 0));
        } else {
            selectedFound = true;
            assertEquals(DisplayMode.SELECT, this.treeLayer.getDisplayModeByPosition(i, 0));
        }
    }
    assertTrue(selectedFound);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 37 with SelectCellCommand

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

the class HierarchicalTreeLayerTest method testSelectLevelHeader.

@Test
public void testSelectLevelHeader() {
    // select first level header in first row
    this.treeLayer.doCommand(new SelectCellCommand(this.treeLayer, 0, 0, false, false));
    // all cells in the first 5 rows should be selected
    assertTrue(this.selectionLayer.isRowPositionFullySelected(0));
    assertTrue(this.selectionLayer.isRowPositionFullySelected(1));
    assertTrue(this.selectionLayer.isRowPositionFullySelected(2));
    assertTrue(this.selectionLayer.isRowPositionFullySelected(3));
    assertTrue(this.selectionLayer.isRowPositionFullySelected(4));
    // last row is a new element, so not selected
    assertFalse(this.selectionLayer.isRowPositionFullySelected(5));
    // select second level header in first row
    this.treeLayer.doCommand(new SelectCellCommand(this.treeLayer, 3, 0, false, false));
    // there is no full row selection at all
    assertFalse(this.selectionLayer.isRowPositionFullySelected(0));
    assertFalse(this.selectionLayer.isRowPositionFullySelected(1));
    assertFalse(this.selectionLayer.isRowPositionFullySelected(2));
    assertFalse(this.selectionLayer.isRowPositionFullySelected(3));
    assertFalse(this.selectionLayer.isRowPositionFullySelected(4));
    assertFalse(this.selectionLayer.isRowPositionFullySelected(5));
    // there is no selection in row 2 and 3
    assertFalse(this.selectionLayer.isRowPositionSelected(2));
    assertFalse(this.selectionLayer.isRowPositionSelected(3));
    // there is no selection in the first level
    assertFalse(this.selectionLayer.isColumnPositionSelected(0));
    assertFalse(this.selectionLayer.isColumnPositionSelected(1));
    // there is a region selection for second and third level in the first
    // two rows
    // start column 2, start row 0, four columns and two rows
    assertTrue(this.selectionLayer.allCellsSelectedInRegion(new Rectangle(2, 0, 4, 2)));
    // select third level header in second row
    this.treeLayer.doCommand(new SelectCellCommand(this.treeLayer, 6, 1, false, false));
    // there is no full row selection at all
    assertFalse(this.selectionLayer.isRowPositionFullySelected(0));
    assertFalse(this.selectionLayer.isRowPositionFullySelected(1));
    assertFalse(this.selectionLayer.isRowPositionFullySelected(2));
    assertFalse(this.selectionLayer.isRowPositionFullySelected(3));
    // there is no selection in row 0, 2 and 3
    assertFalse(this.selectionLayer.isRowPositionSelected(0));
    assertFalse(this.selectionLayer.isRowPositionSelected(2));
    assertFalse(this.selectionLayer.isRowPositionSelected(3));
    // there is no selection in the first and second level
    assertFalse(this.selectionLayer.isColumnPositionSelected(0));
    assertFalse(this.selectionLayer.isColumnPositionSelected(1));
    assertFalse(this.selectionLayer.isColumnPositionSelected(2));
    assertFalse(this.selectionLayer.isColumnPositionSelected(3));
    // there is a region selection for third level in the second row
    // start column 4, start row 1, two columns and one row
    assertTrue(this.selectionLayer.allCellsSelectedInRegion(new Rectangle(4, 1, 2, 1)));
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 38 with SelectCellCommand

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

the class ConfigurableCellBorderTest method shouldReturnASelectedCellWithDottedLineStyling.

@Test
public void shouldReturnASelectedCellWithDottedLineStyling() {
    Style cellStyle = new Style();
    final BorderStyle defaultBorderStyle = new BorderStyle(13, GUIHelper.COLOR_YELLOW, LineStyleEnum.DOTTED);
    cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, defaultBorderStyle);
    // Register line styling for body cells in selection mode
    this.configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.SELECT, SelectionStyleLabels.SELECTION_ANCHOR_STYLE);
    // Select and access cell
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 2, 2, false, false));
    ILayerCell cell = this.natTable.getCellByPosition(2, 2);
    Assert.assertEquals(DisplayMode.SELECT, cell.getDisplayMode());
    // Check for line styling
    Assert.assertEquals(defaultBorderStyle, this.configRegistry.getConfigAttribute(CellConfigAttributes.CELL_STYLE, cell.getDisplayMode(), cell.getConfigLabels().getLabels()).getAttributeValue(CellStyleAttributes.BORDER_STYLE));
}
Also used : BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Style(org.eclipse.nebula.widgets.nattable.style.Style) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 39 with SelectCellCommand

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialCellSelectionOnRowDelete.

@Test
public void shouldRemovePartialCellSelectionOnRowDelete() {
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, true, false));
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 2, true, false));
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 2, true, false));
    assertEquals(4, this.selectionLayer.getSelectedCells().size());
    this.listFixture.remove(0);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(2, selectedCells.size());
    // moved up
    for (ILayerCell cell : selectedCells) {
        assertEquals(0, cell.getRowPosition());
    }
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 40 with SelectCellCommand

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldUpdateSelectionOnShiftSelect.

@Test
public void shouldUpdateSelectionOnShiftSelect() {
    // integration test case for drag/shift selection
    // not really a test case for structural changes but important for
    // selection interactions
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 3, 3, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 5, 5, true, false));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(9, selectedCells.size());
    boolean[] found = new boolean[3];
    for (ILayerCell cell : selectedCells) {
        if (cell.getColumnPosition() >= 5 || cell.getColumnPosition() < 2) {
            fail("wrong column position selected: " + cell.getColumnPosition());
        } else {
            found[cell.getColumnPosition() - 2] = true;
        }
    }
    for (int i = 0; i < found.length; i++) {
        assertTrue("columnPosition " + (i + 3) + " not selected", found[i]);
    }
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, true, false));
    selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(9, selectedCells.size());
    found = new boolean[3];
    for (ILayerCell cell : selectedCells) {
        if (cell.getColumnPosition() >= 3) {
            fail("wrong column position selected: " + cell.getColumnPosition());
        } else {
            found[cell.getColumnPosition()] = true;
        }
    }
    for (int i = 0; i < found.length; i++) {
        assertTrue("columnPosition " + i + " not selected", found[i]);
    }
}
Also used : 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