org.caleigo.core
Class Selection

java.lang.Object
  extended byorg.caleigo.core.Selection
All Implemented Interfaces:
IEntityPool, ISelection, java.io.Serializable
Direct Known Subclasses:
QualifiedSelection

public class Selection
extends java.lang.Object
implements ISelection

Selection is an entity collection class that can store zero or more IEntity objects. The entities stored by this interface are type specified and must be defined by a single IEntityDescriptor. The Selection class is ordered and contained entities can be accesed by index. The class does not accept duplicate entities if contained entity has identity fields.

Version:
1.00
Author:
Dennis Zikovic
See Also:
Serialized Form

Nested Class Summary
protected  class Selection.EntityPoolSet
           
protected  class Selection.EntityRelayListener
           
protected  class Selection.SelectionList
           
 
Constructor Summary
Selection(IEntityDescriptor entityDescriptor)
           
Selection(ISelection selection)
          This is a copy constructor that makes a shallow copy of the contained entities in the provided collection.
 
Method Summary
 boolean addEntity(IEntity entity)
          Adds the provided IEntity object to the end of selection object.
 boolean addEntity(int index, IEntity entity)
          Adds the provided IEntity object to at the specified index in the selection object.
 void addEntityChangeListener(IEntityChangeListener listener)
          Adds IEntityChangeListener to receive notifications of performed data operations on all entities contained in the collection object.
 void addEntityListener(IEntityListener listener)
          Adds IEntityListener to receive notifications of performed data operations on all entities contained in the collection object.
 void addSelectionListener(ISelectionListener listener)
          Adds an ISelectionListener to receive notifiactions of changes in the entity content of the collection object.
 java.util.List asList()
          Returns a List that acts as a wrapper for the selection.
 java.util.Set asSet()
          Returns a Set that acts as a wrapper for the selection.
 void clear()
          Mutation method the removes all entities currently stored in the selection.
 boolean contains(IEntity entity)
          Help method that returns true if the provided IEntity object exists in the selection otherwise false is returned.
 ISelection createSubSelection(int[] indexArray)
          Creates a sub selection with the indexed entities in the called selection.
 ISelection createSubSelection(Qualifier qualifier)
          Creates a sub selection with all qualified entities in the called selection.
 void deleteAll()
          Deletes all contained entities.
 boolean doesAccept(IEntity entity)
          Help method that returns true if the provided IEntity object will be accepted by the selection if added or inserted to it.
protected  void fireContentsChanged()
          Help method to fire a SelectionEvent to all registered SelectionListeners for notification of generally changed contents.
protected  void fireEntityAdded(IEntity entity, int row)
          Help method to fire a SelectionEvent to all registered SelectionListeners for notification of an added entity.
protected  void fireEntityRemoved(IEntity entity, int row)
          Help method to fire a SelectionEvent to all registered SelectionListeners for notification of an removed entity.
 java.lang.Object getData(int row, int column)
          Access method that views the selection objct as a grid where row is the entity index and column is the field index for the stored entities.
 IEntity getEntity(int index)
          Access method that returns the contained IEntity object with the specified index.
 IEntityDescriptor getEntityDescriptor()
          Access method that returns the IEntityDescriptor for the selection.
 int indexOf(IEntity entity)
          Help method that returns the index of the provided IEntity object in the selection if it exists othewise a negative value is returned.
 int indexOf(IFieldDescriptor fieldDescriptor, java.lang.Object fieldData)
          Help method that returns the index of the the first entity object in the selection with the specified field set to the specified value.
 boolean isDirty()
          Return true if any (one or more) of the collections's contained entities has the DIRTY flag set to true that is have unsaved changes.
 boolean isEmpty()
          Boolean access method that return true if the selection is empty.
 java.util.Iterator iterator()
          Returns a java.util.Iterator object that iterates over all entities in the selection.
 void log(java.lang.Object source)
          Help method that logs text information from the collection object using the log package.
 void log(java.lang.Object source, IFieldDescriptor[] fields)
          Help method that logs text information from the collection object using the log package.
 void refreshAll()
          Performs a refresh on all contained entities.
protected  void registerEntityChangeListener()
          Adds a IEntityChangeListener to all contained entities that relays events to IEntityChangeListener registered in the collection object.
protected  void registerEntityListener()
          Adds a IEntityListener to all contained entities that relays events to IEntityListener registered in the collection object.
