com.sas.swing.models
Class MapToTableModelAdapter

com.sas.swing.models.MapToTableModelAdapter
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, java.io.Serializable, javax.swing.table.TableModel

public class MapToTableModelAdapter
implements com.sas.beans.PropertyChangeSource

The MapToTableModelAdapter allows Maps that implement java.util.Map to be used as the model for a javax.swing.JTable. The Map must be set as the model for the adapter, which can then used as the model for the viewer. The adapter can be editable so that the underlying map can be modified and column names can be set so that the displayed columns can be customized.

See Also:
Serialized Form

Field Summary
protected  java.lang.String[] columnNames
          Column names for table model
protected  java.util.List keys
          Internal storage of keys from Map
protected  java.util.Map model
          Model for the Map
protected  javax.swing.event.SwingPropertyChangeSupport spcs
          Used to support property changes in the webAF customizer
protected  boolean tableEditable
          Whether the table model is editable
protected  java.util.List values
          Internal storage of values from Map
 
Constructor Summary
MapToTableModelAdapter()
          Default constructor
MapToTableModelAdapter(int size)
          Overloaded constructor that initializes the delegate to be of given size
MapToTableModelAdapter(java.util.Map m)
          Overloaded constructor that intializes the adapter with the entire entrySet given by the Map
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
protected  void createDelegate()
          Create the delegate object
 int getColumnCount()
          Returns the number of columns in the model.
 java.lang.String getColumnName(int columnIndex)
          Returns the name of the column at columnIndex.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
           
 java.util.Map getModel()
          Returns the model of the adapter
 int getRowCount()
          Returns the number of rows in the model
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if the cell at rowIndex and columnIndex is editable and the table is editable.
 boolean isTableEditable()
          Determine if the table is editable.
 void refresh()
          Force a refresh on the adapter
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void setColumnName(java.lang.String columnName, int columnIndex)
          Sets the name of the column at columnIndex to columnName.
 void setModel(java.util.Map model)
          Sets the model of the adapter to the given Map
 void setTableEditable(boolean editable)
          Set the table to state defined by editable.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
          Sets the value in the cell at columnIndex and rowIndex to aValue.
 

Field Detail

keys

protected java.util.List keys
Internal storage of keys from Map


values

protected java.util.List values
Internal storage of values from Map


model

protected java.util.Map model
Model for the Map


columnNames

protected java.lang.String[] columnNames
Column names for table model


tableEditable

protected boolean tableEditable
Whether the table model is editable


spcs

protected javax.swing.event.SwingPropertyChangeSupport spcs
Used to support property changes in the webAF customizer

Constructor Detail

MapToTableModelAdapter

public MapToTableModelAdapter()
Default constructor


MapToTableModelAdapter

public MapToTableModelAdapter(int size)
Overloaded constructor that initializes the delegate to be of given size

Parameters:
size - Initial size of the delegate representing the Map

MapToTableModelAdapter

public MapToTableModelAdapter(java.util.Map m)
Overloaded constructor that intializes the adapter with the entire entrySet given by the Map

Parameters:
m - Map whose data will be used within the adapter
Method Detail

getRowCount

public int getRowCount()
Returns the number of rows in the model

Specified by:
getRowCount in interface javax.swing.table.TableModel

getColumnCount

public int getColumnCount()
Returns the number of columns in the model. This will always return two columns, one being the keys and the other being the values.

Specified by:
getColumnCount in interface javax.swing.table.TableModel

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Sets the value in the cell at columnIndex and rowIndex to aValue. Only the values in the map can be changed, the keys must remain the same.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
aValue - the new value
rowIndex - the row whose value is to be changed
columnIndex - the column whose value is to be changed

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the cell at rowIndex and columnIndex is editable and the table is editable. Otherwise, setValueAt on the cell will not change the value of that cell. Only the values in the map are editable, the keys must remain the same.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
rowIndex - the row whose value to be queried
columnIndex - the column whose value to be queried
Returns:
true if the cell is editable

setModel

public void setModel(java.util.Map model)
Sets the model of the adapter to the given Map

Parameters:
model - Map whose data will be used within the adapter

getModel

public java.util.Map getModel()
Returns the model of the adapter


setColumnName

public void setColumnName(java.lang.String columnName,
                          int columnIndex)
Sets the name of the column at columnIndex to columnName. Note: this name does not need to be unique; two columns in a table can have the same name. If null is set as the column name, then the default column name will be used.

Parameters:
columnName - the new name of the column
columnIndex - the index of the column

getColumnName

public java.lang.String getColumnName(int columnIndex)
Returns the name of the column at columnIndex. This is used to initialize the table's column header name. Note: this name does not need to be unique; two columns in a table can have the same name. If null is set as the column name, then the default column name will be used.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
columnIndex - the index of the column
Returns:
the name of the column

isTableEditable

public boolean isTableEditable()
Determine if the table is editable. If the table is not editable, then none of the cells will be editable. This value is false by default.


setTableEditable

public void setTableEditable(boolean editable)
Set the table to state defined by editable. Even though the table may be editable, the cell may not be editable.


createDelegate

protected void createDelegate()
Create the delegate object


refresh

public void refresh()
Force a refresh on the adapter


addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface com.sas.beans.PropertyChangeSource

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface com.sas.beans.PropertyChangeSource

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.