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