|
GeoSoft API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object | +--EventManager
Generic event manager class. Events are string based rather than being enumerations which whould have implied a central register of events. When events are strings, only the negotiating classes needs to know about the events existance. It is transparent also to the EventManager who only delegates the events.
A potential problem with string based events are that there might be name conflicts. In a large system, one might consider prefixing the event names to avoid conflicts. If this seems to become a problem, the system is probably bad designed anyway; The number of different event types should be kept low.
The listener class must implement the EventListener interface which implies the update() method. The listener class register itself in the EventManager by:
EventManager.getInstance().addListener ("EventName", this);The source class of the event will call:
EventManager.getInstance().notify ("EventName", object, data);and the EventManager will then call the update() method of every listener.
The definition of object and data is purely up to the involved classes. Typically object will be the source of the event (the created object for a "Create" event, the deleted object for a "Delete" event and so forth.) The additinal data object is for convenience only and will often be null.
Method Summary | |
void |
addListener(String eventName,
EventListener eventListener)
Add a listener. |
static EventManager |
getInstance()
Return the sole instance of the class. |
void |
notify(String eventName,
Object source)
Convenience front-end where the additional data paranmeter is null. |
void |
notify(String eventName,
Object source,
Object data)
Call listeners. |
void |
removeListener(EventListener eventListener)
Remove listener from all events it is registered by. |
void |
removeListener(String eventName,
EventListener eventListener)
Remove listener from specific event. |
Methods inherited from class Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static EventManager getInstance()
public void addListener(String eventName, EventListener eventListener)
eventName
- The event the listener will listen to.eventListener
- The event listener object itself.public void removeListener(String eventName, EventListener eventListener)
eventName
- Event to remove listener from.eventListener
- Listener to remove.public void removeListener(EventListener eventListener)
eventListener
- Event listener to remove.public void notify(String eventName, Object source, Object data)
eventName
- Name of the event.source
- Source of the event (or null).data
- Additinal data of the event (or null).public void notify(String eventName, Object source)
eventName
- Name of the event.source
- Source of the event (or null).
|
GeoSoft API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |