Search in sources :

Example 11 with ColumnDeleteEvent

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

the class DataChangeLayerIdIndexTest method shouldRemoveChangeOnColumnDelete.

@Test
public void shouldRemoveChangeOnColumnDelete() {
    assertEquals("Homer", this.dataLayer.getDataValue(0, 2));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 0, 2, "Nelson"));
    assertEquals("Nelson", this.dataLayer.getDataValue(0, 2));
    // simulate column deletion
    this.dataLayer.fireLayerEvent(new ColumnDeleteEvent(this.dataLayer, 0));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 2 is dirty", this.dataChangeLayer.isRowDirty(2));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 2));
    assertTrue("changed columns are not empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertTrue("changed rows are not empty", this.dataChangeLayer.changedRows.isEmpty());
    assertTrue("changes are not empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 12 with ColumnDeleteEvent

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

the class ColumnHideShowLayerStructuralChangeEventTest method testHandleColumnDeleteEvent.

@Test
public void testHandleColumnDeleteEvent() {
    // 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));
    // delete column index 1: value "two")
    this.contents.get(0).remove(1);
    this.underlyingLayer.fireLayerEvent(new ColumnDeleteEvent(this.underlyingLayer, 1));
    assertEquals(3, this.columnHideShowLayer.getColumnCount());
    assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0));
    assertEquals(2, this.columnHideShowLayer.getColumnIndexByPosition(1));
    assertEquals(3, this.columnHideShowLayer.getColumnIndexByPosition(2));
    assertEquals(-1, this.columnHideShowLayer.getColumnIndexByPosition(3));
    assertEquals("one", this.columnHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("four", this.columnHideShowLayer.getDataValueByPosition(1, 0));
    assertEquals("five", this.columnHideShowLayer.getDataValueByPosition(2, 0));
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with ColumnDeleteEvent

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

the class ColumnHideShowLayerStructuralChangeEventTest method testHandleMultipleColumnDeleteEvent.

@Test
public void testHandleMultipleColumnDeleteEvent() {
    // 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));
    // delete columns in the middle
    this.contents.get(0).remove(1);
    this.contents.get(0).remove(1);
    this.contents.get(0).remove(1);
    this.underlyingLayer.fireLayerEvent(new ColumnDeleteEvent(this.underlyingLayer, new Range(1, 4)));
    assertEquals(2, this.columnHideShowLayer.getColumnCount());
    assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnHideShowLayer.getColumnIndexByPosition(1));
    assertEquals(-1, this.columnHideShowLayer.getColumnIndexByPosition(2));
    assertEquals("one", this.columnHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("five", this.columnHideShowLayer.getDataValueByPosition(1, 0));
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 14 with ColumnDeleteEvent

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

the class ColumnReorderLayerStructuralChangeEventTest method testHandleLastColumnDeleteEvent.

@Test
public void testHandleLastColumnDeleteEvent() {
    // 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));
    // delete last column
    int lastColumnIndex = this.contents.get(0).size() - 1;
    this.contents.get(0).remove(lastColumnIndex);
    this.underlyingLayer.fireLayerEvent(new ColumnDeleteEvent(this.underlyingLayer, lastColumnIndex));
    assertEquals(2, this.columnReorderLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(1));
    assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(2));
    assertEquals(-1, this.columnReorderLayer.getColumnIndexByPosition(3));
    assertEquals("three", this.columnReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.columnReorderLayer.getDataValueByPosition(1, 0));
    assertEquals("one", this.columnReorderLayer.getDataValueByPosition(2, 0));
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) Test(org.junit.Test)

Example 15 with ColumnDeleteEvent

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

the class ColumnReorderLayerStructuralChangeEventTest method testHandleMultipleColumnDeleteEvent.

@Test
public void testHandleMultipleColumnDeleteEvent() {
    // 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));
    // delete columns in the middle
    this.contents.get(0).remove(1);
    this.contents.get(0).remove(1);
    this.underlyingLayer.fireLayerEvent(new ColumnDeleteEvent(this.underlyingLayer, new Range(1, 3)));
    assertEquals(2, this.columnReorderLayer.getColumnCount());
    assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(0));
    assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(1));
    assertEquals(-1, this.columnReorderLayer.getColumnIndexByPosition(2));
    assertEquals("four", this.columnReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("one", this.columnReorderLayer.getDataValueByPosition(1, 0));
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Aggregations

ColumnDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent)17 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)4 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)4 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)3 ColumnInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent)3 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)3 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)2 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)2 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2