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();
}
}
}
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;
}
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);
}
Aggregations