at.spardat.xma.mdl.list
Class ListWM

java.lang.Object
  extended byat.spardat.xma.mdl.WModel
      extended byat.spardat.xma.mdl.list.ListWM
All Implemented Interfaces:
Descriptive, IListWM, ISelectable, Synchronization, Transactional
Direct Known Subclasses:
ListWMClient

public class ListWM
extends WModel
implements IListWM

Widged model to represent a list of choises. It can be used with the SWT-widgets Combo and List. The entries of the list have to be provided by the programmer. All entries must by Atoms of the same type. The supported types are T_STRING, T_BCD, T_DATE and T_TIMESTAMP. There are convinience methods to use Java Strings directly. These Strings are converted to Atoms of type T_STRING internally. For domain values please use ListDomWM.


Field Summary
 
Fields inherited from class at.spardat.xma.mdl.WModel
S_NULL
 
Fields inherited from interface at.spardat.xma.mdl.list.IListWM
S_MULTI_SELECT, S_NOT_STRICT
 
Constructor Summary
ListWM(short id, Page pm, int style)
          Constructs a ListWM.
 
Method Summary
 void add(Atom entry)
          Adds an entry to the list.
 void add(Atom[] entries)
          Adds the entries to the list.
 void add(java.util.Collection entries)
          Adds the entries to the list.
 void add(int index, Atom entry)
          Inserts an entry into the list at the specified position.
 void add(int index, java.lang.String entry)
          Inserts an entry into the list at the specified position.
 void add(java.lang.String entry)
          Adds an entry to the list.
 void add(java.lang.String[] entries)
          Adds the entries to the list.
 boolean changed()
          Yields true if this WidgetModel has changed since the last server side event (or creation).
 void clear()
          Removes all entries from the list and deselects all selected entries.
 void commit()
          This method clears the change history.
 boolean contains(Atom entry)
          Returns true if the list contains the given entry.
 boolean contains(java.lang.String entry)
          Returns true if the list contains the given entry.
 void describe(DNode n)
          describe puts all relevant information about this into the provided node.
 void deselect(java.lang.String key)
          Deselects a particular entry.
 void deselectAll()
          All selected entries get deselected.
 void equalsCS(WModel mServer, int syncPoint)
          Compares this widget model (which must be a client side one) with the server buddy mServer and returns true if they are correct with respect to syncPoint.
 int estimateMemory()
          Provides the estimated number of bytes this widget model consumes in memory, asuming that it is in a committed state, i.e, there are no pending changes.
 void externalize(XmaOutput xo, boolean forceFull)
          Externalizing either saves the actual state or deltas (changes) in a provided XMAObjectOutput.
 Atom getEntry(int index)
          Get the entry at the specified position.
 Atom getEntry(java.lang.String key)
          Get the entry for the given key.
 java.lang.String getSelected()
          Returns the id of the selected element.
 java.lang.String[] getSelection()
          Returns a newly created array containing the ids of the selected entries or an empty array, if nothing is selected.
 int getSelectionCount()
          Returns the number of selected elements.
 java.lang.String getStringEntry(int index)
          Get the entry at the specified position.
 boolean handle(ModelChangeEvent event)
          All events that might change a WidgetModel are executed via this method.
 int indexOf(Atom entry)
          Get the index of the given entry.
 int indexOf(java.lang.String entry)
          Get the index of the given entry.
 void internalize(XmaInput in)
          Updates the state of this with information of the given XMAObjectInput.
 boolean isMultiSelect()
          Returns true if more than one entry may be selected.
 boolean isSelected(java.lang.String key)
          Returns true if the entry with the provided key is selected, false otherwise.
 boolean isStrict()
          Returns if this Selectable has strict behaviour, that is, the selected keys must always be in the underlying domain of this.
 boolean isUserStrict()
          Returns if the user is allowed to enter values not in the list of choices.
 void randomlyChange()
          A implementing subclass must make a random change to its widget model.
 void remove(Atom entry)
          Removes an entry from the list.
 void remove(int index)
          Removes the entry at the given position from the list.
 void remove(java.lang.String entry)
          Removes an entry from the list.
 void replace(int index, Atom newEntry)
          Replaces an entry in the list.
 void replace(int index, java.lang.String newEntry)
          Replaces an entry in the list.
 void rollback()
          This method restores this Widget Model to its state immediately after the last server side event (or creation).
 void select(java.lang.String key)
          Sets the entry with a provided key as selected.
 int size()
          Gets the size of the list.
 
