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));
}
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));
}
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);
}
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));
}
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));
}
Aggregations