org.beanfabrics.model
Class ListPM<T extends PresentationModel>

java.lang.Object
  extended by org.beanfabrics.AbstractBean
      extended by org.beanfabrics.ValidatableBean
          extended by org.beanfabrics.model.AbstractPM
              extended by org.beanfabrics.model.ListPM<T>
All Implemented Interfaces:
java.lang.Iterable<T>, Bean, ContextOwner, IListPM<T>, PresentationModel, Supportable, Validatable

public class ListPM<T extends PresentationModel>
extends AbstractPM
implements IListPM<T>

The ListPM is a list of presentation models. Basically it provides methods for adding, removing, accessing and iterating elements and informs listeners about changes. It also maintains a Selection.

Author:
Michael Karneim

Nested Class Summary
 class ListPM.DefaultValidationRule
          This validation rule defines that this model is invalid whenever a list element is invalid.
 
Nested classes/interfaces inherited from class org.beanfabrics.model.AbstractPM
AbstractPM.PropertiesValidationRule
 
Field Summary
protected  boolean revalidateElementsOnChangeEnabled
           
 
Constructor Summary
  ListPM()
          Constructs an empty list with an initial capacity of ten.
  ListPM(java.util.ArrayList<org.beanfabrics.model.ListPM.Entry> list)
          Constructs a ListPM with the specified list of entries.
  ListPM(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
protected ListPM(java.util.List<org.beanfabrics.model.ListPM.Entry> list)
          Constructs a ListPM with the specified list of entries.
 
Method Summary
 void add(int index, T element)
           
 void add(T element)
           
 void addAll(java.util.Collection<T> col)
           
 void addListListener(ListListener l)
          Adds a ListListener to this model.
 void clear()
           
 boolean contains(T element)
          Returns true if this collection contains the specified element.
 boolean containsAll(java.util.Collection<T> col)
           
protected  ValidationRule createDefaultValidationRule()
           
 T getAt(int index)
          Returns the element at the specified position in this list.
 Selection<T> getSelection()
          Returns the selection of this list.
 java.util.Collection<SortKey> getSortKeys()
          Returns the (immutable) collection of SortKey objects that reflect the current sorting state of this list.
 int indexOf(T element)
          Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
 int[] indicesOf(java.util.Collection<? extends T> col)
          Returns a sorted array of all indices of the given elements starting with the smallest index.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 boolean isRevalidateElementsOnChangeEnabled()
           
 java.util.Iterator<T> iterator()
           
 java.util.ListIterator<T> listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
protected  void onEntriesChanged(java.util.EventObject evt)
           
 boolean remove(T element)
           
 boolean removeAll(java.util.Collection<? extends T> col)
           
 T removeAt(int index)
           
 void removeListListener(ListListener l)
          Removes a ListListener from this model.
 void replace(int index, T newElement)
           
 void replace(T oldElement, T newElement)
           
protected  void revalidateAllExcept(T element)
           
 void revalidateElements()
          Revalidates all elements of this ListPM.
 void setRevalidateElementsOnChangeEnabled(boolean enabled)
           
 int size()
          Returns the number of elements in this collection.
 void sortBy(boolean ascending, Path... paths)
          Sorts the entries of this list pM by comparing the cells at the end of the given paths.
 void sortBy(java.util.Collection<SortKey> newSortKeys)
           
 void sortBy(SortKey... newSortKeys)
           
 void swap(int indexA, int indexB)
          Swaps the position of the two elements specified by the given indexes.
 void swap(T elemA, T elemB)
          Swaps the position of the two specified elements.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this list in proper sequence (from first to last element).
 java.util.Collection<T> toCollection()
          Returns a new Collection of all elements.
 
Methods inherited from class org.beanfabrics.model.AbstractPM
createPropertiesValidationRule, getContext, getSupportMap, revalidateProperties
 
Methods inherited from class org.beanfabrics.ValidatableBean
getValidationState, getValidator, isValid, revalidate, setValidationState
 
Methods inherited from class org.beanfabrics.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, equals, getPropertyChangeSupport, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.beanfabrics.Bean
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeSupport, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface org.beanfabrics.validation.Validatable
getValidationState, getValidator, isValid, revalidate
 
Methods inherited from interface org.beanfabrics.support.Supportable
getSupportMap
 
Methods inherited from interface org.beanfabrics.context.ContextOwner
getContext
 

Field Detail

revalidateElementsOnChangeEnabled

protected boolean revalidateElementsOnChangeEnabled
Constructor Detail

ListPM

public ListPM()
Constructs an empty list with an initial capacity of ten.


ListPM

public ListPM(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.

ListPM

public ListPM(java.util.ArrayList<org.beanfabrics.model.ListPM.Entry> list)
Constructs a ListPM with the specified list of entries.

Parameters:
list - the initial list of entries

ListPM

protected ListPM(java.util.List<org.beanfabrics.model.ListPM.Entry> list)
Constructs a ListPM with the specified list of entries.

Parameters:
list - the initial list of entries
Method Detail

isRevalidateElementsOnChangeEnabled

public boolean isRevalidateElementsOnChangeEnabled()

setRevalidateElementsOnChangeEnabled

public void setRevalidateElementsOnChangeEnabled(boolean enabled)

addListListener

public void addListListener(ListListener l)
Description copied from interface: IListPM
Adds a ListListener to this model.

Specified by:
addListListener in interface IListPM<T extends PresentationModel>

removeListListener

public void removeListListener(ListListener l)
Description copied from interface: IListPM
Removes a ListListener from this model.

Specified by:
removeListListener in interface IListPM<T extends PresentationModel>

onEntriesChanged

protected void onEntriesChanged(java.util.EventObject evt)

revalidateElements

public void revalidateElements()
Revalidates all elements of this ListPM.


revalidateAllExcept

protected void revalidateAllExcept(T element)

replace

public void replace(T oldElement,
                    T newElement)

replace

public void replace(int index,
                    T newElement)

add

public void add(T element)

add

public void add(int index,
                T element)

addAll

public void addAll(java.util.Collection<T> col)

contains

public boolean contains(T element)
Description copied from interface: IListPM
Returns true if this collection contains the specified element.

Specified by:
contains in interface IListPM<T extends PresentationModel>
Returns:
true if this collection contains the specified element

containsAll

public boolean containsAll(java.util.Collection<T> col)

clear

public void clear()

removeAll

public boolean removeAll(java.util.Collection<? extends T> col)

remove

public boolean remove(T element)

removeAt

public T removeAt(int index)

swap

public void swap(int indexA,
                 int indexB)
Description copied from interface: IListPM
Swaps the position of the two elements specified by the given indexes.

Specified by:
swap in interface IListPM<T extends PresentationModel>

swap

public void swap(T elemA,
                 T elemB)
Description copied from interface: IListPM
Swaps the position of the two specified elements.

Specified by:
swap in interface IListPM<T extends PresentationModel>

sortBy

public void sortBy(boolean ascending,
                   Path... paths)
Sorts the entries of this list pM by comparing the cells at the end of the given paths.

Specified by:
sortBy in interface IListPM<T extends PresentationModel>
Parameters:
ascending - if true, the resulting order will be ascending, otherwise descending.
paths - one or more Path objects must be specified to define which pM properties will be used for comparison.

sortBy

public void sortBy(java.util.Collection<SortKey> newSortKeys)
Specified by:
sortBy in interface IListPM<T extends PresentationModel>

sortBy

public void sortBy(SortKey... newSortKeys)
Specified by:
sortBy in interface IListPM<T extends PresentationModel>

getSortKeys

public java.util.Collection<SortKey> getSortKeys()
Returns the (immutable) collection of SortKey objects that reflect the current sorting state of this list.

Specified by:
getSortKeys in interface IListPM<T extends PresentationModel>
Returns:
the (immutable) collection of SortKey objects that reflect the current sorting state of this list

getAt

public T getAt(int index)
Description copied from interface: IListPM
Returns the element at the specified position in this list.

Specified by:
getAt in interface IListPM<T extends PresentationModel>
Returns:
the element at the specified position in this list

toCollection

public java.util.Collection<T> toCollection()
Description copied from interface: IListPM
Returns a new Collection of all elements.

Specified by:
toCollection in interface IListPM<T extends PresentationModel>
Returns:
a new Collection of all elements

toArray

public java.lang.Object[] toArray()
Description copied from interface: IListPM
Returns an array containing all of the elements in this list in proper sequence (from first to last element).

Specified by:
toArray in interface IListPM<T extends PresentationModel>
Returns:
an array containing all of the elements in this list in proper sequence (from first to last element)

getSelection

public Selection<T> getSelection()
Description copied from interface: IListPM
Returns the selection of this list.

Specified by:
getSelection in interface IListPM<T extends PresentationModel>
Returns:
the selection of this list

indexOf

public int indexOf(T element)
Description copied from interface: IListPM
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Specified by:
indexOf in interface IListPM<T extends PresentationModel>
Returns:
the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

indicesOf

public int[] indicesOf(java.util.Collection<? extends T> col)
Returns a sorted array of all indices of the given elements starting with the smallest index.

Parameters:
col - all elements to get the index from
Returns:
a sorted array of all indices of the given elements

size

public int size()
Description copied from interface: IListPM
Returns the number of elements in this collection.

Specified by:
size in interface IListPM<T extends PresentationModel>
Returns:
the number of elements in this collection

isEmpty

public boolean isEmpty()
Description copied from interface: IListPM
Returns true if this collection contains no elements.

Specified by:
isEmpty in interface IListPM<T extends PresentationModel>
Returns:
true if this collection contains no elements

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T extends PresentationModel>

listIterator

public java.util.ListIterator<T> listIterator(int index)
Description copied from interface: IListPM
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.

Specified by:
listIterator in interface IListPM<T extends PresentationModel>
Returns:
a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list

createDefaultValidationRule

protected ValidationRule createDefaultValidationRule()


© 2010 by Michael Karneim, http://www.beanfabrics.org