protected  void registerListeners(IEntity entity)
          Adds listeners relaying events from the specified entity to relevant listeners registered in the collection object.
 boolean removeEntity(IEntity entity)
          Mutation method that removes the provided entity from the selection.
 IEntity removeEntity(int index)
          Mutation method that removes the indexed entity from the selection.
 void removeEntityChangeListener(IEntityChangeListener listener)
          Removes the specified IEntityListener from the collection object.
 void removeEntityListener(IEntityListener listener)
          Removes the specified IEntityListener from the collection object.
 void removeSelectionListener(ISelectionListener listener)
          Removes an ISelectionListener from the collection object.
 void setData(int row, int column, java.lang.Object dataValue)
          Mutation method that views the selection objct as a grid where row is the entity index and column is the field index for the stored entities.
 int size()
          Access method that reurns the number entities currently contained in the selection object.
 void sort(java.util.Comparator comparator)
          This method sorts the called selection using the provided comparator.
 void storeAll()
          Stores all contained entities that have the DIRTY flag set to true.
protected  void unregisterEntityChangeListener()
          Removes the IEntityChangeListener from all contained entities that relays events to IEntityChangeListener registered in the collection object.
protected  void unregisterEntityListener()
          Removes the IEntityListener from all contained entities that relays events to IEntityListener registered in the collection object.
protected  void unregisterListeners(IEntity entity)
          Removes listeners relaying events from the specified entity to relevant listeners registered in the collection object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Selection

public Selection(IEntityDescriptor entityDescriptor)

Selection

public Selection(ISelection selection)
This is a copy constructor that makes a shallow copy of the contained entities in the provided collection.

Method Detail

isDirty

public boolean isDirty()
Return true if any (one or more) of the collections's contained entities has the DIRTY flag set to true that is have unsaved changes.

Specified by:
isDirty in interface ISelection

storeAll

public void storeAll()
Stores all contained entities that have the DIRTY flag set to true. The entities are stored in a single transaction meaning that if one store fails then all fails.

Specified by:
storeAll in interface ISelection

deleteAll

public void deleteAll()
Deletes all contained entities. The entities are deleted in a single transaction meaning that if one delete fails then all fails. USE THIS METHOD WITH CAUTION!

Specified by:
deleteAll in interface ISelection

refreshAll

public void refreshAll()
Performs a refresh on all contained entities. The refresh is batched to save performance.

Specified by:
refreshAll in interface ISelection

addEntity

public boolean addEntity(IEntity entity)
Adds the provided IEntity object to the end of selection object. If an entity with the same identity already exists in the selection the requeat is ignored and false is returned.

Specified by:
addEntity in interface ISelection

addEntity

public boolean addEntity(int index,
                         IEntity entity)
Adds the provided IEntity object to at the specified index in the selection object. If an entity with the same identity already exists in the selection the requeat is ignored and false is returned.

Specified by:
addEntity in interface ISelection

getEntity

public IEntity getEntity(int index)
Access method that returns the contained IEntity object with the specified index.

Specified by:
getEntity in interface ISelection

removeEntity

public boolean removeEntity(IEntity entity)
Mutation method that removes the provided entity from the selection. Returns true if the entity was found and removed otherwise false is returned.

Specified by:
removeEntity in interface ISelection

removeEntity

public IEntity removeEntity(int index)
Mutation method that removes the indexed entity from the selection. Returns the indexed entity if it was found and removed otherwise null is returned. The entities are not effecte in any other way.

Specified by:
removeEntity in interface ISelection

iterator

public java.util.Iterator iterator()
Returns a java.util.Iterator object that iterates over all entities in the selection. The iterator should be read only and should not support the remove method. The entities are not effected in any other way.

Specified by:
iterator in interface ISelection

clear

public void clear()
Mutation method the removes all entities currently stored in the selection. The entities are not effected in any other way.

Specified by:
clear in interface ISelection

size

public int size()
Access method that reurns the number entities currently contained in the selection object.

Specified by:
size in interface ISelection

isEmpty

public boolean isEmpty()
Boolean access method that return true if the selection is empty.

Specified by:
isEmpty in interface ISelection

getData

public java.lang.Object getData(int row,
                                int column)
Access method that views the selection objct as a grid where row is the entity index and column is the field index for the stored entities.

Specified by:
getData in interface ISelection

setData

public void setData(int row,
                    int column,
                    java.lang.Object dataValue)
Mutation method that views the selection objct as a grid where row is the entity index and column is the field index for the stored entities.

Specified by:
setData in interface ISelection

getEntityDescriptor

public IEntityDescriptor getEntityDescriptor()
Access method that returns the IEntityDescriptor for the selection. The selection object will only support entities of that type.

Specified by:
getEntityDescriptor in interface ISelection

createSubSelection

public ISelection createSubSelection(int[] indexArray)
Creates a sub selection with the indexed entities in the called selection. The created selection that should be independant of changes in the source/called selection after the time of creation. If any index in the array is out of bounds it will be ignored and no exception will be thrown.

Specified by:
createSubSelection in interface ISelection

createSubSelection

public ISelection createSubSelection(Qualifier qualifier)
Creates a sub selection with all qualified entities in the called selection. The created selection that should be independant of changes in the source/called selection after the time of creation.

