On Sunday, February 3, 2013 9:25:12 PM UTC+1, BM wrote:
>
> Not sure I am following "wraps a ListBox rather than extends ListBox 
> really means. Would appreciate if you can provide some explanation. 



   1. Take your class
   2. Remove "extends ListBox"
   3. Adds 'private final ListBox listBox' field and constructor that 
   initializes it
   4. prefix all ListBox methods with "listBox." (i.e. invoke them on 
   'listBox' rather than 'this')

 

>
>
> But here is what I came up with. 
> public class WatchedListBoxesWrap extends ListBox implements 
> HasValue<String> {
>     
>     /**
>      * Flag indicating if the handler have been already initialized or not
>      */
>     private boolean valueChangeHandlerInitialized;
>
>     /*
>      * (non-Javadoc)
>      * 
>      * @see com.google.gwt.user.client.ui.HasValue#getValue()
>      */
>     @Override
>     public String getValue() {
>             return getItemText(getSelectedIndex());
>     }
>
>     /*
>      * (non-Javadoc)
>      * 
>      * @see 
> com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object)
>      */
>     @Override
>     public void setValue(String value) {
>             for (int i = 0; i < getItemCount(); i++) {
>                     if (getItemText(i).equals(value)) {
>                             setSelectedIndex(i);
>                             break;
>                     }
>             }
>     }
>
>     /*
>      * (non-Javadoc)
>      * 
>      * @see 
> com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object,
>      * boolean)
>      */
>     @Override
>     public void setValue(String value, boolean arg1) {
>             setValue(value);
>             if (arg1)
>                     ValueChangeEvent.fire(this, value);
>     }
>
>     /*
>      * (non-Javadoc)
>      * 
>      * @seecom.google.gwt.event.logical.shared.HasValueChangeHandlers#
>      * addValueChangeHandler
>      * (com.google.gwt.event.logical.shared.ValueChangeHandler)
>      */
>     @Override
>     public HandlerRegistration addValueChangeHandler(
>                     ValueChangeHandler<String> handler) {
>             // Initialization code
>             if (!valueChangeHandlerInitialized) {
>                     valueChangeHandlerInitialized = true;
>                     addChangeHandler(new ChangeHandler() {
>                             public void onChange(ChangeEvent event) {
>                                     
> ValueChangeEvent.fire(WatchedListBoxesWrap.this, getValue());
>                             }
>                     });
>             }
>             return addHandler(handler, ValueChangeEvent.getType());
>     }
>
> }
>
> What do you think?
>
> On Friday, February 1, 2013 5:31:57 PM UTC-6, Thomas Broyer wrote:
>>
>>
>>
>> On Friday, February 1, 2013 11:11:49 PM UTC+1, BM wrote:
>>>
>>> Thanks Jens and Thomas! Appreciate your quick response. Always learning 
>>> new in GWT! 
>>>
>>> I am not sure the exact difference between ListBox and ValueListbox.
>>>
>>
>> ValueListBox produces the same DOM as ListBox but is "data oriented", a 
>> bit more high-level.
>>  
>>
>>> I can make a custom ListBox called WrappedListBox which extends ListBox 
>>> and implements HasValue<String>. I think that is what you are referring 
>>> here right?
>>>
>>
>> I was more referring to a class that implements HasValue and wraps a 
>> ListBox (rather than extends ListBox).
>>  
>>
>>> But I sometimes get confused that I have to inherit bunch of methods for 
>>> getValue, SetValue and  
>>>
>>> addValueChangeHandler. So do I keep the implementation of getvalue, 
>>> SetValue and addValueChangeHandler  all blank? and just do implementation 
>>> of addValueChangeHandler and copy the method implementation of 
>>> ValueListBox. addValueChangeHandler in that?
>>>
>>>>
>>>>
>> http://turbomanage.wordpress.com/2010/04/01/selectonelistbox-for-use-with-gwtmvp/has
>>  an example. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to