Search in sources :

Example 6 with ClientAreaResizeCommand

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)));
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) Before(org.junit.Before)

Example 7 with ClientAreaResizeCommand

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));
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 8 with ClientAreaResizeCommand

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)));
}
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 9 with ClientAreaResizeCommand

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));
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 10 with ClientAreaResizeCommand

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