javax.rad.util
Class EventHandler<L>

java.lang.Object
  extended by javax.rad.util.EventHandler<L>
Type Parameters:
L - the Listener type
Direct Known Subclasses:
ModelEventHandler, RuntimeEventHandler, StorageEventHandler

public class EventHandler<L>
extends Object

Platform and technology independent event handler. It is designed for use with UI elements and non UI elements. There can be used with any Listener Interface. and implicit forwarded to any function. button.eventAction().addListener( new ActionListener() { public void actionPerformed(ActionEvent pEvent) { doSave(); } }); button.eventAction().addListener(this, "doSave");


Constructor Summary
EventHandler(Class<L> pListenerType, Class... pParameterTypes)
          Constructs a new EventHandler, the listener type may only have 1 method.
EventHandler(Class<L> pListenerType, String pListenerMethodName, Class... pParameterTypes)
          Constructs a new EventHandler.
 
Method Summary
 void addListener(L pListener)
          Adds a listener.
 void addListener(L pListener, int pIndex)
          Adds a listener at a given index.
 void addListener(Object pListener, String pMethodName)
          Adds a listener.
 void addListener(Object pListener, String pMethodName, int pIndex)
          Adds a listener at a given position.
 L createListener(Object pListener, String pMethodName)
          Creates a new listener interface for calling the given method for the given object.
 Object dispatchEvent(Object... pEventParameter)
          Dispatches the given events to all listeners.
static Object getCurrentDispatchObject()
          Gets the current dispatch object.
 L getDefaultListener()
          Gets the default listener.
static Object getLastDispatchedObject()
          Gets the last dispatched object.
 L getListener(int pIndex)
          Gets the listener at the position.
 int getListenerCount()
          Gets the count of listeners.
 L[] getListeners()
          Gets all listeners.
static Throwable getWrappedException(Throwable pCause)
          Gets the cause of an exception that is a wrapper exception, like InvocationTargetException.
static Throwable getWrappedExceptionAllowSilent(Throwable pCause)
          Gets the cause of an exception that is a wrapper exception, like InvocationTargetException.
 boolean isDispatchEventsEnabled()
          Gets whether event dispatching is enabled.
 void removeAllListeners()
          Removes all known listeners.
 void removeListener(int pIndex)
          Removes the listener at the position.
 void removeListener(Object pListener)
          Removes all listener methods added with the given object, or the listener, if an interface was added.
 void removeListener(Object pListener, String pMethodName)
          Removes the listener added with the method.
 void setDefaultListener(L pListener)
          Sets the default listener.
 void setDefaultListener(Object pListener, String pMethodName)
          Sets the default listener.
 void setDispatchEventsEnabled(boolean pEnabled)
          Sets whether event dispatching is en- or disabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventHandler

public EventHandler(Class<L> pListenerType,
                    Class... pParameterTypes)
Constructs a new EventHandler, the listener type may only have 1 method.

Parameters:
pListenerType - the listener type interface.
pParameterTypes - parameter types to check additional.

EventHandler

public EventHandler(Class<L> pListenerType,
                    String pListenerMethodName,
                    Class... pParameterTypes)
Constructs a new EventHandler.

Parameters:
pListenerType - the listener type interface.
pListenerMethodName - the method to be called inside the interface.
pParameterTypes - parameter types to check additional.
Method Detail

addListener

public void addListener(L pListener)
Adds a listener. If the Listener is already added, it is removed before, and added at the end.

Parameters:
pListener - the listener.

addListener

public void addListener(L pListener,
                        int pIndex)
Adds a listener at a given index. If the Listener is already added, it is removed before, and added at the new position.

Parameters:
pListener - the listener.
pIndex - the index to add.

addListener

public void addListener(Object pListener,
                        String pMethodName)
Adds a listener. If the Listener is already added, it is removed before, and added at the end.

Parameters:
pListener - the listener object.
pMethodName - the method name.

addListener

public void addListener(Object pListener,
                        String pMethodName,
                        int pIndex)
Adds a listener at a given position. If the Listener is already added, it is removed before, and added at the new position.

Parameters:
pListener - the listener object.
pMethodName - the method name.
pIndex - the index to add

removeListener

public void removeListener(int pIndex)
Removes the listener at the position.

Parameters:
pIndex - the position.

removeListener

public void removeListener(Object pListener)
Removes all listener methods added with the given object, or the listener, if an interface was added.

Parameters:
pListener - the listener.

removeListener

public void removeListener(Object pListener,
                           String pMethodName)
Removes the listener added with the method.

Parameters:
pListener - the listener object.
pMethodName - the method name.

removeAllListeners

public void removeAllListeners()
Removes all known listeners.


getListenerCount

public int getListenerCount()
Gets the count of listeners.

Returns:
the count of listeners.

getListener

public L getListener(int pIndex)
Gets the listener at the position.

Parameters:
pIndex - the position.
Returns:
all listeners.

getListeners

public L[] getListeners()
Gets all listeners.

Returns:
all listeners.

setDefaultListener

public void setDefaultListener(L pListener)
Sets the default listener.

Parameters:
pListener - the listener.

setDefaultListener

public void setDefaultListener(Object pListener,
                               String pMethodName)
Sets the default listener.

Parameters:
pListener - the listener object.
pMethodName - the method name.

getDefaultListener

public L getDefaultListener()
Gets the default listener.

Returns:
the default listener.

dispatchEvent

public Object dispatchEvent(Object... pEventParameter)
                     throws Throwable
Dispatches the given events to all listeners.

Parameters:
pEventParameter - the event parameter.
Returns:
the return value of the deaultListener, if it is called, or null if dispatching is disabled or no listeners were called
Throws:
Throwable - if an exception occurs.

createListener

public L createListener(Object pListener,
                        String pMethodName)
Creates a new listener interface for calling the given method for the given object.

Parameters:
pListener - the object.
pMethodName - the method.
Returns:
the Interface.

setDispatchEventsEnabled

public void setDispatchEventsEnabled(boolean pEnabled)
Sets whether event dispatching is en- or disabled.

Parameters:
pEnabled - true to enable dispatching, false to ignore dispatching

isDispatchEventsEnabled

public boolean isDispatchEventsEnabled()
Gets whether event dispatching is enabled.

Returns:
true if event dispatching is enabled, false if it's disabled

getLastDispatchedObject

public static Object getLastDispatchedObject()
Gets the last dispatched object.

Returns:
the object

getCurrentDispatchObject

public static Object getCurrentDispatchObject()
Gets the current dispatch object.

Returns:
the object or null if no object was found

getWrappedException

public static Throwable getWrappedException(Throwable pCause)
Gets the cause of an exception that is a wrapper exception, like InvocationTargetException.

Parameters:
pCause - the wrapper exception
Returns:
the wrapped(inner) exception

getWrappedExceptionAllowSilent

public static Throwable getWrappedExceptionAllowSilent(Throwable pCause)
Gets the cause of an exception that is a wrapper exception, like InvocationTargetException. This methods doesn't unwrap exception that were wrapped with SilentAbortException.

Parameters:
pCause - the wrapper exception
Returns:
the wrapped(inner) exception


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.