Search in sources :

Example 6 with TurnViewportOnCommand

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

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