Tuesday, April 24, 2018

Re: Editor and enumeration or object cast

Do you know how to use this EnumEditor in a ui.xml file?  I tried this:
ui.xml:
...
        <thisPackage:EnumEditor styleName="WidgetWrapper-radioButton" ui:field="chemoTeachType"/>
...
java:
...
    @UiField
    EnumEditor<ChemoTeachType> chemoTeachType;
...

Where ChemoTeachType is my enum.

But I get this error from the GWT compiler:

...
            [ERROR] com.mscs.emr.web.dashboardcomp.client.patient.clinicalProfile.careplan2.EnumEditor has no default (zero args) constructor. To fix this, you can define a @UiFactory method on the UiBinder's owner, or annotate a constructor of EnumEditor with @UiConstructor.     [ERROR] Errors in 'com/mscs/emr/web/dashboardcomp/client/patient/clinicalProfile/careplan2/PatOcmHeaderEditor.java'        [ERROR] Line 36: Failed to resolve 'com.mscs.emr.web.dashboardcomp.client.patient.clinicalProfile.careplan2.PatOcmHeaderEditor.PatOcmHeaderEditorUiBinder' via deferred binding  
...

On Wednesday, November 17, 2010 at 2:20:07 PM UTC-8, mbmacri wrote:
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." <jerome.ca...@gmail.com> 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." <jerome.ca...@gmail.com> 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 "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment