project35.mda.model
Class RecordModel

java.lang.Object
  extended by project35.mda.model.RecordNameProvider
      extended by project35.mda.model.RecordModel
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class RecordModel
extends RecordNameProvider

The main model data structure Project35 uses to describe model record types.


Copyright (c) 2008 Kevin Garwood for Project35. The original code was developed by Kevin Garwood for the University of Manchester. Revisions have been made for Project35, a project that is independent of that institution. This code is licensed under the Academic Free License version 3.0. The code attribution for the original code is included here:

Copyright (c) Kevin Garwood and University of Manchester 2007. All rights reserved. Licensed under the Academic Free License version 3.0. For more information on the terms and conditions, please see the file "LICENSE" that is included in this distribution.


Version:
1.0
Author:
Kevin Garwood (kgarwood@users.sourceforge.net)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class project35.mda.model.RecordNameProvider
containingListModel, instanceIdentifier, isVisible, toolTipText, useInstanceIdentifier
 
Constructor Summary
RecordModel()
           
 
Method Summary
 void addChild(java.lang.String selectionFieldName, RecordNameProvider child, boolean enableSave)
          assumes selection field name will be valid and represent a list field
 void addField(DataFieldModel field)
          adds a field to the model
 void addReference(RecordModelReference reference)
           
 java.lang.Object clone()
          only reports errors in the edit fields
 java.lang.String computeDisplayName()
           
 java.lang.String computeDisplayName(boolean useTruncation)
           
 void enableSaveChanges(boolean flag)
          sets whether the record can save changes.
 java.util.ArrayList getAttributeFields()
          gets a list of those edit fields that represent XML attributes
 java.lang.String getDisplayName()
           
 java.lang.String[] getEditFieldNames()
          provides the list of edit field names.
 java.util.ArrayList getEditFields()
          provides a list of edit fields
 java.util.ArrayList getElementFields()
           
 DataFieldModel getField(java.lang.String fieldName)
          returns the data field model associated with the given field name
 java.util.ArrayList getFields()
           
 java.net.URL getHelpLink()
          returns the context sensitive help associated with this record
 java.lang.Integer getIdentifier()
           
 IDFieldModel getIDField()
           
 java.util.ArrayList getListFields()
           
 ListFieldModel getListModelForChildType(java.lang.String childType)
          Project35's project35.io.XMLFileReader uses this method to reconstitute a record tree based on an XML file.
 java.lang.String[] getMissingRecordTypes()
          this is a convenience method for helping to determine which of its required list fields remains empty.
 java.lang.String getNameSpacePrefix()
          Get the value of nameSpacePrefix.
 java.util.ArrayList getProxyListFields()
           
 java.lang.String getRecordClassName()
          Get the value of recordClassName.
 java.util.ArrayList getReferences()
           
 java.lang.String getValue(java.lang.String fieldName)
           
 void informListenersOfGainedFocus()
          method used to inform listeners that the record has gained focus this method is invoked when edit button in list field is pressed.
 void informListenersOfNameChange()
          informs change listeners if the display name has changed.
 boolean isAmbiguous()
          Returns whether this RecordModel is ambiguous or not.
 boolean isEditField(java.lang.String fieldName)
          convenience method for determining whether the field is an edit field or not.
 boolean isListField(java.lang.String fieldName)
          convenience method for determining whether the field is a list field or not.
 boolean isNewRecord()
           
 boolean isRequiredField(java.lang.String fieldName)
           
 void removeAllChildren(java.lang.String fieldName)
           
 DataFieldModel removeField(DataFieldModel field)
          Removes a field from the model
 void removeFields(java.util.ArrayList fieldsToRemove)
          Removes a field from the model
 void removeReference(RecordModelReference reference)
           
 void replaceField(DataFieldModel oldFieldModel, DataFieldModel newFieldModel)
           
 void resolveReferences()
           
 boolean saveChanges()
          determines whether the model needs to have changes saved
 void setDisplayName(java.lang.String displayName)
          sets the display name of the record
 void setFields(java.util.ArrayList fields)
          sets the data fields for this record
 void setHelpLink(java.net.URL helpLink)
          sets URL for context sensitive help
 void setIdentifier(java.lang.Integer identifier)
           
 void setNameSpacePrefix(java.lang.String nameSpacePrefix)
          Set the value of nameSpacePrefix.
 void setNewRecord(boolean isNewRecord)
          sets whether a record is designated as new or already existing.
 void setRecordClassName(java.lang.String recordClassName)
          Set the value of recordClassName.
 void setSaveChanges(boolean saveChanges)
          determines if changes need to be saved This method really means: "Something has changed in the record and it has been committed." Because a change has been committed, the method sets "isNewRecord" to false.
 void setValue(java.lang.String fieldName, java.lang.String value, boolean enableSaveChanges)
          assumes we are guaranteed that the field name will be legal and that the fieldname will refer to some edit field.
 java.lang.String toString()
           
 void updateDisplayName()
          updates the display name of therecord
 
