Search in sources :

Example 31 with ClientAreaResizeCommand

use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayerTest method testHideShowSaveStatePercentageSizingWithoutFixOnResize.

@Test
public void testHideShowSaveStatePercentageSizingWithoutFixOnResize() {
    // enable percentage sizing
    this.bodyDataLayer.setColumnPercentageSizing(true);
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(false);
    this.bodyDataLayer.setDefaultMinColumnWidth(10);
    this.bodyDataLayer.setMinColumnWidth(4, 20);
    // trigger percentage calculation
    ClientAreaResizeCommand resizeCommand = new ClientAreaResizeCommand(null);
    resizeCommand.setCalcArea(new Rectangle(0, 0, 500, 500));
    this.hideShowLayer.doCommand(resizeCommand);
    assertEquals(500, this.hideShowLayer.getWidth());
    // this results in 10 percent
    this.bodyDataLayer.setColumnWidthByPosition(1, 50);
    this.bodyDataLayer.setColumnPositionResizable(4, false);
    assertTrue(this.bodyDataLayer.isColumnPositionResizable(1));
    assertFalse(this.bodyDataLayer.isColumnPositionResizable(4));
    this.hideShowLayer.hideColumnPositions(1, 4);
    assertEquals(500, this.hideShowLayer.getWidth());
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(4));
    assertFalse(this.bodyDataLayer.isColumnPositionResizable(1));
    assertFalse(this.bodyDataLayer.isColumnPositionResizable(4));
    // test save state
    Properties props = new Properties();
    this.hideShowLayer.saveState("hidden", props);
    String hidden = props.getProperty("hidden" + ResizeColumnHideShowLayer.PERSISTENCE_KEY_HIDDEN_COLUMNS);
    assertNotNull(hidden);
    assertEquals("1:[-1|-1|true|true|10.0],4:[-1|20|false|true|-1.0],", hidden);
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Properties(java.util.Properties) Test(org.junit.Test)

Example 32 with ClientAreaResizeCommand

use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayerTest method testHideResizeShowDynamicPercentageSizedColumnsWithMinSize.

@Test
public void testHideResizeShowDynamicPercentageSizedColumnsWithMinSize() {
    this.bodyDataLayer.setColumnPercentageSizing(true);
    this.bodyDataLayer.setDefaultMinColumnWidth(25);
    ClientAreaResizeCommand cmd = new ClientAreaResizeCommand(null);
    cmd.setCalcArea(new Rectangle(0, 0, 600, 100));
    this.hideShowLayer.doCommand(cmd);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(120, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(120, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(120, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(120, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(120, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.hideColumnPositions(2);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(4));
    // resize first column to 100
    this.bodyDataLayer.setColumnWidthByPosition(0, 100);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(101, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(199, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.showAllColumns();
    // because of the resize the current visible percentage columns are
    // fixed, showing the hidden column again makes it visible, and because
    // of the min size config, the other columns are updated to not exceed
    // 600
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(96, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(191, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(25, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(144, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(144, this.hideShowLayer.getColumnWidthByPosition(4));
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 33 with ClientAreaResizeCommand

use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayerTest method testHideResizeShowSpecificColumn2.

@Test
public void testHideResizeShowSpecificColumn2() {
    // the last two columns should take the remaining space
    this.bodyDataLayer.setColumnPercentageSizing(3, true);
    this.bodyDataLayer.setColumnPercentageSizing(4, true);
    ClientAreaResizeCommand cmd = new ClientAreaResizeCommand(null);
    cmd.setCalcArea(new Rectangle(0, 0, 600, 100));
    this.hideShowLayer.doCommand(cmd);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.hideColumnPositions(1);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(4));
    // resize a column
    this.bodyDataLayer.setColumnWidthByPosition(0, 40);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(260, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.showAllColumns();
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(203, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(157, this.hideShowLayer.getColumnWidthByPosition(4));
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 34 with ClientAreaResizeCommand

use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayerTest method testHideResizeShowSpecificColumn3.

@Test
public void testHideResizeShowSpecificColumn3() {
    // specify a default min width
    this.bodyDataLayer.setDefaultMinColumnWidth(25);
    // the last two columns should take the remaining space
    this.bodyDataLayer.setColumnPercentageSizing(3, true);
    this.bodyDataLayer.setColumnPercentageSizing(4, true);
    this.bodyDataLayer.setColumnWidthByPosition(1, 300);
    ClientAreaResizeCommand cmd = new ClientAreaResizeCommand(null);
    cmd.setCalcArea(new Rectangle(0, 0, 600, 100));
    this.hideShowLayer.doCommand(cmd);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(50, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(50, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.hideColumnPositions(1);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(4));
    // resize a column
    this.bodyDataLayer.setColumnWidthByPosition(0, 200);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(100, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.showAllColumns();
    assertEquals(650, this.hideShowLayer.getWidth());
    assertEquals(25, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(25, this.hideShowLayer.getColumnWidthByPosition(4));
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 35 with ClientAreaResizeCommand

use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayerTest method testColumnPositionAfterHide.

@Test
public void testColumnPositionAfterHide() {
    this.bodyDataLayer.setColumnPercentageSizing(true);
    ClientAreaResizeCommand cmd = new ClientAreaResizeCommand(null);
    cmd.setCalcArea(new Rectangle(0, 0, 1000, 100));
    this.hideShowLayer.doCommand(cmd);
    assertEquals(1000, this.hideShowLayer.getWidth());
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.hideColumnPositions(1, 2, 3);
    assertEquals(1000, this.hideShowLayer.getWidth());
    assertEquals(500, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(500, this.hideShowLayer.getColumnWidthByPosition(4));
    assertEquals(0, this.hideShowLayer.getColumnPositionByX(480));
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Aggregations

ClientAreaResizeCommand (org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand)48 Rectangle (org.eclipse.swt.graphics.Rectangle)46 Test (org.junit.Test)31 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)17 Shell (org.eclipse.swt.widgets.Shell)17 Before (org.junit.Before)9 GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)4 Properties (java.util.Properties)3 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)3 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)2 RowResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 StructuralRefreshCommand (org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand)1 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)1 CellEditorCreatedEvent (org.eclipse.nebula.widgets.nattable.edit.CellEditorCreatedEvent)1