use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.
the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionIfASelectedRowIsModified.
@Test
public void shouldClearSelectionIfASelectedRowIsModified() {
this.selectionModel.addSelection(2, 3);
this.selectionModel.handleLayerEvent(new RowDeleteEvent(this.dataLayer, 3));
Assert.assertTrue(this.selectionModel.isEmpty());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveCellSelectionOnRowDelete.
@Test
public void shouldRemoveCellSelectionOnRowDelete() {
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));
assertEquals(2, 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(0, selectedCells.size());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.
the class RowSelectionModelStructuralChangeEventHandlerTest method shouldOnlyRemoveSelectionForDeleted.
@Test
public void shouldOnlyRemoveSelectionForDeleted() {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, new int[] { 1, 2 }, true, false, 1));
assertEquals(2, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(2, this.selectionLayer.getSelectedRowCount());
// Ford motor at top and selected
assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
boolean fordFound = false;
boolean alphabetFound = false;
for (Range selection : this.selectionLayer.getSelectedRowPositions()) {
for (int i = selection.start; i < selection.end; i++) {
if ("B Ford Motor".equals(this.listFixture.get(i).getSecurity_description())) {
fordFound = true;
}
if ("A Alphabet Co.".equals(this.listFixture.get(i).getSecurity_description())) {
alphabetFound = true;
}
}
}
assertTrue("B Ford Motor not found", fordFound);
assertTrue("A Alphabet Co. not found", alphabetFound);
this.listFixture.remove(0);
// fire event to trigger structural refresh
this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
// another value on top now
assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("A Alphabet Co.", getSelected().getSecurity_description());
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.
the class RowReorderLayerStructuralChangeEventTest method testHandleRowDeleteEvent.
@Test
public void testHandleRowDeleteEvent() {
// test start order: 0 1 2 3
assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(0));
assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(1));
assertEquals(2, this.rowReorderLayer.getRowIndexByPosition(2));
assertEquals(3, this.rowReorderLayer.getRowIndexByPosition(3));
assertEquals("one", this.rowReorderLayer.getDataValueByPosition(0, 0));
assertEquals("two", this.rowReorderLayer.getDataValueByPosition(0, 1));
assertEquals("three", this.rowReorderLayer.getDataValueByPosition(0, 2));
assertEquals("four", this.rowReorderLayer.getDataValueByPosition(0, 3));
// reorder to inverse order: 3 2 1 0
this.rowReorderLayer.reorderRowPosition(3, 0);
this.rowReorderLayer.reorderRowPosition(3, 1);
this.rowReorderLayer.reorderRowPosition(3, 2);
assertEquals(3, this.rowReorderLayer.getRowIndexByPosition(0));
assertEquals(2, this.rowReorderLayer.getRowIndexByPosition(1));
assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(2));
assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(3));
assertEquals("four", this.rowReorderLayer.getDataValueByPosition(0, 0));
assertEquals("three", this.rowReorderLayer.getDataValueByPosition(0, 1));
assertEquals("two", this.rowReorderLayer.getDataValueByPosition(0, 2));
assertEquals("one", this.rowReorderLayer.getDataValueByPosition(0, 3));
// delete row position 1 (index 2: value "three")
this.contents.remove(2);
this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, 2));
assertEquals(2, this.rowReorderLayer.getRowIndexByPosition(0));
assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(1));
assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(2));
assertEquals(-1, this.rowReorderLayer.getRowIndexByPosition(3));
assertEquals("four", this.rowReorderLayer.getDataValueByPosition(0, 0));
assertEquals("two", this.rowReorderLayer.getDataValueByPosition(0, 1));
assertEquals("one", this.rowReorderLayer.getDataValueByPosition(0, 2));
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.
the class RowStructuralChangeEventIntegrationTest method shouldUpdateOnInsertAndDelete.
@Test
public void shouldUpdateOnInsertAndDelete() {
this.contents.add("six");
this.underlyingLayer.fireLayerEvent(new RowInsertEvent(this.underlyingLayer, 5));
this.viewportLayer.doCommand(new RowReorderCommand(this.viewportLayer, 3, 6));
this.viewportLayer.doCommand(new RowReorderCommand(this.viewportLayer, 3, 5));
this.viewportLayer.doCommand(new MultiRowHideCommand(this.viewportLayer, new int[] { 2, 3, 5 }));
assertEquals("[0, 1, 2, 5, 4, 3]", this.rowReorderLayer.getRowIndexOrder().toString());
assertEquals("[2, 3, 5]", this.rowHideShowLayer.getHiddenRowIndexes().toString());
this.contents.add(3, "test");
this.underlyingLayer.fireLayerEvent(new RowInsertEvent(this.underlyingLayer, 3));
assertEquals("[0, 1, 2, 3, 6, 5, 4]", this.rowReorderLayer.getRowIndexOrder().toString());
assertEquals("[2, 4, 6]", this.rowHideShowLayer.getHiddenRowIndexes().toString());
this.contents.remove(3);
this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, 3));
assertEquals("[0, 1, 2, 5, 4, 3]", this.rowReorderLayer.getRowIndexOrder().toString());
assertEquals("[2, 3, 5]", this.rowHideShowLayer.getHiddenRowIndexes().toString());
}
Aggregations