Search in sources :

Example 1 with ColumnInsertEvent

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

the class DataChangeLayerTest method shouldUpdateChangeOnColumnInsert.

@Test
public void shouldUpdateChangeOnColumnInsert() {
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 2, "Muntz"));
    assertEquals("Muntz", this.dataLayer.getDataValue(1, 2));
    // simulate column deletion
    this.dataLayer.fireLayerEvent(new ColumnInsertEvent(this.dataLayer, 0));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(2, 2).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
    assertTrue("Column 2 is not dirty", this.dataChangeLayer.isColumnDirty(2));
    assertTrue("Row 2 is not dirty", this.dataChangeLayer.isRowDirty(2));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(2, 2));
    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 : UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Test(org.junit.Test)

Example 2 with ColumnInsertEvent

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

the class ColumnHideShowLayerStructuralChangeEventTest method testHandleColumnAddEvent.

@Test
public void testHandleColumnAddEvent() {
    // test start order: 0 1 2 3 4
    assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnHideShowLayer.getColumnIndexByPosition(1));
    assertEquals(2, this.columnHideShowLayer.getColumnIndexByPosition(2));
    assertEquals(3, this.columnHideShowLayer.getColumnIndexByPosition(3));
    assertEquals(4, this.columnHideShowLayer.getColumnIndexByPosition(4));
    assertEquals("one", this.columnHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.columnHideShowLayer.getDataValueByPosition(1, 0));
    assertEquals("three", this.columnHideShowLayer.getDataValueByPosition(2, 0));
    assertEquals("four", this.columnHideShowLayer.getDataValueByPosition(3, 0));
    assertEquals("five", this.columnHideShowLayer.getDataValueByPosition(4, 0));
    // hide column at position 2: 0 1 3 4
    List<Integer> columnsToHide = new ArrayList<Integer>();
    columnsToHide.add(2);
    this.columnHideShowLayer.hideColumnPositions(columnsToHide);
    assertEquals(4, this.columnHideShowLayer.getColumnCount());
    assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnHideShowLayer.getColumnIndexByPosition(1));
    assertEquals(3, this.columnHideShowLayer.getColumnIndexByPosition(2));
    assertEquals(4, this.columnHideShowLayer.getColumnIndexByPosition(3));
    assertEquals(-1, this.columnHideShowLayer.getColumnIndexByPosition(4));
    assertEquals("one", this.columnHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.columnHideShowLayer.getDataValueByPosition(1, 0));
    assertEquals("four", this.columnHideShowLayer.getDataValueByPosition(2, 0));
    assertEquals("five", this.columnHideShowLayer.getDataValueByPosition(3, 0));
    // add column add index 2
    this.contents.get(0).add(2, "test");
    this.underlyingLayer.fireLayerEvent(new ColumnInsertEvent(this.underlyingLayer, 2));
    assertEquals(5, this.columnHideShowLayer.getColumnCount());
    assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnHideShowLayer.getColumnIndexByPosition(1));
    assertEquals(2, this.columnHideShowLayer.getColumnIndexByPosition(2));
    assertEquals(4, this.columnHideShowLayer.getColumnIndexByPosition(3));
    assertEquals(5, this.columnHideShowLayer.getColumnIndexByPosition(4));
    assertEquals(-1, this.columnHideShowLayer.getColumnIndexByPosition(5));
    assertEquals("one", this.columnHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.columnHideShowLayer.getDataValueByPosition(1, 0));
    assertEquals("test", this.columnHideShowLayer.getDataValueByPosition(2, 0));
    assertEquals("four", this.columnHideShowLayer.getDataValueByPosition(3, 0));
    assertEquals("five", this.columnHideShowLayer.getDataValueByPosition(4, 0));
}
Also used : ArrayList(java.util.ArrayList) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Test(org.junit.Test)

Example 3 with ColumnInsertEvent

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

the class ColumnReorderLayerStructuralChangeEventTest method testHandleColumnAddEvent.

