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