Search in sources :

Example 11 with ClientAreaResizeCommand

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

the class ResizeColumnHideShowLayerTest method testShowSpecificColumnsPercentageWidth.

@Test
public void testShowSpecificColumnsPercentageWidth() {
    this.bodyDataLayer.setColumnPercentageSizing(true);
    ClientAreaResizeCommand cmd = new ClientAreaResizeCommand(null);
    cmd.setCalcArea(new Rectangle(0, 0, 1500, 100));
    this.hideShowLayer.doCommand(cmd);
    assertEquals(1500, this.hideShowLayer.getWidth());
    assertEquals(300, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(300, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(300, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(300, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(300, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.hideColumnPositions(1, 4);
    assertEquals(1500, this.hideShowLayer.getWidth());
    assertEquals(500, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(500, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(500, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.showColumnIndexes(1);
    assertEquals(1500, this.hideShowLayer.getWidth());
    assertEquals(375, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(375, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(375, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(375, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(0, 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 12 with ClientAreaResizeCommand

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

the class ResizeColumnHideShowLayerTest method testHideShowFixedPercentageSizedColumnsByIndex.

@Test
public void testHideShowFixedPercentageSizedColumnsByIndex() {
    this.bodyDataLayer.setColumnWidthPercentageByPosition(0, 15);
    this.bodyDataLayer.setColumnWidthPercentageByPosition(1, 15);
    this.bodyDataLayer.setColumnWidthPercentageByPosition(2, 15);
    this.bodyDataLayer.setColumnWidthPercentageByPosition(3, 15);
    this.bodyDataLayer.setColumnWidthPercentageByPosition(4, 40);
    ClientAreaResizeCommand cmd = new ClientAreaResizeCommand(null);
    cmd.setCalcArea(new Rectangle(0, 0, 600, 100));
    this.hideShowLayer.doCommand(cmd);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(240, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.hideColumnPositions(1, 2);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(129, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(129, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(342, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.showColumnIndexes(1, 2);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(240, 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 13 with ClientAreaResizeCommand

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

the class ResizeColumnHideShowLayerTest method testHideShowSaveStatePercentageSizing.

@Test
public void testHideShowSaveStatePercentageSizing() {
    // enable percentage sizing
    this.bodyDataLayer.setColumnPercentageSizing(true);
    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 causes the calculation of percentage values for all columns
    // (20%) then column 1 gets 10 percent and column 2 gets 30%
    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|20.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 14 with ClientAreaResizeCommand

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

the class ResizeColumnHideShowLayerTest method testHideResizeShowSpecificColumn4.

@Test
public void testHideResizeShowSpecificColumn4() {
    // 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, 180);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(120, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.showAllColumns();
    assertEquals(630, 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 15 with ClientAreaResizeCommand

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

the class ResizeColumnHideShowLayerTest method testHideResizeShowMixedPercentageSizedColumns.

@Test
public void testHideResizeShowMixedPercentageSizedColumns() {
    this.bodyDataLayer.setColumnPercentageSizing(true);
    this.bodyDataLayer.setColumnWidthPercentageByPosition(0, 15);
    this.bodyDataLayer.setColumnWidthPercentageByPosition(1, 15);
    this.bodyDataLayer.setColumnWidthPercentageByPosition(3, 15);
    this.bodyDataLayer.setColumnWidthPercentageByPosition(4, 15);
    ClientAreaResizeCommand cmd = new ClientAreaResizeCommand(null);
    cmd.setCalcArea(new Rectangle(0, 0, 600, 100));
    this.hideShowLayer.doCommand(cmd);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(240, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.hideColumnPositions(3);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(330, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(4));
    // resize a column
    this.bodyDataLayer.setColumnWidthByPosition(0, 100);
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(100, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(80, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(330, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(90, this.hideShowLayer.getColumnWidthByPosition(4));
    this.hideShowLayer.showAllColumns();
    // with some rounding issues and corrections this will be the result
    // at least all columns in an appropriate ratio are visible again
    assertEquals(600, this.hideShowLayer.getWidth());
    assertEquals(87, this.hideShowLayer.getColumnWidthByPosition(0));
    assertEquals(70, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(287, this.hideShowLayer.getColumnWidthByPosition(2));
    assertEquals(78, this.hideShowLayer.getColumnWidthByPosition(3));
    assertEquals(78, 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)

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