public class EditableGridDataModel extends SimpleGridDataModel implements Editable
It allows dynamically add / update and remove rows and columns. It also resizes the model if the specified row or column is too long.
Modifier and Type | Class and Description |
---|---|
protected static class |
EditableGridDataModel.RowComparator
This is a row comparator implementation.
|
Modifier | Constructor and Description |
---|---|
protected |
EditableGridDataModel(DataModelCallbackHandler<Editable> handler)
Creates a new instnace of this class and defines the handler.
|
|
EditableGridDataModel(Object[][] data)
Creates an instance of this class and initializes it with the data.
|
Modifier and Type | Method and Description |
---|---|
void |
addColumn(int beforeColumn,
Object[] column)
This method adds a column into the model.
|
void |
addColumn(int beforeColumn,
String name,
Object[] column)
This method adds the specified column in the data model.
|
void |
addListener(EditableModelListener listener)
This method registers the specified listener to receive model events.
|
void |
addRow(int beforeRow,
Object[] row)
This method adds the specified row in the data model.
|
protected void |
checkColumnNumber(int columnNumber,
int max)
This method checks whether the specified column is in valid range and throws the
IllegalArgumentException if it isn't. |
protected void |
checkRowNumber(int rowNumber,
int max)
This method checks whether the specified row is in valid range and throws the
IllegalArgumentException if it isn't. |
void |
clearRemovedRows()
This method clears removed rows from the model history
|
protected EditableModelEvent |
createEvent(EditableModelEvent.EventType eventType)
Creates a new model event.
|
protected EditableModelEvent |
createEvent(EditableModelEvent.EventType eventType,
int row,
int column)
Creates a new model event.
|
protected GridRow |
createGridRow(int columnCount)
This method creates a new identified list instance.
|
protected EditableGridDataModel.RowComparator |
createRowComparator(int sortColumn,
Comparator<Object> comparator)
This method creates a row comparator.
|
protected void |
fireColumnEvent(EditableModelEvent.EventType eventType,
int column)
Fires a column change events.
|
protected void |
fireEvent(EditableModelEvent event)
This method fires the specified event.
|
protected void |
fireRowEvent(EditableModelEvent.EventType eventType,
int row)
Fires a row change events.
|
String[] |
getColumnNames()
This method gets a list of column names.
|
protected List<String> |
getColumnNamesList()
Getter for property 'columnNames'.
|
GridColumn[] |
getColumns()
Gets an array of all model columns.
|
Object[][] |
getData()
This method returns the data set of the model.
|
protected List<? extends GridRow> |
getDataList()
Gets a list of data.
|
GridColumn |
getGridColumn(int index)
Gets a grid column by index.
|
DataModelCallbackHandler<Editable> |
getHandler()
This method returns a callback handler instance.
|
protected String |
getInternalRowIdentifier(int row)
This method returns an internal row identifier.
|
protected List<EditableModelListener> |
getListeners()
Gets a list of registered listeners.
|
Object[][] |
getRemovedRows()
This method returns removed rows.
|
GridRow |
getRow(int index)
Gets a grid row by index.
|
Object[] |
getRowData(int rowNumber)
This method returns row data by the specified row number.
|
GridRow[] |
getRows()
This method returns an original list of rows.
|
protected List<String> |
getSublist(List<String> list,
int start,
int end)
This method extract a sublist of the specified list.
|
int |
getTotalColumnCount()
Getter for property 'totalColumnCount'.
|
int |
getTotalRowCount()
This method is overriden to avoid possible recursions.
|
protected GridRow |
normalizeColumnsCount(Object[] row)
This method normalizes a number of columns in all rows adding empty cells.
|
protected ArrayList<Object> |
normalizeRowsCount(Object[] column)
This method normalizes a number of rows in all columns adding empty cells.
|
protected void |
prepareData(Object[][] data,
int rowCount,
int columnCount)
This method initializes the data set with the specified values.
|
protected void |
prepareEvent(EditableModelEvent event)
This method prepares the specified event for sending, initilizing necessary fields.
|
void |
removeAll()
This method removes all rows from the model.
|
void |
removeColumn(int columnNumber)
This method removes a column from the model.
|
void |
removeColumn(String name)
This method deletes the specified column in the data model.
|
void |
removeListener(EditableModelListener listener)
This method unregisters the specified listener to stop model events receiving.
|
void |
removeRow(int rowNumber)
This method removes the specified row in the data model.
|
void |
setColumNames(String[] names)
This method sets a list of column names
This list must be in the same order like the data array columns (see
Editable.update(Object[][]) for details. |
void |
setHandler(DataModelCallbackHandler<Editable> handler)
This method sets a callback handler.
|
void |
setSortColumn(int sortColumn,
Comparator<Object> comparator)
This method sets a sort column and uses the specified comparator.
|
void |
update(int row,
int column,
Object data)
This method updates the specified cell with the value.
|
void |
update(Object[][] data)
Use this method to update the model with a new value.
|
void |
updateColumn(int columnNumber,
Object[] column)
This method updates the specified column in the data model.
|
void |
updateColumn(String name,
Object[] column)
This method updates the specified column in the data model.
|
void |
updateRow(int rowNumber,
Object[] row)
This method updates the specified row in the data model.
|
getCurrentPageNumber, getDisplayedPages, getEndPage, getEndRow, getPageable, getPageSize, getSortColumn, getStartPage, getStartRow, getTotalPagesNumber, isAscending, isEmpty, setAscending, setCurrentPageNumber, setDisplayedPages, setPageable, setPageSize, setSortColumn, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getEndRow, getSortColumn, getStartRow, isAscending, isEmpty, setAscending, setSortColumn
getCurrentPageNumber, getDisplayedPages, getEndPage, getPageSize, getStartPage, getTotalPagesNumber, setCurrentPageNumber, setDisplayedPages, setPageSize
public EditableGridDataModel(Object[][] data)
It automatically resizes the data set if it's too small.
data
- is a data set.protected EditableGridDataModel(DataModelCallbackHandler<Editable> handler)
handler
- is a callback handler to be invoked on changes.public void addRow(int beforeRow, Object[] row) throws IllegalArgumentException
It normalizes the model if the row is too long.
addRow
in interface Editable
beforeRow
- is a number of the new row in the grid.row
- is new row data.IllegalArgumentException
- if the row number is in invalid range.public void updateRow(int rowNumber, Object[] row) throws IllegalArgumentException
It normalizes the model if the row is too long.
updateRow
in interface Editable
rowNumber
- is a number of the row in the grid.row
- is new data.IllegalArgumentException
- if the row number is in invalid range.public void removeRow(int rowNumber) throws IllegalArgumentException
removeRow
in interface Editable
rowNumber
- is a number of the row in the grid.IllegalArgumentException
- if the row number is in invalid range.public void addColumn(int beforeColumn, Object[] column) throws IllegalArgumentException
addColumn
in interface Editable
beforeColumn
- a column number.column
- a column data set.IllegalArgumentException
- if the column number is invalid.public void addColumn(int beforeColumn, String name, Object[] column) throws IllegalArgumentException
It normalizes the model if the column is too long.
addColumn
in interface Editable
beforeColumn
- is a number of the new column in the grid.name
- is a name of the column.column
- is new column data.IllegalArgumentException
- if the column number is in invalid range.public void updateColumn(int columnNumber, Object[] column)
It normalizes the model if the column is too long.
updateColumn
in interface Editable
columnNumber
- is a number of the column in the grid.column
- is new data.IllegalArgumentException
- if the column number is in invalid range.public void updateColumn(String name, Object[] column)
It normalizes the model if the column is too long.
updateColumn
in interface Editable
name
- is a name of the column.column
- is new data.public void removeColumn(int columnNumber) throws IllegalArgumentException
removeColumn
in interface Editable
columnNumber
- a column number.IllegalArgumentException
- if the column number is invalid.public void removeColumn(String name)
removeColumn
in interface Editable
name
- is a name of the column.public Object[] getRowData(int rowNumber)
getRowData
in interface GridDataModel
getRowData
in class SimpleGridDataModel
rowNumber
- is a number of row to be returned.public void removeAll()
public void update(int row, int column, Object data)
public void setSortColumn(int sortColumn, Comparator<Object> comparator)
setSortColumn
in interface Editable
sortColumn
- is a sort column.comparator
- is a column comparator.protected EditableGridDataModel.RowComparator createRowComparator(int sortColumn, Comparator<Object> comparator)
sortColumn
- is a sort column.comparator
- is a cell comparator.public int getTotalColumnCount()
getTotalColumnCount
in interface Editable
public Object[][] getRemovedRows()
getRemovedRows
in interface Editable
public void clearRemovedRows()
clearRemovedRows
in interface Editable
public int getTotalRowCount()
getTotalRowCount
in interface GridDataModel
getTotalRowCount
in class SimpleGridDataModel
public DataModelCallbackHandler<Editable> getHandler()
getHandler
in interface Editable
public void setHandler(DataModelCallbackHandler<Editable> handler)
setHandler
in interface Editable
handler
- a callback handler.public void update(Object[][] data)
public void addListener(EditableModelListener listener)
addListener
in interface Editable
listener
- is a model listener to register.public void removeListener(EditableModelListener listener)
removeListener
in interface Editable
listener
- is a model listener to be removed.protected void checkColumnNumber(int columnNumber, int max) throws IllegalArgumentException
IllegalArgumentException
if it isn't.columnNumber
- is a column number to check.max
- is a max limit of the range.IllegalArgumentException
- if check failed.protected void checkRowNumber(int rowNumber, int max)
IllegalArgumentException
if it isn't.rowNumber
- is a row number to check.max
- is a max limit of the range.IllegalArgumentException
- if check failed.public Object[][] getData()
getData
in interface GridDataModel
getData
in class SimpleGridDataModel
protected GridRow normalizeColumnsCount(Object[] row)
If the specified row is shorter then the current columns count, it add empty cells to the row.
row
- is a pattern row.protected ArrayList<Object> normalizeRowsCount(Object[] column)
If the specified column is shorter then the current rows count, it add empty cells to the column.
column
- is a pattern column.protected void prepareData(Object[][] data, int rowCount, int columnCount)
It tries to fill the data set and if the specified value is shorter it adds empty cells. Otherwise it increases the size of the data set.
data
- is a data to put into the data set.rowCount
- is a row count of the data set.columnCount
- is a column count of the data set.protected GridRow createGridRow(int columnCount)
columnCount
- is a column count value.public GridRow[] getRows()
public GridColumn[] getColumns()
getColumns
in interface Editable
public GridRow getRow(int index)
public GridColumn getGridColumn(int index)
getGridColumn
in interface Editable
index
- is an index value.public String[] getColumnNames()
getColumnNames
in interface Editable
public void setColumNames(String[] names)
Editable.update(Object[][])
for details.setColumNames
in interface Editable
names
- is a list of column names.protected String getInternalRowIdentifier(int row)
row
- is a row number.protected List<String> getColumnNamesList()
protected List<String> getSublist(List<String> list, int start, int end)
list
- is a list of values.start
- is a start index (including).end
- is an end index (excluding).protected List<? extends GridRow> getDataList()
protected List<EditableModelListener> getListeners()
protected void prepareEvent(EditableModelEvent event)
event
- is an event to be prepared.protected void fireEvent(EditableModelEvent event)
event
- is an event to fire.protected void fireRowEvent(EditableModelEvent.EventType eventType, int row)
eventType
- is a concrete row event type.row
- is a row number.protected void fireColumnEvent(EditableModelEvent.EventType eventType, int column)
eventType
- is a concrete column event type.column
- is a column number.protected EditableModelEvent createEvent(EditableModelEvent.EventType eventType)
eventType
- is an event type.protected EditableModelEvent createEvent(EditableModelEvent.EventType eventType, int row, int column)
eventType
- is an event type.row
- is a row number.column
- is a column number.Copyright © 2008–2013. All rights reserved.