public abstract class AbstractListDatasource extends Observable implements IListDatasource
IListDatasource
based on a
Vector
to manage its data model. It uses Observable
to notify
changes to a number of Observer
.Constructor and Description |
---|
AbstractListDatasource() |
AbstractListDatasource(Observer observer)
create the datasource and add one initial
Observer ; see also
Observable.addObserver(Observer) |
Modifier and Type | Method and Description |
---|---|
void |
addElement(java.lang.Object object)
Add a new object to the data model.
|
void |
addElementAtIndex(java.lang.Object object,
int index)
Insert a new object to the data model at the given row index.
|
void |
addElements(java.util.Vector objects)
Add multiple new objects to the data model.
|
int |
compare(java.lang.Object o1,
java.lang.Object o2)
use the
IComparator to compare two elements; if no
IComparator is set (see setComparator(IComparator) , "0" is
returned |
IComparator |
getComparator()
Use this method to get the current
IComparator used by the
ListView . |
java.lang.Object |
getElementAtIndex(int index)
Call this method to get the object of the data model at a given index.
|
java.util.Vector |
getElements()
Call this method to get all objects in the data model managed by this
datasource.
|
DatasourceException |
getException()
Use this method to get the last exception that has been caught while
reloading the datasource.
|
java.util.Vector |
getFilteredElements()
Returns all elements matching the
IListDatasource.getFilterExpression() . |
java.lang.String |
getFilterExpression()
Returns the filter expression currently used.
|
int |
getNumberOfElements()
Call this method to get the total number of objects in the data model managed
by this datasource.
|
java.lang.Object |
getSelectedElement()
Returns the currently selected object of the
ListView or
null if no object was set as selected. |
boolean |
hasException()
Use this method to check for exceptions that might have been caught while
reloading the datasource.
|
boolean |
isFilteredElement(java.lang.Object object)
Returns
true if the given object matches the filter for this
datasource returned by IListDatasource.getFilterExpression() . |
abstract void |
reloadElements()
Use to reload the objects managed by the datasource.
|
void |
removeAllElements()
Removes all objects from the data model.
|
void |
removeElement(java.lang.Object object)
Remove the given object from the data model.
|
void |
removeElementAtIndex(int index)
Remove the object at the given index of the data model.
|
void |
resort()
Call this method to manually resort the contents of the data model.
|
void |
setComparator(IComparator comparator)
Use this method to set a
IComparator implementation to be used when
sorting or resorting the data model representation in the ListView . |
void |
setElements(java.util.Vector objects)
Set the elements managed by the datasource to the given
Vector
of objects. |
void |
setFilterExpression(java.lang.String valueFilter)
Use this method to set a filter expression and enable filtering for the
datasource.
|
void |
setSelectedElement(java.lang.Object object)
Set the object selected by the
ListView . |
addObserver, deleteObserver, notifyObservers, notifyObservers
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getExpressionValue, matchesExpression, setExpressionValue
getExpressionValue, setExpressionValue
public AbstractListDatasource()
public AbstractListDatasource(Observer observer)
Observer
; see also
Observable.addObserver(Observer)
observer
- the Observer
to be notified of changespublic java.lang.String getFilterExpression()
IListDatasource
null
will be returnedgetFilterExpression
in interface IListDatasource
public void setFilterExpression(java.lang.String valueFilter)
IListDatasource
IListDatasource.getNumberOfElements()
,
IListDatasource.getElements()
, etc. You typically use filter to implement searches
in a . An expression can be any String an
IListDatasource
implementation uses to reference an object.setFilterExpression
in interface IListDatasource
valueFilter
- the filter string the datasource uses to filter it's contentpublic java.util.Vector getFilteredElements()
IListDatasource
IListDatasource.getFilterExpression()
. If no
filter is set, all elements will be returned. If the datasource content is
changed, on the next call of this method the filter is applied first before
returning the result.getFilteredElements
in interface IListDatasource
IListDatasource.getFilterExpression()
or all
elements if IListDatasource.getFilterExpression()
returns null
public boolean isFilteredElement(java.lang.Object object)
IListDatasource
true
if the given object matches the filter for this
datasource returned by IListDatasource.getFilterExpression()
. You need to implement
this method specifically for your datasource and the object types managed.isFilteredElement
in interface IListDatasource
object
- the object to test if it matches IListDatasource.getFilterExpression()
true
if the filter returned by
IListDatasource.getFilterExpression()
matches the object, false
if it does notpublic java.util.Vector getElements()
IListDatasource
Vector
returned will not change the contents
of the data model.getElements
in interface IListDatasource
public int getNumberOfElements()
IListDatasource
getNumberOfElements
in interface IListDatasource
public void removeElementAtIndex(int index)
IListDatasource
removeElementAtIndex
in interface IListDatasource
index
- the row index of the object to be removedpublic void removeElement(java.lang.Object object)
IListDatasource
removeElement
in interface IListDatasource
object
- the object to be removedpublic void removeAllElements()
IListDatasource
removeAllElements
in interface IListDatasource
public void addElement(java.lang.Object object)
IListDatasource
addElement
in interface IListDatasource
object
- the object to be added to the data modelpublic void addElementAtIndex(java.lang.Object object, int index)
IListDatasource
addElementAtIndex
in interface IListDatasource
object
- the object to be added to the data modelindex
- the index to add the object atpublic void addElements(java.util.Vector objects)
IListDatasource
addElements
in interface IListDatasource
objects
- a Vector
of objects to be addedpublic void setElements(java.util.Vector objects)
IListDatasource
Vector
of objects. This overwrites the current elements.setElements
in interface IListDatasource
objects
- to be managed by the datasourcepublic java.lang.Object getElementAtIndex(int index)
IListDatasource
getElementAtIndex
in interface IListDatasource
index
- the row index of the object starting at 0.public void setSelectedElement(java.lang.Object object)
IListDatasource
ListView
.setSelectedElement
in interface IListDatasource
object
- the selected objectpublic java.lang.Object getSelectedElement()
IListDatasource
ListView
or
null
if no object was set as selected.getSelectedElement
in interface IListDatasource
ListView
public void setComparator(IComparator comparator)
IListDatasource
IComparator
implementation to be used when
sorting or resorting the data model representation in the ListView
.setComparator
in interface IListDatasource
comparator
- the comparator implementation used for sortingpublic IComparator getComparator()
IListDatasource
IComparator
used by the
ListView
.getComparator
in interface IListDatasource
IComparator
implementation currently used or
null
if sorting is disabled.public int compare(java.lang.Object o1, java.lang.Object o2)
IComparator
to compare two elements; if no
IComparator
is set (see setComparator(IComparator)
, "0" is
returnedo1
- the one object to be comparedo2
- the other object to be compared againstIComparator
is set; otherwise: the result of the
IComparator
public void resort()
IListDatasource
ListView.reload()
to
reflect the changes in the user interface.resort
in interface IListDatasource
public boolean hasException()
IListDatasource
hasException
in interface IListDatasource
true
if there was an exception when initializing the
elements.public DatasourceException getException()
IListDatasource
getException
in interface IListDatasource
public abstract void reloadElements()
IListDatasource
reloadElements
in interface IListDatasource