com.pcauto.gui.table
Class OrderTranslatorEntityList

java.lang.Object
  extended bycom.pcauto.gui.table.OrderTranslatorEntityList
All Implemented Interfaces:
EntityList, EntityListListener, java.util.EventListener

public class OrderTranslatorEntityList
extends java.lang.Object
implements EntityList, EntityListListener

This OrderTranslatorEntityList provides a temporary ordering of the EntityList for display purposes. This allows the user to modify the view order in the table, without modifying the actual data order in the EntityList. OrderTranslatorEntityList contains a mapping between the order in this OrderTranslatorEntityList and the order in the EntityList used by the table. If the order of the entities in the table is not locked to the order of the entities in the EntityList, then the user can manipulate the order in this OrderTranslatorEntityList only. If the order is locked, then the order in both the EntityList and this OrderTranslatorEntityList is modified. This class can be used to allow the user to have a custom entity order that is different from the EntityList order.


Constructor Summary
OrderTranslatorEntityList()
          Constructs a new OrderTranslatorEntityList.
OrderTranslatorEntityList(EntityList e, EntityTableColumnModel c)
          Constructs a new OrderTranslatorEntityList with the given EntityList and EntityTableColumnModel.
 
Method Summary
 boolean addEntity(java.lang.Object entityInstance)
          Adds a new entity to the EntityList and updates this OrderTranslatorEntityList.
 void addEntityListListener(EntityListListener e)
          Adds a listener for EntityList events.
protected  void fireListChanged(EntityListEvent e)
          Generates a list changed event based on the event that occurred.
 EntityTableColumnModel getColumnModel()
          Returns the column model being used.
 int getCount()
          Returns the number of entities in the EntityList.
 java.lang.Object getDefaultEntity()
          Returns the default entity which contains desirable column values.
 java.lang.Object getEntity(int index)
          Returns the entity at the specified index.
 int getEntityIndex(int index)
          Returns the index of the entity in the EntityList corresponding to the given index in this OrderTranslatorEntityList
 EntityList getEntityList()
          Returns the current EntityList.
 void getEntityListOrder()
          Makes the table order the same as the EntityList order.
 java.lang.Object getNewDefaultEntity()
          Returns a new entity containing desirable column values.
 java.lang.Object getNewEntity()
          Returns a new entity.
 int getViewIndex(int entityIndex)
          Returns the index of an entity in the table, given the index of the same entity in the EntityList.
 boolean insertEntity(int index, java.lang.Object entityInstance)
          Inserts the given entity at the index specified and moves all other entities to make room for the new entity if needed.
 boolean isOrderLockedToList()
          Returns true if the table data order in this OrderTranslatorEntityList is the same as the underlying EntityList, false otherwise.
 boolean isRowSortingAllowed()
          Returns true if row sorting is enabled, false otherwise.
 void listChanged(EntityListEvent evt)
          The list changed event handler.
 boolean moveEntity(int startIndex, int endIndex, int newIndex)
          Moves the entities between the startIndex and endIndex inclusive to the new location specified by the newIndex.
 boolean removeEntity(int index)
          Removes the entity at the specified index.
 void removeEntityListListener(EntityListListener e)
          Removes an existing listener that listened for changes in the EntityList.
 void replaceAll(EntityList e)
          Replaces all the entities in the EntityList with those specified by the new EntityList.
 void setColumnModel(EntityTableColumnModel c)
          Changes the column model to the one specified.
 void setDefaultEntity(java.lang.Object o)
          Replaces the current entity that is used to hold desirable column values.
 boolean setEntity(int index, java.lang.Object entityInstance)
          Replaces the entity at the specified index.
 void setEntityList(EntityList e)
          Sets the EntityList and thus replaces all the entities in the table by the entities in the EntityList provided.
 void setEntityListOrder()
          Sets the order of the entities in the EntityList to match the order of the entities in the table.
 void setOrderLockedToList(boolean b)
          Sets the order of the table entities in this OrderTranslatorEntityList to match that of the underlying EntityList.
 void setRowSortingAllowed(boolean b)
          Enables or disables row sorting.
 void sortByColumn(int column)
          Sorts the table rows according to the column index given.
 void sortByColumn(int column, boolean ascending)
          Sorts the table rows in ascending or descending order according to the column index given.
 void sortByColumns(java.util.Vector columns)
          Sorts the row in the table by the given columns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OrderTranslatorEntityList