Specified by:
createSubSelection in interface ISelection

contains

public boolean contains(IEntity entity)
Help method that returns true if the provided IEntity object exists in the selection otherwise false is returned.

Specified by:
contains in interface ISelection

indexOf

public int indexOf(IEntity entity)
Help method that returns the index of the provided IEntity object in the selection if it exists othewise a negative value is returned.

Specified by:
indexOf in interface ISelection

indexOf

public int indexOf(IFieldDescriptor fieldDescriptor,
                   java.lang.Object fieldData)
Help method that returns the index of the the first entity object in the selection with the specified field set to the specified value.

Specified by:
indexOf in interface ISelection

doesAccept

public boolean doesAccept(IEntity entity)
Help method that returns true if the provided IEntity object will be accepted by the selection if added or inserted to it. Reasons for not accepting an entity is wrong type (IEntityDescriptor), already included (valid only if the entity descripror has identity fields) or if the selection is qualified the entity may fail qualification.

Specified by:
doesAccept in interface ISelection

sort

public void sort(java.util.Comparator comparator)
This method sorts the called selection using the provided comparator. One single content change event will be fired when this method is called. Note that if the provided Comparator does not support IEntity objects an exeption will be thrown.

Specified by:
sort in interface ISelection
See Also:
EntityCollator

asSet

public java.util.Set asSet()
Returns a Set that acts as a wrapper for the selection. The Set object should reflect changes to and from the wrapped selection.

Specified by:
asSet in interface ISelection

asList

public java.util.List asList()
Returns a List that acts as a wrapper for the selection. The List object should reflect changes to and from the wrapped selection.

Specified by:
asList in interface ISelection

addSelectionListener

public void addSelectionListener(ISelectionListener listener)
Adds an ISelectionListener to receive notifiactions of changes in the entity content of the collection object.

Specified by:
addSelectionListener in interface ISelection

removeSelectionListener

public void removeSelectionListener(ISelectionListener listener)
Removes an ISelectionListener from the collection object.

Specified by:
removeSelectionListener in interface ISelection

addEntityListener

public void addEntityListener(IEntityListener listener)
Adds IEntityListener to receive notifications of performed data operations on all entities contained in the collection object.

Specified by:
addEntityListener in interface ISelection

removeEntityListener

public void removeEntityListener(IEntityListener listener)
Removes the specified IEntityListener from the collection object.

Specified by:
removeEntityListener in interface ISelection

addEntityChangeListener

public void addEntityChangeListener(IEntityChangeListener listener)
Adds IEntityChangeListener to receive notifications of performed data operations on all entities contained in the collection object. Note that changes can in specific situations like during end-user editation be very frequent.

Specified by:
addEntityChangeListener in interface ISelection

removeEntityChangeListener

public void removeEntityChangeListener(IEntityChangeListener listener)
Removes the specified IEntityListener from the collection object.

Specified by:
removeEntityChangeListener in interface ISelection

fireContentsChanged

protected void fireContentsChanged()
Help method to fire a SelectionEvent to all registered SelectionListeners for notification of generally changed contents.


fireEntityAdded

protected void fireEntityAdded(IEntity entity,
                               int row)
Help method to fire a SelectionEvent to all registered SelectionListeners for notification of an added entity.


fireEntityRemoved

protected void fireEntityRemoved(IEntity entity,
                                 int row)
Help method to fire a SelectionEvent to all registered SelectionListeners for notification of an removed entity.


registerListeners

protected void registerListeners(IEntity entity)
Adds listeners relaying events from the specified entity to relevant listeners registered in the collection object. Both IEntityListener and IEntityChangeListener are handled by the method.


unregisterListeners

protected void unregisterListeners(IEntity entity)
Removes listeners relaying events from the specified entity to relevant listeners registered in the collection object. Both IEntityListener and IEntityChangeListener are handled by the method.


registerEntityListener

protected void registerEntityListener()
Adds a IEntityListener to all contained entities that relays events to IEntityListener registered in the collection object.


unregisterEntityListener

protected void unregisterEntityListener()
Removes the IEntityListener from all contained entities that relays events to IEntityListener registered in the collection object.


registerEntityChangeListener

protected void registerEntityChangeListener()
Adds a IEntityChangeListener to all contained entities that relays events to IEntityChangeListener registered in the collection object.


unregisterEntityChangeListener

protected void unregisterEntityChangeListener()
Removes the IEntityChangeListener from all contained entities that relays events to IEntityChangeListener registered in the collection object.


log

public void log(java.lang.Object source)
Help method that logs text information from the collection object using the log package. This method only logs identity field data.


log

public void log(java.lang.Object source,
                IFieldDescriptor[] fields)
Help method that logs text information from the collection object using the log package. This method logs data from all specified fields.



Copyright © 2005 Caleigo. All Rights Reserved.