com.extjs.gxt.ui.client.store
Class Record

java.lang.Object
  extended by com.extjs.gxt.ui.client.store.Record

public class Record
extends java.lang.Object

Records wrap model instances and provide specialized editing features, including modification tracking and editing capabilities.

Rather than editing a model from a store directly, record can be used to "buffer" any changes to the model. Changes can be "committed" or "rejected" at both the record and store level.

Record instances can be retrieved from the container store by calling @link Store.getRecord(ModelData). To get a list of modified records call @link Store.getModifiedRecords(). Code snippet:

 Record record = store.getRecord(store.getAt(0));
 record.set("foo", "bar");
 List<Record> modified = store.getModifiedRecords();
 for (Record r : modified) {
 
 }
 store.commitChanges();
 


Nested Class Summary
static class Record.RecordUpdate
          Update enumeration.
 
Field Summary
protected  ModelData model
          The wrapped model.
protected  RpcMap modified
          Contains a map of all fields that have been modified and their original values or null if no fields have been modified.
 
Constructor Summary
Record(java.util.Map<java.lang.String,java.lang.Object> properties)
          Creates a new record, wrapping a new model data instance.
Record(ModelData wrappedModel)
          Creates a new record.
 
Method Summary
 void beginEdit()
          Begin an edit.
 void cancelEdit()
          Cancels all changes made in the current edit operation.
protected  void clearError()
           
 void commit(boolean silent)
          Usually called by the ListStore which owns the Record.
 void endEdit()
          End an edit.
 java.lang.Object get(java.lang.String property)
          Returns the value for the property.
 java.util.Map<java.lang.String,java.lang.Object> getChanges()
          Gets a map of only the fields that have been modified since this record was created or committed.
 ModelData getModel()
          Returns the wrapped model instance.
 java.util.Collection<java.lang.String> getPropertyNames()
           
protected  boolean hasError()
           
 boolean isDirty()
          Returns true if the record has uncommitted changes.
 boolean isEditing()
          Returns true if the record is being updated.
 boolean isModified(java.lang.String property)
          Returns true if the field passed has been modified since the load or last commit.
 boolean isValid(java.lang.String property)
          Returns true if the record is valid.
protected  void join(Store store)
           
 void reject(boolean silent)
          Usually called by the ListStore which owns the Record.
 void set(java.lang.String name, java.lang.Object value)
          Set the named field to the specified value.
 void setDirty(boolean dirty)
          Manually sets the dirty state of the record.
 void setValid(java.lang.String property, boolean valid)
          Sets whether the record is valid (defaults to true).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

modified

protected RpcMap modified
Contains a map of all fields that have been modified and their original values or null if no fields have been modified.


model

protected ModelData model
The wrapped model.

Constructor Detail

Record

public Record(java.util.Map<java.lang.String,java.lang.Object> properties)
Creates a new record, wrapping a new model data instance.

Parameters:
properties - the initial values

Record

public Record(ModelData wrappedModel)
Creates a new record.

Parameters:
wrappedModel - the model
Method Detail

beginEdit

public void beginEdit()
Begin an edit. While in edit mode, no events are relayed to the containing store.


cancelEdit

public void cancelEdit()
Cancels all changes made in the current edit operation.


commit

public void commit(boolean silent)
Usually called by the ListStore which owns the Record. Commits all changes made to the Record since either creation, or the last commit operation.

Parameters:
silent - true to skip notification of the owning store of the change

endEdit

public void endEdit()
End an edit. If any data was modified, the model is updated and the containing store is notified.


get

public java.lang.Object get(java.lang.String property)
Returns the value for the property.

Parameters:
property - the property name
Returns:
the value

getChanges

public java.util.Map<java.lang.String,java.lang.Object> getChanges()
Gets a map of only the fields that have been modified since this record was created or committed.

Returns:
the changed fields

getModel

public ModelData getModel()
Returns the wrapped model instance.

Returns:
the model

getPropertyNames

public java.util.Collection<java.lang.String> getPropertyNames()

isDirty

public boolean isDirty()
Returns true if the record has uncommitted changes.

Returns:
the dirty state

isEditing

public boolean isEditing()
Returns true if the record is being updated.

Returns:
the editing state

isModified

public boolean isModified(java.lang.String property)
Returns true if the field passed has been modified since the load or last commit.

Parameters:
property - the property name
Returns:
true if modified

isValid

public boolean isValid(java.lang.String property)
Returns true if the record is valid.

Parameters:
property - the property name
Returns:
true if the record is valid

reject

public void reject(boolean silent)
Usually called by the ListStore which owns the Record. Rejects all changes made to the Record since either creation, or the last commit operation. Modified fields are reverted to their original values.

Parameters:
silent - true to skip notification of the owning store of the change

set

public void set(java.lang.String name,
                java.lang.Object value)
Set the named field to the specified value.

Parameters:
name - the name of the field to set
value - the value of the field to set

setDirty

public void setDirty(boolean dirty)
Manually sets the dirty state of the record. Typically, the dirty state is managed by the record itself.

Parameters:
dirty - the dirty state

setValid

public void setValid(java.lang.String property,
                     boolean valid)
Sets whether the record is valid (defaults to true). The valid state of a record is not modified or changed by the record itself. Both EditorGrid and FieldBinding will set the valid state of the record to match the field's valid state after an edit completes.

Parameters:
property - the property name
valid - true if valid, false otherwise

clearError

protected void clearError()

hasError

protected boolean hasError()

join

protected void join(Store store)