com.pcauto.gui.table
Class ProxyEntityList

java.lang.Object
  extended bycom.pcauto.gui.table.ProxyEntityList
All Implemented Interfaces:
EntityList

public class ProxyEntityList
extends java.lang.Object
implements EntityList

The ProxyEntityList implements the EntityList interface which 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 ProxyEntityList.

This class serves as a bridge between an EntityList and a List. Users can quickly utilize the EntityTable to display and manipulate their existing List data by using this ProxyEntityList.

Note: Problems may result if the List is manipulated natively (not through ProxyEntityList or EntityTable).


Constructor Summary
ProxyEntityList()
          Constructs a new ProxyEntityList.
ProxyEntityList(java.lang.Object prototype)
          Constructs a new ProxyEntityList using the given prototype.
ProxyEntityList(java.lang.Object prototype, java.util.List list)
          Constructs a new ProxyEntityList using the given prototype, and List of entries.
 
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.
protected  java.lang.reflect.Method findMethod(java.lang.Class type, java.lang.String name, java.lang.Class[] classes)
           
protected  void fireListChanged(EntityListEvent e)
          Generates a list changed event based on the event that occurred.
 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.util.List getList()
          Returns the list containing all the entities in the table.
 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 prototype)
          Sets the entity that contains desirable default values.
 boolean setEntity(int index, java.lang.Object entityInstance)
          Replaces the entity instance at the specified index.
 void setList(java.util.List list)
          Replaces the current entities inside this container with the entities in the list parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyEntityList

public ProxyEntityList()
Constructs a new ProxyEntityList.


ProxyEntityList

public ProxyEntityList(java.lang.Object prototype)
Constructs a new ProxyEntityList using the given prototype. The prototype is a sample entity. It will be used when calling getNewEntity to return a new entity instance of the same type as the prototype parameter.

Parameters:
prototype - the prototype to use

ProxyEntityList

public ProxyEntityList(java.lang.Object prototype,
                       java.util.List list)
Constructs a new ProxyEntityList using the given prototype, and List of entries. The prototype is a sample entity. It will be used when calling getNewEntity to return a new entity instance of the same type as the prototype parameter. The List is used to initialize the entities for this ProxyEntityList.

Parameters:
prototype - the prototype
list - the List of entities
Method Detail

getList

public java.util.List getList()
Returns the list containing all the entities in the table.

Returns:
the List containing the entities

setList

public void setList(java.util.List list)
Replaces the current entities inside this container with the entities in the list parameter.

Parameters:
list - the List containing the new entities

getCount

public int getCount()
Description copied from interface: EntityList
Returns the number of entities stored in this EntityList.

Specified by:
getCount in interface EntityList
Returns:
the number of entities in the list

getEntity

public java.lang.Object getEntity(int index)
Description copied from interface: EntityList
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.

Specified by:
getEntity in interface EntityList
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
Description copied from interface: EntityList
Replaces the entity instance at the specified index. The first entity is at index 0.

Specified by:
setEntity in interface EntityList
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()
Description copied from interface: EntityList
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.

Specified by:
getNewEntity in interface EntityList
Returns:
the Object reference to the new entity instance

getNewDefaultEntity

public java.lang.Object getNewDefaultEntity()
Description copied from interface: EntityList
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.

Specified by:
getNewDefaultEntity in interface EntityList
Returns:
the Object reference to the new entity instance

getDefaultEntity

public java.lang.Object getDefaultEntity()
Description copied from interface: EntityList
Returns an entity instance containing desirable default values.

Specified by:
getDefaultEntity in interface EntityList
Returns:
Object reference to the entity containing the desirable values

setDefaultEntity

public void setDefaultEntity(java.lang.Object prototype)
Description copied from interface: EntityList
Sets the entity that contains desirable default values.

Specified by:
setDefaultEntity in interface EntityList
Parameters:
prototype - the Object representing the entity holding the desirable values

addEntity

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

Specified by:
addEntity in interface 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
Description copied from interface: EntityList
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.

Specified by:
insertEntity in interface EntityList
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
Description copied from interface: EntityList
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.

Specified by:
moveEntity in interface EntityList
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
Description copied from interface: EntityList
Removes the specified entity. The first index is at 0.

Specified by:
removeEntity in interface EntityList
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.

addEntityListListener

public void addEntityListListener(EntityListListener e)
Description copied from interface: EntityList
Adds a listener for list change events.

Specified by:
addEntityListListener in interface EntityList
Parameters:
e - the EntityListListener to add

removeEntityListListener

public void removeEntityListListener(EntityListListener e)
Description copied from interface: EntityList
Removes an entity list listener so that list changes will not trigger events for that listener.

Specified by:
removeEntityListListener in interface EntityList
Parameters:
e - the EntityListListener to remove

replaceAll

public void replaceAll(EntityList v)
Description copied from interface: EntityList
Replaces all the current entities with those given by the EntityList parameter.

Specified by:
replaceAll in interface EntityList
Parameters:
v - the EntityList holding the new entities

fireListChanged

protected void fireListChanged(EntityListEvent e)
Generates a list changed event based on the event that occurred. The event can indicate things such as the addition or removal of an entity. This method is called when the list has changed.

Parameters:
e - the EntityListEvent that occurred

findMethod

protected java.lang.reflect.Method findMethod(java.lang.Class type,
                                              java.lang.String name,
                                              java.lang.Class[] classes)
                                       throws java.lang.NoSuchMethodException,
                                              java.lang.SecurityException
Throws:
java.lang.NoSuchMethodException
java.lang.SecurityException