org.bibalex.daf.commongui.datamodels
Class UIListEditableModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by javax.swing.DefaultListModel
          extended by org.bibalex.daf.commongui.datamodels.UIListEditableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.ListModel

public class UIListEditableModel
extends javax.swing.DefaultListModel

A data model Class used with JLists, allows The JList data to be modified (add or remove entries). It can be intialized using a DataTable. But the DataTable values are copied into the DefaultListModel. This class allows modification, in case of using it when no modifications are required it is recommended to use the UIListModel instead. As the last one consumes less memory.

Author:
Fadi.Edward
See Also:
Serialized Form

Nested Class Summary
 class UIListEditableModel.ListObject
          This class in used to maintain the Object in the list, an ID to identify the record and a value to be displayed are maintained.
 
Field Summary
protected  int colID
          The index of the Column in the DataTable considered as ID.
protected  int colVisisble
          The index of the Column in the DataTable to be displayed in the List.
protected  DataTable dataTable
          The DataTable that initilize the value of List.
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
UIListEditableModel(DataTable dataTable, int colID, int colVisible)
          Constructor (1).
UIListEditableModel(int colID, int colVisible)
          Constructor (2).
 
Method Summary
 boolean addElement(int id, java.lang.String value)
          Adds a new element to the List.
 boolean addElementAt(int index, int id, java.lang.String value)
          Adds a new element to the List at a specific index location.
 DataTable getDataTable()
          Retrives dataTable that formed the model.
 int getIDAt(int index)
          Retrives the ID of the Item at the given index.
 java.lang.Object[] getIDs()
          Retreives all the IDs on the list and returns them as an Object[] (the IDs are of Integer type).
 void setDataTable(DataTable dt)
          update dataTable that formed the model.
 
Methods inherited from class javax.swing.DefaultListModel
add, addElement, capacity, clear, contains, copyInto, elementAt, elements, ensureCapacity, firstElement, get, getElementAt, getSize, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, removeRange, set, setElementAt, setSize, size, toArray, toString, trimToSize
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

colID

protected int colID
The index of the Column in the DataTable considered as ID.


colVisisble

protected int colVisisble
The index of the Column in the DataTable to be displayed in the List.


dataTable

protected DataTable dataTable
The DataTable that initilize the value of List.

Constructor Detail

UIListEditableModel

public UIListEditableModel(DataTable dataTable,
                           int colID,
                           int colVisible)
Constructor (1). Construct the model from a DataTable.

Parameters:
dataTable - The DataTable to extract the data from.
colID - The index of the column indicating the ID in the DataTable.
colVisible - The index of the column to be displayed on the list from the DataTable.

UIListEditableModel

public UIListEditableModel(int colID,
                           int colVisible)
Constructor (2). No DataTable is used, for constructing using a DataTable please refer to Constructor (1).

Parameters:
colID - The index of the column indicating the ID in the DataTable.
colVisible - The index of the column to be displayed on the list from the DataTable.
Method Detail

getIDAt

public int getIDAt(int index)
Retrives the ID of the Item at the given index.

Parameters:
index - The index of the item.
Returns:
The ID.

getDataTable

public DataTable getDataTable()
Retrives dataTable that formed the model.

Returns:
DataTable.

setDataTable

public void setDataTable(DataTable dt)
update dataTable that formed the model.

Parameters:
dt - The DataTable to be used in the UIListModel.

addElement

public boolean addElement(int id,
                          java.lang.String value)
Adds a new element to the List.

Parameters:
id - The ID of the added element.
value - The displayed value of the added element.
Returns:
false if the element already exists, true otherwise.

addElementAt

public boolean addElementAt(int index,
                            int id,
                            java.lang.String value)
Adds a new element to the List at a specific index location. (need revision)

Parameters:
index - The index location to add the element to.
id - The ID of the added element.
value - The displayed value of the added element.
Returns:
false if the element already exists, true otherwise.

getIDs

public java.lang.Object[] getIDs()
Retreives all the IDs on the list and returns them as an Object[] (the IDs are of Integer type). (Mostly used to update the DataBase with the new selected values.)

Returns:
Object Array representing all the IDs in the list.