Hi.

Here is my EnumEditor implementation based on a ListBox. It should
give you an idea of how to implement it using option buttons:

package com.leasingsaas.client.ui.widgets;

import java.util.HashMap;

import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.user.client.ui.ListBox;

public class EnumEditor<T extends Enum<T>> extends ListBox implements
LeafValueEditor<T> {
        Class<T> clazz;
        HashMap<T, Integer> index = new HashMap<T, Integer>();

        public EnumEditor(Class<T> e) {
                super();
                this.clazz = e;
                int idx = 0;
                for (T t : e.getEnumConstants()) {
                        this.addItem(t.toString());
                        index.put(t, idx);
                        idx++;
                }
        }

        @Override
        public void setValue(T value) {
                if (value == null) {
                        setSelectedIndex(-1);
                } else {
                        setSelectedIndex(index.get(value));
                }
        }

        @Override
        public T getValue() {
                int idx = getSelectedIndex();
                if (idx == -1)
                        return null;
                else {
                        System.out.println("Returning value of: " + 
getItemText(idx));
                        return Enum.valueOf(clazz, getItemText(idx));
                }
        }
}

On 16 nov, 07:58, "Jerome C." <[email protected]> wrote:
> nobody has an idea on how to manage enum with the neweditorframework
> without rewriting a class for each enum ?
>
> I just want to create a RadioButtonGroup which is used to editenumerationbut 
> I don't know how tocastmy enum...
>
> Any help is welcome.
>
> On 12 nov, 11:39, "Jerome C." <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > I try to create editors with neweditormechanism. How do you do when
> > your bean property is not the same that youreditor.
>
> > For example, how can I have aneditorwhich can editEnumeration?
>
> > I've tried to create a RadioButtonGroup which displays values of an
> >enumerationand try to make this class aneditor.
>
> > Here is the code: this is just a flow panel where each child is a
> > RadioButton
>
> > public class RadioButtonGroup<T extendsEnum<T>> extends FlowPanel
> > implements LeafValueEditor<T>
> > {
> >         public RadioButtonGroup()
> >         {
>
> >         }
>
> >         @Override
> >         public T getValue()
> >         {
> >                 T result = null;
>
> >                 for (int i = 0; i < getWidgetCount(); i++)
> >                 {
> >                         RadioButton radio = (RadioButton) getWidget(i);
>
> >                         if (radio.getValue())
> >                         {
> >                                 // ????????? how can Icastit ?
> >                                 result = radio.getFormValue();
> >                                 break;
> >                         }
> >                 }
>
> >                 return result;
> >         }
>
> >         @Override
> >         public void setValue(T value)
> >         {
> >                 for (int i = 0; i < getWidgetCount(); i++)
> >                 {
> >                         RadioButton radio = (RadioButton) getWidget(i);
>
> >                         if (radio.getFormValue().equals(value.toString()))
> >                         {
> >                                 radio.setValue(true);
> >                                 break;
> >                         }
> >                 }
> >         }
>
> > }
>
> > thanks for any help

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to