org.openswing.swing.table.model.client
Class VOListTableModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended byorg.openswing.swing.table.model.client.VOListTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class VOListTableModel
extends javax.swing.table.AbstractTableModel

Title: OpenSwing Framework

Description: TableModel based on a ValueObject list.

Copyright: Copyright (C) 2006 Mauro Carniel

This file is part of OpenSwing Framework. This library is free software; you can redistribute it and/or modify it under the terms of the (LGPL) Lesser General Public License as published by the Free Software Foundation; GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The author may be contacted at: maurocarniel@tin.it

See Also:
Serialized Form

Constructor Summary
VOListTableModel(VOListAdapter fieldAdapter, VOListTableModelListener modelListener)
           
 
Method Summary
 void addObject(ValueObject object)
          Add a ValueObject to TableModel.
 void clear()
          Remove all ValueObjects from the data vector.
 void clearModified()
          Reset the modification flag for this model.
 java.util.ArrayList getChangedRowIndexes()
           
 int[] getChangedRowNumbers()
           
 java.util.ArrayList getChangedRows()
           
 java.lang.Class getColumnClass(int column)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int column)
           
 int getColumnType(int column)
           
 java.util.Vector getDataVector()
           
 java.lang.Object getField(int row, java.lang.String attributeName)
          Get value within a value object, for the specified attribute name.
 int getMode()
           
 ValueObject getObjectForRow(int row)
           
 java.util.ArrayList getOldVOsChanged()
           
 int getRowCount()
           
 int getRowForObject(ValueObject object)
           
 java.lang.Object getValueAt(int row, int column)
           
 java.lang.Class getValueObjectType()
           
 void insertObjectAt(ValueObject object, int row)
          Insert a ValueObject at the specified position in the data vector.
 boolean isCellEditable(int row, int column)
           
 boolean isModified()
           
 void removeObjectAt(int row)
          Remove the ValueObject at the specified position from the data vector.
 void setField(int row, java.lang.String attributeName, java.lang.Object value)
          Set value within a value object, for the specified attribute name.
 void setMode(int mode)
          Set the current edit grid mode; default value: READONLY.
 boolean setValue(java.lang.Object value, int row, int column)
          Set the value at the specified row and column in the TableModel, only if: - the grid is editable and the value is valid (i.e.
 void setValueAt(java.lang.Object value, int row, int column)
          Set the value at the specified row and column in the TableModel.
 void updateObjectAt(int row)
          Notify the model that the ValueObject at the given row has been updated.
 void updateObjectAt(ValueObject object, int row)
          Update TableModel with the ValueObject.
 void updateValueObjectsAt(int[] rowNumbers, ValueObject[] objects)
          Update ValueObjects into TableModel for the specified rows.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VOListTableModel

public VOListTableModel(VOListAdapter fieldAdapter,
                        VOListTableModelListener modelListener)
Parameters:
fieldAdapter - adapter che collega modello dati e value object
Method Detail

getColumnName

public final java.lang.String getColumnName(int column)
Parameters:
column - index of the column
Returns:
name of the attribute that corresponds to the given column

getColumnType

public final int getColumnType(int column)
Parameters:
column - index of the column
Returns:
column type

addObject

public final void addObject(ValueObject object)
Add a ValueObject to TableModel.

Parameters:
object - ValueObject to add

insertObjectAt

public final void insertObjectAt(ValueObject object,
                                 int row)
Insert a ValueObject at the specified position in the data vector. A new row will be inserted at the corresponding position in the table model.

Parameters:
object - ValueObject to add
row - row at which to insert the object

updateObjectAt

public final void updateObjectAt(int row)
Notify the model that the ValueObject at the given row has been updated.

Parameters:
row - row of the updated object

clear

public final void clear()
Remove all ValueObjects from the data vector. All rows will be removed from the TableModel.


removeObjectAt

public final void removeObjectAt(int row)
Remove the ValueObject at the specified position from the data vector. The row at the corresponding position in the table model will be removed.

Parameters:
row - row of the object to remove

getRowCount

public final int getRowCount()
Returns:
number of objects in the data vector (e.g., the number of rows in the TableModel)

getColumnCount

public final int getColumnCount()
Returns:
number of columns in this table model (e.g., the number of fields as reported by the attribute adapter)

getValueAt

public final java.lang.Object getValueAt(int row,
                                         int column)
Parameters:
row - row index
column - column index
Returns:
Object at the specified coordinates

getObjectForRow

public final ValueObject getObjectForRow(int row)
Parameters:
row - row index
Returns:
ValueObject represented in the given row
See Also:
getRowForObject(org.openswing.swing.message.receive.java.ValueObject)

getRowForObject

public final int getRowForObject(ValueObject object)
Parameters:
object - ValueObject to locate
Returns:
row in the TableModel that represents the given object
See Also:
getObjectForRow(int)

isModified

public final boolean isModified()
Returns:
true if modifications have been made, and false otherwise
See Also:
clearModified()

clearModified

public final void clearModified()
Reset the modification flag for this model.

See Also:
isModified()

getColumnClass

public final java.lang.Class getColumnClass(int column)
Parameters:
column - column index
Returns:
Class object for the specified column

updateObjectAt

public final void updateObjectAt(ValueObject object,
                                 int row)
Update TableModel with the ValueObject.

Parameters:
object - new ValueObject
row - row index

getDataVector

public final java.util.Vector getDataVector()
Returns:
ValueObject list

isCellEditable

public final boolean isCellEditable(int row,
                                    int column)
Parameters:
row - row index
column - column index
Returns:
true if the cell at the given row and column is editable and false otherwise. The editable state is based on FieldAdapter and on current grid edit mode.

setMode

public final void setMode(int mode)
Set the current edit grid mode; default value: READONLY.

Parameters:
mode - current edit grid mode

getMode

public final int getMode()
Returns:
current edit grid mode

setValueAt

public final void setValueAt(java.lang.Object value,
                             int row,
                             int column)
Set the value at the specified row and column in the TableModel.

Parameters:
row - row index
column - column index
value - new object for the specified coordinates

getField

public final java.lang.Object getField(int row,
                                       java.lang.String attributeName)
Get value within a value object, for the specified attribute name.

Parameters:
row - row index
Returns:
object value related to the specified attribute name and row

setField

public final void setField(int row,
                           java.lang.String attributeName,
                           java.lang.Object value)
Set value within a value object, for the specified attribute name. Note: no validation task is performed.

Parameters:
row - row index
value - new Object to set onto ValueObject

setValue

public final boolean setValue(java.lang.Object value,
                              int row,
                              int column)
Set the value at the specified row and column in the TableModel, only if: - the grid is editable and the value is valid (i.e. GridController.validateCell method returns true) - the grid is in read only mode

Parameters:
row - row index
column - column index
value - new object for the specified coordinates
Returns:
true if value being setted is valid, false otherwise

getChangedRows

public final java.util.ArrayList getChangedRows()
Returns:
list of ValueObjects which have been changed (used when the grid is in INSERT/EDIT mode)

getChangedRowIndexes

public final java.util.ArrayList getChangedRowIndexes()
Returns:
list of indexes of TableModel changed rows (Integer objects)

getChangedRowNumbers

public final int[] getChangedRowNumbers()
Returns:
int[] row indexes related to ValueObjects which have been changed (used when the grid is in INSERT/EDIT mode)

updateValueObjectsAt

public final void updateValueObjectsAt(int[] rowNumbers,
                                       ValueObject[] objects)
Update ValueObjects into TableModel for the specified rows.

Parameters:
rowNumbers - row indexes in TableModel
objects - ValueObject to update into TableModel

getValueObjectType

public final java.lang.Class getValueObjectType()
Returns:
ValueObject type

getOldVOsChanged

public final java.util.ArrayList getOldVOsChanged()
Returns:
list of value objects that have been changed; content: list of original v.o. (before changes)