Search in sources :

Example 1 with TurnViewportOnCommand

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

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

the class AutoResizeHelper method restore.

/**
 * Restore the original state of the layer before in-memory rendering
 * preparations.
 */
protected void restore() {
    this.layer.removeLayerListener(this.resizeListener);
    this.layer.setClientAreaProvider(this.originalClientAreaProvider);
    this.layer.doCommand(new TurnViewportOnCommand());
}
Also used : TurnViewportOnCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand)

Example 3 with TurnViewportOnCommand

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

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

the class NatExporter method exportLayer.

/**
 * Exports the given {@link ILayer} to the given {@link OutputStream} using
 * the provided {@link ITableExporter}.
 *
 * @param exporter
 *            The {@link ITableExporter} that should be used for exporting.
 * @param outputStream
 *            The {@link OutputStream} that should be used to write the
 *            export to.
 * @param layer
 *            The {@link ILayer} that should be exported.
 * @param configRegistry
 *            The {@link IConfigRegistry} needed to retrieve the export
 *            configurations.
 *
 * @since 1.5
 */
protected void exportLayer(final ITableExporter exporter, final OutputStream outputStream, final ILayer layer, final IConfigRegistry configRegistry) {
    if (this.preRender) {
        AutoResizeHelper.autoResize(layer, configRegistry);
    }
    IClientAreaProvider originalClientAreaProvider = layer.getClientAreaProvider();
    // This needs to be done so that the layer can return all the cells
    // not just the ones visible in the viewport
    layer.doCommand(new TurnViewportOffCommand());
    setClientAreaToMaximum(layer);
    // if a SummaryRowLayer is in the layer stack, we need to ensure that
    // the values are calculated
    layer.doCommand(new CalculateSummaryRowValuesCommand());
    // if a FormulaDataProvider is involved, we need to ensure that the
    // formula evaluation is disabled so the formula itself is exported
    // instead of the calculated value
    layer.doCommand(new DisableFormulaEvaluationCommand());
    ProgressBar progressBar = null;
    if (this.shell != null) {
        Shell childShell = new Shell(this.shell.getDisplay(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
        // $NON-NLS-1$
        childShell.setText(Messages.getString("NatExporter.exporting"));
        int endRow = layer.getRowCount() - 1;
        progressBar = new ProgressBar(childShell, SWT.SMOOTH);
        progressBar.setMinimum(0);
        progressBar.setMaximum(endRow);
        progressBar.setBounds(0, 0, 400, 25);
        progressBar.setFocus();
        childShell.pack();
        childShell.open();
    }
    try {
        exporter.exportTable(this.shell, progressBar, outputStream, layer, configRegistry);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        // These must be fired at the end of the thread execution
        layer.setClientAreaProvider(originalClientAreaProvider);
        layer.doCommand(new TurnViewportOnCommand());
        layer.doCommand(new EnableFormulaEvaluationCommand());
        if (progressBar != null) {
            Shell childShell = progressBar.getShell();
            progressBar.dispose();
            childShell.dispose();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CalculateSummaryRowValuesCommand(org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand) TurnViewportOnCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) DisableFormulaEvaluationCommand(org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand) EnableFormulaEvaluationCommand(org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) ProgressBar(org.eclipse.swt.widgets.ProgressBar) IOException(java.io.IOException)

Example 5 with TurnViewportOnCommand

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

the class AutoResizeColumnCommandHandler method doCommand.

@Override
public boolean doCommand(ILayer targetLayer, AutoResizeColumnsCommand command) {
    // Need to resize selected columns even if they are outside the viewport
    // As this command is triggered by the InitialAutoResizeCommand we know
    // that the targetLayer is the
    // NatTable itself
    targetLayer.doCommand(new TurnViewportOffCommand());
    int[] columnPositions = ObjectUtils.asIntArray(command.getColumnPositions());
    int[] gridColumnPositions = command.doPositionTransformation() ? convertFromPositionToCommandLayer(columnPositions) : columnPositions;
    int[] gridColumnWidths = MaxCellBoundsHelper.getPreferredColumnWidths(command.getConfigRegistry(), command.getGCFactory(), this.commandLayer, gridColumnPositions);
    this.commandLayer.doCommand(new MultiColumnResizeCommand(this.commandLayer, gridColumnPositions, gridColumnWidths, true));
    targetLayer.doCommand(new TurnViewportOnCommand());
    return true;
}
Also used : TurnViewportOnCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand) MultiColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.MultiColumnResizeCommand) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand)

Aggregations

TurnViewportOnCommand (org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand)6 TurnViewportOffCommand (org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand)5 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 PrintEntireGridCommand (org.eclipse.nebula.widgets.nattable.print.command.PrintEntireGridCommand)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 PrinterData (org.eclipse.swt.printing.PrinterData)1 ProgressBar (org.eclipse.swt.widgets.ProgressBar)1 ScrollBar (org.eclipse.swt.widgets.ScrollBar)1 Scrollable (org.eclipse.swt.widgets.Scrollable)1