Class FormulaDataProvider
- java.lang.Object
-
- org.eclipse.nebula.widgets.nattable.formula.FormulaDataProvider
-
- All Implemented Interfaces:
IDataProvider
- Direct Known Subclasses:
FormulaRowDataProvider
public class FormulaDataProvider extends Object implements IDataProvider
IDataProvider
that is able to evaluate formulas. It wraps around aIDataProvider
and checks if the requested value is a formula (starts with '='). Otherwise the value of the wrappedIDataProvider
is returned.- Since:
- 1.4
- See Also:
FormulaParser
-
-
Field Summary
Fields Modifier and Type Field Description protected FormulaErrorReporter
errorReporter
protected boolean
formulaEvaluationEnabled
protected FormulaParser
formulaParser
protected IDataProvider
underlyingDataProvider
-
Constructor Summary
Constructors Constructor Description FormulaDataProvider(IDataProvider underlyingDataProvider)
FormulaDataProvider(IDataProvider underlyingDataProvider, FormulaParser parser)
This constructor supports the specification of aFormulaParser
to customize parsing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configureCaching(ILayer layer)
Configure the caching behavior of thisFormulaDataProvider
.int
getColumnCount()
Object
getDataValue(int columnIndex, int rowIndex)
Gets the value at the given column and row index.FormulaErrorReporter
getErrorReporter()
FormulaParser
getFormulaParser()
Object
getNativeDataValue(int columnIndex, int rowIndex)
Returns the data value out of the underlyingIDataProvider
without checking and performing formula evaluation.Collection<String>
getRegisteredFunctions()
int
getRowCount()
protected IDataProvider
getUnderlyingDataProvider()
protected Object
processFormula(String formula, int columnIndex, int rowIndex)
Process the given formula String by using the internalFormulaParser
.void
registerFunction(String functionName, Class<? extends AbstractFunction> value)
Register a new function that can be evaluated.void
setDataValue(int columnIndex, int rowIndex, Object newValue)
Sets the value at the given column and row index.void
setErrorReporter(FormulaErrorReporter errorReporter)
void
setFormulaCachingEnabled(boolean enabled)
Enable/Disable formula result caching.void
setFormulaEvaluationEnabled(boolean enabled)
Enable/Disable formula evaluation.
-
-
-
Field Detail
-
underlyingDataProvider
protected IDataProvider underlyingDataProvider
-
formulaParser
protected FormulaParser formulaParser
-
errorReporter
protected FormulaErrorReporter errorReporter
-
formulaEvaluationEnabled
protected boolean formulaEvaluationEnabled
-
-
Constructor Detail
-
FormulaDataProvider
public FormulaDataProvider(IDataProvider underlyingDataProvider)
- Parameters:
underlyingDataProvider
- TheIDataProvider
that should be wrapped.
-
FormulaDataProvider
public FormulaDataProvider(IDataProvider underlyingDataProvider, FormulaParser parser)
This constructor supports the specification of aFormulaParser
to customize parsing.- Parameters:
underlyingDataProvider
- TheIDataProvider
that should be wrapped.parser
- TheFormulaParser
that should be used for formula parsing.
-
-
Method Detail
-
getDataValue
public Object getDataValue(int columnIndex, int rowIndex)
Description copied from interface:IDataProvider
Gets the value at the given column and row index.- Specified by:
getDataValue
in 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
protected Object processFormula(String formula, int columnIndex, int rowIndex)
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
public void configureCaching(ILayer layer)
Configure the caching behavior of thisFormulaDataProvider
.- Parameters:
layer
- TheILayer
to which the internalCalculatedValueCache
is connected to. Typically theDataLayer
to which thisFormulaDataProvider
is set. If this value isnull
formula result caching can not be enabled because theCalculatedValueCache
needs to operate on anILayer
.
-
getNativeDataValue
public Object getNativeDataValue(int columnIndex, int rowIndex)
Returns the data value out of the underlyingIDataProvider
without 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
IDataProvider
without formula evaluation.
-
setDataValue
public void setDataValue(int columnIndex, int rowIndex, Object newValue)
Description copied from interface:IDataProvider
Sets the value at the given column and row index. Optional operation. Should throw UnsupportedOperationException if this operation is not supported.- Specified by:
setDataValue
in 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:
getColumnCount
in interfaceIDataProvider
- Returns:
- The number of columns this
IDataProvider
handles.
-
getRowCount
public int getRowCount()
- Specified by:
getRowCount
in interfaceIDataProvider
- Returns:
- The number of rows this
IDataProvider
handles.
-
getUnderlyingDataProvider
protected IDataProvider getUnderlyingDataProvider()
- Returns:
- The underlying
IDataProvider
.
-
setFormulaEvaluationEnabled
public void setFormulaEvaluationEnabled(boolean enabled)
Enable/Disable formula evaluation.- Parameters:
enabled
-true
to enable formula evaluation,false
to 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
-true
to enable formula result caching and background processing of parsing and calculation,false
to disable it.- See Also:
configureCaching(ILayer)
-
registerFunction
public void registerFunction(String functionName, Class<? extends AbstractFunction> value)
Register a new function that can be evaluated.- Parameters:
functionName
- The name of the function that is used in a formulavalue
- The type ofAbstractFunction
that should be used when evaluation a formula that contains the given function.
-
getRegisteredFunctions
public Collection<String> getRegisteredFunctions()
- Returns:
- The names of the registered functions that are evaluated by this
FormulaDataProvider
.
-
getFormulaParser
public FormulaParser getFormulaParser()
- Returns:
- The
FormulaParser
that is used by thisFormulaDataProvider
to parse function strings.
-
getErrorReporter
public FormulaErrorReporter getErrorReporter()
- Returns:
- The
FormulaErrorReporter
that is used to report formula errors to the user.
-
setErrorReporter
public void setErrorReporter(FormulaErrorReporter errorReporter)
- Parameters:
errorReporter
- TheFormulaErrorReporter
that should be used to report formula errors to the user.
-
-