Search in sources :

Example 1 with RowInsertEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent in project nebula.widgets.nattable by eclipse.

the class DataChangeLayerIdIndexTest method shouldUpdateOnMultiRowInsert.

@Test
public void shouldUpdateOnMultiRowInsert() {
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 3, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 5, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 7, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 9, "Lovejoy"));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 0));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 3));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 4));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 5));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 6));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 7));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 8));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 9));
    this.dataModel.add(9, new Person(44, "Nelson", "Muntz", Gender.MALE, false, new Date(), 100d));
    this.dataModel.add(7, new Person(43, "Nelson", "Muntz", Gender.MALE, false, new Date(), 100d));
    this.dataModel.add(5, new Person(42, "Nelson", "Muntz", Gender.MALE, false, new Date(), 100d));
    this.dataModel.add(3, new Person(41, "Nelson", "Muntz", Gender.MALE, false, new Date(), 100d));
    this.dataModel.add(1, new Person(40, "Nelson", "Muntz", Gender.MALE, false, new Date(), 100d));
    this.dataLayer.fireLayerEvent(new RowInsertEvent(this.dataLayer, new Range(1, 1), new Range(3, 3), new Range(5, 5), new Range(7, 7), new Range(9, 9)));
    assertEquals(23, this.dataModel.size());
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 0));
    assertEquals("Muntz", this.dataLayer.getDataValue(1, 1));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 2));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 3));
    assertEquals("Muntz", this.dataLayer.getDataValue(1, 4));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 5));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 6));
    assertEquals("Muntz", this.dataLayer.getDataValue(1, 7));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 8));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 9));
    assertEquals("Muntz", this.dataLayer.getDataValue(1, 10));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 11));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 12));
    assertEquals("Muntz", this.dataLayer.getDataValue(1, 13));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 14));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 0));
    assertEquals("Muntz", this.dataChangeLayer.getDataValueByPosition(1, 1));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 2));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 3));
    assertEquals("Muntz", this.dataChangeLayer.getDataValueByPosition(1, 4));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 5));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 6));
    assertEquals("Muntz", this.dataChangeLayer.getDataValueByPosition(1, 7));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 8));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 9));
    assertEquals("Muntz", this.dataChangeLayer.getDataValueByPosition(1, 10));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 11));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 12));
    assertEquals("Muntz", this.dataChangeLayer.getDataValueByPosition(1, 13));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 14));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 0).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 3).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 4).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 5).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 6).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 7).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 8).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 9).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 10).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 11).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 12).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 13).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 14).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 15).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 0 is not dirty", this.dataChangeLayer.isRowDirty(0));
    assertFalse("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(1));
    assertTrue("Row 2 is not dirty", this.dataChangeLayer.isRowDirty(2));
    assertFalse("Row 3 is not dirty", this.dataChangeLayer.isRowDirty(3));
    assertFalse("Row 4 is not dirty", this.dataChangeLayer.isRowDirty(4));
    assertTrue("Row 5 is not dirty", this.dataChangeLayer.isRowDirty(5));
    assertFalse("Row 6 is not dirty", this.dataChangeLayer.isRowDirty(6));
    assertFalse("Row 7 is not dirty", this.dataChangeLayer.isRowDirty(7));
    assertTrue("Row 8 is not dirty", this.dataChangeLayer.isRowDirty(8));
    assertFalse("Row 9 is not dirty", this.dataChangeLayer.isRowDirty(9));
    assertFalse("Row 10 is not dirty", this.dataChangeLayer.isRowDirty(10));
    assertTrue("Row 11 is not dirty", this.dataChangeLayer.isRowDirty(11));
    assertFalse("Row 12 is not dirty", this.dataChangeLayer.isRowDirty(12));
    assertFalse("Row 13 is not dirty", this.dataChangeLayer.isRowDirty(13));
    assertTrue("Row 14 is not dirty", this.dataChangeLayer.isRowDirty(14));
    assertFalse("Row 15 is not dirty", this.dataChangeLayer.isRowDirty(15));
    assertFalse("Row 16 is not dirty", this.dataChangeLayer.isRowDirty(16));
    assertFalse("Row 17 is not dirty", this.dataChangeLayer.isRowDirty(17));
    assertFalse("Row 18 is not dirty", this.dataChangeLayer.isRowDirty(18));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 2));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 5));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 8));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 11));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 14));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 4));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(0, 2));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(2, 3));
    assertFalse("changed columns are empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertFalse("changed rows are empty", this.dataChangeLayer.changedRows.isEmpty());
    assertFalse("changes are empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Date(java.util.Date) Test(org.junit.Test)

Example 2 with RowInsertEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent in project nebula.widgets.nattable by eclipse.

the class CompositeFreezeLayerHideShowTest method testFreezeDeleteRows.

@Test
public void testFreezeDeleteRows() {
    this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 3));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(4, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(3, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(1, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(4, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(80, this.viewportLayer.getMinimumOrigin().getY());
    // fake a multi row delete with no details on which rows are deleted
    // technically the same as collapsing or filtering a GlazedLists
    this.rowCount = 2;
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, new ArrayList<Range>()));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(3, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(0, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(-1, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // since the RowHideShowLayer is involved in the current composition
    // the number of rows is cached and we need to update this before reset
    this.rowCount = 5;
    this.dataLayer.fireLayerEvent(new RowInsertEvent(this.dataLayer, new Range(0, 2)));
    reset();
}
Also used : FreezeRowCommand(org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand) RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) ArrayList(java.util.ArrayList) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 3 with RowInsertEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent in project nebula.widgets.nattable by eclipse.

the class RowHideShowLayerStructuralChangeEventTest method testHandleRowAddEvent.

@Test
public void testHandleRowAddEvent() {
    // test start order: 0 1 2 3 4
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(2, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(3));
    assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(4));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
    assertEquals("three", this.rowHideShowLayer.getDataValueByPosition(0, 2));
    assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 3));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 4));
    // hide row at position 2: 0 1 3 4
    List<Integer> rowsToHide = new ArrayList<Integer>();
    rowsToHide.add(2);
    this.rowHideShowLayer.hideRowPositions(rowsToHide);
    assertEquals(4, this.rowHideShowLayer.getRowCount());
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(3));
    assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(4));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
    assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 2));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 3));
    // add row add index 2
    this.contents.add(2, "test");
    this.underlyingLayer.fireLayerEvent(new RowInsertEvent(this.underlyingLayer, 2));
    assertEquals(5, this.rowHideShowLayer.getRowCount());
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(2, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(3));
    assertEquals(5, this.rowHideShowLayer.getRowIndexByPosition(4));
    assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(5));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
    assertEquals("test", this.rowHideShowLayer.getDataValueByPosition(0, 2));
    assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 3));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 4));
}
Also used : RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with RowInsertEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent in project nebula.widgets.nattable by eclipse.

