com.sibvisions.rad.model.mem
Class DataRow

java.lang.Object
  extended by com.sibvisions.rad.model.mem.DataRow
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<IDataRow>, IDataRow
Direct Known Subclasses:
ChangeableDataRow

public class DataRow
extends java.lang.Object
implements IDataRow, java.io.Serializable

An DataRow is a list of table column's.
The DataRow is also a storage independent row.

Example:

 
 // construct a RowDefinition
 RowDefinition rdRowDefinition = new RowDefinition();
 
 // construct some ColumnDefinitions
 ColumnDefinition cdId   = new ColumnDefinition("id");
 ColumnDefinition cdName = new ColumnDefinition("name");
 
 rdRowDefinition.addColumnDefinition(cdId);             
 rdRowDefinition.addColumnDefinition(cdName);

 // construct DataRow
 DataRow drDataRow = new DataRow(rdRowDefinition);
 
 drDataRow.setValue("id", new BigDecimal(1));
 drDataRow.setValue("name", "The name");  
 
 

See Also:
IDataRow, RowDefinition, RemoteDataBook, MemDataPage, Serialized Form

Field Summary
protected  java.lang.Object[] oaStorage
          The storage for this DataRow.
protected  IRowDefinition rdRowDefinition
          The RowDefinition of this DataRow.
 
Constructor Summary
  DataRow()
          Constructs a DataRow without a new instance of IRowDefinition.
  DataRow(IRowDefinition pRowDefinition)
          Constructs a DataRow with a given IRowDefinition.
protected DataRow(IRowDefinition pRowDefinition, java.lang.Object[] pData)
          Constructs a DataRow with a given IRowDefinition and initialize it a copy of the Object[] data.
 
Method Summary
 void addControl(IControl pControl)
          Adds the given IControl to this IDataRow as control.
 void cancelEditingControls()
          Informs all registered controls that they should cancel any pending editing operation and revert to the values in this IDataRow.
 int compareTo(IDataRow pDataRow)
          
 int compareTo(IDataRow pDataRow, SortDefinition pSortDefinition)
          Compares this IDataRow with the given IDataRow, by considering the given SortDefinition and comparing the values of both rows according to the SortDefinition.
 IDataRow createDataRow(java.lang.String[] pColumnNames)
          Creates and returns a new IDataRow which only contains the specified columns and their values.
 IDataRow createEmptyDataRow(java.lang.String[] pColumnNames)
          Creates and returns a new empty IDataRow which only contains the specified columns without any values.
 IDataRow createEmptyRow(java.lang.String[] pColumnNames)
          Deprecated. 
 boolean equals(IDataRow pDataRow, java.lang.String[] pColumnNames)
          Compares this IDataRow with the given IDataRow for equality, but only compares the values in the column whose names are given, ignoring all not given columns.
 boolean equals(java.lang.Object pObject)
          
 DataRowHandler eventValuesChanged()
          Gets the DataRowHandler for the values changed event.
 DataRowHandler eventValuesChanged(java.lang.String pColumnName)
          Gets the DataRowHandler for the values changed event for the specified column.
 IControl[] getControls()
          Gets all registered IControls as array.
 IRowDefinition getRowDefinition()
          Gets the IRowDefinition that is used.
 java.lang.Object getValue(int pColumnIndex)
          Returns the value of the column by index.
 java.lang.Object getValue(java.lang.String pColumnName)
          Returns the value of the named column.
 java.lang.String getValueAsString(java.lang.String pColumnName)
          Returns the value of the named column converted to a String.
 java.lang.Object[] getValues(java.lang.String[] pColumnNames)
          Gets the values from all specified columns as an Object array.
 java.lang.String[] getValuesAsString(java.lang.String[] pColumnNames)
          Gets the values from all specified columns and converts them to a String array.
protected  boolean hasControls()
          Gets whether at least one control was added to this row.
 int hashCode()
          
protected  void invokeCancelEditingControls()
          It invokes for each IComponent the cancelEditing() method.
protected  void invokeRepaintListeners()
          It invokes for each IComponent the notifyRepaint() method.