Methods inherited from class at.spardat.xma.mdl.WModel
cleanUpAfterServerEvent, getId, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListWM

public ListWM(short id,
              Page pm,
              int style)
Constructs a ListWM. The behaviour can be ajusted with the following styles
Method Detail

changed

public boolean changed()
Description copied from class: WModel
Yields true if this WidgetModel has changed since the last server side event (or creation). Some models have a more complex state, e.g., a table has a domain and a selection, where either may change. In this case, subclasses will provide more detailed information on what aspect of the model really has changed.

Specified by:
changed in interface Transactional
Specified by:
changed in class WModel
Returns:
true if changed, false otherwise

rollback

public void rollback()
Description copied from class: WModel
This method restores this Widget Model to its state immediately after the last server side event (or creation).

Specified by:
rollback in interface Transactional
Specified by:
rollback in class WModel

commit

public void commit()
Description copied from class: WModel
This method clears the change history. Calling rollback afterwards won't have any effect.

Specified by:
commit in interface Transactional
Specified by:
commit in class WModel

handle

public boolean handle(ModelChangeEvent event)
Description copied from class: WModel
All events that might change a WidgetModel are executed via this method.

Specified by:
handle in class WModel
Parameters:
event - the event carrying the information of a change.
Returns:
true if change has been applied, false if it has been rejected.

clear

public void clear()
Description copied from interface: IListWM
Removes all entries from the list and deselects all selected entries.

Specified by:
clear in interface IListWM
Specified by:
clear in class WModel

describe

public void describe(DNode n)
Description copied from interface: Descriptive
describe puts all relevant information about this into the provided node. The implementing method may construct subnodes of node.

Specified by:
describe in interface Descriptive
Overrides:
describe in class WModel
See Also:
Descriptive.describe(at.spardat.xma.mdl.util.DNode)

randomlyChange

public void randomlyChange()
Description copied from class: WModel
A implementing subclass must make a random change to its widget model. This method is used to extensively test the synchronization mechanism.

Specified by:
randomlyChange in class WModel

equalsCS

public void equalsCS(WModel mServer,
                     int syncPoint)
Description copied from class: WModel
Compares this widget model (which must be a client side one) with the server buddy mServer and returns true if they are correct with respect to syncPoint. If syncPoint is zero, the client model has been externalized and the changes have been applied to the server model. If synPoint is one, the server model has been externalized and the chagnes have been applied to the client model.

This method is for debugging purpose and assumes that client and server models are running within the same VM. It tests if the models the programmer views after a synchronization operation are consistent.

This method requires that this is a client side model.

This method does not throw an exception if models are the same in terms of their contained model data. If it is allowed that models differ (for example some one way tables), this method must take this fact into account. If the models differ, this indicates a programming error and a RuntimeException is thrown.

Specified by:
equalsCS in class WModel
Parameters:
mServer - the server side model partner for this.
syncPoint - 0 if the point in time is after a client to server sychnronization, 1 if the point is after a server to client synchronization.

estimateMemory

public int estimateMemory()
Description copied from class: WModel
Provides the estimated number of bytes this widget model consumes in memory, asuming that it is in a committed state, i.e, there are no pending changes. This is just to get a crude feeling about memory consumption. It needs not to be exact, which is also not possible as long as a JVM does not provide the numbers.

Specified by:
estimateMemory in class WModel
Returns:
estimated number of bytes this model consumes in memory

add

public void add(Atom entry)
Description copied from interface: IListWM
Adds an entry to the list. The entry is appended at the end of the selection list.

Specified by:
add in interface IListWM
Parameters:
entry - to add

add

public void add(java.lang.String entry)
Description copied from interface: IListWM
Adds an entry to the list. The entry is appended at the end of the selection list.

Specified by:
add in interface IListWM
Parameters:
entry - to add

add

public void add(int index,
                Atom entry)
Description copied from interface: IListWM
Inserts an entry into the list at the specified position.

Specified by:
add in interface IListWM
Parameters:
index - the desired zero base index of the new entry
entry - to add

