If you need to make something occur sequential that is happening in
events, I did the following.

This is the issue I had.

In loading my screen up with I needed to build part of the screen
(buttons and the like) from data received from the server.  Thus,
until this data was received some init work could not be completed.
The part that build up the buttons from the server was a separate
subsystem I was using.  Thus I created a class that would us this
subsystem and attach to its event handling (this was part of the
subsystem) and when the event was fired it would use the data from the
server to build its part of the screen and then call another method
that was linked with it to complete the init functions.


The below code is the main part of the init for the application.  The
last line is a class that creates a master menu from the server.  It
requires a class to be passed that I used to complete the init.  This
class is used after it has completed its code, thus allowing you to
have sequential initialization.


// Setup the header
//@ TODO Get the root URL
Header.setUrl(result + "/Pages/Header.html");
Header.setStyleName("Header");
Header.setSize(HeaderWidth + "px", HeaderHeight + "px");

// Setup the page
Page.setStyleName("Page");
Page.setSize(PageWidth + "px", PageHeight + "px");

// Setup the notice panel
//@ TODO: Notice.setStyleName("NoticePanel");
Notice.setSize(NoticeWidth + "px", NoticeHeight + "px");
Label x1 = new Label("We have a notice");
Label x2 = new Label("We have another notice");
Notice.add(x1);
Notice.add(x2);

// Setup the quick menu
SetupQuickMenu();

// Setup the menu
myMenu = new MasterMenu(Page, ButtonWidth, myOnComplete);


The last line created a class that had an event that would talk to the
server getting data about how to build up several buttons, after it
completed its event the event would call a method in the class
myOnComplete, thus forcing a sequential init for the application.

See below

private class onxComplete implements MasterMenuComplete {

        @Override
        public void onComplete() {
                Menu.setSize(MenuWidth + "px", MenuHeight + "px");
                Menu.add(myMenu.getStackPanel(), StackPanelLeft, StackPanelTop);

                // Setup the master panel
                MasterPanel.setSize(MasterPanelWidth + "px", MasterPanelHeight +
"px");
                //# TODO: MasterPanel.setStyleName("MasterPanel");
                MasterPanel.add(Header, HeaderLeft, HeaderTop);
                MasterPanel.add(Menu, MenuLeft, MenuTop);
                MasterPanel.add(Page, PageLeft, PageTop);
                MasterPanel.add(QuickMenu, QuickMenuLeft, QuickMenuTop);
                MasterPanel.add(Notice, NoticeLeft, NoticeTop);

                // Display root panel.
                RootPanel.get("maindisplay").add(MasterPanel);

                // Fire off the default button.
                myMenu.clickDefault();          }
};



The Async call back class is below

AsyncCallback<ButtonRec[]> callback = new AsyncCallback<ButtonRec[]>()
{
        String      groupName = "";
        ButtonGroup group;

        @Override
        public void onFailure(Throwable caught) {
                // TODO Auto-generated method stub

        }

        @Override
        public void onSuccess(ButtonRec[] result) {
                if (result.length > 0) {
                        for (int i=0; i < result.length; i++) {
                                if 
(groupName.compareTo(result[i].getGroupName()) != 0) {
                                        group = new 
ButtonGroup(result[i].getGroupName(), -1, "", 0);
                                        group.setMaintainState(true);
                                        groupName = result[i].getGroupName();
                                        myMenu.Add(group);
                                }
                                if (result[i].isDefaultButton()) {
                                        group.setDefaultButton(new MyMenuButton(
                                                                        group, 
result[i].getButtonName(),
                                                                        
result[i].getURL(), ButtonWidth,
                                                                        
MenuButtonHandler));
                                } else {
                                        new MyMenuButton(
                                                                        group, 
result[i].getButtonName(),
                                                                        
result[i].getURL(), ButtonWidth,
                                                                        
MenuButtonHandler);
                                }
                        }
                        myMenu.LoadMenu();
                        CompleteCall.onComplete();
                }
        }

};


The last call CompleteCall.onComplete() is the class that was
registered with the MasterMenu class.  After it creates its buttons it
then calls this method to complete init of the application.

I did this just to figure out how to have sequential init when dealing
with events.

It works, a bit complicated but given the limitation of the browser
environment you really do not have a lot of choices.




On May 28, 12:08 pm, davidroe <roe.da...@gmail.com> wrote:
> Timer t = new Timer() {
>   public void run() {
>     // do something after a delay
>   }
>
> };
>
> // delay running for 2 seconds
> t.schedule(2000);
>
> HTH,
> /dave
>
> On May 28, 10:05 am, Adil BENHAMID <enst.de.breta...@gmail.com> wrote:
>
>
>
> > as an example I want to display a button then wait two seconds before
> > displaying the next one.
>
> > 2009/5/28 Adil BENHAMID <enst.de.breta...@gmail.com>
>
> > > I would like to to make a temporization between two calls.
>
> > > 2009/5/28 Jason Essington <jason.essing...@gmail.com>
>
> > >> Thread is not part of java that is emulated in GWT. Javascript is
> > >> single threaded so thread.sleep() has no meaning, you might as well do
> > >> while(true);  (I don't actually suggest doing that)
>
> > >> What is it that you are trying to accomplish with Thread.sleep()?
>
> > >> -jason
>
> > >> On May 28, 2009, at 10:37 AM, Adil Ben wrote:
>
> > >> > Hello,
>
> > >> > I need to call the method Thread.sleep() in my GWT code. But GWT does
> > >> > not integrate this class.
> > >> > How to solve this?
>
> > >> > i get the following error
> > >> > "No source code is available for type java.lang.Thread; did you
> > >> > forget to inherit a required module?"
>
> > >> > Regards.
>
> > > --
> > > ¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°
> > > Adil BENHAMID
> > > º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø
>
> > --
> > ¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°
> > Adil BENHAMID
> > º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to