Search in sources :

Example 1 with DefaultFormulaConfiguration

use of org.eclipse.nebula.widgets.nattable.formula.config.DefaultFormulaConfiguration in project nebula.widgets.nattable by eclipse.

the class FormulaFillHandlePasteTest method setup.

@Before
public void setup() {
    InternalCellClipboard clipboard = new InternalCellClipboard();
    this.selectionLayer.registerCommandHandler(new InternalCopyDataCommandHandler(this.selectionLayer, clipboard));
    this.selectionLayer.registerCommandHandler(new FormulaFillHandlePasteCommandHandler(this.selectionLayer, clipboard, this.formulaDataProvider));
    this.natTable.addConfiguration(new DefaultFormulaConfiguration(this.formulaDataProvider, this.selectionLayer, clipboard));
    this.natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE);
        }
    });
    this.natTable.configure();
}
Also used : InternalCellClipboard(org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard) DefaultFormulaConfiguration(org.eclipse.nebula.widgets.nattable.formula.config.DefaultFormulaConfiguration) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) FormulaFillHandlePasteCommandHandler(org.eclipse.nebula.widgets.nattable.formula.command.FormulaFillHandlePasteCommandHandler) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) InternalCopyDataCommandHandler(org.eclipse.nebula.widgets.nattable.copy.command.InternalCopyDataCommandHandler) Before(org.junit.Before)

Example 2 with DefaultFormulaConfiguration

use of org.eclipse.nebula.widgets.nattable.formula.config.DefaultFormulaConfiguration in project nebula.widgets.nattable by eclipse.

the class FormulaIntegrationTest method setup.

@Before
public void setup() {
    this.natTable.addConfiguration(new DefaultFormulaConfiguration(this.formulaDataProvider, this.gridLayerStack.getBodyLayer().getSelectionLayer(), new InternalCellClipboard()));
    this.natTable.configure();
    this.natTable.addLayerListener(this.listenerFixture);
    // enable caching
    this.formulaDataProvider.configureCaching(this.gridLayerStack.getBodyDataLayer());
    this.dataProvider.setDataValue(0, 0, "5");
    this.dataProvider.setDataValue(1, 0, "3");
    this.dataProvider.setDataValue(2, 0, "=A1*B1");
    this.dataProvider.setDataValue(0, 2, "5");
    this.dataProvider.setDataValue(0, 3, "5");
    this.dataProvider.setDataValue(0, 4, "=SUM(A3:A4)");
    this.dataProvider.setDataValue(1, 2, "3");
    this.dataProvider.setDataValue(1, 3, "3");
    this.dataProvider.setDataValue(1, 4, "=SUM(B3:B4)");
    this.dataProvider.setDataValue(2, 4, "=SUM(A5;B5)");
}
Also used : InternalCellClipboard(org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard) DefaultFormulaConfiguration(org.eclipse.nebula.widgets.nattable.formula.config.DefaultFormulaConfiguration) Before(org.junit.Before)

Example 3 with DefaultFormulaConfiguration

use of org.eclipse.nebula.widgets.nattable.formula.config.DefaultFormulaConfiguration 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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) EnableFormulaEvaluationCommand(org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand) DisableFormulaEvaluationCommand(org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillHandleConfiguration(org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FormulaTooltipErrorReporter(org.eclipse.nebula.widgets.nattable.formula.FormulaTooltipErrorReporter) GridLayout(org.eclipse.swt.layout.GridLayout) DefaultFormulaConfiguration(org.eclipse.nebula.widgets.nattable.formula.config.DefaultFormulaConfiguration) PoiExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.PoiExcelExporter) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) HSSFExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter)

Aggregations

DefaultFormulaConfiguration (org.eclipse.nebula.widgets.nattable.formula.config.DefaultFormulaConfiguration)3 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 InternalCellClipboard (org.eclipse.nebula.widgets.nattable.copy.InternalCellClipboard)2 Before (org.junit.Before)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)1 InternalCopyDataCommandHandler (org.eclipse.nebula.widgets.nattable.copy.command.InternalCopyDataCommandHandler)1 HSSFExcelExporter (org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter)1 PoiExcelExporter (org.eclipse.nebula.widgets.nattable.extension.poi.PoiExcelExporter)1 FillHandleConfiguration (org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration)1 FormulaTooltipErrorReporter (org.eclipse.nebula.widgets.nattable.formula.FormulaTooltipErrorReporter)1 DisableFormulaEvaluationCommand (org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand)1 EnableFormulaEvaluationCommand (org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand)1 FormulaFillHandlePasteCommandHandler (org.eclipse.nebula.widgets.nattable.formula.command.FormulaFillHandlePasteCommandHandler)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1