protected  void invokeSaveEditingControls()
          It invokes for each IComponent the saveEditing() method.
 void notifyRepaintControls()
          Informs all registered controls that there are new values and that they must redraw themselves.
 void removeControl(IControl pControl)
          Removes the given IControl to this IDataRow as control.
 void saveEditingControls()
          Informs all registered controls that they should save their values.
 void setDefaultValues()
          Sets the Default Values from the RowDefinition to the DataRow.
 void setValue(java.lang.String pColumnName, java.lang.Object pValue)
          Sets the value of the named column.
protected  void setValueIntern(int pColumnIndex, java.lang.Object pValue, ColumnDefinition pColumnDefinition)
          Sets the value of the named column in this IDataRow.
 void setValues(java.lang.String[] pColumnNames, java.lang.Object[] pValues)
          Sets all columns of the given names to the given values.
protected  void setValuesIntern(java.lang.String[] pColumnNames, java.lang.Object[] pValues)
          It sets the values without throwing an event.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

rdRowDefinition

protected IRowDefinition rdRowDefinition
The RowDefinition of this DataRow.


oaStorage

protected java.lang.Object[] oaStorage
The storage for this DataRow.

Constructor Detail

DataRow

public DataRow()
Constructs a DataRow without a new instance of IRowDefinition.


DataRow

public DataRow(IRowDefinition pRowDefinition)
Constructs a DataRow with a given IRowDefinition.

Parameters:
pRowDefinition - the IRowDefinition

DataRow

protected DataRow(IRowDefinition pRowDefinition,
                  java.lang.Object[] pData)
Constructs a DataRow with a given IRowDefinition and initialize it a copy of the Object[] data.

Parameters:
pRowDefinition - the IRowDefinition
pData - the Object[] with data of the DataRow.
Method Detail

getRowDefinition

public IRowDefinition getRowDefinition()
Gets the IRowDefinition that is used.

The IRowDefinition contains all the information about the columns.

Specified by:
getRowDefinition in interface IDataRow
Returns:
the IRowDefinition that is used.

getValue

public java.lang.Object getValue(int pColumnIndex)
                          throws ModelException
Returns the value of the column by index.

Specified by:
getValue in interface IDataRow
Parameters:
pColumnIndex - the column index.
Returns:
the value of the column.
Throws:
ModelException - if the column index is out of bounds.
See Also:
IDataRow.getValue(String)

getValue

public java.lang.Object getValue(java.lang.String pColumnName)
                          throws ModelException
Returns the value of the named column.

Specified by:
getValue in interface IDataRow
Parameters:
pColumnName - the name of the column.
Returns:
the value of the named column.
Throws:
ModelException - if there is no column with the given name.
See Also:
IDataRow.getValue(int)

getValueAsString

public java.lang.String getValueAsString(java.lang.String pColumnName)
                                  throws ModelException
Returns the value of the named column converted to a String.

Specified by:
getValueAsString in interface IDataRow
Parameters:
pColumnName - the name of the column.
Returns:
the value of the named column converted to a String.
Throws:
ModelException - if there is no column with the given name.
See Also:
IDataRow.getValue(int), IDataRow.getValue(String), IDataType.convertToString(Object)

setValue

public void setValue(java.lang.String pColumnName,
                     java.lang.Object pValue)
              throws ModelException
Sets the value of the named column.

After the value has changed the value changed event and value changed (by name) event are invoked and fired. Afterwards all registered IControls are notified of the change by invoking IControl.notifyRepaint().

Specified by:
setValue in interface IDataRow
Parameters:
pColumnName - the column name.
pValue - the new value for the named column.
Throws:
ModelException - if there is no column with the given name or the given value can not be converted to the IDataType of the column.
See Also:
IDataRow.eventValuesChanged(), IDataRow.eventValuesChanged(String), IDataType.convertToTypeClass(Object)

getValues

public java.lang.Object[] getValues(java.lang.String[] pColumnNames)
                             throws ModelException
Gets the values from all specified columns as an Object array.

Note that the returned Object array does not represent an internal state of the IDataRow. Modifying the array does not change the IDataRow.