public OrderTranslatorEntityList()
Constructs a new OrderTranslatorEntityList.


OrderTranslatorEntityList

public OrderTranslatorEntityList(EntityList e,
                                 EntityTableColumnModel c)
Constructs a new OrderTranslatorEntityList with the given EntityList and EntityTableColumnModel. The EntityList determines what entities are currently in the table, and the EntityTableColumnModel determines the columns that are in the table and their properties. For example, columns can be hidden, locked or read-only. See EntityTableColumnModel for more information.

Parameters:
e - the EntityList
c - the TableColumnModel
Method Detail

getEntityList

public EntityList getEntityList()
Returns the current EntityList. This stores all the entities in the table. The reference to the EntityList is stored internally.

Returns:
the EntityList

setEntityList

public void setEntityList(EntityList e)
Sets the EntityList and thus replaces all the entities in the table by the entities in the EntityList provided.

Parameters:
e - the EntityList

getColumnModel

public EntityTableColumnModel getColumnModel()
Returns the column model being used. This determines what columns are in the table and their attributes such as hidden and read-only. See EntityTableColumnModel for more information.

Returns:
the EntityTableColumnModel

setColumnModel

public void setColumnModel(EntityTableColumnModel c)
Changes the column model to the one specified. This determines what columns are in the table and their attributes such as hidden and read-only. See EntityTableColumnModel for more information.

Parameters:
c - the EntityTableColumnModel, the new column model

getCount

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

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

getEntityIndex

public int getEntityIndex(int index)
Returns the index of the entity in the EntityList corresponding to the given index in this OrderTranslatorEntityList

Parameters:
index - in this OrderTranslatorEntityList
Returns:
index in the EntityList

getEntity

public java.lang.Object getEntity(int index)
Returns the entity at the specified index. The first valid index is 0. If the entity index is out of bounds then null is returned.

Specified by:
getEntity in interface EntityList
Parameters:
index - the entity index
Returns:
the Object representing the entity at the specified index

setEntity

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

Specified by:
setEntity in interface EntityList
Parameters:
index - the index of the entity to replace
entityInstance - the Object representing the new entity
Returns:
true on success, false on failure
Throws:
{@link - EntityListException} on any EntityList events
EntityListException - on EntityList events. It is used to communicate events to the user.

getNewEntity

public java.lang.Object getNewEntity()
Returns a new entity. This is used primarily to add new entities to the EntityList. The values of the entity returned can be modified and then passed to methods such as setEntity to add or replace existing entities in the EntityList.

Specified by:
getNewEntity in interface EntityList
Returns:
the Object representing a new instance of an entity

getNewDefaultEntity

public java.lang.Object getNewDefaultEntity()
Returns a new entity containing desirable column values. This is used primarily to add new entities to the EntityList. The values of the entity returned can be modified and then passed to methods such as setEntity(int, Object) to add or replace existing entities in the EntityList. This method has the same values as the entity assigned using the setDefaultEntity(Object) method.

Specified by:
getNewDefaultEntity in interface EntityList
Returns:
the Object representing a new instance of a row entity

getDefaultEntity

public java.lang.Object getDefaultEntity()
Returns the default entity which contains desirable column values. The returned entity is currently used to specify default values to display in the virtual row.

Specified by:
getDefaultEntity in interface EntityList
Returns:
the Object that represents the entity that contains the desirable values

setDefaultEntity

public void setDefaultEntity(java.lang.Object o)
Replaces the current entity that is used to hold desirable column values. The entity provided as a parameter is currently used to specify default values to display ini the virtual row.

Specified by:
setDefaultEntity in interface EntityList
Parameters:
o - the Object entity containing desirable values

addEntity

public boolean addEntity(java.lang.Object entityInstance)
                  throws EntityListException
Adds a new entity to the EntityList and updates this OrderTranslatorEntityList.

Specified by:
addEntity in interface EntityList
Parameters:
entityInstance - the new entity to add
Returns:
true on success, false on failure
Throws:
EntityListException - on any EntityList errors

insertEntity

public boolean insertEntity(int index,
                            java.lang.Object entityInstance)
                     throws EntityListException
Inserts the given entity at the index specified and moves all other entities to make room for the new entity if needed. The first index is 0. This method modifies the EntityList and this OrderTranslatorEntityList if necessary. See the class description for information on when this OrderTranslatorEntityList will be modified.

