0

Events and targets

asked 2007-02-22 18:09:22 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4172958

By: alfred_doeblin

The signature of the constructor of the class Event reads like follows:

public Event(java.lang.String name,
Component target,
java.lang.Object data)

Constructs a simple event.

Parameters:
target - a component, or null to indicate broadcasting the event to all root components.
data - an arbitary data

However I think 'target' is an extremely inappropiate name; it's not the target that matters --after all it's usually the components that have an interest in a certain event that will receive it-- but the 'source' (which, of course, is what this parameter is meant to stand for).

There is more weird stuff scattered along the code, but this one is specially misleading, for it just expresses the opposite to what it should be --and actually is.

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2007-02-24 10:18:15 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4176130

By: henrichen

Please see Events.postEvent() and you should know why it is "target" rather than "source" ;).

/henri

link publish delete flag offensive edit

answered 2007-02-24 17:46:43 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4176498

By: alfred_doeblin

I had done it before posting; of course, doing Events.postEvent amounts to injecting a programmatically created event into the system, which declares to have originated on the component named 'target'.

When a listener to events of the type displayed by the posted event receives it, it will see that the 'target' of the event, i.e., its source, is just the 'target' specified when invoking postEvent.

In other words: it's the source of the event that listeners perceive --and are actually interested in. This is very logical, for the 'target' of an event can only be a listener... and listeners know themselves very well, not needing any event to tell them.

Developers may think of the originating component as a target; but users of the api will indefectibly have the opposite point of view. For instance, java.util.EventObject follows this naming convention: it really makes sense and is very easy to understand.

With kind regards

Alfred

link publish delete flag offensive edit

answered 2007-02-26 11:43:35 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4178575

By: frankiec

Until I read this I was putting the "target" as the component of where I was sending the event.

API Recommendation:

Event(String name, Component source, Object data)

link publish delete flag offensive edit

answered 2007-03-01 10:12:14 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4185516

By: tomyeh

Well, it is a bit late to change some method name like this.

link publish delete flag offensive edit

answered 2007-03-02 10:50:47 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4187575

By: frankiec

Tom,

I understand the apprehension to change but we (developers) are not new to going through this. If it makes sense, improves readability and is consistent with the true nature of the objective than it is a good change!

All too often I've seen frameworks decay due to pollution and resistance to refactor because of the installed base.

And it is a syntactical change not a semantic change, it won't break anything or cause anyone to have to search/replace or anything like that unless I'm missing something. Even if it did we all possess tools that can make the change within seconds...even in very large applications.

My 0.02
Frank

link publish delete flag offensive edit

answered 2007-03-02 12:30:41 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4187634

By: frankiec

My apologies.

Yes, the event.getTarget() would need to change to event.getSource().

Frank

link publish delete flag offensive edit

answered 2008-08-27 20:26:28 +0800

dastultz gravatar image dastultz
797 8

I suppose it depends on your perspective. If you are posting an event you a firing it at a target. If you are listening for an event you might want to know where it came from which is the source. So it seems Events.postEvent(target...) is correct but it should be event.getSource(). Really it seems it should be Events.postEvent(source, target) where source is the context I am within when I fire the event and target is only useful for finding the listener. Then the listener could call event.getSource to communicate with the sender. In the case of onClick for a button, the button is the sender of the event so should be the result of event.getSource().

Just my two cents...

/Daryl

link publish delete flag offensive edit

answered 2010-03-24 21:19:07 +0800

aktejo gravatar image aktejo
155 3

agree,..

evt.getSource is way sooooo immppoorrrtannnttt

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2007-02-22 18:09:22 +0800

Seen: 455 times

Last updated: Mar 24 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More