@Test
public void testHandleColumnAddEvent() {
    // test start order: 0 1 2 3
    assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(1));
    assertEquals(2, this.columnReorderLayer.getColumnIndexByPosition(2));
    assertEquals(3, this.columnReorderLayer.getColumnIndexByPosition(3));
    assertEquals("one", this.columnReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.columnReorderLayer.getDataValueByPosition(1, 0));
    assertEquals("three", this.columnReorderLayer.getDataValueByPosition(2, 0));
    assertEquals("four", this.columnReorderLayer.getDataValueByPosition(3, 0));
    // reorder to inverse order: 3 2 1 0
    this.columnReorderLayer.reorderColumnPosition(3, 0);
    this.columnReorderLayer.reorderColumnPosition(3, 1);
    this.columnReorderLayer.reorderColumnPosition(3, 2);
    assertEquals(3, this.columnReorderLayer.getColumnIndexByPosition(0));
    assertEquals(2, this.columnReorderLayer.getColumnIndexByPosition(1));
    assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(2));
    assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(3));
    assertEquals("four", this.columnReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("three", this.columnReorderLayer.getDataValueByPosition(1, 0));
    assertEquals("two", this.columnReorderLayer.getDataValueByPosition(2, 0));
    assertEquals("one", this.columnReorderLayer.getDataValueByPosition(3, 0));
    // add row add index 2
    this.contents.get(0).add(2, "test");
    this.underlyingLayer.fireLayerEvent(new ColumnInsertEvent(this.underlyingLayer, 2));
    assertEquals(4, this.columnReorderLayer.getColumnIndexByPosition(0));
    assertEquals(3, this.columnReorderLayer.getColumnIndexByPosition(1));
    assertEquals(2, this.columnReorderLayer.getColumnIndexByPosition(2));
    assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(3));
    assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(4));
    assertEquals("four", this.columnReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("three", this.columnReorderLayer.getDataValueByPosition(1, 0));
    assertEquals("test", this.columnReorderLayer.getDataValueByPosition(2, 0));
    assertEquals("two", this.columnReorderLayer.getDataValueByPosition(3, 0));
    assertEquals("one", this.columnReorderLayer.getDataValueByPosition(4, 0));
}
Also used : ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Test(org.junit.Test)

Example 4 with ColumnInsertEvent

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

the class RenameColumnIntegrationTest method shouldUpdateRenamedColumnOnAddingMultipleColumnRanges.

@Test
public void shouldUpdateRenamedColumnOnAddingMultipleColumnRanges() {
    this.natTableFixture.doCommand(new TurnViewportOffCommand());
    assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
    this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 5, TEST_COLUMN_NAME));
    assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(5, 0).toString());
    // simulate deletion of a column
    this.provider.setColumnCount(this.provider.getColumnCount() + 3);
    this.grid.getColumnHeaderDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), new Range(1, 3), new Range(7, 8)));
    assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(7, 0).toString());
    assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
}
Also used : RenameColumnHeaderCommand(org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) Test(org.junit.Test)

Example 5 with ColumnInsertEvent

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

the class ColumnStructuralChangeEventIntegrationTest method shouldUpdateHiddenOnInsert.

@Test
public void shouldUpdateHiddenOnInsert() {
    DefaultBodyLayerStack body = this.grid.getBodyLayer();
    ColumnHideShowLayer hideShowLayer = body.getColumnHideShowLayer();
    body.doCommand(new MultiColumnHideCommand(body, new int[] { 2, 3, 5 }));
    assertEquals("[2, 3, 5]", hideShowLayer.getHiddenColumnIndexes().toString());
    this.provider.setColumnCount(7);
    this.grid.getBodyDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), 3));
    assertEquals("[2, 4, 6]", hideShowLayer.getHiddenColumnIndexes().toString());
}
Also used : ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) Test(org.junit.Test)

Aggregations

ColumnInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent)15 Test (org.junit.Test)13 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)7 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)4 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)4 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)4 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)4 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)3 ColumnDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2 TurnViewportOffCommand (org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand)2 SingleClickSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration)2 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2