public class DatasourceNotification
extends java.lang.Object
A DatasourceNotification
is used by datasources to notify it's
observers about the type and the data that changed by an operation. If you
create your own datasources as subclass of AbstractListDatasource
most DatasourceNotification
s will be send automatically. When
overwriting any of AbstractListDatasource
methods to manage it's
data, e.g. AbstractListDatasource#setElements(Vector)
, make sure to
call AbstractListDatasource#notifyObservers(Object)
providing a
DatasourceNotification
as argument.
You can create DatasourceNotification
s given any of the
supported types. Optionally you can provide the objects that were added,
removed or updated.
new DatasourceNotification(DatasourceNotification.TYPE_SET); nf.setAddedObjects(myNewSetObjects); nf.setRemovedObjects(elements);
The following types of notifications are supported:
TYPE_ADD
- notify objects were addedTYPE_REMOVE
- notify objects were removedTYPE_UPDATE
- notify objects were updatedTYPE_CLEAR
- notify all objects were removedTYPE_SET
- notify all objects were removed and new objects were
setTYPE_RELOAD
- notify datasource reload finishedTYPE_SELECTION_CHANGE
- notify the selected object of the
datasource changedTYPE_FILTER_CHANGE
- notify the filter used by the datasource
was changedTYPE_SERVICE_EXEC
- notify a service being executed to load new
data for the datasourcepublic void update(final Observable observable, final Object object) { if (object != null && object instanceof DatasourceNotification) { DatasourceNotification notification = (DatasourceNotification) object; switch (notification.getType()) { case DatasourceNotification.TYPE_SERVICE_EXEC: // do something break; case DatasourceNotification.TYPE_ADD: case DatasourceNotification.TYPE_RELOAD: case DatasourceNotification.TYPE_SET: { // do something break; } default: break; } } else if (object instanceof DatasourceException) { onDatasourceError((IListDatasource) observable, (Exception) object); } }
Modifier and Type | Field and Description |
---|---|
static int |
TYPE_ADD
Objects in the datasource were added.
|
static int |
TYPE_CLEAR
All objects were removed from the datasource
|
static int |
TYPE_FILTER_CHANGE
The filter used by the datasource was changed.
|
static int |
TYPE_RELOAD
The datasource was successfully reloaded.
|
static int |
TYPE_REMOVE
Objects in the datasource were removed.
|
static int |
TYPE_SELECTION_CHANGE
The selected object of the datasource changed.
|
static int |
TYPE_SERVICE_EXEC
A service was executed to load new data for the datasource.
|
static int |
TYPE_SET
New objects have been set.
|
static int |
TYPE_UPDATE
Objects in the datasource were updated.
|
Constructor and Description |
---|
DatasourceNotification(int type)
Create a new
DatasourceNotification using the given type. |
DatasourceNotification(int type,
java.lang.Object object)
Create a new
DatasourceNotification using the given type and
a single object that was changed. |
DatasourceNotification(int type,
java.util.Vector objects)
Create a new
DatasourceNotification using the given type and
the objects itself that were changed. |
Modifier and Type | Method and Description |
---|---|
java.util.Vector |
getAddedObjects()
Returns the added objects or
NULL if no objects were added
in this type of DatasourceNotification |
java.util.Vector |
getRemovedObjects()
Returns the removed objects or
NULL if no objects were
removed in this type of DatasourceNotification |
int |
getType()
Returns the type of the
DatasourceNotification . |
java.util.Vector |
getUpdatedObjects()
Returns the updated objects or
NULL if no objects were
updated in this type of DatasourceNotification |
void |
setAddedObjects(java.util.Vector addedObjects)
Sets the added objects.
|
void |
setRemovedObjects(java.util.Vector removedObjects)
Sets the removed objects.
|
void |
setUpdatedObjects(java.util.Vector updatedObjects)
Sets the updated objects.
|
public static final int TYPE_UPDATE
public static final int TYPE_REMOVE
public static final int TYPE_ADD
public static final int TYPE_CLEAR
public static final int TYPE_SET
public static final int TYPE_RELOAD
public static final int TYPE_SELECTION_CHANGE
public static final int TYPE_FILTER_CHANGE
public static final int TYPE_SERVICE_EXEC
public DatasourceNotification(int type)
DatasourceNotification
using the given type.type
- the type indicating the change of data to be notifiedpublic DatasourceNotification(int type, java.util.Vector objects)
DatasourceNotification
using the given type and
the objects itself that were changed.type
- the type indicating the change of data to be notifiedobjects
- the objects changedpublic DatasourceNotification(int type, java.lang.Object object)
DatasourceNotification
using the given type and
a single object that was changed.type
- the type indicating the change of data to be notifiedobjects
- the object itself that was changedpublic java.util.Vector getUpdatedObjects()
NULL
if no objects were
updated in this type of DatasourceNotification
public void setUpdatedObjects(java.util.Vector updatedObjects)
updatedObjects
- the objects updated as Vector
public java.util.Vector getAddedObjects()
NULL
if no objects were added
in this type of DatasourceNotification
public void setAddedObjects(java.util.Vector addedObjects)
addedObjects
- the objects added as Vector
public java.util.Vector getRemovedObjects()
NULL
if no objects were
removed in this type of DatasourceNotification
public void setRemovedObjects(java.util.Vector removedObjects)
removedObjects
- the objects removed as Vector
public int getType()
DatasourceNotification
.