com.pcauto.gui.table
Interface EntityList

All Known Implementing Classes:
OrderTranslatorEntityList, ProxyEntityList

public interface EntityList

The EntityList interface describes the functions that must be provided for managing entities within an ordered list. This container allows for operations to manage entities(for example, to add or remove entities) and to add and remove event listeners that listen for changes in this EntityList.

Index values identifying entity positions start at zero (0).

Several operations can throw an EntityListException. These exceptions allow events to be communicated to the user.


Method Summary
 boolean addEntity(java.lang.Object entityInstance)
          Adds a new entity to this EntityList.
 void addEntityListListener(EntityListListener e)
          Adds a listener for list change events.
 int getCount()
          Returns the number of entities stored in this EntityList.
 java.lang.Object getDefaultEntity()
          Returns an entity instance containing desirable default values.
 java.lang.Object getEntity(int index)
          Returns the entity instance stored in the specified position.
 java.lang.Object getNewDefaultEntity()
          Returns a new instance of the entity being managed by this Entitylist.
 java.lang.Object getNewEntity()
          Returns a new instance of the entity being managed by this Entitylist.
 boolean insertEntity(int index, java.lang.Object entityValue)
          Inserts an entity into this EntityList.
 boolean moveEntity(int startIndex, int endIndex, int newIndex)
          Moves entities starting from the start index, to the end index, to a new location starting at the new index given.
 boolean removeEntity(int index)
          Removes the specified entity.
 void removeEntityListListener(EntityListListener e)
          Removes an entity list listener so that list changes will not trigger events for that listener.
 void replaceAll(EntityList v)
          Replaces all the current entities with those given by the EntityList parameter.
 void setDefaultEntity(java.lang.Object o)
          Sets the entity that contains desirable default values.
 boolean setEntity(int index, java.lang.Object entityInstance)
          Replaces the entity instance at the specified index.
 

Method Detail

getCount

public int getCount()
Returns the number of entities stored in this EntityList.

Returns:
the number of entities in the list

getEntity

public java.lang.Object getEntity(int index)
Returns the entity instance stored in the specified position. If the index is out of bounds, a null reference is returned. The first entity is at index 0.

Parameters:
index - position from which to get the entity
Returns:
the Object entity at the specified position

setEntity

public boolean setEntity(int index,
                         java.lang.Object entityInstance)
                  throws EntityListException
Replaces the entity instance at the specified index. The first entity is at index 0.

Parameters:
index - the position of the entity to be replaced
entityInstance - the Object instance which will replace the original
Returns:
true on success, false on failure
Throws:
EntityListException - on EntityList events. It is used to communicate events to the user.

getNewEntity

public java.lang.Object getNewEntity()
Returns a new instance of the entity being managed by this Entitylist. The entity managed by this EntityList refers to the object type/class that is used in this EntityList. The actual type is defined by the user. This new entity does not necessarily have the same properties as that of the entity provided by the getDefaultEntity() function. The purpose of this function is to make creation of entities and thus addition of the entities to this EntityList easier by not having to be concerned with creation of the entities externally. This function MUST return a new entity instance on each invocation, otherwise this EntityList may be populated with duplicate entities.

Returns:
the Object reference to the new entity instance

getNewDefaultEntity

public java.lang.Object getNewDefaultEntity()
Returns a new instance of the entity being managed by this Entitylist. The entity managed by this EntityList refers to the object type/class that is used in this EntityList. The actual type is defined by the user. This new entity has the same properties as that of the entity provided by the getDefaultEntity() function. The purpose of this function is to make creation of entities and thus addition of the entities to this EntityList easier by not having to be concerned with creation of the entities externally. This function MUST return a new entity instance on each invocation, otherwise this EntityList may be populated with duplicate entities.

Returns:
the Object reference to the new entity instance

getDefaultEntity

public java.lang.Object getDefaultEntity()
Returns an entity instance containing desirable default values.

Returns:
Object reference to the entity containing the desirable values

setDefaultEntity

public void setDefaultEntity(java.lang.Object o)
Sets the entity that contains desirable default values.

Parameters:
o - the Object representing the entity holding the desirable values

addEntity

public boolean addEntity(java.lang.Object entityInstance)
                  throws EntityListException
Adds a new entity to this EntityList. The entity is placed at the end of this EntityList.

Parameters:
entityInstance - the Object to add
Returns:
true on success, false on failure
Throws:
EntityListException - on EntityList events. It is used to communicate events to the user.

insertEntity

public boolean insertEntity(int index,
                            java.lang.Object entityValue)
                     throws EntityListException
Inserts an entity into this EntityList. The entity will be placed at the specified index and the entities at, and after the specified index will be moved down by one. The first valid index is 0.

Parameters:
index - the index where the entity object will be placed
entityValue - the Object to insert
Returns:
true on success, false on failure
Throws:
EntityListException - on EntityList events. It is used to communicate events to the user.

moveEntity

public boolean moveEntity(int startIndex,
                          int endIndex,
                          int newIndex)
                   throws EntityListException
Moves entities starting from the start index, to the end index, to a new location starting at the new index given. The entities at, and after the specified newIndex will be moved down to make room for the entities being moved. The appropriate adjustments are also made for the other entities, such as moving them up to fill any gaps. All indices begin at 0.

Parameters:
startIndex - the index of the first entity to move
endIndex - index of the last entity to move
newIndex - the destination index
Returns:
true on success, false on failure
Throws:
EntityListException - on EntityList events. It is used to communicate events to the user.

removeEntity

public boolean removeEntity(int index)
                     throws EntityListException
Removes the specified entity. The first index is at 0.

Parameters:
index - the index of the entity to remove
Returns:
true on success, false on failure
Throws:
EntityListException - on EntityList events. It is used to communicate events to the user.

replaceAll

public void replaceAll(EntityList v)
Replaces all the current entities with those given by the EntityList parameter.

Parameters:
v - the EntityList holding the new entities

addEntityListListener

public void addEntityListListener(EntityListListener e)
Adds a listener for list change events.

Parameters:
e - the EntityListListener to add

removeEntityListListener

public void removeEntityListListener(EntityListListener e)
Removes an entity list listener so that list changes will not trigger events for that listener.

Parameters:
e - the EntityListListener to remove