Class AutomaticSpanningDataProvider
- All Implemented Interfaces:
IDataProvider,ISpanningDataProvider,IPersistable
It wraps the IDataProvider that is used for providing the data to the NatTable, so it is possible to use existing code and enhance it easily with the auto spanning feature.
To use the auto spanning feature you simply need to exchange the DataLayer in your layer composition with the SpanningDataLayer and wrap the existing IDataProvider with this AutomaticSpanningDataProvider.
Note:
Mixing of automatic column and row spanning could cause several rendering
issues if there can be no rectangle build out of matching cell values. If a
mixing is needed, a more complicated calculation algorithm need to be
implemented that checks every columns and row by building the spanning cell
for the matching rectangle. As this would be quite time consuming
calculations, this is not supported out of the box by NatTable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
DOT, VALUE_SEPARATOR -
Constructor Summary
ConstructorsConstructorDescriptionAutomaticSpanningDataProvider(IDataProvider underlyingDataProvider, boolean autoColumnSpan, boolean autoRowSpan) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAutoSpanningColumnPositions(Integer... columnPositions) Configures the given column positions for auto spanning.voidaddAutoSpanningRowPositions(Integer... rowPositions) Configures the given row positions for auto spanning.voidClears the list of column positions for which auto spanning rows is enabled.voidClears the list of row positions for which auto spanning columns is enabled.getCellByPosition(int columnPosition, int rowPosition) intprotected intgetColumnSpan(int columnPosition, int rowPosition) Calculates the number of columns to span regarding the data of the cells.getDataValue(int columnIndex, int rowIndex) Gets the value at the given column and row index.intprotected intgetRowSpan(int columnPosition, int rowPosition) Calculates the number of rows to span regarding the data of the cells.protected intgetStartColumnPosition(int columnPosition, int rowPosition) Checks if the column to the left of the given column position contains the same value.protected intgetStartRowPosition(int columnPosition, int rowPosition) Checks if the row above the given row position contains the same value.booleanbooleanprotected booleanisAutoSpanEnabledForColumn(int columnPosition, int rowPosition) Check if the given column should be used for auto spanning.protected booleanisAutoSpanEnabledForRow(int columnPosition, int rowPosition) Check if the given row should be used for auto spanning.voidloadState(String prefix, Properties properties) Restore the state out of the given Properties identified by the specified prefix.voidremoveAutoSpanningColumnPositions(Integer... columnPositions) Removes the given column positions for auto spanning.voidremoveAutoSpanningRowPositions(Integer... rowPositions) Removes the given row positions for auto spanning.voidsaveState(String prefix, Properties properties) Saves the state to the given Properties using the specified prefix.voidsetAutoColumnSpan(boolean autoColumnSpan) voidsetAutoRowSpan(boolean autoRowSpan) voidsetDataValue(int columnIndex, int rowIndex, Object newValue) Sets the value at the given column and row index.protected booleanvaluesNotEqual(Object value1, Object value2) Check if the given values are equal.
-
Field Details
-
PERSISTENCE_KEY_AUTO_COLUMN_SPAN
- See Also:
-
PERSISTENCE_KEY_AUTO_ROW_SPAN
- See Also:
-
PERSISTENCE_KEY_AUTO_SPAN_COLUMNS
- See Also:
-
PERSISTENCE_KEY_AUTO_SPAN_ROWS
- See Also:
-
-
Constructor Details
-
AutomaticSpanningDataProvider
public AutomaticSpanningDataProvider(IDataProvider underlyingDataProvider, boolean autoColumnSpan, boolean autoRowSpan) - Parameters:
underlyingDataProvider- The IDataProvider that should be wrapped by this AutomaticSpanningDataProviderautoColumnSpan- Flag to configure this AutomaticSpanningDataProvider to perform automatic column spanningautoRowSpan- Flag to configure this AutomaticSpanningDataProvider to perform automatic row spanning
-
-
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.
-
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.
-
getCellByPosition
- Specified by:
getCellByPositionin interfaceISpanningDataProvider
-
isAutoSpanEnabledForColumn
protected boolean isAutoSpanEnabledForColumn(int columnPosition, int rowPosition) Check if the given column should be used for auto spanning.- Parameters:
columnPosition- The column position to check for auto spanningrowPosition- The row position for which the column spanning should be checked- Returns:
trueif for that column position auto spanning is enabled
-
isAutoSpanEnabledForRow
protected boolean isAutoSpanEnabledForRow(int columnPosition, int rowPosition) Check if the given row should be used for auto spanning.- Parameters:
columnPosition- The column position for which the row spanning should be checked.rowPosition- The row position to check for auto spanning- Returns:
trueif for that row position auto spanning is enabled
-
addAutoSpanningColumnPositions
Configures the given column positions for auto spanning. This means that the rows in the given columns will be automatically spanned if the content is equal. Setting column positions for auto spanning will cause that the rows in all other columns won't be auto spanned anymore.- Parameters:
columnPositions- The column positions to add for auto spanning.
-
addAutoSpanningRowPositions
Configures the given row positions for auto spanning. This means that the columns in the given rows will be automatically spanned if the content is equal. Setting row positions for auto spanning will cause that the columns in all other rows won't be auto spanned anymore.- Parameters:
rowPositions- The row positions to add for auto spanning.
-
removeAutoSpanningColumnPositions
Removes the given column positions for auto spanning.- Parameters:
columnPositions- The column positions to remove for auto spanning.
-
removeAutoSpanningRowPositions
Removes the given row positions for auto spanning.- Parameters:
rowPositions- The row positions to remove for auto spanning.
-
clearAutoSpanningColumnPositions
public void clearAutoSpanningColumnPositions()Clears the list of column positions for which auto spanning rows is enabled. Note that clearing the list and leaving the autoRowSpan flag set totruewill cause that on all columns the row spanning will be performed. -
clearAutoSpanningRowPositions
public void clearAutoSpanningRowPositions()Clears the list of row positions for which auto spanning columns is enabled. Note that clearing the list and leaving the autoColumnSpan flag set totruewill cause that on all rows the column spanning will be performed. -
getStartColumnPosition
protected int getStartColumnPosition(int columnPosition, int rowPosition) Checks if the column to the left of the given column position contains the same value. In this case the given column is spanned with the one to the left and therefore that column position will be returned here.- Parameters:
columnPosition- The column position whose spanning starting column is searchedrowPosition- The row position where the column spanning should be performed.- Returns:
- The column position where the spanning starts or the given column position if it is not spanned with the columns to the left.
-
getStartRowPosition
protected int getStartRowPosition(int columnPosition, int rowPosition) Checks if the row above the given row position contains the same value. In this case the given row is spanned with the above and therefore the above row position will be returned here.- Parameters:
columnPosition- The column position for which the row spanning should be checkedrowPosition- The row position whose spanning state should be checked.- Returns:
- The row position where the spanning starts or the given row position if it is not spanned with rows above.
-
getColumnSpan
protected int getColumnSpan(int columnPosition, int rowPosition) Calculates the number of columns to span regarding the data of the cells.- Parameters:
columnPosition- The column position to start the check for spanningrowPosition- The row position for which the column spanning should be checked- Returns:
- The number of columns to span
-
getRowSpan
protected int getRowSpan(int columnPosition, int rowPosition) Calculates the number of rows to span regarding the data of the cells.- Parameters:
columnPosition- The column position for which the row spanning should be checkedrowPosition- The row position to start the check for spanning- Returns:
- The number of rows to span
-
valuesNotEqual
Check if the given values are equal. This method isnullsage.- Parameters:
value1- The first value to check for equality with the second valuevalue2- The second value to check for equality with the first value.- Returns:
trueif the given values are not equal.
-
isAutoColumnSpan
public boolean isAutoColumnSpan()- Returns:
trueif automatic column spanning is enabled
-
setAutoColumnSpan
public void setAutoColumnSpan(boolean autoColumnSpan) - Parameters:
autoColumnSpan-trueto enable automatic column spanning,falseto disable it
-
isAutoRowSpan
public boolean isAutoRowSpan()- Returns:
trueif automatic row spanning is enabled
-
setAutoRowSpan
public void setAutoRowSpan(boolean autoRowSpan) - Parameters:
autoRowSpan-trueto enable automatic row spanning,falseto disable it
-
saveState
Description copied from interface:IPersistableSaves the state to the given Properties using the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.- Specified by:
saveStatein interfaceIPersistable- Parameters:
prefix- The prefix to use for the state keys. Is also used as the state configuration name.properties- The Properties instance to save the state to.
-
loadState
Description copied from interface:IPersistableRestore the state out of the given Properties identified by the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.- Specified by:
loadStatein interfaceIPersistable- Parameters:
prefix- The prefix to use for the state keys. Is also used as the state configuration name.properties- The Properties instance to load the state from.
-