add

public void add(int index,
                java.lang.String entry)
Description copied from interface: IListWM
Inserts an entry into the list at the specified position.

Specified by:
add in interface IListWM
Parameters:
index - the desired zero base index of the new entry
entry - to add

add

public void add(Atom[] entries)
Description copied from interface: IListWM
Adds the entries to the list. The entries are appended at the end of the list.

Specified by:
add in interface IListWM
Parameters:
entries - to add

add

public void add(java.lang.String[] entries)
Description copied from interface: IListWM
Adds the entries to the list. The entries are appended at the end of the list.

Specified by:
add in interface IListWM
Parameters:
entries - to add

add

public void add(java.util.Collection entries)
Description copied from interface: IListWM
Adds the entries to the list. The entries are appended at the end of the list. The collection may contain Atoms or Strings. If it contains Atoms, all entries must be Atoms with the same type. If it contains Strings, all entries must be Strings.

Specified by:
add in interface IListWM
Parameters:
entries - to add

getEntry

public Atom getEntry(int index)
Description copied from interface: IListWM
Get the entry at the specified position.

Specified by:
getEntry in interface IListWM
Parameters:
index - the index of the desired entry.
Returns:
the entry at the given index.

getStringEntry

public java.lang.String getStringEntry(int index)
Description copied from interface: IListWM
Get the entry at the specified position.

Specified by:
getStringEntry in interface IListWM
Parameters:
index - the index of the desired entry.
Returns:
the entry at the given index.

getEntry

public Atom getEntry(java.lang.String key)
Description copied from interface: IListWM
Get the entry for the given key.

Specified by:
getEntry in interface IListWM
Parameters:
key - string representation of the desired entry.
Returns:
the entry corresponding to the string representation.

indexOf

public int indexOf(Atom entry)
Description copied from interface: IListWM
Get the index of the given entry.

Specified by:
indexOf in interface IListWM
Parameters:
entry - the entry of which the index is desired.
Returns:
the index of the given entry.

indexOf

public int indexOf(java.lang.String entry)
Description copied from interface: IListWM
Get the index of the given entry.

Specified by:
indexOf in interface IListWM
Parameters:
entry - the entry of which the index is desired.
Returns:
the index of the given entry.

remove

public void remove(Atom entry)
Description copied from interface: IListWM
Removes an entry from the list.

Specified by:
remove in interface IListWM
Parameters:
entry - to remove

remove

public void remove(java.lang.String entry)
Description copied from interface: IListWM
Removes an entry from the list.

Specified by:
remove in interface IListWM
Parameters:
entry - to remove

remove

public void remove(int index)
Description copied from interface: IListWM
Removes the entry at the given position from the list.

Specified by:
remove in interface IListWM
Parameters:
index -

replace

public void replace(int index,
                    Atom newEntry)
Description copied from interface: IListWM
Replaces an entry in the list. The old entry at the given index position is replaced by the entry given as parameter.

Specified by:
replace in interface IListWM
Parameters:
index - the index of the entry to replace.
newEntry - the new entry to insert.

replace

public void replace(int index,
                    java.lang.String newEntry)
Description copied from interface: IListWM
Replaces an entry in the list. The old entry at the given index position is replaced by the entry given as parameter.

Specified by:
replace in interface IListWM
Parameters:
index - the index of the entry to replace.
newEntry - the new entry to insert.

contains

public boolean contains(Atom entry)
Description copied from interface: IListWM
Returns true if the list contains the given entry.

Specified by:
contains in interface IListWM
Parameters:
entry -
Returns:
true if the given entry is contained in the list.

contains

public boolean contains(java.lang.String entry)
Description copied from interface: IListWM
Returns true if the list contains the given entry.

Specified by:
contains in interface IListWM
Parameters:
entry -
Returns:
true if the given entry is contained in the list.

size

public int size()
Description copied from interface: IListWM
Gets the size of the list.

Specified by:
size in interface IListWM
Returns:
the number of entries.

select

public void select(java.lang.String key)
Description copied from interface: ISelectable
Sets the entry with a provided key as selected. If this model does not allow multiselection, a previous selected element is deselected before.

If isStrict() and the provided key is not contained in the underlying domain, this method does nothing.

