use of org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand in project nebula.widgets.nattable by eclipse.
the class _305_FormulaDataExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
// TODO add combo box and text field for editing formulas
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
ConfigRegistry configRegistry = new ConfigRegistry();
final FormulaGridLayer gridLayer = new FormulaGridLayer();
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
final FormulaBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
natTable.addConfiguration(new FillHandleConfiguration(bodyLayer.getSelectionLayer()));
// This is the formula specific configuration
natTable.addConfiguration(new DefaultFormulaConfiguration(bodyLayer.getFormulaDataProvider(), bodyLayer.getSelectionLayer(), natTable.getInternalCellClipboard()));
bodyLayer.getFormulaDataProvider().setErrorReporter(new FormulaTooltipErrorReporter(natTable, bodyLayer.getDataLayer()));
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
PoiExcelExporter exporter = new HSSFExcelExporter();
exporter.setApplyBackgroundColor(false);
exporter.setFormulaParser(bodyLayer.getFormulaDataProvider().getFormulaParser());
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, exporter);
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
final Button toggleFormulaButton = new Button(panel, SWT.PUSH);
toggleFormulaButton.setText("Disable Formula Evaluation");
toggleFormulaButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_305_FormulaDataExample.this.evaluationEnabled = !_305_FormulaDataExample.this.evaluationEnabled;
if (_305_FormulaDataExample.this.evaluationEnabled) {
natTable.doCommand(new EnableFormulaEvaluationCommand());
toggleFormulaButton.setText("Disable Formula Evaluation");
} else {
natTable.doCommand(new DisableFormulaEvaluationCommand());
toggleFormulaButton.setText("Enable Formula Evaluation");
}
}
});
return panel;
}
use of org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand in project nebula.widgets.nattable by eclipse.
the class FormulaIntegrationTest method testDisableFormulaResolution.
@Test
public void testDisableFormulaResolution() throws InterruptedException {
this.natTable.doCommand(new DisableFormulaEvaluationCommand());
assertNotNull(this.natTable.getDataValueByPosition(3, 1));
assertEquals("=A1*B1", this.natTable.getDataValueByPosition(3, 1));
this.natTable.doCommand(new EnableFormulaEvaluationCommand());
assertNull(this.natTable.getDataValueByPosition(3, 1));
// wait until calculation is processed
Thread.sleep(50);
assertEquals(new BigDecimal("15"), this.natTable.getDataValueByPosition(3, 1));
}
use of org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand 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();
}
}
}
Aggregations