org.jdesktop.dataset
Class DataColumn

java.lang.Object
  extended by org.jdesktop.dataset.DataColumn

public class DataColumn
extends java.lang.Object

A DataColumn defines information for values in a single column of a DataTable. The DataColumn doesn't contain an actual value for a column, but rather gives the data type, and name, and tells us whether the column is required, whether it is writeable, and whether it is the primary key column for the table. The data type for a value in a DataColumn is always a Java Class.

A DataColumn is always associated with a specific DataTable, usually the DataTable that instantiated it.

If a DataColumn is marked as a primary key, this is for tables with a single column primary key; multiple-column keys are not supported.

Note as well that a DataColumn is purely passive and doesn't itself validate actions against the DataTable. If the column is required, or if it is read-only, the DataColumn will not enforce this, nor will it enforce uniqueness on primary key columns.

Author:
rbair

Field Summary
protected static java.lang.String DEFAULT_NAME_PREFIX
          Used as a prefix for auto-generated DataColumn names.
 
Constructor Summary
protected DataColumn(DataTable table)
          Create a new DataColumn.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to this class for any changes to bean properties.
 void addPropertyChangeListener(java.lang.String property, java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to this class for specific property changes.
 java.lang.Object getDefaultValue()
           
 java.lang.String getExpression()
           
 java.lang.String getName()
          Returns the name of the DataColumn.
 DataTable getTable()
          Returns the DataTable that this column belongs to.
 java.lang.Class getType()
          Returns the type of the values for this DataColumn as a Java Class.
 java.lang.Object getValueForRow(DataRow row)
           
 boolean isKeyColumn()
          Returns whether the column is a key column or not
 boolean isReadOnly()
           
 boolean isRequired()
           
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Stops notifying a specific listener of any changes to bean properties.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Stops notifying a specific listener of changes to a specific property.
 void setDefaultValue(java.lang.Object defaultValue)
          Set the value to use as a default when a new field for this column is created, such as when a new row is created.
 void setExpression(java.lang.String expression)
          Sets the expression that this column will use to calculate its values.
 void setKeyColumn(boolean value)
          Sets this column to be a key column.
 void setName(java.lang.String name)
          Sets the name of the DataColumn.
 void setReadOnly(boolean readOnly)
          Sets whether this column is read-only or not.
 void setRequired(boolean required)
          Specifies whether the fields in this column must have a value (cannot be null).
 void setType(java.lang.Class type)
          Sets the type for the values of this DataColumn as a Java Class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NAME_PREFIX

protected static final java.lang.String DEFAULT_NAME_PREFIX
Used as a prefix for auto-generated DataColumn names.

See Also:
Constant Field Values
Constructor Detail

DataColumn

protected DataColumn(DataTable table)
Create a new DataColumn. To construct a DataColumn, do not call new DataColumn(table) directly. Rather, call table.addColumn().

Parameters:
table - cannot be null. The DataTable that created this DataColumn.
Method Detail

getTable

public DataTable getTable()
Returns the DataTable that this column belongs to.


getName

public java.lang.String getName()
Returns the name of the DataColumn.


setName

public void setName(java.lang.String name)
Sets the name of the DataColumn. The name must be valid., or the change will not be made. If the name is invalid, a warning will be posted. Validity for names is defined in DataSetUtils.isValidName(java.lang.String).


getType

public java.lang.Class getType()
Returns the type of the values for this DataColumn as a Java Class.


setType

public void setType(java.lang.Class type)
Sets the type for the values of this DataColumn as a Java Class.

Parameters:
type - If null, then the type is set to Object.class.

isReadOnly

public boolean isReadOnly()
Returns:
true if this DataColumn is read-only.

setReadOnly

public void setReadOnly(boolean readOnly)
Sets whether this column is read-only or not.

Parameters:
readOnly - If true, column is read-only.

isRequired

public boolean isRequired()
Returns:
true if the fields in this column need to have a value before they can be saved to the data store. The DataColumn is required if the required flag is set by the setRequired(boolean) method, or if the DataColumn is a keyColumn.
TODO need to decide if that is true, or if it is always required!

setRequired

public void setRequired(boolean required)
Specifies whether the fields in this column must have a value (cannot be null).

Parameters:
required -

getDefaultValue

public java.lang.Object getDefaultValue()
Returns:
the value to use as a default value when a new field for this column is created, such as when a new row is created.

setDefaultValue

public void setDefaultValue(java.lang.Object defaultValue)
Set the value to use as a default when a new field for this column is created, such as when a new row is created.

Parameters:
defaultValue -

isKeyColumn

public boolean isKeyColumn()
Returns whether the column is a key column or not


setKeyColumn

public void setKeyColumn(boolean value)
Sets this column to be a key column. This implicitly places a unique constraint on the column. When this flag is set, no checks are made to ensure correctness. However, the column will automatically be marked as being required.

Parameters:
value -

getExpression

public java.lang.String getExpression()
Returns:
the expression for calculating values in this column

setExpression

public void setExpression(java.lang.String expression)
Sets the expression that this column will use to calculate its values. If the expression property on this column is set, then the values for each row in the column are determined based on the expression.

This is currently unimplemented. TODO

Parameters:
expression - the expression for calculating values in this column

getValueForRow

public java.lang.Object getValueForRow(DataRow row)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener to this class for any changes to bean properties.

Parameters:
listener - The PropertyChangeListener to notify of changes to this instance.

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String property,
                                      java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener to this class for specific property changes.

Parameters:
listener - The PropertyChangeListener to notify of changes to this instance.
property - The name of the property to listen to changes for.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Stops notifying a specific listener of any changes to bean properties.

Parameters:
listener - The listener to stop receiving notifications.

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)
Stops notifying a specific listener of changes to a specific property.

Parameters:
propertyName - The name of the property to ignore from now on.
listener - The listener to stop receiving notifications.


Copyright © 2005 Sun Microsystems All Rights Reserved.