Problem with events

2 views
Skip to first unread message

eugenio....@gmail.com

unread,
Nov 14, 2007, 5:31:49 AM11/14/07
to Google Web Toolkit
Hi all,
using the MVC pattern for the client side faced me the problem that I
could not find an event system in GWT.
I have a class "State" that it represents the states of my program.
Two classes(LoadConfiguration and Simulation) modified their interface
following the change of the class State.
So I decided to implement the observer pattern, Observable is State
and Observer is LoadConfiguration and Simulation.
How do I use the events and the listeners with gwt?
Do you have any idea?

My class State
public class State {

public static int PROGRAM_STOPPED = 0000;
public static int PROGRAM_STARTED = 9999;
public static int NOTHINGFILE_LOADED = 0;
.............
}

Best regards,
Eugenio

Ian Bambury

unread,
Nov 14, 2007, 6:55:11 AM11/14/07
to Google-We...@googlegroups.com
There's an explanation of how to create a custom listener here - http://www.examples.roughian.com/v1/#MiniProject_Listener

Ian
 
http://examples.roughian.com
--------------------------------------------

eugenio....@gmail.com

unread,
Nov 14, 2007, 12:34:21 PM11/14/07
to Google Web Toolkit
The example doesn't extend any class "event".
My class State she must extend what interface? EventListener ?
LoadConfiguration and Simulation are two classes listeners.

Best regards,
Eugenio

On 14 Nov, 12:55, "Ian Bambury" <ianbamb...@gmail.com> wrote:
> There's an explanation of how to create a custom listener here -http://www.examples.roughian.com/v1/#MiniProject_Listener
>
> Ian
>

> On 14/11/2007, eugenio.ricce...@gmail.com <eugenio.ricce...@gmail.com>


> wrote:
>
>
>
>
>
>
>
> > Hi all,
> > using the MVC pattern for the client side faced me the problem that I
> > could not find an event system in GWT.
> > I have a class "State" that it represents the states of my program.
> > Two classes(LoadConfiguration and Simulation) modified their interface
> > following the change of the class State.
> > So I decided to implement the observer pattern, Observable is State
> > and Observer is LoadConfiguration and Simulation.
> > How do I use the events and the listeners with gwt?
> > Do you have any idea?
>
> > My class State
> > public class State {
>
> > public static int PROGRAM_STOPPED = 0000;
> > public static int PROGRAM_STARTED = 9999;
> > public static int NOTHINGFILE_LOADED = 0;
> > .............
> > }
>
> > Best regards,
> > Eugenio
>

> --
>
> Ian
> --------------------------------------------http://examples.roughian.com
> --------------------------------------------- Nascondi testo tra virgolette -
>
> - Mostra testo tra virgolette -

Ian Bambury

unread,
Nov 14, 2007, 1:41:41 PM11/14/07
to Google-We...@googlegroups.com
Hi Eugenio,
 
If the event exists in GWT (Click, MouseDown, whatever) then you just use those directly (or bubble them upwards through your own widgets, maybe)
 
But you appear to to want an onStateChange() event, in which case you need to roll your own. That link I mentioned shows you how.
 
Basically you need to create an interface which defines what the source of events will do, and listeners must have these methods (even if they don't actually do anything)
 
Your source (public class State()) need to be able to register listeners (and maybe delete them from the list as well). It needs to have a setter method, and in the setter method, if the state is changed, it notifies all the listeners.
 
But as I say, it's all in the walkthrough
 
Ian
 
--------------------------------------------
http://examples.roughian.com
--------------------------------------------

Peter Blazejewicz

unread,
Nov 14, 2007, 6:05:58 PM11/14/07
to Google Web Toolkit
hi Eugenio,
you don't need to inherit from existing interfaces or classes, that's
not "regular" java where we are stick to existing event model, at end
you will have javascript which does not know anything about
inheritence and such things (yet, until ECMA4 will arrive
http://weblogs.mozillazine.org/roadmap/archives/2007/10/open_letter_to_chris_wilson.html
at some point),
you can or you don't need to use Event abstraction,
see similiar topic with samples (including post from GWT team member
which desribes Ian post and linked example deeper),
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/6635205f5ce8208a/

regards,
Peter
On Nov 14, 6:34 pm, "eugenio.ricce...@gmail.com"

charlie...@gmail.com

unread,
Nov 14, 2007, 9:00:13 PM11/14/07
to Google Web Toolkit
I use MVC, with events and data binding, by using the GWTx
PropertyChangeSupport stuff - http://code.google.com/p/gwtx/. Works
the same way as PropertyChangeSupport works in standard Java (JavaBean
properties).

The events and listeners with GWT are really more for browser events,
though they could be used for other things as well I suppose. The kind
of events MVC needs, at least on the app level, where the model is
observed by the view, have nothing to do with that (although that is
really another layer of MVC, yes, a Button has it's own MVC, but app
level doesn't need to worry about that).

It might be cleaner if you either look more towards PCS, or just
create your own events and listeners (the Roughian examples do that
for instance, just create your own having nothing to do with GWT, as
you normally would - just have to stay within the limited JRE, or
extend it, like GWTx does).


On Nov 14, 5:31 am, "eugenio.ricce...@gmail.com"
Reply all
Reply to author
Forward
0 new messages