Though not the cleanest design, I passed a reference to the timer to
the dialogbox that will stop and start it upon closing and opening.
void addDialogBox(AlertTimer alertTimer, Map data, int groupType){...
On Jul 8, 5:50 pm, Jaroslav Záruba <[email protected]> wrote:
> The method run() is what gets called when your timer elapses/fires. For
> repeating timers this means that it gets fired repeatedly, and your timer
> gets scheduled repeatedly repeatedly. (Yes I wrote it twice.)
> This is what it should look like:
> new Timer() { @Override public void run() {
> // this gets fired once per 5000ms
> // you can make static method to access instance of your module,
> // this way you don't need to write another class for your timer
> MyEntryPoint.getInstance().refreshData();
>
> // maybe there is some more elegant way to access "this module",
> // I'm still in the learning process too :)
>
>
>
> }
> }.scheduleRepeating(5000);
> On Fri, Jul 9, 2010 at 2:30 AM, ccg123 <[email protected]> wrote:
> > Thank you. I changed it and now it occurs every 5 secs as expected. I
> > have a question concerning calling this inner class from another
> > component. So now the inner class looks like this:
> > .
> > .
> > .
> > static class AlertTimer extends Timer {
> > AlertEntryPoint entryPoint = null;
> > public AlertTimer(AlertEntryPoint alertEntryPoint) {
> > entryPoint = alertEntryPoint;
> > }
>
> > @Override
> > public void run() {
> > scheduleRepeating(1000 * 5);
>
> > entryPoint.refreshData();
> > }
>
> > }
>
> > �...@override
> > public void onModuleLoad() {
> > AlertEntryPoint.AlertTimer timer = new AlertTimer(this);
> > timer.run();
> > }
> > .
> > .
> > .
>
> > And from another component I want to cancel the scheduler. How do I
> > get a handle on the instance of AlertTimer in the code below?
>
> Just like in regular Java - by passing stuff in parameters, or by making the
> timer static member of some class.
>
>
>
> > public class ImageButton extends PushButton {
> > .
> > .
> > .
> > public ImageButton(Image image) {
> > super(image);
> > }
>
> > void addDialogBox(Map data, int groupType){
> > listener = new ClickListener() {
> > public void onClick(Widget sender) {
> > dialogbox.hide();
>
> > //start the timer again - how do i get the
> > instance of AlertTimer?
> > ??????????????????????????
> > }
> > };
>
> > On Jul 8, 4:24 pm, Jaroslav Záruba <[email protected]> wrote:
> > > Are you sure this is what you want?
>
> > > while(!stop)
> > > {
> > > // without the alert all this stuff happens bazillion times each second
> > > schedule(1000*10);
> > > entryPoint.refreshData();
>
> > > }
>
> > > I'm not sure whether Timer likes to get scheduled again before it reached
> > > its first timeout.
> > > Also it looks like you might be interested in Timer.scheduleRepeating()
> > > and Timer.cancel();
>
> > > On Fri, Jul 9, 2010 at 12:52 AM, ccg123 <[email protected]> wrote:
> > > > Why does the timer below get triggered every second, popping up the
> > > > alert and crashing the browser? I expect it to be triggered every 10
> > > > seconds:
>
> > > > public class AlertEntryPoint implements EntryPoint {
>
> > > > Map<Integer, List<AlertDTO>> alertGroupByTypeDTOs = new
> > > > TreeMap<Integer, List<AlertDTO>>();
> > > > List locationsInfoDTOList = new ArrayList<LocationsInfoDTO>();
>
> > > > static class AlertTimer extends Timer {
> > > > AlertEntryPoint entryPoint = null;
> > > > public AlertTimer(AlertEntryPoint alertEntryPoint) {
> > > > entryPoint = alertEntryPoint;
> > > > }
>
> > > > boolean stop;
> > > > �...@override
> > > > public void run() {
> > > > while (!stop) {
> > > > schedule(1000 * 10);
>
> > > > entryPoint.refreshData();
>
> > > > Window.alert("Somebody started me");
> > > > }
>
> > > > }
>
> > > > }
>
> > > > �...@override
> > > > public void onModuleLoad() {
> > > > //refreshData();
>
> > > > AlertEntryPoint.AlertTimer timer = new AlertTimer(this);
> > > > timer.run();
> > > > }
> > > > .
> > > > .
> > > > .
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Google Web Toolkit" group.
> > > > To post to this group, send email to
> > [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<google-web-toolkit%[email protected]>
> > <google-web-toolkit%[email protected]<google-web-toolkit%[email protected]>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<google-web-toolkit%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.