Search in sources :

Example 1 with InitializeAutoResizeColumnsCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.

the class AutoResizeColumnsTest method autoResizeOneColumn.

/**
 * These sequence of actions were causing a nasty bug in AutoResize
 */
@Test
public void autoResizeOneColumn() throws Exception {
    GridLayer gridLayer = new DummyGridLayerStack();
    setClientAreaProvider(gridLayer);
    // Resize column
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
    assertEquals(10, gridLayer.getColumnWidthByPosition(2));
    // Auto resize the one column
    InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 2, this.configRegistry, this.gcFactory);
    gridLayer.doCommand(command);
    // Note: the actual resized width is platform specific (font
    // dependency),
    // hence we can't compare against a fixed value.
    int columnWidth = gridLayer.getColumnWidthByPosition(2);
    assertTrue(columnWidth > 10);
    // Reorder columns
    gridLayer.doCommand(new ColumnReorderCommand(gridLayer, 2, 1));
    assertEquals(columnWidth, gridLayer.getColumnWidthByPosition(1));
    // Select all columns
    gridLayer.doCommand(new SelectAllCommand());
    // Resize all selected columns
    command = new InitializeAutoResizeColumnsCommand(gridLayer, 1, this.configRegistry, this.gcFactory);
    gridLayer.doCommand(command);
    for (int columnPosition = 1; columnPosition <= 20; columnPosition++) {
        assertTrue("column " + columnPosition + " should have been resized, but it is still its original width", gridLayer.getColumnWidthByPosition(columnPosition) != 100);
    }
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 2 with InitializeAutoResizeColumnsCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.

the class InitializeAutoResizeColumnsCommandHandler method doCommand.

@Override
protected boolean doCommand(InitializeAutoResizeColumnsCommand initCommand) {
    int columnPosition = initCommand.getColumnPosition();
    if (this.selectionLayer.isColumnPositionFullySelected(columnPosition)) {
        initCommand.setSelectedColumnPositions(this.selectionLayer.getFullySelectedColumnPositions());
    } else {
        initCommand.setSelectedColumnPositions(new int[] { columnPosition });
    }
    // Fire command carrying the selected columns
    initCommand.getSourceLayer().doCommand(new AutoResizeColumnsCommand(initCommand));
    return true;
}
Also used : InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) AutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.AutoResizeColumnsCommand)

Example 3 with InitializeAutoResizeColumnsCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.

the class MenuItemProviders method autoResizeAllSelectedColumnMenuItemProvider.

public static IMenuItemProvider autoResizeAllSelectedColumnMenuItemProvider(final String menuLabel) {
    return new IMenuItemProvider() {

        @Override
        public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
            MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
            autoResizeColumns.setText(Messages.getLocalizedMessage(menuLabel));
            autoResizeColumns.setEnabled(true);
            autoResizeColumns.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    int columnPosition = getNatEventData(event).getColumnPosition();
                    natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GCFactory(natTable)));
                }
            });
        }
    };
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 4 with InitializeAutoResizeColumnsCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.

the class MenuItemProviders method autoResizeColumnMenuItemProvider.

public static IMenuItemProvider autoResizeColumnMenuItemProvider(final String menuLabel) {
    return new IMenuItemProvider() {

        @Override
        public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
            MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
            autoResizeColumns.setText(Messages.getLocalizedMessage(menuLabel));
            // $NON-NLS-1$
            autoResizeColumns.setImage(GUIHelper.getImage("auto_resize"));
            autoResizeColumns.setEnabled(true);
            autoResizeColumns.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    int columnPosition = getNatEventData(event).getColumnPosition();
                    natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GCFactory(natTable)));
                }
            });
        }
    };
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 5 with InitializeAutoResizeColumnsCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.

the class AutoResizeColumnsTest method shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected.

/**
 * Scenario: Multiple columns are selected but a non selected column is auto
 * resized.
 */
@Test
public void shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected() throws Exception {
    GridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
    setClientAreaProvider(gridLayer);
    // Resize grid column 1, 2
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 1, 10));
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
    assertEquals(10, gridLayer.getColumnWidthByPosition(1));
    assertEquals(10, gridLayer.getColumnWidthByPosition(2));
    // Fully select columns 1, 2
    SelectionLayer selectionLayer = ((DefaultBodyLayerStack) gridLayer.getBodyLayer()).getSelectionLayer();
    selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 0, 0, false, false));
    selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 1, 0, true, false));
    assertEquals(2, selectionLayer.getFullySelectedColumnPositions().length);
    // Resize grid column 5
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 5, 10));
    assertEquals(10, gridLayer.getColumnWidthByPosition(5));
    // Auto resize column 5
    InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 5, this.configRegistry, this.gcFactory);
    gridLayer.doCommand(command);
    // Columns 1 and 2 should not be resized
    assertEquals(10, gridLayer.getColumnWidthByPosition(1));
    assertEquals(10, gridLayer.getColumnWidthByPosition(2));
    assertTrue(gridLayer.getColumnWidthByPosition(5) > 10);
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) Test(org.junit.Test)

Aggregations

InitializeAutoResizeColumnsCommand (org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand)6 GCFactory (org.eclipse.nebula.widgets.nattable.util.GCFactory)3 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)2 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)2 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Menu (org.eclipse.swt.widgets.Menu)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 Test (org.junit.Test)2 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)1 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)1 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)1 AutoResizeColumnsCommand (org.eclipse.nebula.widgets.nattable.resize.command.AutoResizeColumnsCommand)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1 SelectAllCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand)1 SelectColumnCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand)1 Point (org.eclipse.swt.graphics.Point)1