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.
> > º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø- Hide quoted text -
>
> - Show quoted text -