JIDE 3.5.15

com.jidesoft.grid
Class DefaultSpanTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by javax.swing.table.DefaultTableModel
          extended by com.jidesoft.grid.DefaultSpanTableModel
All Implemented Interfaces:
SpanModel, SpanTableModel, Serializable, TableModel

public class DefaultSpanTableModel
extends DefaultTableModel
implements SpanTableModel

DefaultSpanTableModel adds SpanModel support to DefaultTableModel. You can use it as replacement for DefaultTableModel. Instead of return a cell span programmatically like in AbstractSpanTableModel, you can use addCellSpan(CellSpan) or removeCellSpan(int, int) to control the cell span.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.DefaultTableModel
columnIdentifiers, dataVector
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DefaultSpanTableModel()
           
DefaultSpanTableModel(int rowCount, int columnCount)
           
DefaultSpanTableModel(Object[][] data, Object[] columnNames)
           
DefaultSpanTableModel(Object[] columnNames, int rowCount)
           
DefaultSpanTableModel(Vector columnNames, int rowCount)
           
DefaultSpanTableModel(Vector data, Vector columnNames)
           
 
Method Summary
 void addCellSpan(CellSpan cellSpan)
          Adds a cell span.
 void addSpanModelListener(SpanModelListener l)
          Adds a listener to the list that's notified each time a change to the span model occurs.
 void fireTableSpanAdded(CellSpan cellSpan)
          Notifies all listeners that a cell span is added at cell (row, column).
 void fireTableSpanChanged()
          Notifies all listeners that all span values in the table's rows may have changed.
 void fireTableSpanChanged(SpanModelEvent e)
          Forwards the given notification event to all SpanModelListeners that registered themselves as listeners for this table model.
 void fireTableSpanRemoved(CellSpan cellSpan)
          Notifies all listeners that a cell span is removed at cell (row, column).
 CellSpan getCellSpanAt(int rowIndex, int columnIndex)
          Gets the cell span at the specified row and column index.
 SpanModelListener[] getSpanModelListeners()
          Returns an array of all the table model listeners registered on this model.
 void insertRow(int row, Object[] rowData)
           
 void insertRow(int row, Vector rowData)
           
 boolean isCellSpanOn()
          Checks if the span is on.
 void moveRow(int start, int end, int to)
           
 void removeAllCellSpans()
          Removes all cell spans.
 void removeCellSpan(int rowIndex, int columnIndex)
          Removes the cell span.
 void removeRow(int row)
           
 void removeSpanModelListener(SpanModelListener l)
          Removes a listener from the list that's notified each time a change to the data model occurs.
 void setCellSpanOn(boolean cellSpanOn)
           
 void setRowCount(int rowCount)
           
 
Methods inherited from class javax.swing.table.DefaultTableModel
addColumn, addColumn, addColumn, addRow, addRow, convertToVector, convertToVector, getColumnCount, getColumnName, getDataVector, getRowCount, getValueAt, isCellEditable, newDataAvailable, newRowsAdded, rowsRemoved, setColumnCount, setColumnIdentifiers, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setValueAt
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, getColumnCount, getColumnName, getRowCount, getValueAt, isCellEditable, removeTableModelListener, setValueAt
 

Constructor Detail

DefaultSpanTableModel

public DefaultSpanTableModel()

DefaultSpanTableModel

public DefaultSpanTableModel(int rowCount,
                             int columnCount)

DefaultSpanTableModel

public DefaultSpanTableModel(Vector columnNames,
                             int rowCount)

DefaultSpanTableModel

public DefaultSpanTableModel(Object[] columnNames,
                             int rowCount)

DefaultSpanTableModel

public DefaultSpanTableModel(Vector data,
                             Vector columnNames)

DefaultSpanTableModel

public DefaultSpanTableModel(Object[][] data,
                             Object[] columnNames)
Method Detail

getCellSpanAt

public CellSpan getCellSpanAt(int rowIndex,
                              int columnIndex)
