Class FormulaDataProvider
java.lang.Object
org.eclipse.nebula.widgets.nattable.formula.FormulaDataProvider
- All Implemented Interfaces:
IDataProvider
- Direct Known Subclasses:
FormulaRowDataProvider
IDataProvider that is able to evaluate formulas. It wraps around a
IDataProvider and checks if the requested value is a formula (starts
with '='). Otherwise the value of the wrapped IDataProvider is
returned.- Since:
- 1.4
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FormulaErrorReporterprotected booleanprotected FormulaParserprotected IDataProvider -
Constructor Summary
ConstructorsConstructorDescriptionFormulaDataProvider(IDataProvider underlyingDataProvider) FormulaDataProvider(IDataProvider underlyingDataProvider, FormulaParser parser) This constructor supports the specification of aFormulaParserto customize parsing. -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigureCaching(ILayer layer) Configure the caching behavior of thisFormulaDataProvider.intgetDataValue(int columnIndex, int rowIndex) Gets the value at the given column and row index.getNativeDataValue(int columnIndex, int rowIndex) Returns the data value out of the underlyingIDataProviderwithout checking and performing formula evaluation.intprotected IDataProviderprotected ObjectprocessFormula(String formula, int columnIndex, int rowIndex) Process the given formula String by using the internalFormulaParser.voidregisterFunction(String functionName, Class<? extends AbstractFunction> value) Register a new function that can be evaluated.voidsetDataValue(int columnIndex, int rowIndex, Object newValue) Sets the value at the given column and row index.voidsetErrorReporter(FormulaErrorReporter errorReporter) voidsetFormulaCachingEnabled(boolean enabled) Enable/Disable formula result caching.voidsetFormulaEvaluationEnabled(boolean enabled) Enable/Disable formula evaluation.
-
Field Details
-
underlyingDataProvider
-
formulaParser
-
errorReporter
-
formulaEvaluationEnabled
protected boolean formulaEvaluationEnabled
-
-
Constructor Details
-
FormulaDataProvider
- Parameters:
underlyingDataProvider- TheIDataProviderthat should be wrapped.
-
FormulaDataProvider
This constructor supports the specification of aFormulaParserto customize parsing.- Parameters:
underlyingDataProvider- TheIDataProviderthat should be wrapped.parser- TheFormulaParserthat should be used for formula parsing.
-
-
Method Details
-
getDataValue
Description copied from interface:IDataProviderGets the value at the given column and row index.- Specified by:
getDataValuein interfaceIDataProvider- Parameters:
columnIndex- The column index of the cell whose value is requested.rowIndex- The row index of the cell whose value is requested.- Returns:
- The data value associated with the specified cell coordintates.
-
processFormula
Process the given formula String by using the internalFormulaParser.- Parameters:
formula- The formula to process.columnIndex- The column index of the cell that contains the formula. Needed for error handling.rowIndex- The row index of the cell that contains the formula. Needed for error handling.- Returns:
- The result of the processed formula or an error markup in case an error occurred on processing.
-
configureCaching
Configure the caching behavior of thisFormulaDataProvider.- Parameters:
layer- TheILayerto which the internalCalculatedValueCacheis connected to. Typically theDataLayerto which thisFormulaDataProvideris set. If this value isnullformula result caching can not be enabled because theCalculatedValueCacheneeds to operate on anILayer.
-
getNativeDataValue
Returns the data value out of the underlyingIDataProviderwithout checking and performing formula evaluation. Needed in order to edit formulas in a NatTable or outside the NatTable.- Parameters:
columnIndex- The column index of the requested value.rowIndex- The row index of the requested value.- Returns:
- The value of the underlying
IDataProviderwithout formula evaluation.
-
setDataValue
Description copied from interface:IDataProviderSets the value at the given column and row index. Optional operation. Should throw UnsupportedOperationException if this operation is not supported.- Specified by:
setDataValuein interfaceIDataProvider- Parameters:
columnIndex- The column index of the cell whose value should be changed.rowIndex- The row index of the cell whose value should be changed.newValue- The new value that should be set.
-
getColumnCount
public int getColumnCount()- Specified by:
getColumnCountin interfaceIDataProvider- Returns:
- The number of columns this
IDataProviderhandles.
-
getRowCount
public int getRowCount()- Specified by:
getRowCountin interfaceIDataProvider- Returns:
- The number of rows this
IDataProviderhandles.
-
getUnderlyingDataProvider
- Returns:
- The underlying
IDataProvider.
-
setFormulaEvaluationEnabled
public void setFormulaEvaluationEnabled(boolean enabled) Enable/Disable formula evaluation.- Parameters:
enabled-trueto enable formula evaluation,falseto disable it.
-
setFormulaCachingEnabled
public void setFormulaCachingEnabled(boolean enabled) Enable/Disable formula result caching. Enabling the formula result caching means that the parsing and calculation of formulas is performed in a background thread. The result is cached to reduce processing time, so the rendering is performed faster. Disabling the formula result caching means that parsing and calculation of formulas is performed always in the current thread which might lead to slower rendering.- Parameters:
enabled-trueto enable formula result caching and background processing of parsing and calculation,falseto disable it.- See Also:
-
registerFunction
Register a new function that can be evaluated.- Parameters:
functionName- The name of the function that is used in a formulavalue- The type ofAbstractFunctionthat should be used when evaluation a formula that contains the given function.
-
getRegisteredFunctions
- Returns:
- The names of the registered functions that are evaluated by this
FormulaDataProvider.
-
getFormulaParser
- Returns:
- The
FormulaParserthat is used by thisFormulaDataProviderto parse function strings.
-
getErrorReporter
- Returns:
- The
FormulaErrorReporterthat is used to report formula errors to the user.
-
setErrorReporter
- Parameters:
errorReporter- TheFormulaErrorReporterthat should be used to report formula errors to the user.
-