Search in sources :

Example 16 with RowDeleteEvent

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

Example 17 with RowDeleteEvent

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

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

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

Example 20 with RowDeleteEvent

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());
}
Also used : RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) RowReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand) 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