Search in sources :

Example 21 with ClientAreaResizeCommand

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

the class SelectionSearchStrategyTest method setUp.

@Before
public void setUp() {
    this.bodyDataProvider = new IDataProvider() {

        @Override
        public int getColumnCount() {
            return GridLayerFixture.bodyDataProvider.getColumnCount();
        }

        @Override
        public int getRowCount() {
            return GridLayerFixture.bodyDataProvider.getRowCount();
        }

        @Override
        public Object getDataValue(int columnIndex, int rowIndex) {
            if (columnIndex == 0 || columnIndex == 9) {
                return CELL_VALUE;
            }
            return GridLayerFixture.bodyDataProvider.getDataValue(columnIndex, rowIndex);
        }

        @Override
        public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
            throw new UnsupportedOperationException();
        }
    };
    this.gridLayer = new DefaultGridLayer(this.bodyDataProvider, GridLayerFixture.colHeaderDataProvider, GridLayerFixture.rowHeaderDataProvider, GridLayerFixture.cornerDataProvider);
    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)));
    this.selectionLayer = this.gridLayer.getBodyLayer().getSelectionLayer();
    this.configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(this.configRegistry);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) Shell(org.eclipse.swt.widgets.Shell) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) Rectangle(org.eclipse.swt.graphics.Rectangle) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Before(org.junit.Before)

Example 22 with ClientAreaResizeCommand

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

the class GridLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
        ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
        Rectangle possibleArea = clientAreaResizeCommand.getScrollable().getClientArea();
        // remove the column header height and the row header width from the
        // client area to
        // ensure that only the body region is used for percentage
        // calculation
        Rectangle rowLayerArea = getRowHeaderLayer().getClientAreaProvider().getClientArea();
        Rectangle columnLayerArea = getColumnHeaderLayer().getClientAreaProvider().getClientArea();
        possibleArea.width = possibleArea.width - rowLayerArea.width;
        possibleArea.height = possibleArea.height - columnLayerArea.height;
        clientAreaResizeCommand.setCalcArea(possibleArea);
    }
    return super.doCommand(command);
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 23 with ClientAreaResizeCommand

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

