GeoSoft API

no.geosoft.cc.event
Class EventManager

Object
  |
  +--EventManager

public class EventManager
extends Object

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.

Author:
GeoSoft

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

getInstance

public static EventManager getInstance()
Return the sole instance of the class.

Returns:
The EventManager singelton.

addListener

public void addListener(String eventName,
                        EventListener eventListener)
Add a listener.

Parameters:
eventName - The event the listener will listen to.
eventListener - The event listener object itself.

removeListener

public void removeListener(String eventName,
                           EventListener eventListener)
Remove listener from specific event.

Parameters:
eventName - Event to remove listener from.
eventListener - Listener to remove.

removeListener

public void removeListener(EventListener eventListener)
Remove listener from all events it is registered by. Convenient way of cleaning up an listener object being destroyed.

Parameters:
eventListener - Event listener to remove.

notify

public void notify(String eventName,
                   Object source,
                   Object data)
Call listeners. The definition of object and data is purely up to the communicating classes.

Parameters:
eventName - Name of the event.
source - Source of the event (or null).
data - Additinal data of the event (or null).

notify

public void notify(String eventName,
                   Object source)
Convenience front-end where the additional data paranmeter is null.

Parameters:
eventName - Name of the event.
source - Source of the event (or null).

GeoSoft API

Copyright © 2004 - Geotechnical Software Services     geosoft.no