Acá va un poco de luz ( here's a little bit of light ).
public class AccountManager extends Composite implements HasValueChangeHandlers<Integer> { public AccountManager() { ...... ...... ...... ...... initWidget(bar); } protected Integer getValue() { return <some value>; } private void loadAccounts() { AccountRemote.Util.getInstance().getAllAccount(new DefaultCallback() { @SuppressWarnings("unchecked") public void onSuccess(Object result) { if (result != null) { accounts = (List<Account>) result; // Save the accounts accountList.clear(); accountsHM.clear(); for (Account account : accounts) { accountList.addItem (account.getAccountName()); // Save the accounts accountsHM.put (account.getAccountName(), account); } // Update the list of the accounts in all clients ValueChangeEvent.fire (this,getValue()); } } }); public HandlerRegistration addValueChangeHandler(final ValueChangeHandler<Integer> handler) { return addHandler(handler,ValueChangeEvent.getType()); } } On 9 jun, 18:15, Iván López <lopez.i...@gmail.com> wrote: > Hi all!, > > I've a little problem upgrading my code from 1.5.3 to 1.6.4. I've > an AccountManager class that manages the accounts and when a change is > done it fires an event to all the components to update its list of > accounts. > > AccountManager: > > private ChangeListenerCollection changeListeners; > > public void addChangeListener(ChangeListener listener) { > if (changeListeners == null) { > changeListeners = new ChangeListenerCollection(); > } > changeListeners.add(listener); > } > public void removeChangeListener(ChangeListener listener) { > if (changeListeners != null) { > changeListeners.remove(listener); > } > } > private void fireChangeEvent() { > if (changeListeners != null) { > changeListeners.fireChange(accountMainPanel); > } > } > > private void loadAccounts() { > AccountRemote.Util.getInstance().getAllAccount(new > DefaultCallback() > { > > @SuppressWarnings("unchecked") > public void onSuccess(Object result) { > if (result != null) { > accounts = (List<Account>)result; > > // Save the accounts > accountList.clear(); > accountsHM.clear(); > for (Account account : accounts) { > > accountList.addItem(account.getAccountName()); > > // Save the accounts > > accountsHM.put(account.getAccountName(), account); > } > > // Update the list of the > accounts in all clients > fireChangeEvent(); > } > } > }); > } > > And in the clients I have this code: > // ChangeListener to update the account list whenever an > account > change is done. > ApplicationParameters.getInstance().getApplication > ().getAccountManager().addChangeListener(new ChangeListener() { > public void onChange(Widget sender) { > // Update the accounts > setFilterAccounts(ApplicationParameters.getInstance().getApplication > ().getAccountManager().getAccounts()); > } > }); > > Now I'm trying to update this code to use EventHandlers but I've no > idea what I should change. I've try with: > public HandlerRegistration addChangeHandler(ChangeHandler handler) { > return addDomHandler(handler, ChangeEvent.getType()); > } > > But I cann't control when fire the event, I mean, when I change > something the event is fired and the clients are updated even if it is > not necessary. > > Please, could someone bring me to the light :-). > > Thanks a lot. > > Regards, Iván. > > P.S: Excuse me for me poor english. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---