Methods inherited from class project35.mda.model.RecordNameProvider
addChangeListener, clearChangeListeners, fireChangeEvent, getChangeListeners, getContainingListModel, getParentRecordModel, getToolTip, informListenersOfChildCreation, informListenersOfDestruction, isVisible, notifyListeners, removeChangeListener, setChangeListener, setChangeListeners, setContainingListModel, setInstanceIdentifier, setIsVisible, setToolTipText, setUseInstanceIdentifier, useInstanceIdentifier
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RecordModel

public RecordModel()
Method Detail

getIdentifier

public java.lang.Integer getIdentifier()

getDisplayName

public java.lang.String getDisplayName()
Specified by:
getDisplayName in class RecordNameProvider
Returns:
the display name of the record. This comprises the names of edit fields that have been designated as display name fields

getIDField

public IDFieldModel getIDField()

getFields

public java.util.ArrayList getFields()
Returns:
the list of fields

getField

public DataFieldModel getField(java.lang.String fieldName)
returns the data field model associated with the given field name

Parameters:
fieldName - the name of the data field
Returns:
the data field model

isRequiredField

public boolean isRequiredField(java.lang.String fieldName)
Parameters:
fieldName - the name of a field
Returns:
true if the given fieldName is required; otherwise it's an optional field

isListField

public boolean isListField(java.lang.String fieldName)
convenience method for determining whether the field is a list field or not. Assumes that the field name is a legitimate field for this record

Parameters:
fieldName - the name of the data field
Returns:
true if the field is a list field; otherwise false

isEditField

public boolean isEditField(java.lang.String fieldName)
convenience method for determining whether the field is an edit field or not. Assumes that the field name is a legitimate field for this record

Parameters:
fieldName - the field name
Returns:
true if the field is an edit field; otherwise false

getRecordClassName

public java.lang.String getRecordClassName()
Get the value of recordClassName.

Specified by:
getRecordClassName in class RecordNameProvider
Returns:
value of recordClassName.

getListFields

public java.util.ArrayList getListFields()
Returns:
list of list fields for the record

getProxyListFields

public java.util.ArrayList getProxyListFields()
Returns:
list of proxy list fields. Proxy list fields are a result of parsing schema where the list is defined in one placed and merely referenced in other places

getEditFieldNames

public java.lang.String[] getEditFieldNames()
provides the list of edit field names. This is a convenience method used in Project35's default data import feature.

Returns:
list of edit field names

getEditFields

public java.util.ArrayList getEditFields()
provides a list of edit fields

Returns:
list of edit fields

getAttributeFields

public java.util.ArrayList getAttributeFields()
gets a list of those edit fields that represent XML attributes


getElementFields

public java.util.ArrayList getElementFields()

getMissingRecordTypes

public java.lang.String[] getMissingRecordTypes()
this is a convenience method for helping to determine which of its required list fields remains empty. Used in validation checks.

Returns:
list of missing record types.

computeDisplayName

public java.lang.String computeDisplayName()
Specified by:
computeDisplayName in class RecordNameProvider

computeDisplayName

public java.lang.String computeDisplayName(boolean useTruncation)
Returns:
the current display name based on a concatentation of edit fields that have been designated as display fields

getHelpLink

public java.net.URL getHelpLink()
returns the context sensitive help associated with this record

Returns:
the url for the context sensitive help

isNewRecord

public boolean isNewRecord()
Returns:
true if the record is newly created; otherwise false if the record already exists. project35.view.RecordView uses this method result to disable the delete button for new records and to enable it for existing records

isAmbiguous

public boolean isAmbiguous()
Returns whether this RecordModel is ambiguous or not. Example of an ambiguous XML schema construct:
 <xs:element name="test">
     <xs:complexType>
         <xs:sequence>
             <xs:element name="test1" type="xs:float" minOccurs="0"/>
             <xs:element name="test1" type="xs:float" maxOccurs="unbounded"/>
         </xs:sequence>
     </xs:complexType>
 </xs:element>
 

Returns:
whether this RecordModel is ambiguous or not.

getNameSpacePrefix

public java.lang.String getNameSpacePrefix()
Get the value of nameSpacePrefix.

