Search in sources :

Example 26 with RowDeleteEvent

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));
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Test(org.junit.Test)

Example 27 with RowDeleteEvent

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));
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 28 with RowDeleteEvent

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());
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 29 with RowDeleteEvent

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());
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 30 with RowDeleteEvent

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

Aggregations

RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)36 Test (org.junit.Test)35 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)10 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)9 ArrayList (java.util.ArrayList)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)4 SelectionLayerStructuralChangeEventHandler (org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler)4 DiscardDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand)2 SaveDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand)2 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)2 RowInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent)2 EventList (ca.odell.glazedlists.EventList)1 FilterList (ca.odell.glazedlists.FilterList)1 SortedList (ca.odell.glazedlists.SortedList)1 TransformedList (ca.odell.glazedlists.TransformedList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1