Hello,
You could use MVP to make things much easier and to make client code to
use only objects instead of primitive widgets such as listbox.
Here is some example that could make things more clear:
// this class should be used by your code
class CustomerListBox {
interface Display {
void addListBoxItem(String item);
void removeListBoxItem(Integer index);
//.....
Integer getSelectedItemIndex();
}
private final Display display;
private final List<Customer> customers = new ArrayList<Customer>();
public CustomerListBox(Display display) {
this.display = display;
}
public void addCustomer(Customer customer) {
display.addListBoxItem(customer.getCustomerName());
customers.add(customer);
}
public Customer getSelectedCustomer() {
return customer.get(display.getSelectedItemIndex());
}
public void go(HasWidgets parent) {
parent.add((Widget)display);
}
}
class CustomerListBoxDisplay extends Composite implements
CustomerListBox.Display {
private ListBox listBox = new ListBox();
public CustomerListBoxDisplay() {
initWidget(listBox);
}
public Integer getSelectedItemIndex() {
return listBox.getSelectedIndex();
}
// and etc
}
CustomerListBox customerListBox = new CustomerListBox(new
CustomerListBoxDisplay());
customerListBox.addCustomer(new Customer("1"));
customerListBox.addCustomer(new Customer("2"));
Customer selectedCustomer = customerListBox.getSelectedCustomer();
and etc
Hope this would help.
Regards,
Miroslav
> --
>
> 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-we...@googlegroups.com.
> To unsubscribe from this group, send email to
google-web-tool...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=.
>
>