use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.
the class ColumnGroupHeaderLayerTest method setup.
@Before
public void setup() {
this.gridLayer = new GridLayerFixture();
this.model = new ColumnGroupModel();
// 10 columns in header
this.columnGroupLayer = new ColumnGroupHeaderLayer(this.gridLayer.getColumnHeaderLayer(), this.gridLayer.getBodyLayer().getSelectionLayer(), this.model);
this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_1, 0, 1);
this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_2, 5, 6);
this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_3, 8, 9);
this.gridLayer.setClientAreaProvider(new IClientAreaProvider() {
@Override
public Rectangle getClientArea() {
return new Rectangle(0, 0, 1050, 250);
}
});
this.gridLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.V_SCROLL | SWT.H_SCROLL)));
}
use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.
the class ResizeColumnHideShowLayerTest method testHideResizeShowDynamicPercentageSizedColumns.
@Test
public void testHideResizeShowDynamicPercentageSizedColumns() {
this.bodyDataLayer.setColumnPercentageSizing(true);
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, but because
// of a fixed percentage value it will only have the size of 1 pixel
assertEquals(600, this.hideShowLayer.getWidth());
assertEquals(100, this.hideShowLayer.getColumnWidthByPosition(0));
assertEquals(199, this.hideShowLayer.getColumnWidthByPosition(1));
assertEquals(1, this.hideShowLayer.getColumnWidthByPosition(2));
assertEquals(150, this.hideShowLayer.getColumnWidthByPosition(3));
assertEquals(150, 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 testHideShowLoadStatePercentageSizing.
@Test
public void testHideShowLoadStatePercentageSizing() {
// enable percentage sizing
this.bodyDataLayer.setColumnPercentageSizing(true);
// trigger percentage calculation
ClientAreaResizeCommand resizeCommand = new ClientAreaResizeCommand(null);
resizeCommand.setCalcArea(new Rectangle(0, 0, 600, 600));
this.hideShowLayer.doCommand(resizeCommand);
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));
Properties defaultState = new Properties();
this.hideShowLayer.saveState("default", defaultState);
this.hideShowLayer.hideColumnPositions(1, 4);
assertEquals(600, this.hideShowLayer.getWidth());
assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(0));
assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(1));
assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(2));
assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(3));
assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(4));
assertEquals(2, this.hideShowLayer.getHiddenColumnIndexes().size());
assertTrue("1 is not contained in hidden column indexes", this.hideShowLayer.getHiddenColumnIndexes().contains(Integer.valueOf(1)));
assertTrue("4 is not contained in hidden column indexes", this.hideShowLayer.getHiddenColumnIndexes().contains(Integer.valueOf(4)));
// save the state
Properties hiddenState = new Properties();
this.hideShowLayer.saveState("hidden", hiddenState);
// load default state again
this.hideShowLayer.loadState("default", defaultState);
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));
assertTrue("hidden column indexes are not empty", this.hideShowLayer.getHiddenColumnIndexes().isEmpty());
this.hideShowLayer.loadState("hidden", hiddenState);
assertEquals(600, this.hideShowLayer.getWidth());
assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(0));
assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(1));
assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(2));
assertEquals(200, this.hideShowLayer.getColumnWidthByPosition(3));
assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(4));
assertEquals(2, this.hideShowLayer.getHiddenColumnIndexes().size());
assertTrue("1 is not contained in hidden column indexes", this.hideShowLayer.getHiddenColumnIndexes().contains(Integer.valueOf(1)));
assertTrue("4 is not contained in hidden column indexes", this.hideShowLayer.getHiddenColumnIndexes().contains(Integer.valueOf(4)));
}
use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.
the class ResizeColumnHideShowLayerTest method testHideShowCustomColumnWithPercentageLastColumn.
@Test
public void testHideShowCustomColumnWithPercentageLastColumn() {
// change width of the column that gets hidden
this.bodyDataLayer.setColumnWidthByPosition(1, 50);
// the last column should take the remaining space
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(250, this.hideShowLayer.getColumnWidthByPosition(4));
this.hideShowLayer.hideColumnPositions(1);
assertEquals(600, this.hideShowLayer.getWidth());
assertEquals(300, this.hideShowLayer.getColumnWidthByPosition(4));
this.hideShowLayer.showAllColumns();
assertEquals(600, this.hideShowLayer.getWidth());
assertEquals(250, 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 testHideShowPercentageSizedColumnsAndSpecificMinWidth.
@Test
public void testHideShowPercentageSizedColumnsAndSpecificMinWidth() {
this.bodyDataLayer.setColumnPercentageSizing(true);
this.bodyDataLayer.setMinColumnWidth(2, 20);
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));
this.hideShowLayer.showAllColumns();
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));
}
Aggregations