use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.
the class RowReorderLayerStructuralChangeEventTest method testHandleLastRowDeleteEvent.
@Test
public void testHandleLastRowDeleteEvent() {
// 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 last row in list
int lastRowIndex = this.contents.size() - 1;
this.contents.remove(lastRowIndex);
this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, lastRowIndex));
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("three", 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 RowReorderLayerStructuralChangeEventTest method testHandleMultipleRowDeleteEvent.
@Test
public void testHandleMultipleRowDeleteEvent() {
// 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 rows in the middle
this.contents.remove(1);
this.contents.remove(1);
this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, new Range(1, 3)));
assertEquals(2, this.rowReorderLayer.getRowCount());
assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(0));
assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(1));
assertEquals(-1, this.rowReorderLayer.getRowIndexByPosition(2));
assertEquals("four", this.rowReorderLayer.getDataValueByPosition(0, 0));
assertEquals("one", this.rowReorderLayer.getDataValueByPosition(0, 1));
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest 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 PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveSelectionOnDelete.
@Test
public void shouldRemoveSelectionOnDelete() {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
// Ford motor at top and selected
assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("B Ford Motor", getSelected().getSecurity_description());
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());
// selection should be empty since the selected row was deleted
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
assertEquals(0, this.selectionLayer.getSelectedRowCount());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent 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());
}
}
Aggregations