Specified by:
getValues in interface IDataRow
Parameters:
pColumnNames - the names of the columns from which to get the values. Can be null for all columns (which is equal to IRowDefinition.getColumnNames().
Returns:
the values from all specified columns as an Object array.
Throws:
ModelException - if there is no column with one of the specified names.
See Also:
IDataRow.getValue(int), IDataRow.getValue(String)

getValuesAsString

public java.lang.String[] getValuesAsString(java.lang.String[] pColumnNames)
                                     throws ModelException
Gets the values from all specified columns and converts them to a String array.

Note that the returned String array does not represent an internal state of the IDataRow. Modifying the array does not change the IDataRow.

Specified by:
getValuesAsString in interface IDataRow
Parameters:
pColumnNames - the names of the columns from which to get the values. Can be null for all columns.
Returns:
the values from all specified columns as a String array.
Throws:
ModelException - if there is no column with one of the specified names.
See Also:
IDataRow.getValueAsString(String), IDataRow.getValues(String[]), IDataType.convertToString(Object)

setValues

public void setValues(java.lang.String[] pColumnNames,
                      java.lang.Object[] pValues)
               throws ModelException
Sets all columns of the given names to the given values.

The String array which represents the column names is directly mapped to the Object array which holds the values. So they must be equal in length.

After the value has changed the value changed event and value changed (by name) event are invoked and fired. Afterwards all registered IControls are notified of the change by invoking IControl.notifyRepaint().

Specified by:
setValues in interface IDataRow
Parameters:
pColumnNames - a String array of the column names. Can be null for all columns (which is equal to IRowDefinition.getColumnNames().
pValues - a Object array of values to set in the corresponding columns.
Throws:
ModelException - if there is no column with one of the specified names or if any of the values could not be converted to the IDataType of the column.
See Also:
IDataRow.eventValuesChanged(), IDataRow.eventValuesChanged(String), IDataRow.setValue(String, Object), IDataType.convertToTypeClass(Object)

createDataRow

public IDataRow createDataRow(java.lang.String[] pColumnNames)
                       throws ModelException
Creates and returns a new IDataRow which only contains the specified columns and their values.

Specified by:
createDataRow in interface IDataRow
Parameters:
pColumnNames - a String array of column names. Can be null for all columns (which is equal to IRowDefinition.getColumnNames().
Returns:
a new IDataRow which only contains the specified columns and their values.
Throws:
ModelException - if new IDataRow could not be constructed.

createEmptyRow

@Deprecated
public IDataRow createEmptyRow(java.lang.String[] pColumnNames)
                        throws ModelException
Deprecated. 

Creates and returns a new empty IDataRow which only contains the specified columns without any values.

Specified by:
createEmptyRow in interface IDataRow
Parameters:
pColumnNames - a String array of column names. Can be null for all columns (which is equal to IRowDefinition.getColumnNames().
Returns:
a new empty IDataRow which only contains the specified columns without any values.
Throws:
ModelException - if new IDataRow could not be constructed.

createEmptyDataRow

public IDataRow createEmptyDataRow(java.lang.String[] pColumnNames)
                            throws ModelException
Creates and returns a new empty IDataRow which only contains the specified columns without any values.

Specified by:
createEmptyDataRow in interface IDataRow
Parameters:
pColumnNames - a String array of column names. Can be null for all columns (which is equal to IRowDefinition.getColumnNames().
Returns:
a new empty IDataRow which only contains the specified columns without any values.
Throws:
ModelException - if new IDataRow could not be constructed.

equals

public boolean equals(java.lang.Object pObject)

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(IDataRow pDataRow)

Specified by:
compareTo in interface java.lang.Comparable<IDataRow>

compareTo

public int compareTo(IDataRow pDataRow,
                     SortDefinition pSortDefinition)
Compares this IDataRow with the given IDataRow, by considering the given SortDefinition and comparing the values of both rows according to the SortDefinition.

It reacts for the most part like a "normal" compareTo would, except that it takes SortDefinition.isAscending() into consideration, and if it is false the result will be negated.

Specified by:
compareTo in interface IDataRow
Parameters:
pDataRow - the @link DataRow} to compare with.
pSortDefinition - the SortDefinition to us for the comparison.
Returns:
a negative integer, zero, or a positive integer as this IDataRow is less than, equal to, or greater than the specified IDataRow.

equals

public boolean equals(IDataRow pDataRow,
                      java.lang.String[] pColumnNames)
Compares this IDataRow with the given IDataRow for equality, but only compares the values in the column whose names are given, ignoring all not given columns.

Specified by:
equals in interface IDataRow
Parameters:
pDataRow - the IDataRow to compare with this IDataRow
pColumnNames - a String array of the names of the columns to compare.
Returns:
true if they are found equal.

addControl

public void addControl(IControl pControl)
Adds the given IControl to this IDataRow as control.

The registered IControl will be notified of changes in this IDataRow.

Specified by:
addControl in interface IDataRow
Parameters:
pControl - the IControl to add.
See Also:
IDataRow.removeControl(IControl), IDataRow.getControls()

removeControl

public void removeControl(IControl pControl)
Removes the given IControl to this IDataRow as control.

Specified by:
removeControl in interface IDataRow
Parameters:
pControl - the IControl to remove.
See Also:
IDataRow.addControl(IControl), IDataRow.getControls()

getControls

public IControl[] getControls()
Gets all registered IControls as array.

Specified by:
getControls in interface IDataRow
Returns:
all registered IControls as array.

eventValuesChanged

public DataRowHandler eventValuesChanged()
Gets the DataRowHandler for the values changed event.

The values changed event is fired every time a value changes in this IDataRow.

Specified by:
eventValuesChanged in interface IDataRow
Returns:
the DataRowHandler for the values changed event.
See Also:
IDataRow.eventValuesChanged(String), IDataRow.setValue(String, Object), IDataRow.setValues(String[], Object[])

eventValuesChanged

public DataRowHandler eventValuesChanged(java.lang.String pColumnName)
Gets the DataRowHandler for the values changed event for the specified column.

The values changed event is fired every time a value changes in this IDataRow.

Specified by:
eventValuesChanged in interface IDataRow
Parameters:
pColumnName - the name of the column.
Returns:
the DataRowHandler for the values changed event for the specified column.
See Also:
IDataRow.eventValuesChanged(), IDataRow.setValue(String, Object), IDataRow.setValues(String[], Object[])

notifyRepaintControls

public void notifyRepaintControls()
Informs all registered controls that there are new values and that they must redraw themselves. For this purpose the IControl.notifyRepaint() method is invoked on all registered IControls.

Specified by:
notifyRepaintControls in interface IDataRow
See Also:
IControl.notifyRepaint()

saveEditingControls

public void saveEditingControls()
                         throws ModelException
Informs all registered controls that they should save their values. For this purpose the IControl.saveEditing() method is invoked on all registered IControls.

Specified by:
saveEditingControls in interface IDataRow
Throws:
ModelException - if saving of any of the registered IControls fails.
See Also:
IControl.notifyRepaint()

cancelEditingControls

public void cancelEditingControls()
Informs all registered controls that they should cancel any pending editing operation and revert to the values in this IDataRow. For this purpose the IControl.cancelEditing() method is invoked on all registered IControls.

Specified by:
cancelEditingControls in interface IDataRow

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

setValueIntern

protected void setValueIntern(int pColumnIndex,
                              java.lang.Object pValue,
                              ColumnDefinition pColumnDefinition)
                       throws ModelException
Sets the value of the named column in this IDataRow.

Parameters:
pColumnIndex - the column name
pValue - the new value for the column in this IDataRow
pColumnDefinition - the ColumnDefinition
Throws:
ModelException - if the column name is not in this IDataRow or the pValue is not convertible/too large to/for the IDataType of the column

setValuesIntern

protected void setValuesIntern(java.lang.String[] pColumnNames,
                               java.lang.Object[] pValues)
                        throws ModelException
It sets the values without throwing an event.

Parameters:
pColumnNames - the column names to use.
pValues - the values to use
Throws:
ModelException - if the value couldn't set into the memory.

invokeRepaintListeners

protected void invokeRepaintListeners()
It invokes for each IComponent the notifyRepaint() method.


invokeSaveEditingControls

protected void invokeSaveEditingControls()
                                  throws ModelException
It invokes for each IComponent the saveEditing() method.

Throws:
ModelException - if saving the editors fails.

invokeCancelEditingControls

protected void invokeCancelEditingControls()
It invokes for each IComponent the cancelEditing() method.


setDefaultValues

public void setDefaultValues()
                      throws ModelException
Sets the Default Values from the RowDefinition to the DataRow.

Throws:
ModelException - if the set value fails

hasControls

protected boolean hasControls()
Gets whether at least one control was added to this row.

Returns:
true if this row has at least one control


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.