|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.AbstractSignal
eu.webtoolkit.jwt.AbstractEventSignal
eu.webtoolkit.jwt.AbstractJSignal
eu.webtoolkit.jwt.JSignal2<A1,A2>
public abstract class JSignal2<A1,A2>
A signal to relay JavaScript to Java calls, passing 2 arguments.
The signal is identified by a unique name within the scope of a WObject,
or a unique global name (when declaring the signal in your WApplication).
The argument types A1 and A2 must be a String, WString, or a wrapper class
of one of the Java primitive types. Values of the corresponding JavaScript types can be passed
to the JavaScript call.
Note that this is an abstract class. To create a JSignal, you should specialize this class, but
you do not need to reimplement any method. The reason for this is to circumvent limitations in
Java to obtain introspection in the types of the arguments, and provide suitable marshaling
of data from JavaScript to Java. The easiest way to instantiate an object of this class is:
JSignal2
Example code:
class MyWidget extends WCompositeWidget
{
public MyWidget()
{
doSome = new JSignal2
The following JavaScript statement will emit the signal for a
DOM element element that corresponds to a widget of class MyWidget:
Wt.emit(element, 'dosome', 'foo', 42);
The element can be a DOM element, or the object ID of a WObject,
or the constant 'Wt' which is an alias for WApplication's id.
You can use the methods createCall(String arg1, String arg2) to
let the signal itself generate this JavaScript call for you:
doSome_.createCall("'foo'", "42");
The JavaScript generated by createCall(String arg1, String arg2) is possibly
affected by every connect or disconnect to the signal.
In practice, you will use this class internally within a widget and call
createCall(String arg1, String arg2) only after you connected internal slots to signal.
It is also possible to propagate an original JavaScript event as a last argument,
of type WMouseEvent or WKeyEvent.
In that case, the second argument in Wt.emit() must be an object which indicates
also the JavaScript event and event target.
Consider a signal declaration:
JSignal2
Then, the following would be a suitable JavaScript call:
Wt.emit(Wt, {name: 'dosome', event: event, eventObject: object}, 'foo', 42);
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class eu.webtoolkit.jwt.AbstractEventSignal |
|---|
AbstractEventSignal.AutoLearnListener, AbstractEventSignal.JavaScriptListener, AbstractEventSignal.LearningListener, AbstractEventSignal.PreLearnListener |
| Nested classes/interfaces inherited from class eu.webtoolkit.jwt.AbstractSignal |
|---|
AbstractSignal.Connection |
| Constructor Summary | |
|---|---|
JSignal2(WObject sender,
java.lang.String name)
Creates a signal. |
|
| Method Summary | |
|---|---|
AbstractSignal.Connection |
addListener(WObject listenerOwner,
Signal.Listener listener)
Adds a listener for this signal. |
AbstractSignal.Connection |
addListener(WObject listenerOwner,
Signal2.Listener<A1,A2> listener)
Adds a listener for this signal. |
java.lang.String |
createCall(java.lang.String arg1,
java.lang.String arg2)
Returns a JavaScript statement that triggers this signal. |
protected int |
getListenerCount()
Returns the number of connected listeners. |
void |
removeListener(Signal.Listener listener)
Removes a listener. |
void |
removeListener(Signal2.Listener<A1,A2> listener)
Removes a listener. |
void |
trigger(A1 arg1,
A2 arg2)
Triggers the signal. |
| Methods inherited from class eu.webtoolkit.jwt.AbstractJSignal |
|---|
createUserEventCall, getName |
| Methods inherited from class eu.webtoolkit.jwt.AbstractEventSignal |
|---|
addListener, addListener, addListener, addListener, addListener, addListener, createUserEventCall, disconnect, isCanAutoLearn, isConnected, isDefaultActionPrevented, isPropagationPrevented, preventDefaultAction, preventDefaultAction, preventPropagation, preventPropagation, removeListener, trigger |
| Methods inherited from class eu.webtoolkit.jwt.AbstractSignal |
|---|
getListeners, isBlocked, setBlocked |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JSignal2(WObject sender,
java.lang.String name)
sender - the object that will be identified as the sender for this signal.name - the signal name (must be unique for each sender)| Method Detail |
|---|
public AbstractSignal.Connection addListener(WObject listenerOwner,
Signal2.Listener<A1,A2> listener)
Each listener will be triggered whenever the signal is triggered.
listenerOwner - the enclosing object for a listener implemented using an (anonymous) inner classlistener - the listener
AbstractSignal.addListener(WObject, eu.webtoolkit.jwt.Signal.Listener)protected int getListenerCount()
AbstractSignal
getListenerCount in class AbstractEventSignalpublic void removeListener(Signal2.Listener<A1,A2> listener)
listener - a listener that was previously added
public void trigger(A1 arg1,
A2 arg2)
The arguments are passed to the listeners.
arg1 - Argument 1arg2 - Argument 2
public java.lang.String createCall(java.lang.String arg1,
java.lang.String arg2)
You can use this to trigger the signal from within generated JavaScript code.
arg1 - JavaScript argument 1.arg2 - JavaScript argument 2.
public AbstractSignal.Connection addListener(WObject listenerOwner,
Signal.Listener listener)
AbstractSignalEach listener will be notified when the signal is triggered.
An owner object may be passed when the listener is implemented using an (anonymous) inner class. In that case the owner object should be the enclosing object of the listener object, and this is used to bind the lifetime of the listener. To avoid the owner object from not being garbage collected when it is no longer used, only the owner object will add a reference to the listener, while the signal will use a weak reference.
This avoids the most common reason for memory leaks in Java
implementations of the Observer pattern: the owner object will not get
garbage collected because of the (anonymous) listener object having a
reference to it, even if the receiver object is no longer referenced from
anywhere. When the owner object is not null, the listener is
stored using a strong reference in the owner object, and using a weak
reference in the signal.
addListener in class AbstractSignallistenerOwner - if not null, the enclosing object for a
listener implemented using an inner classlistener - the listener
public void removeListener(Signal.Listener listener)
AbstractSignal
removeListener in class AbstractSignallistener - a listener that was previously added.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||