Well, I don't know about the event bus and I have yet to watch that
GWT best practices video (but I really should!) and I haven't done MVP
with GWT, BUT I'm super creative so here's what I would do with your
situation! :D

I would have an object that is rather more aware of the all
recoverPanelFromHistory async actions going on. This object would
store a copy of each other object that is performing the
recoverPanelFromHistory for a specific panel. (in other words a list
of objects that have the method(s) controlling all that async
goodness) The code inside recoverPanelFromHistory() that does the
async data retrieval from the server would talk back to this object,
which is the "owner". It tells the Owner that it's finished getting
the data (even when it already had the data cached). Every time the
owner gets told that one of it's "subjects" finished getting data it
checks to see if that was the last "subject" to get it's data, and if
so it talks to the mainContentPanel and gets it to do it's view change
(clear and add). Inside the recoverPanelFromHistory code you can do
your repeatedly trying to obtain the data and even if you don't get
the data until a day later when the user finally reconnects your code
will be able to continue on no prob.

Did that make sense? It makes sense in my head, so if it doesn't make
perfect sense to you ask me to clarify things and I'll do my best!

You'll have to do some refactoring... the code inside
recoverPanelFromHistory() that does the depth search through all
children and fires recoverPanelFromHistory() on all children and their
children you'll want to still happen at the place where you currently
call recoverPanelFromHistory() from the top of the tree... BUT you'll
want to refactor the code that does the data cache check and then
calls the async-data-get out of that method. The depth search of all
children will add each child (aka "subject") to the Owner object.
After the Owner knows about all of it's subjects it then loops through
and calls the recoverPanelFromHistory() code which does the data cache
check and asyn-data-get goodness. This way the owner doesn't think
it's done loading just cuz the first subject added has it's data
cached and immediately tells the owner before any other subjects have
been added..... did that make sense?

btw, did I just invent an event bus?

cheers! ^_^

On Jun 15, 8:23 pm, fmod <francisco.mode...@gdsoft.eu> wrote:
> Using the event bus may help 
> there.http://code.google.com/events/io/2009/sessions/GoogleWebToolkitBestPr...
> and the two 
> articleshttp://code.google.com/webtoolkit/articles/mvp-architecture.html
>
> On Jun 15, 9:14 am, ping2ravi <ping2r...@gmail.com> wrote:
>
>
>
> > Hi Guys,
> > I have just implemented a multipage(basically multi url) website using
> > History. It works great using history token. But i need something else
> > from GWT which i am not able to solve.
> > Now when user clicks on something(link/button etc) i add the token to
> > History and my history callbacks get called.
> > Now in history value change handler i do something like this
>
> > 1) FInd out what page need to be dispalyed(basically identify the
> > panels etc).
> > 2) now each of my panel which can have history implementing
> > hasHistory(my own) interface, which has function
> > recoverPanelFromHistory.
> > 3) In this function, i check if i have client side data cahced for
> > this panel, if yes then load it into panel and display it(basically
> > add to main panel widget tree).
> > 4) But if no cache data found then go to server and get data.
>
> > one such implementation
> > @Override
> >         public boolean recoverPanelFromHistory(Map<String, String>
> > historyTokens) {
> >                 String page = historyTokens.get(PAGE_PARAM);
> >                 boolean returnValue = false;
> >                 if("home".equalsIgnoreCase(page))
> >                 {
> >                         returnValue =
> > userHomePanel.recoverPanelFromHistory(historyTokens); //and this
> > function will calls its child panels if they support history
> >                         if(returnValue )
> >                         {
> >                                 mainContentPanel.clear(); //clearing the 
> > mainPanel view of client
> >                                 mainContentPanel.add(userHomePanel); //and 
> > adding the view
> > according to history token value
> >                         }
> >                       else
> >                       {
> >                            //dont change the browser view and stay at
> > current panel/view/page. This also means child panel can not be
> > recovered and there must be some problem with history tokens provided.
> >                       }
>
> >                 }
> >                 if("profile".equalsIgnoreCase(page))
> >                 {
> >                         returnValue =
> > prodilePanel.recoverPanelFromHistory(historyTokens); //and this
> > function will calls its child panels if they support history
> >                         if(returnValue )
> >                         {
> >                                 mainContentPanel.clear(); //clearing the 
> > mainPanel view of client
> >                                 mainContentPanel.add(profilePanel); //and 
> > adding the view
> > according to history token value
> >                         }
> >                       else
> >                       {
> >                            //dont change the browser view and stay at
> > current panel/view/page. This also means child panel can not be
> > recovered and there must be some problem with history tokens provided.
> >                       }
>
> >                 }
> >                 return returnValue;
>
> >         }
>
> > So till now theoretically it sounds good and works good.
>
> > Problem starts when lets say user lost his Internet connection or call
> > fail at server because of any system level error..
>
> > userHomePanel.recoverPanelFromHistory(historyTokens);
>
> > This function does following things.
> > 1) get the data from cache for this panel
> > 2) if found call loadDataIntoPanel(data) function and load it into
> > panel and return true.
> > 3)  else call the server to get data.
> >     Now server call is async and I need to return some value from
> > userHomePanel.recoverPanelFromHistory(historyTokens);, so if i return
> > true and call fails at server because of some network problem then
> > ideally i dont want to switch to new view as per this history action
> > but my function has already returned true and mainPanle has already
> > changed the view to new panel.
> > Now i dont want child panels to call parentPanel's method to tell them
> > later that server call was success or failure so that main parent
> > panel can decide whethere i should switch panels/view or not. If child
> > need to know parent then my all panels will be too much dependent on
> > each other and they will be too much crossed chain to each other.
>
> > If you see gmail it uses such features. If you have loaded ur inbox
> > and then you lost ur internet connection and then u click on any
> > email. Then gmail doesnt take you to single mail viewer page and then
> > tell "oh u lost ur connection" but it just keep you on inbox view and
> > keep trying and after some time stop trying.
>
> > How can i achieve such functionality.?
> > Are there any existing libraries to do that or any particular design
> > pattern is there?
>
> > Thanks, in advance
>
> > Ravi.

-- 
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-tool...@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