PDA

View Full Version : New EventSystem



FireGlow
7 Jul 2009, 12:51 PM
Hey Guys!

I migrated my project vom 1.2.4. to 2.0 but I have a problem with the event system....

I tried to add the Events like this


registerEventTypes( new EventType(NUMBER_XYZ));

Then I fire a dispatch:


registerEventTypes(new EventType(NUMBER_XYZ));

But the canHandle()-method doesn't find the event (core-code) :



/**
* Determines if the controller can handle the particular event. Default
* implementation checks against registered event types then queries all child
* controllers.
*
* @param event the event
* @return <code>true</code> if event can be handled, <code>false</code>
* otherwise
*/
public boolean canHandle(AppEvent event) {
if (supportedEvents != null && supportedEvents.contains(event.getType()))
return true;
if (children != null) {
for (Controller c : children) {
if (c.canHandle(event)) return true;
}
}
return false;
}

And I know why:

supportedEvents.contains(event.getType()))

This code directly compares the 2 Objects and not the eventCodeNumbers()... because EventType doesn't implemented an own equal/compareTo-Method....

Am I Doing anything wrong? I don't want to create a class for every EventType....

sven
7 Jul 2009, 1:39 PM
Your approach is not correct. Each eventtype has to be an own object and if the the events are the same, the reference has to be the same. Take a look how GXT is handling this.

FireGlow
7 Jul 2009, 1:44 PM
Where I can have a look?

Because i only see that I need to create around 100 objects and handle them in a center... that's not really a good way I think?

sven
7 Jul 2009, 1:48 PM
If you have 100 different events, than yes you have to do that.

But oyu can automate that. You can have a method that generates a eventtype for an specific ID and if that ID already exists it returns the eventtype

FireGlow
7 Jul 2009, 2:00 PM
Jeah thought about that...

if i may ask, why you just don't stand with the integer implementation?

Now you cannot use switch/case in the handle part :/

maku
8 Jul 2009, 2:58 AM
The new EventType is really a pain when you have to migrate a rather big application.

I don't understand why there is not a smoother migration possibility. (e.g. provide a slightly better backward compatibility).

Now we have hundreds of code locations to change.

BTW, I would to expect that new EventType(1000).equals(new EventType(1000)). But it isn't.

Regards,
Martin

FireGlow
8 Jul 2009, 3:15 AM
yep that was my problem too....

for migration reasons it would be better to implement this equals method.