the class ViewportLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
        if (this.processingClientAreaResizeCommand) {
            return false;
        }
        this.processingClientAreaResizeCommand = true;
        // on client area resize we reset the keep in viewport row position
        this.keepInViewportRowPosition = -1;
        ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
        // remember the difference from client area to body region area
        // needed because the scrollbar will be removed and therefore the
        // client area will become bigger
        Scrollable scrollable = clientAreaResizeCommand.getScrollable();
        Rectangle clientArea = scrollable.getClientArea();
        Rectangle calcArea = clientAreaResizeCommand.getCalcArea();
        int widthDiff = clientArea.width - calcArea.width;
        int heightDiff = clientArea.height - calcArea.height;
        boolean initialClientAreaResize = false;
        if (this.hBarListener == null && this.horizontalScrollbarEnabled) {
            initialClientAreaResize = true;
            ScrollBar hBar = scrollable.getHorizontalBar();
            if (hBar != null) {
                if (this.horizontalScroller != null) {
                    hBar.setEnabled(false);
                    hBar.setVisible(false);
                } else {
                    this.horizontalScroller = new ScrollBarScroller(hBar);
                }
                this.hBarListener = new HorizontalScrollBarHandler(this, this.horizontalScroller);
                if (scrollable instanceof NatTable) {
                    this.hBarListener.setTable((NatTable) scrollable);
                }
            }
        }
        if (this.vBarListener == null && this.verticalScrollbarEnabled) {
            initialClientAreaResize = true;
            ScrollBar vBar = scrollable.getVerticalBar();
            if (vBar != null) {
                if (this.verticalScroller != null) {
                    vBar.setEnabled(false);
                    vBar.setVisible(false);
                } else {
                    this.verticalScroller = new ScrollBarScroller(vBar);
                }
                this.vBarListener = new VerticalScrollBarHandler(this, this.verticalScroller);
                if (scrollable instanceof NatTable) {
                    this.vBarListener.setTable((NatTable) scrollable);
                }
            }
        }
        if (initialClientAreaResize) {
            handleGridResize();
            // after handling the scrollbars recalculate the area to use for
            // percentage calculation
            Rectangle possibleArea = scrollable.getClientArea();
            possibleArea.width = possibleArea.width - widthDiff;
            possibleArea.height = possibleArea.height - heightDiff;
            clientAreaResizeCommand.setCalcArea(possibleArea);
        }
        // we don't return true here because the ClientAreaResizeCommand
        // needs to be handled by the DataLayer in case percentage sizing is
        // enabled. if we would return true, the DataLayer wouldn't be able
        // to calculate the column/row sizes regarding the client area
        boolean result = super.doCommand(command);
        if (!initialClientAreaResize) {
            handleGridResize();
        }
        // we need to first give underlying layers the chance to process the
        // command and afterwards set the processing flag to false
        // this way we avoid processing the resize multiple times because of
        // re-calculation in conjunction with scrollbar visibility state
        // changes
        this.processingClientAreaResizeCommand = false;
        return result;
    } else if (command instanceof TurnViewportOffCommand) {
        this.savedOrigin = this.origin;
        this.viewportOff = true;
        return true;
    } else if (command instanceof TurnViewportOnCommand) {
        this.viewportOff = false;
        this.origin = this.savedOrigin;
        // only necessary in case of split viewports and auto resizing, but
        // shouldn't hurt in other cases
        recalculateScrollBars();
        return true;
    } else if (command instanceof PrintEntireGridCommand) {
        moveCellPositionIntoViewport(0, 0);
    }
    return super.doCommand(command);
}
Also used : ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Scrollable(org.eclipse.swt.widgets.Scrollable) PrintEntireGridCommand(org.eclipse.nebula.widgets.nattable.print.command.PrintEntireGridCommand) TurnViewportOnCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 24 with ClientAreaResizeCommand

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

the class FreezeHandlerTest method testFreezeColumnResize.

@Test
public void testFreezeColumnResize() {
    this.compositeFreezeLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 1500, 400);
        }
    });
    // Fire this command so that the viewport can be initialized
    this.compositeFreezeLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL)));
    this.compositeFreezeLayer.doCommand(new FreezeColumnCommand(this.compositeFreezeLayer, 2));
    assertEquals(3, this.freezeLayer.getColumnCount());
    assertEquals(7, this.viewportLayer.getColumnCount());
    assertEquals(300, this.viewportLayer.getOrigin().getX());
    this.compositeFreezeLayer.doCommand(new ColumnResizeCommand(this.freezeLayer, 2, 200));
    assertEquals(3, this.freezeLayer.getColumnCount());
    assertEquals(7, this.viewportLayer.getColumnCount());
    assertEquals(400, this.viewportLayer.getOrigin().getX());
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) 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) Test(org.junit.Test)

Example 25 with ClientAreaResizeCommand

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

the class FreezeHandlerTest method testFreezeAllColumnsResize.

@Test
public void testFreezeAllColumnsResize() {
    this.compositeFreezeLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 1500, 400);
        }
    });
    // Fire this command so that the viewport can be initialized
    this.compositeFreezeLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL)));
    this.compositeFreezeLayer.doCommand(new FreezeColumnCommand(this.compositeFreezeLayer, 9));
    assertEquals(10, this.freezeLayer.getColumnCount());
    assertEquals(0, this.viewportLayer.getColumnCount());
    assertEquals(1000, this.viewportLayer.getOrigin().getX());
    this.compositeFreezeLayer.doCommand(new ColumnResizeCommand(this.freezeLayer, 2, 200));
    assertEquals(10, this.freezeLayer.getColumnCount());
    assertEquals(0, this.viewportLayer.getColumnCount());
    assertEquals(1100, this.viewportLayer.getOrigin().getX());
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) 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) 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