Returns:
value of nameSpacePrefix.

removeReference

public void removeReference(RecordModelReference reference)

addReference

public void addReference(RecordModelReference reference)

getReferences

public java.util.ArrayList getReferences()

saveChanges

public boolean saveChanges()
determines whether the model needs to have changes saved

Returns:
true if the changes to the record should be saved; otherwise false

replaceField

public void replaceField(DataFieldModel oldFieldModel,
                         DataFieldModel newFieldModel)

addField

public void addField(DataFieldModel field)
adds a field to the model

Parameters:
field - to add to the record.

removeFields

public void removeFields(java.util.ArrayList fieldsToRemove)
Removes a field from the model

Parameters:
field - Field to be removed.

removeField

public DataFieldModel removeField(DataFieldModel field)
Removes a field from the model

Parameters:
field - Field to be removed.
Returns:
The removed field or null if model didn't contain this field.

getValue

public java.lang.String getValue(java.lang.String fieldName)

setValue

public void setValue(java.lang.String fieldName,
                     java.lang.String value,
                     boolean enableSaveChanges)
assumes we are guaranteed that the field name will be legal and that the fieldname will refer to some edit field. Otherwise, we'll have to toss around exceptions in try-catch loops that can get expensive for large data sets. Assumes that the field name is a legitimate edit field in the record assume for date fields, it's always in the cannonical format

Parameters:
fieldName - name of the field. Assumes the field name is appropriate for the model
value - the value for the edit field.

getListModelForChildType

public ListFieldModel getListModelForChildType(java.lang.String childType)
Project35's project35.io.XMLFileReader uses this method to reconstitute a record tree based on an XML file. This method should only be used in situations where the record is guaranteed to have only one kind of list field that could support the given child type. It will not be helpful if there are multiple lists that could support it. Project35 limits its ability to read XML data files to those created with unambiguous schemas

Parameters:
childType - the type of subrecord that might belong to one of the record's list fields.
Returns:
the first list field that can accommodate the given child type.

addChild

public void addChild(java.lang.String selectionFieldName,
                     RecordNameProvider child,
                     boolean enableSave)
assumes selection field name will be valid and represent a list field


removeAllChildren

public void removeAllChildren(java.lang.String fieldName)

setRecordClassName

public void setRecordClassName(java.lang.String recordClassName)
Set the value of recordClassName.

Parameters:
recordClassName - Value to assign to recordClassName.

setFields

public void setFields(java.util.ArrayList fields)
sets the data fields for this record

Parameters:
fields - the list of fields

setSaveChanges

public void setSaveChanges(boolean saveChanges)
determines if changes need to be saved This method really means: "Something has changed in the record and it has been committed." Because a change has been committed, the method sets "isNewRecord" to false.

Parameters:
saveChanges - true if changes should be saved; otherwise false

informListenersOfNameChange

public void informListenersOfNameChange()
informs change listeners if the display name has changed. the listeners will then update their lists to reflect the changes in the name


informListenersOfGainedFocus

public void informListenersOfGainedFocus()
method used to inform listeners that the record has gained focus this method is invoked when edit button in list field is pressed.

Overrides:
informListenersOfGainedFocus in class RecordNameProvider

setNewRecord

public void setNewRecord(boolean isNewRecord)
sets whether a record is designated as new or already existing.

Parameters:
isNewRecord - true if the record is new; otherwise the record already exists

setDisplayName

public void setDisplayName(java.lang.String displayName)
sets the display name of the record

Parameters:
displayName - the new display name for the record

updateDisplayName

public void updateDisplayName()
updates the display name of therecord

Specified by:
updateDisplayName in class RecordNameProvider

enableSaveChanges

public void enableSaveChanges(boolean flag)
sets whether the record can save changes. Normally you will want to allow the record model to save changes. The exception comes when record models are created and populated by reading a file.

Parameters:
flag - true if record should be allowed to save changes otherwise false.

setHelpLink

public void setHelpLink(java.net.URL helpLink)
sets URL for context sensitive help

Parameters:
helpLink - the URL that describes help for this record model

resolveReferences

public void resolveReferences()

setIdentifier

public void setIdentifier(java.lang.Integer identifier)

setNameSpacePrefix

public void setNameSpacePrefix(java.lang.String nameSpacePrefix)
Set the value of nameSpacePrefix.

Parameters:
nameSpacePrefix - Value to assign to nameSpacePrefix.

clone

public java.lang.Object clone()
only reports errors in the edit fields

Specified by:
clone in class RecordNameProvider
Returns:
null if there are no errors with the record. otherwise returns an appropriate error message. The other validate

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object