Specified by:
insertEntity in interface EntityList
Parameters:
index - the location where the new entity should be placed
entityInstance - the new entity to add
Returns:
true on success, false on failure
Throws:
EntityListException - on any EntityList errors

moveEntity

public boolean moveEntity(int startIndex,
                          int endIndex,
                          int newIndex)
                   throws EntityListException
Moves the entities between the startIndex and endIndex inclusive to the new location specified by the newIndex. Indices start at 0. This method modifies the EntityList and this OrderTranslatorEntityList if necessary. See the class description for information on when this OrderTranslatorEntityList will be modified.

Specified by:
moveEntity in interface EntityList
Parameters:
startIndex - the index of the first entity to move
endIndex - the index of the last entity to move
newIndex - the new location of the entities
Returns:
true on success, false on failure.
Throws:
EntityListException - on any EntityList errors

removeEntity

public boolean removeEntity(int index)
                     throws EntityListException
Removes the entity at the specified index. Indices begin at 0. This method modifies the EntityList and this OrderTranslatorEntityList.

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 any EntityList errors

replaceAll

public void replaceAll(EntityList e)
Replaces all the entities in the EntityList with those specified by the new EntityList.

Specified by:
replaceAll in interface EntityList
Parameters:
e - the EntityList which, holds the new entities

isOrderLockedToList

public boolean isOrderLockedToList()
Returns true if the table data order in this OrderTranslatorEntityList is the same as the underlying EntityList, false otherwise.

Returns:
true if order locked, false otherwise

setOrderLockedToList

public void setOrderLockedToList(boolean b)
Sets the order of the table entities in this OrderTranslatorEntityList to match that of the underlying EntityList.

Parameters:
b - enabled if true, disabled otherwise

isRowSortingAllowed

public boolean isRowSortingAllowed()
Returns true if row sorting is enabled, false otherwise. If row sorting is enabled, then rows can be sorted by double clicking on the column headers, otherwise rows can't be sorted.

Returns:
true if row sorting is allowed, false otherwise

setRowSortingAllowed

public void setRowSortingAllowed(boolean b)
Enables or disables row sorting. If row sorting is enabled, then rows can be sorted by double clicking on the column headers, otherwise rows can't be sorted.

Parameters:
b - enabled if true, disabled otherwise

sortByColumns

public void sortByColumns(java.util.Vector columns)
Sorts the row in the table by the given columns. See the class description about when the underlying EntityList order is affected.

Parameters:
columns - the columns to sort by

sortByColumn

public void sortByColumn(int column)
Sorts the table rows according to the column index given. This results in all rows being sorted in either ascending or descending order by the values in the column specified by the given index. Each call to this method alternates the sorting order between ascending and descending.

Parameters:
column - the column index

sortByColumn

public void sortByColumn(int column,
                         boolean ascending)
Sorts the table rows in ascending or descending order according to the column index given. This results in all rows being sorted in either ascending or descending order by the values in the column specified by the given index. The actual sort order depends on the parameter. The order will be ascending if the ascending parameter is true, otherwise the order will be descending.

Parameters:
column - the column index
ascending - sorts ascending if true, else descending

getEntityListOrder

public void getEntityListOrder()
Makes the table order the same as the EntityList order. This makes the order of the entities in the table and the EntityList identical.


setEntityListOrder

public void setEntityListOrder()
Sets the order of the entities in the EntityList to match the order of the entities in the table.


getViewIndex

public int getViewIndex(int entityIndex)
Returns the index of an entity in the table, given the index of the same entity in the EntityList. This returns the index of the entity that the user sees in the table. This funciton maps an index in the underlying data to an index in the table view that is managed by this OrderTranslatorEntityList.

Parameters:
entityIndex - the entity index
Returns:
the view index

listChanged

public void listChanged(EntityListEvent evt)
The list changed event handler. This method is called when the EntityList changes. The EntityListEvent specifies the event that occurred and any other relevant information. See EntityListEvent for more information.

Specified by:
listChanged in interface EntityListListener
Parameters:
evt - the EntityListEvent representing the event tha occurred

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 a row. This method is called when the list has changed.

Parameters:
e - the EntityListEvent that occurred

addEntityListListener

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

Specified by:
addEntityListListener in interface EntityList
Parameters:
e - the new listener

removeEntityListListener

public void removeEntityListListener(EntityListListener e)
Removes an existing listener that listened for changes in the EntityList.

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