the class RowReorderLayerStructuralChangeEventTest method testHandleRowAddEvent.

@Test
public void testHandleRowAddEvent() {
    // 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));
    // add row add index 2
    this.contents.add(2, "test");
    this.underlyingLayer.fireLayerEvent(new RowInsertEvent(this.underlyingLayer, 2));
    assertEquals(4, this.rowReorderLayer.getRowIndexByPosition(0));
    assertEquals(3, this.rowReorderLayer.getRowIndexByPosition(1));
    assertEquals(2, this.rowReorderLayer.getRowIndexByPosition(2));
    assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(3));
    assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(4));
    assertEquals("four", this.rowReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("three", this.rowReorderLayer.getDataValueByPosition(0, 1));
    assertEquals("test", this.rowReorderLayer.getDataValueByPosition(0, 2));
    assertEquals("two", this.rowReorderLayer.getDataValueByPosition(0, 3));
    assertEquals("one", this.rowReorderLayer.getDataValueByPosition(0, 4));
}
Also used : RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) Test(org.junit.Test)

Example 5 with RowInsertEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent in project nebula.widgets.nattable by eclipse.

the class SummaryRowIntegrationTest method rowAddShouldClearCacheAndCalculateNewSummary.

@Test
public void rowAddShouldClearCacheAndCalculateNewSummary() throws Exception {
    // Trigger summary calculation
    Object askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 4);
    assertNull(askPriceSummary);
    Thread.sleep(100);
    // Verify calculated summary value
    askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 4);
    assertEquals("110.0", askPriceSummary.toString());
    // Add data and fire event
    this.dataList.add(new RowDataFixture("SID", "SDesc", "A", new Date(), new PricingTypeBean("MN"), 2.0, 2.1, 100, true, 3.0, 1.0, 1.0, 1000, 100000, 50000));
    this.dataLayer.fireLayerEvent(new RowInsertEvent(this.dataLayer, 4));
    // Trigger summary calculation - on the new summary row
    askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 5);
    assertEquals("110.0", askPriceSummary.toString());
    Thread.sleep(100);
    // Verify summary value is REcalculated
    askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 5);
    assertEquals("112.1", askPriceSummary.toString());
}
Also used : RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) PricingTypeBean(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RowInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent)9 Test (org.junit.Test)9 Date (java.util.Date)5 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)4 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)4 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)3 ArrayList (java.util.ArrayList)2 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)2 PricingTypeBean (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean)1 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)1 FreezeRowCommand (org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand)1 MultiRowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand)1 RowReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand)1