Search in sources :

Example 6 with TurnViewportOffCommand

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

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

Example 8 with TurnViewportOffCommand

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

the class LayerPrinter method setupPrinter.

/**
 * Opens the PrintDialog to let the user specify the printer and print
 * configurations to use.
 *
 * @param shell
 *            The Shell which should be the parent for the PrintDialog
 * @return The selected printer with the print configuration made by the
 *         user.
 */
private Printer setupPrinter(final Shell shell) {
    final PrintDialog printDialog = new PrintDialog(shell);
    printDialog.setStartPage(1);
    printDialog.setScope(PrinterData.ALL_PAGES);
    Integer orientation = this.printTargets.get(0).configRegistry.getConfigAttribute(PrintConfigAttributes.DEFAULT_PAGE_ORIENTATION, DisplayMode.NORMAL);
    if (orientation != null) {
        printDialog.getPrinterData().orientation = orientation;
    }
    if (this.calculatePageCount) {
        // trigger content based auto-resizing
        if (LayerPrinter.this.preRender) {
            for (PrintTarget target : LayerPrinter.this.printTargets) {
                AutoResizeHelper.autoResize(target.layer, target.configRegistry);
            }
        }
        // the whole table
        for (PrintTarget target : this.printTargets) {
            target.layer.doCommand(new TurnViewportOffCommand());
        }
        try {
            Printer defaultPrinter = new Printer();
            int pageCount = getPageCount(defaultPrinter);
            defaultPrinter.dispose();
            printDialog.setEndPage(pageCount);
        } finally {
            // turn viewport on
            for (PrintTarget target : this.printTargets) {
                target.layer.doCommand(new TurnViewportOnCommand());
            }
        }
    }
    PrinterData printerData = printDialog.open();
    if (printerData == null) {
        return null;
    }
    return new Printer(printerData);
}
Also used : TurnViewportOnCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) Point(org.eclipse.swt.graphics.Point)

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