public class TLcdModelChangedEvent extends EventObject
TLcdModelChangedEvent
implements change events that occurred in
a model
, as received by a model listener
.
A TLcdModelChangedEvent
has an integer code
property specifying
the global changes.
Its value is a any logical OR operation of OBJECTS_ADDED
, OBJECTS_CHANGED
,
SOME_OBJECTS_REMOVED
, ALL_OBJECTS_CHANGED
and ALL_OBJECTS_REMOVED
.
A TLcdModelChangedEvent
also has information specifying the
model changes in more detail, i.e. per object in an ILcdModel.
The elements() method returns an Enumeration of all the objects that
have been added, removed or changed with respect to the ILcdModel.
The int value returned by retrieveChange(java.lang.Object)
specifies
the type of change of any Object in this Enumeration. This value is one of:
OBJECT_ADDED
, OBJECT_CHANGED
, or OBJECT_REMOVED
.
Note 1: if ALL_OBJECTS_REMOVED
is set in the getCode()
method, only the
changes after the removal of all objects are detailed.
Note 2: if ALL_OBJECTS_CHANGED
is set in the getCode()
method, all changes
before and after are detailed. ALL_OBJECTS_CHANGED
will not alter the set of changes
retrieved by elements()
.
Here is example code on how to handle an event:
public void modelChanged(TLcdModelChangedEvent aEvent) {
if ((aEvent.getCode() & TLcdModelChangedEvent.ALL_OBJECTS_CHANGED) != 0) {
// all elements were changed (note: still process individual events after)
}
if ((aEvent.getCode() & TLcdModelChangedEvent.ALL_OBJECTS_REMOVED) != 0) {
// all elements were removed (note: still process individual events after)
}
try (TLcdLockUtil.Lock lock = TLcdLockUtil.readLock(aEvent.getModel())) {
Enumeration elements = aEvent.elements();
while (elements.hasMoreElements()) {
Object element = elements.nextElement();
int change = aEvent.retrieveChange(element);
if (change == TLcdModelChangedEvent.OBJECT_ADDED) {
// ...
} else if (change == TLcdModelChangedEvent.OBJECT_CHANGED) {
// ...
} else if (change == TLcdModelChangedEvent.OBJECT_REMOVED) {
// ...
}
}
}
}
Modifier and Type | Field and Description |
---|---|
static int |
ALL_OBJECTS_CHANGED
Indicates that all objects of the model have been changed.
|
static int |
ALL_OBJECTS_REMOVED
Indicates that all objects of the model have been removed, i.e.,
the model is now empty.
|
static int |
OBJECT_ADDED
Indicates for a given element that it has been added to the model.
|
static int |
OBJECT_CHANGED
Indicates for a given model element that its contents have been changed.
|
static int |
OBJECT_REMOVED
Indicates for a given element that it has been removed from the model.
|
static int |
OBJECTS_ADDED
Indicates that objects have been added to the model.
|
static int |
OBJECTS_CHANGED
Indicates that at least some objects in the model have changed.
|
static int |
SOME_OBJECTS_REMOVED
Indicates that some objects have been removed from the model.
|
source
Constructor and Description |
---|
TLcdModelChangedEvent(ILcdModel aModel,
int aCode,
Map aModelChanges)
Constructs a new
TLcdModelChangedEvent with the given parameters. |
Modifier and Type | Method and Description |
---|---|
boolean |
containsElement(Object aObject)
Returns whether
aObject is associated to this TLcdModelChangedEvent. |
int |
elementCount()
Returns the number of Objects associated to this TLcdModelChangedEvent.
|
Enumeration |
elements()
Returns an Enumeration of all the objects that have been added, removed or
changed with respect to the ILcdModel.
|
int |
getCode()
Returns the global model change of this
TLcdModelChangedEvent . |
ILcdModel |
getModel()
Returns the
ILcdModel that is the source of this
TLcdModelChangedEvent . |
int |
retrieveChange(Object aObject)
Returns the details concerning aObject in this
TLcdModelChangedEvent . |
String |
toString()
Returns a general description of this event.
|
getSource
public static final int OBJECTS_CHANGED
public static final int OBJECTS_ADDED
public static final int SOME_OBJECTS_REMOVED
public static final int ALL_OBJECTS_REMOVED
public static final int ALL_OBJECTS_CHANGED
public static final int OBJECT_CHANGED
public static final int OBJECT_ADDED
public static final int OBJECT_REMOVED
public TLcdModelChangedEvent(ILcdModel aModel, int aCode, Map aModelChanges)
TLcdModelChangedEvent
with the given parameters.aModel
- the model that is firing this event.aCode
- the code indicating the global model changes.aModelChanges
- the hash table that details the model changes. The key is the object that has changed.
The value is (an Integer wrapper of) the change itself, which can be one of OBJECT_REMOVED,
OBJECT_ADDED, OBJECT_CHANGED.public ILcdModel getModel()
ILcdModel
that is the source of this
TLcdModelChangedEvent
.ILcdModel
that is the source of this
TLcdModelChangedEvent
.public int getCode()
TLcdModelChangedEvent
.TLcdModelChangedEvent
.
This can be OBJECTS_CHANGED, OBJECTS_ADDED, SOME_OBJECTS_REMOVED, ALL_OBJECTS_REMOVED or
ALL_OBJECTS_CHANGED or a binary or of these values.
See template code
on how to use this method.
public Enumeration elements()
See template code
on how to use this method.
retrieveChange(java.lang.Object)
public int elementCount()
public boolean containsElement(Object aObject)
aObject
is associated to this TLcdModelChangedEvent.aObject
- the object to check for.aObject
is associated to this TLcdModelChangedEventpublic int retrieveChange(Object aObject)
TLcdModelChangedEvent
. One of OBJECT_ADDED, OBJECT_CHANGED,
or OBJECT_REMOVED
See template code
on how to use this method.
aObject
- the object to retrieve the type of change for.TLcdModelChangedEvent
. One of OBJECT_ADDED, OBJECT_CHANGED,
or OBJECT_REMOVEDpublic String toString()
toString
in class EventObject