Search in sources :

Example 1 with RowReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand in project nebula.widgets.nattable by eclipse.

the class PersistenceIntegrationTest method saveStateToPropeties.

public void saveStateToPropeties() throws Exception {
    // Resize column 2 to 200px
    assertEquals(100, this.natTableFixture.getColumnWidthByPosition(2));
    this.natTableFixture.doCommand(new ColumnResizeCommand(this.natTableFixture, 2, 200));
    assertEquals(200, this.natTableFixture.getColumnWidthByPosition(2));
    // Resize row 2 to 100px
    assertEquals(20, this.natTableFixture.getRowHeightByPosition(2));
    this.natTableFixture.doCommand(new RowResizeCommand(this.natTableFixture, 2, 100));
    assertEquals(100, this.natTableFixture.getRowHeightByPosition(2));
    // Reorder column 1 --> 5 (grid coordinates)
    // 0, 1, 2, 3, 4, 5,.. --> 1, 2, 3, 0, 4, 5,..
    assertEquals(0, this.natTableFixture.getColumnIndexByPosition(1));
    this.natTableFixture.doCommand(new ColumnReorderCommand(this.natTableFixture, 1, 5));
    assertEquals(1, this.natTableFixture.getColumnIndexByPosition(1));
    // Reorder row 1 --> 5 (grid coordinates)
    // 0, 1, 2, 3, 4, 5,.. --> 1, 2, 3, 0, 4, 5,..
    assertEquals(0, this.natTableFixture.getRowIndexByPosition(1));
    this.natTableFixture.doCommand(new RowReorderCommand(this.natTableFixture, 1, 5));
    assertEquals(1, this.natTableFixture.getRowIndexByPosition(1));
    // Hide column with index 3 (grid coordinates)
    assertEquals(3, this.natTableFixture.getColumnIndexByPosition(3));
    this.natTableFixture.doCommand(new ColumnHideCommand(this.natTableFixture, 3));
    assertEquals(0, this.natTableFixture.getColumnIndexByPosition(3));
    this.natTableFixture.saveState(TEST_PERSISTENCE_PREFIX, this.properties);
    // Ensure that properties got persisted
    assertEquals("true", this.properties.get("testPrefix.COLUMN_HEADER.columnWidth.resizableByDefault"));
    assertEquals("100", this.properties.get("testPrefix.COLUMN_HEADER.columnWidth.defaultSize"));
    assertEquals("true", this.properties.get("testPrefix.COLUMN_HEADER.rowHeight.resizableByDefault"));
    assertEquals("40", this.properties.get("testPrefix.ROW_HEADER.columnWidth.defaultSize"));
    assertEquals("true", this.properties.get("testPrefix.ROW_HEADER.rowHeight.resizableByDefault"));
    assertEquals("true", this.properties.get("testPrefix.ROW_HEADER.columnWidth.resizableByDefault"));
    assertEquals("40", this.properties.get("testPrefix.ROW_HEADER.rowHeight.defaultSize"));
    assertEquals("20", this.properties.get("testPrefix.CORNER.rowHeight.defaultSize"));
    assertEquals("true", this.properties.get("testPrefix.CORNER.columnWidth.resizableByDefault"));
    assertEquals("true", this.properties.get("testPrefix.CORNER.rowHeight.resizableByDefault"));
    assertEquals("20", this.properties.get("testPrefix.BODY.rowHeight.defaultSize"));
    assertEquals("true", this.properties.get("testPrefix.BODY.rowHeight.resizableByDefault"));
    assertEquals("true", this.properties.get("testPrefix.BODY.columnWidth.resizableByDefault"));
    assertEquals("1,2,3,0,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,", this.properties.get("testPrefix.BODY.columnIndexOrder"));
    assertEquals("1:100,", this.properties.get("testPrefix.BODY.rowHeight.sizes"));
    assertEquals("1:200,", this.properties.get("testPrefix.BODY.columnWidth.sizes"));
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) RowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) RowReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand)

Example 2 with RowReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand 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)

