Class TLcdModelChangedEvent
- All Implemented Interfaces:
Serializable
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()
.
Example/template code
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) {
// ...
}
}
}
}
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Indicates that all objects of the model have been changed.static final int
Indicates that all objects of the model have been removed, i.e., the model is now empty.static final int
Indicates for a given element that it has been added to the model.static final int
Indicates for a given model element that its contents have been changed.static final int
Indicates for a given element that it has been removed from the model.static final int
Indicates that objects have been added to the model.static final int
Indicates that at least some objects in the model have changed.static final int
Indicates that some objects have been removed from the model.Fields inherited from class java.util.EventObject
source
-
Constructor Summary
ConstructorDescriptionTLcdModelChangedEvent
(ILcdModel aModel, int aCode, Map aModelChanges) Constructs a newTLcdModelChangedEvent
with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsElement
(Object aObject) Returns whetheraObject
is associated to this TLcdModelChangedEvent.int
Returns the number of Objects associated to this TLcdModelChangedEvent.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 thisTLcdModelChangedEvent
.getModel()
Returns theILcdModel
that is the source of thisTLcdModelChangedEvent
.int
retrieveChange
(Object aObject) Returns the details concerning aObject in thisTLcdModelChangedEvent
.toString()
Returns a general description of this event.Methods inherited from class java.util.EventObject
getSource
-
Field Details
-
OBJECTS_CHANGED
public static final int OBJECTS_CHANGEDIndicates that at least some objects in the model have changed.- See Also:
-
OBJECTS_ADDED
public static final int OBJECTS_ADDEDIndicates that objects have been added to the model.- See Also:
-
SOME_OBJECTS_REMOVED
public static final int SOME_OBJECTS_REMOVEDIndicates that some objects have been removed from the model.- See Also:
-
ALL_OBJECTS_REMOVED
public static final int ALL_OBJECTS_REMOVEDIndicates that all objects of the model have been removed, i.e., the model is now empty.- See Also:
-
ALL_OBJECTS_CHANGED
public static final int ALL_OBJECTS_CHANGEDIndicates that all objects of the model have been changed.- See Also:
-
OBJECT_CHANGED
public static final int OBJECT_CHANGEDIndicates for a given model element that its contents have been changed.- See Also:
-
OBJECT_ADDED
public static final int OBJECT_ADDEDIndicates for a given element that it has been added to the model.- See Also:
-
OBJECT_REMOVED
public static final int OBJECT_REMOVEDIndicates for a given element that it has been removed from the model.- See Also:
-
-
Constructor Details
-
TLcdModelChangedEvent
Constructs a newTLcdModelChangedEvent
with the given parameters.- 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.
-
-
Method Details
-
getModel
Returns theILcdModel
that is the source of thisTLcdModelChangedEvent
.- Returns:
- the
ILcdModel
that is the source of thisTLcdModelChangedEvent
.
-
getCode
public int getCode()Returns the global model change of thisTLcdModelChangedEvent
.- Returns:
- the global model change of this
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.
-
elements
Returns an Enumeration of all the objects that have been added, removed or changed with respect to the ILcdModel.See
template code
on how to use this method.- Returns:
- an Enumeration of all the objects that have been added, removed or changed with respect to the ILcdModel.
- See Also:
-
elementCount
public int elementCount()Returns the number of Objects associated to this TLcdModelChangedEvent.- Returns:
- the number of Objects associated to this TLcdModelChangedEvent
-
containsElement
Returns whetheraObject
is associated to this TLcdModelChangedEvent.- Parameters:
aObject
- the object to check for.- Returns:
- whether
aObject
is associated to this TLcdModelChangedEvent
-
retrieveChange
Returns the details concerning aObject in thisTLcdModelChangedEvent
. One of OBJECT_ADDED, OBJECT_CHANGED, or OBJECT_REMOVEDSee
template code
on how to use this method.- Parameters:
aObject
- the object to retrieve the type of change for.- Returns:
- the details concerning aObject in this
TLcdModelChangedEvent
. One of OBJECT_ADDED, OBJECT_CHANGED, or OBJECT_REMOVED
-
toString
Returns a general description of this event. The exact details of the representation are unspecified and are subject to change.- Overrides:
toString
in classEventObject
- Returns:
- a general description of this event.
-