Gets the cell span at the specified row and column index.

Specified by:
getCellSpanAt in interface SpanModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
the cell span at the specified row and column index.

addCellSpan

public void addCellSpan(CellSpan cellSpan)
Adds a cell span. There is no need to specify the row and column index because the information is in the cell span. Once a cell span is added, all cells in the range will return this cell span when getCellSpanAt() is called.

There is only one cell span allowed on the anchor cell. In the other word, if you try to add another cell span on the anchor cell, it will remove previous cell span, then add the new one. As long as anchor cells are different, two cell span can have overlap, even one cell span contains the other one.

Parameters:
cellSpan - a CellSpan to be added.

removeCellSpan

public void removeCellSpan(int rowIndex,
                           int columnIndex)
Removes the cell span.

Parameters:
rowIndex - the row index.
columnIndex - the column index.

removeAllCellSpans

public void removeAllCellSpans()
Removes all cell spans.

Note: If you want to turn of all cell spans temporarily, you should use setCellSpanOn(false).


isCellSpanOn

public boolean isCellSpanOn()
Description copied from interface: SpanModel
Checks if the span is on. The CellSpanTable will ignore all the CellSpans defined in this model if this method returns false.

Since 3.5.12, please fire table data changed event if the returned value of this method is changed. Otherwise the CellSpanTable might still use the cached value to improve performance.

Specified by:
isCellSpanOn in interface SpanModel
Returns:
true if span is on. Otherwise false.

setCellSpanOn

public void setCellSpanOn(boolean cellSpanOn)

addSpanModelListener

public void addSpanModelListener(SpanModelListener l)
Adds a listener to the list that's notified each time a change to the span model occurs.

Parameters:
l - the SpanModelListener

removeSpanModelListener

public void removeSpanModelListener(SpanModelListener l)
Removes a listener from the list that's notified each time a change to the data model occurs.

Parameters:
l - the SpanModelListener

getSpanModelListeners

public SpanModelListener[] getSpanModelListeners()
Returns an array of all the table model listeners registered on this model.

Returns:
all of this model's SpanModelListeners or an empty array if no table model listeners are currently registered
Since:
1.4
See Also:
addSpanModelListener(com.jidesoft.grid.SpanModelListener), removeSpanModelListener(com.jidesoft.grid.SpanModelListener)

fireTableSpanChanged

public void fireTableSpanChanged()
Notifies all listeners that all span values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in the order of the columns) is assumed to be the same.

See Also:
SpanModelEvent, EventListenerList

fireTableSpanAdded

public void fireTableSpanAdded(CellSpan cellSpan)
Notifies all listeners that a cell span is added at cell (row, column).

Parameters:
cellSpan - the CellSpan which was just added
See Also:
SpanModelEvent

fireTableSpanRemoved

public void fireTableSpanRemoved(CellSpan cellSpan)
Notifies all listeners that a cell span is removed at cell (row, column).

Parameters:
cellSpan - the CellSpan which was just removed
See Also:
SpanModelEvent

fireTableSpanChanged

public void fireTableSpanChanged(SpanModelEvent e)
Forwards the given notification event to all SpanModelListeners that registered themselves as listeners for this table model.

Parameters:
e - the event to be forwarded
See Also:
addSpanModelListener(com.jidesoft.grid.SpanModelListener), SpanModelEvent, EventListenerList

insertRow

public void insertRow(int row,
                      Object[] rowData)
Overrides:
insertRow in class DefaultTableModel

insertRow

public void insertRow(int row,
                      Vector rowData)
Overrides:
insertRow in class DefaultTableModel

moveRow

public void moveRow(int start,
                    int end,
                    int to)
Overrides:
moveRow in class DefaultTableModel

removeRow

public void removeRow(int row)
Overrides:
removeRow in class DefaultTableModel

setRowCount

public void setRowCount(int rowCount)
Overrides:
setRowCount in class DefaultTableModel

JIDE 3.5.15