Search in sources :

Example 1 with TurnViewportOffCommand

use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.

the class RenameColumnIntegrationTest method shouldUpdateRenamedColumnOnAddingMultipleColumnRanges.

@Test
public void shouldUpdateRenamedColumnOnAddingMultipleColumnRanges() {
    this.natTableFixture.doCommand(new TurnViewportOffCommand());
    assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
    this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 5, TEST_COLUMN_NAME));
    assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(5, 0).toString());
    // simulate deletion of a column
    this.provider.setColumnCount(this.provider.getColumnCount() + 3);
    this.grid.getColumnHeaderDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), new Range(1, 3), new Range(7, 8)));
    assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(7, 0).toString());
    assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
}
Also used : RenameColumnHeaderCommand(org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) Test(org.junit.Test)

Example 2 with TurnViewportOffCommand

use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.

the class AutoResizeRowCommandHandler method doCommand.

@Override
public boolean doCommand(ILayer targetLayer, AutoResizeRowsCommand command) {
    // Need to resize selected rows even if they are outside the viewport
    targetLayer.doCommand(new TurnViewportOffCommand());
    int[] rowPositions = ObjectUtils.asIntArray(command.getRowPositions());
    int[] gridRowPositions = command.doPositionTransformation() ? convertFromPositionToCommandLayer(rowPositions) : rowPositions;
    int[] gridRowHeights = MaxCellBoundsHelper.getPreferredRowHeights(command.getConfigRegistry(), command.getGCFactory(), this.commandLayer, gridRowPositions);
    this.commandLayer.doCommand(new MultiRowResizeCommand(this.commandLayer, gridRowPositions, gridRowHeights, true));
    targetLayer.doCommand(new TurnViewportOnCommand());
    return true;
}
Also used : TurnViewportOnCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand) MultiRowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.MultiRowResizeCommand) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand)

Example 3 with TurnViewportOffCommand

use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.

the class AutoResizeHelper method init.

/**
 * Prepare the layer for complete in-memory rendering.
 */
protected void init() {
    this.layer.addLayerListener(this.resizeListener);
    this.layer.setClientAreaProvider(this.clientAreaProvider);
    this.layer.doCommand(new TurnViewportOffCommand());
    this.layer.doCommand(new PrintEntireGridCommand());
}
Also used : TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) PrintEntireGridCommand(org.eclipse.nebula.widgets.nattable.print.command.PrintEntireGridCommand)

Example 4 with TurnViewportOffCommand

use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand 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 5 with TurnViewportOffCommand

use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.

the class RenameColumnIntegrationTest method shouldUpdateRenamedColumnOnAddingMultipleColumn.

@Test
public void shouldUpdateRenamedColumnOnAddingMultipleColumn() {
    this.natTableFixture.doCommand(new TurnViewportOffCommand());
    assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
    this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 5, TEST_COLUMN_NAME));
    assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(5, 0).toString());
    // simulate deletion of a column
    this.provider.setColumnCount(this.provider.getColumnCount() + 3);
    this.grid.getColumnHeaderDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), new Range(1, 4)));
    assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(8, 0).toString());
    assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
}
Also used : RenameColumnHeaderCommand(org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) Test(org.junit.Test)

Aggregations

TurnViewportOffCommand (org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand)8 TurnViewportOnCommand (org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand)5 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)2 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 ColumnInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent)2 PrintEntireGridCommand (org.eclipse.nebula.widgets.nattable.print.command.PrintEntireGridCommand)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 DisableFormulaEvaluationCommand (org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand)1 EnableFormulaEvaluationCommand (org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand)1 ClientAreaResizeCommand (org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand)1 MultiColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.MultiColumnResizeCommand)1 MultiRowResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.MultiRowResizeCommand)1 CalculateSummaryRowValuesCommand (org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand)1 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 PrintDialog (org.eclipse.swt.printing.PrintDialog)1 Printer (org.eclipse.swt.printing.Printer)1