Specified by:
select in interface ISelectable
Parameters:
key - the entry to select

deselect

public void deselect(java.lang.String key)
Description copied from interface: ISelectable
Deselects a particular entry. If the entry for the provided key is not selected, this method does nothing.

Specified by:
deselect in interface ISelectable
Parameters:
key - identifies the entry to deselect. If the entry with the provided key is not selected, this method does nothing.

deselectAll

public void deselectAll()
Description copied from interface: ISelectable
All selected entries get deselected. After calling this method, the condition getSelectionCount() == 0 holds.

Specified by:
deselectAll in interface ISelectable

isMultiSelect

public boolean isMultiSelect()
Description copied from interface: ISelectable
Returns true if more than one entry may be selected.

Specified by:
isMultiSelect in interface ISelectable
Returns:
boolean true if the widget model realizing this interface allows multiselection.

getSelected

public java.lang.String getSelected()
Description copied from interface: ISelectable
Returns the id of the selected element. If nothing is selected, null is returned. If more than one entry is selected, some of them is returned. Note that the selected id need not have to be in the underlying domain of this if !isStrict().

Usually, this method is the preferred way of querying the selection state if !isMultiSelect().

Specified by:
getSelected in interface ISelectable
Returns:
key of selected entry or null if nothing is selected

getSelection

public java.lang.String[] getSelection()
Description copied from interface: ISelectable
Returns a newly created array containing the ids of the selected entries or an empty array, if nothing is selected.

Specified by:
getSelection in interface ISelectable
Returns:
array of the selected keys. The length of the array equals getSelectionCount().

getSelectionCount

public int getSelectionCount()
Description copied from interface: ISelectable
Returns the number of selected elements.

Specified by:
getSelectionCount in interface ISelectable
Returns:
number of selected elements

isSelected

public boolean isSelected(java.lang.String key)
Description copied from interface: ISelectable
Returns true if the entry with the provided key is selected, false otherwise.

Specified by:
isSelected in interface ISelectable

isStrict

public boolean isStrict()
Description copied from interface: ISelectable
Returns if this Selectable has strict behaviour, that is, the selected keys must always be in the underlying domain of this. In the case of !isStrict(), the selected key may be freely choosen and need not be drawn from the domain.

Strict behaviour is only supported if !isMultiSelect(). That means, isMultiSelect() always implies isStrict().

Specified by:
isStrict in interface ISelectable
Returns:
true if the widget model implementing this interface supports strict behaviour, false otherwise.

isUserStrict

public boolean isUserStrict()
Returns if the user is allowed to enter values not in the list of choices.

Returns:
true if the user can enter additional values

externalize

public void externalize(XmaOutput xo,
                        boolean forceFull)
                 throws java.io.IOException
Description copied from interface: Synchronization
Externalizing either saves the actual state or deltas (changes) in a provided XMAObjectOutput. The default behaviour is to serialize the changes if changes are beeing tracked. This behaviour may be overwritten by forceFull. If true, the complete state information is written.

If forceFull is false, the object implementing this interface must also implement Transactional. If the object implementing this is able to track changes, these are the changes since the last syncpoint.

Specified by:
externalize in interface Synchronization
Parameters:
xo - the serialization destination
forceFull - if true, the complete state is written and deltas are ignored.
Throws:
java.io.IOException - on serialization errors

internalize

public void internalize(XmaInput in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Description copied from interface: Synchronization
Updates the state of this with information of the given XMAObjectInput. in either contains changes or the complete new state information. If in contains changes the implementing class also must implement Transactional and the state after calling internalize is !Transactional.changed(), e.g., a syncpoint is defined.

This method is not allowed to throw Exceptions because that would leave models in an inconsistent state. Thrown exceptions are considered to be programming errors. Internalize must not throw technical exceptions which indicate system or ressource failures. That implies that the person implementing internalize is not allowed to access ressources outside the JVM, either directly or via calls to other methods. Examples of ressource access which must not be triggered are calls to communication of file system services.

Specified by:
internalize in interface Synchronization
Parameters:
in - the XMAObjectInput. If a XMAObjectInputChangeListener is set in the object in, it will be notified after applying changes read from in.
Throws:
java.lang.ClassNotFoundException - on serialization errors
java.io.IOException - on serialization errors