Example 3 with RowReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand in project nebula.widgets.nattable by eclipse.

the class RowStructuralChangeEventIntegrationTest method testReorderHide.

@Test
public void testReorderHide() {
    testInit();
    // reorder to inverse order: 4 3 2 1 0
    this.natTable.doCommand(new RowReorderCommand(this.viewportLayer, 4, 0));
    this.natTable.doCommand(new RowReorderCommand(this.viewportLayer, 4, 1));
    this.natTable.doCommand(new RowReorderCommand(this.viewportLayer, 4, 2));
    this.natTable.doCommand(new RowReorderCommand(this.viewportLayer, 4, 3));
    // hide row at position 2: 0 1 3 4
    this.natTable.doCommand(new RowHideCommand(this.viewportLayer, 2));
    assertEquals(4, this.viewportLayer.getRowCount());
    assertEquals(4, this.viewportLayer.getRowIndexByPosition(0));
    assertEquals(3, this.viewportLayer.getRowIndexByPosition(1));
    assertEquals(1, this.viewportLayer.getRowIndexByPosition(2));
    assertEquals(0, this.viewportLayer.getRowIndexByPosition(3));
    assertEquals(-1, this.viewportLayer.getRowIndexByPosition(4));
    assertEquals("five", this.viewportLayer.getDataValueByPosition(0, 0));
    assertEquals("four", this.viewportLayer.getDataValueByPosition(0, 1));
    assertEquals("two", this.viewportLayer.getDataValueByPosition(0, 2));
    assertEquals("one", this.viewportLayer.getDataValueByPosition(0, 3));
}
Also used : RowReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand) RowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand) MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) Test(org.junit.Test)

Example 4 with RowReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand in project nebula.widgets.nattable by eclipse.

the class RowStructuralChangeEventIntegrationTest method testReorder.

@Test
public void testReorder() {
    testInit();
    // reorder to inverse order: 4 3 2 1 0
    this.natTable.doCommand(new RowReorderCommand(this.viewportLayer, 4, 0));
    this.natTable.doCommand(new RowReorderCommand(this.viewportLayer, 4, 1));
    this.natTable.doCommand(new RowReorderCommand(this.viewportLayer, 4, 2));
    this.natTable.doCommand(new RowReorderCommand(this.viewportLayer, 4, 3));
    assertEquals(4, this.viewportLayer.getRowIndexByPosition(0));
    assertEquals(3, this.viewportLayer.getRowIndexByPosition(1));
    assertEquals(2, this.viewportLayer.getRowIndexByPosition(2));
    assertEquals(1, this.viewportLayer.getRowIndexByPosition(3));
    assertEquals(0, this.viewportLayer.getRowIndexByPosition(4));
    assertEquals("five", this.viewportLayer.getDataValueByPosition(0, 0));
    assertEquals("four", this.viewportLayer.getDataValueByPosition(0, 1));
    assertEquals("three", this.viewportLayer.getDataValueByPosition(0, 2));
    assertEquals("two", this.viewportLayer.getDataValueByPosition(0, 3));
    assertEquals("one", this.viewportLayer.getDataValueByPosition(0, 4));
}
Also used : RowReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand) Test(org.junit.Test)

Example 5 with RowReorderCommand

use of org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand in project nebula.widgets.nattable by eclipse.

the class RowReorderLayerTest method canHandleRowReorderCommand.

@Test
public void canHandleRowReorderCommand() throws Exception {
    RowReorderLayer reorderLayer = new RowReorderLayer(new DataLayerFixture());
    RowReorderCommand reorderCommand = new RowReorderCommand(reorderLayer, 0, 2);
    assertTrue(reorderLayer.doCommand(reorderCommand));
}
Also used : DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) BaseDataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture) RowReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand) Test(org.junit.Test)

Aggregations

RowReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand)6 Test (org.junit.Test)5 MultiRowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand)3 RowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)1 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)1 RowInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent)1 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)1 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)1 RowResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)1 BaseDataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture)1 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)1