Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.elexis.actions
Class ElexisEventDispatcher

java.lang.Object
  extended by Job
      extended by ch.elexis.actions.ElexisEventDispatcher

public final class ElexisEventDispatcher
extends Job

The Elexis event dispatcher system manages and distributes the information of changing, creating, deleting and selecting PersistentObjects. An event is fired when such an action occures. This might be due to a user interaction or to an non-interactive job. A view that handles user selection of PersistentObjects MUST fire an appropriate Event through ElexisEventdispatcher.getinstance().fire(ElexisEvent ee) Notification of deletion, modification and creation of PeristentObjects occurs transparently via the PersistentObject base class. A client that wishes to be informed on such events must register an ElexisEventListener. The catchElexisEvent() Method of this listener is called in a non-UI-thread an should be finished as fast as possible. If lengthy operations are neccessary, these must be sheduled in a separate thread, The Listener can specify objects, classes and event types it wants to be informed. If no such filter is given, it will be informed about all events.

Author:
gerry

Method Summary
 void addListeners(ElexisEventListener... els)
          Add listeners for ElexisEvents.
static void clearSelection(java.lang.Class<?> clazz)
          inform the system, that no object of the specified type is selected anymore
 void dump()
           
 void fire(ElexisEvent... ees)
          Fire an ElexisEvent.
static void fireSelectionEvent(PersistentObject po)
          inform the system that an object has been selected
static void fireSelectionEvents(PersistentObject... objects)
          inform the system, that several objects have been selected
static ElexisEventDispatcher getInstance()
           
static PersistentObject getSelected(java.lang.Class<?> template)
          find the last selected object of a given type
static Patient getSelectedPatient()
          shortcut
 void registerDispatcher(java.lang.Class<? extends PersistentObject> eventClass, IElexisEventDispatcher ied)
          It is possible to register a dispatcher for a given class.
static void reload(java.lang.Class<?> clazz)
          inform the system, that all object of a specified class have to be reloaded from storage
 void removeListeners(ElexisEventListener... els)
          remove listeners.
 void shutDown()
           
 void unregisterDispatcher(java.lang.Class<? extends PersistentObject> ec, IElexisEventDispatcher ied)
          Unregister a previosly registered dispatcher
static void update(PersistentObject po)
          inform the system, that the specified object has changed some values or properties
 boolean waitUntilEventQueueIsEmpty(long millis)
          Let the dispatcher Thread empty the queue.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ElexisEventDispatcher getInstance()

registerDispatcher

public void registerDispatcher(java.lang.Class<? extends PersistentObject> eventClass,
                               IElexisEventDispatcher ied)
                        throws ElexisException
It is possible to register a dispatcher for a given class. If such a dispatcher exists, as an event of this class is fired, the event will be routed through that dispatcher. Only one dispatcher can be registered for a given class. The main purpose of this feature is to allow plugins to take care of their data classes by themselves.

Parameters:
eventClass - A Subclass of PersistentObject the dispatcher will take care of
ied - the dispatcher to register
Throws:
ElexisException - if there is already a dispatcher registered for that class.

unregisterDispatcher

public void unregisterDispatcher(java.lang.Class<? extends PersistentObject> ec,
                                 IElexisEventDispatcher ied)
                          throws ElexisException
Unregister a previosly registered dispatcher

Parameters:
ec - th class the dispatcher takes care of
ied - the dispatcher to unregister
Throws:
ElexisException - if the dispatcher was not registered, or if the class was registered with a different dispatcher

addListeners

public void addListeners(ElexisEventListener... els)
Add listeners for ElexisEvents. The listener tells the system via its getElexisEventFilter method, what classes it will catch. If a dispatcher for that class was registered, the call will be routed to that dispatcher.

Parameters:
el - one ore more ElexisEventListeners that have to return valid values on el.getElexisEventFilter()

removeListeners

public void removeListeners(ElexisEventListener... els)
remove listeners. If a listener was added before, it will be removed. Otherwise nothing will happen

Parameters:
el - The Listener to remove

fire

public void fire(ElexisEvent... ees)
Fire an ElexisEvent. The class concerned is named in ee.getObjectClass. If a dispatcher for that class was registered, the event will be forwarded to that dispatcher. Otherwise, it will be sent to all registered listeners. The call to the dispatcher or the listener will always be in a separate thread and not in the UI thread.So care has to be taken if the callee has to change the UI Note: Only one Event is dispatched at a given time. If more events arrive, they will be pushed into a FIFO-Queue. If more than one equivalent event is pushed into the queue, only the last entered will be dispatched.

Parameters:
ee - the event to fire.

getSelected

public static PersistentObject getSelected(java.lang.Class<?> template)
find the last selected object of a given type

Parameters:
template - tha class defining the object to find
Returns:
the last object of the given type or null if no such object is selected

fireSelectionEvent

public static void fireSelectionEvent(PersistentObject po)
inform the system that an object has been selected

Parameters:
po - the object that is selected now

fireSelectionEvents

public static void fireSelectionEvents(PersistentObject... objects)
inform the system, that several objects have been selected

Parameters:
objects -

clearSelection

public static void clearSelection(java.lang.Class<?> clazz)
inform the system, that no object of the specified type is selected anymore

Parameters:
clazz - the class of which selection was removed

reload

public static void reload(java.lang.Class<?> clazz)
inform the system, that all object of a specified class have to be reloaded from storage

Parameters:
clazz - the clazz whose objects are invalidated

update

public static void update(PersistentObject po)
inform the system, that the specified object has changed some values or properties

Parameters:
po - the object that was modified

getSelectedPatient

public static Patient getSelectedPatient()
shortcut


shutDown

public void shutDown()

waitUntilEventQueueIsEmpty

public boolean waitUntilEventQueueIsEmpty(long millis)
Let the dispatcher Thread empty the queue. If the queue is empty, this method returns immediately. Otherwise, the current thread waits until it is empty or the provided wasit time has expired.

Parameters:
millis - The time to wait bevor returning
Returns:
false if waiting was interrupted

dump

public void dump()

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis