public class AutomaticSpanningDataProvider extends Object implements 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 exising 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.
Modifier and Type | Field and 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 |
DOT, VALUE_SEPARATOR
Constructor and Description |
---|
AutomaticSpanningDataProvider(IDataProvider underlyingDataProvider,
boolean autoColumnSpan,
boolean autoRowSpan) |
Modifier and Type | Method and 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.
|
public static final String PERSISTENCE_KEY_AUTO_COLUMN_SPAN
public static final String PERSISTENCE_KEY_AUTO_ROW_SPAN
public static final String PERSISTENCE_KEY_AUTO_SPAN_COLUMNS
public static final String PERSISTENCE_KEY_AUTO_SPAN_ROWS
public AutomaticSpanningDataProvider(IDataProvider underlyingDataProvider, boolean autoColumnSpan, boolean autoRowSpan)
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 spanningpublic Object getDataValue(int columnIndex, int rowIndex)
IDataProvider
getDataValue
in interface IDataProvider
public void setDataValue(int columnIndex, int rowIndex, Object newValue)
IDataProvider
setDataValue
in interface IDataProvider
public int getColumnCount()
getColumnCount
in interface IDataProvider
public int getRowCount()
getRowCount
in interface IDataProvider
public DataCell getCellByPosition(int columnPosition, int rowPosition)
getCellByPosition
in interface ISpanningDataProvider
protected boolean isAutoSpanEnabledForColumn(int columnPosition, int rowPosition)
columnPosition
- The column position to check for auto spanningrowPosition
- The row position for which the column spanning should be checkedtrue
if for that column position auto spanning is enabledprotected boolean isAutoSpanEnabledForRow(int columnPosition, int rowPosition)
columnPosition
- The column position for which the row spanning should be checked.rowPosition
- The row position to check for auto spanningtrue
if for that row position auto spanning is enabledpublic void addAutoSpanningColumnPositions(Integer... columnPositions)
columnPositions
- The column positions to add for auto spanning.public void addAutoSpanningRowPositions(Integer... rowPositions)
rowPositions
- The row positions to add for auto spanning.public void removeAutoSpanningColumnPositions(Integer... columnPositions)
columnPositions
- The column positions to remove for auto spanning.public void removeAutoSpanningRowPositions(Integer... rowPositions)
rowPositions
- The row positions to remove for auto spanning.public void clearAutoSpanningColumnPositions()
true
will cause that on all columns the row spanning will be performed.public void clearAutoSpanningRowPositions()
true
will cause that on all rows the column spanning will be performed.protected int getStartColumnPosition(int columnPosition, int rowPosition)
columnPosition
- The column position whose spanning starting column is searchedrowPosition
- The row position where the column spanning should be performed.protected int getStartRowPosition(int columnPosition, int rowPosition)
columnPosition
- The column position for which the row spanning
should be checkedrowPosition
- The row position whose spanning state should be checked.protected int getColumnSpan(int columnPosition, int rowPosition)
columnPosition
- The column position to start the check for spanningrowPosition
- The row position for which the column spanning should be checkedprotected int getRowSpan(int columnPosition, int rowPosition)
columnPosition
- The column position for which the row spanning
should be checkedrowPosition
- The row position to start the check for spanningprotected boolean valuesNotEqual(Object value1, Object value2)
null
sage.value1
- The first value to check for equality with the second valuevalue2
- The second value to check for equality with the first value.true
if the given values are not equal.public boolean isAutoColumnSpan()
true
if automatic column spanning is enabledpublic void setAutoColumnSpan(boolean autoColumnSpan)
autoColumnSpan
- true
to enable automatic column spanning,
false
to disable itpublic boolean isAutoRowSpan()
true
if automatic row spanning is enabledpublic void setAutoRowSpan(boolean autoRowSpan)
autoRowSpan
- true
to enable automatic row spanning,
false
to disable itpublic void saveState(String prefix, Properties properties)
IPersistable
saveState
in interface IPersistable
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.public void loadState(String prefix, Properties properties)
IPersistable
loadState
in interface IPersistable
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.Copyright © 2013. All Rights Reserved.