Class AutomaticSpanningDataProvider
- java.lang.Object
-
- org.eclipse.nebula.widgets.nattable.data.AutomaticSpanningDataProvider
-
- All Implemented Interfaces:
IDataProvider
,ISpanningDataProvider
,IPersistable
public class AutomaticSpanningDataProvider extends Object implements ISpanningDataProvider, IPersistable
This implementation of ISpanningDataProvider will automatically span cells if the containing cell values are equal. It supports configuration whether the automatic spanning should be performed for columns or rows. It is even possible to configure which columns/rows should be checked for auto spanning.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
Fields Modifier and Type Field Description static String
PERSISTENCE_KEY_AUTO_COLUMN_SPAN
static String
PERSISTENCE_KEY_AUTO_ROW_SPAN
static String
PERSISTENCE_KEY_AUTO_SPAN_COLUMNS
static String
PERSISTENCE_KEY_AUTO_SPAN_ROWS
-
Fields inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
DOT, VALUE_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description AutomaticSpanningDataProvider(IDataProvider underlyingDataProvider, boolean autoColumnSpan, boolean autoRowSpan)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAutoSpanningColumnPositions(Integer... columnPositions)
Configures the given column positions for auto spanning.void
addAutoSpanningRowPositions(Integer... rowPositions)
Configures the given row positions for auto spanning.void
clearAutoSpanningColumnPositions()
Clears the list of column positions for which auto spanning rows is enabled.void
clearAutoSpanningRowPositions()
Clears the list of row positions for which auto spanning columns is enabled.DataCell
getCellByPosition(int columnPosition, int rowPosition)
int
getColumnCount()
protected int
getColumnSpan(int columnPosition, int rowPosition)
Calculates the number of columns to span regarding the data of the cells.Object
getDataValue(int columnIndex, int rowIndex)
Gets the value at the given column and row index.int
getRowCount()
protected int
getRowSpan(int columnPosition, int rowPosition)
Calculates the number of rows to span regarding the data of the cells.protected int
getStartColumnPosition(int columnPosition, int rowPosition)
Checks if the column to the left of the given column position contains the same value.protected int
getStartRowPosition(int columnPosition, int rowPosition)
Checks if the row above the given row position contains the same value.boolean
isAutoColumnSpan()
boolean
isAutoRowSpan()
protected boolean
isAutoSpanEnabledForColumn(int columnPosition, int rowPosition)
Check if the given column should be used for auto spanning.protected boolean
isAutoSpanEnabledForRow(int columnPosition, int rowPosition)
Check if the given row should be used for auto spanning.void
loadState(String prefix, Properties properties)
Restore the state out of the given Properties identified by the specified prefix.void
removeAutoSpanningColumnPositions(Integer... columnPositions)
Removes the given column positions for auto spanning.void
removeAutoSpanningRowPositions(Integer... rowPositions)
Removes the given row positions for auto spanning.void
saveState(String prefix, Properties properties)
Saves the state to the given Properties using the specified prefix.void
setAutoColumnSpan(boolean autoColumnSpan)
void
setAutoRowSpan(boolean autoRowSpan)
void
setDataValue(int columnIndex, int rowIndex, Object newValue)
Sets the value at the given column and row index.protected boolean
valuesNotEqual(Object value1, Object value2)
Check if the given values are equal.
-
-
-
Field Detail
-
PERSISTENCE_KEY_AUTO_COLUMN_SPAN
public static final String PERSISTENCE_KEY_AUTO_COLUMN_SPAN
- See Also:
- Constant Field Values
-
PERSISTENCE_KEY_AUTO_ROW_SPAN
public static final String PERSISTENCE_KEY_AUTO_ROW_SPAN
- See Also:
- Constant Field Values
-
PERSISTENCE_KEY_AUTO_SPAN_COLUMNS
public static final String PERSISTENCE_KEY_AUTO_SPAN_COLUMNS
- See Also:
- Constant Field Values
-
PERSISTENCE_KEY_AUTO_SPAN_ROWS
public static final String PERSISTENCE_KEY_AUTO_SPAN_ROWS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 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.
-
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.
-
getCellByPosition
public DataCell getCellByPosition(int columnPosition, int rowPosition)
- Specified by:
getCellByPosition
in 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:
true
if 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:
true
if for that row position auto spanning is enabled
-
addAutoSpanningColumnPositions
public void addAutoSpanningColumnPositions(Integer... columnPositions)
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
public void addAutoSpanningRowPositions(Integer... rowPositions)
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
public void removeAutoSpanningColumnPositions(Integer... columnPositions)
Removes the given column positions for auto spanning.- Parameters:
columnPositions
- The column positions to remove for auto spanning.
-
removeAutoSpanningRowPositions
public void removeAutoSpanningRowPositions(Integer... rowPositions)
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 totrue
will 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 totrue
will 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
protected boolean valuesNotEqual(Object value1, Object value2)
Check if the given values are equal. This method isnull
sage.- 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:
true
if the given values are not equal.
-
isAutoColumnSpan
public boolean isAutoColumnSpan()
- Returns:
true
if automatic column spanning is enabled
-
setAutoColumnSpan
public void setAutoColumnSpan(boolean autoColumnSpan)
- Parameters:
autoColumnSpan
-true
to enable automatic column spanning,false
to disable it
-
isAutoRowSpan
public boolean isAutoRowSpan()
- Returns:
true
if automatic row spanning is enabled
-
setAutoRowSpan
public void setAutoRowSpan(boolean autoRowSpan)
- Parameters:
autoRowSpan
-true
to enable automatic row spanning,false
to disable it
-
saveState
public void saveState(String prefix, Properties properties)
Description copied from interface:IPersistable
Saves 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:
saveState
in 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
public void loadState(String prefix, Properties properties)
Description copied from interface:IPersistable
Restore 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:
loadState
in 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.
-
-