Tuesday, January 1, 2013

Re: dynamic update data

define some class with a name like ClientContext or something like that. Let that class be the "home" of the client entities you want to manage (like your pizzas). This class is responsble of mantaining this "client entities" both by let you add/remove the entities and also let observers to subscribe to "entity changes". So when you add / remove entities you notify the observers. Then register a Entity change listener and when notified for an entity change, just update all the GUI components that need to be updated when you add/remove pizzas. Something like this:

public class ClientContext {
private List<Pizza> pizzas;
public void add(Pizza p) {
pizzas.add(p);
notifyAllListeners();
}
public void addPizzaListener(PizzaListener l){...}
public void notifyAllListeners(){for(PizzaListener l : listeners){l.notifyPizzasChange(); }}
}

..then on your GUI code...:
ClientContext.getInstance().addPizzaListener(new PizzaListener(){
public void notifyPizzasChange(){update the list box using ClientContext.getInstance().getPizzas()}
})

Hope this can clarify something... Happy new year to you too!

P/D: in these cases, I often find much more useful to have a Map<String, Pizza> for storing the pizzas by id. Also you can use a cheap map using Js Objects directly instead of java.util.Map implementations, like this: http://code.google.com/p/yuigwt/source/browse/trunk/yuigwt/src/org/sgx/yuigwt/yui/util/LWMap.java 

On Tuesday, January 1, 2013 5:29:57 PM UTC+1, Aldin wrote:
Happy New Year!

Your idea is not bad. But I don't know how to achieve your logic. I trying to implement your idea without success.
I can add my new pizza object to ArrayList of pizza objects but how to update the ListBox???


On Mon, Dec 24, 2012 at 6:14 PM, Sebastián Gurin <sebast...@gmail.com> wrote:
If the pizza objects that your client posses are not a very big number, then, instead updating against the server, you can mantain a local collection of pizzas in the client. I mean, write a class like PizzaHome or something like that that contains a collection or a map of pizzas. When you add a new pizza or remove a pizza, make a call to the server for adding/updating and then modify the local pizza home PizzaHome.getInstance().addNew(pizza1). The Pizza home can be an Observable that notify other interested part of your client when the local pizza collection changes. Also from time to time you can synchronize this PizzaHome with your server.

On Monday, December 24, 2012 8:48:00 AM UTC-2, Aldin wrote:
Hi guys,

I am developing pizza ordering application. I have two forms:

1) For inserting new pizza
2) and for ordering.

Here you can see:




When I insert a new pizza and go to check on combo box (picture ordering) I can't see my new pizza in combo box. The new pizza is inserted in my databases. The pizzas in combo box are from my database.

I have one idea.  But I don't think it is good. To use

    Timer t = new Timer() {        public void run() {          //display all pizza from my database every 2 se to combobox        }      };
t.schedule(2000);

Any idea for better approach???
Thanks

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/1VMHjsTx0o4J.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
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 view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/ZpGfUttNR3MJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment