PDA

View Full Version : Custom PropertyEditor / ValueBaseInputCell



p33t
18 Apr 2012, 11:39 PM
I'm trying to write a custom field editor that will translate between Long and String. IE: String representation on screen but field type is a Long.

I've implemented the PropertyEditor (HrMinPropertyEditor (http://subversion.assembla.com/svn/freshcode_public/learn/gwt/src/main/java/biz/freshcode/learn/gwt/client/experiment/forms/HrMinPropertyEditor.java)) but don't know how to wire it in. My HrMinField (http://subversion.assembla.com/svn/freshcode_public/learn/gwt/src/main/java/biz/freshcode/learn/gwt/client/experiment/forms/HrMinField.java) is quite clunky as I needed to use a TriggerFieldCell because the generic types inside TextInputCell prevented me from using it.

Do I need to do a subclass of ValueBaseInputCell? That seems strange since my PropertyEditor has all the Long / String conversions. It also looks difficult.

If so, is there a simple example or some documentation I can read?

BTW, my learning project is Maven based and should be easy to fire up if necessary:

svn checkout http://subversion.assembla.com/svn/freshcode_public/learn/gwt/ learn-gwt
mvn gwt:run
Navigate to GXT | Forms | Time Edit


Thanks in advance,
Pete

p33t
23 Apr 2012, 6:07 PM
Well I managed to get something going using a Converter and a Validator. The code below uses a Builder to construct the UI but you should be able to get the gist...

From my PeriodBeanEditor (http://subversion.assembla.com/svn/freshcode_public/learn/gwt/src/main/java/biz/freshcode/learn/gwt/client/experiment/forms/PeriodBeanEditor.java):

@Ignore
TextField hrMinField;

ConverterEditorAdapter<Long, String, TextField> hrMin;

@Override
protected Widget createWidget() {
FlowLayoutContainer c = new FlowLayoutContainerBuilder()
.add(new FieldLabelBuilder()
.text("Hr Min")
.widget(hrMinField = new TextFieldBuilder()
.allowBlank(false)
.addValidator(HrMinConverter.VALIDATOR)
.textField)
.fieldLabel)
.flowLayoutContainer;
hrMin = new ConverterEditorAdapter(hrMinField, HrMinConverter.INSTANCE);
return c;
}


From my HrMinConverter (http://subversion.assembla.com/svn/freshcode_public/learn/gwt/src/main/java/biz/freshcode/learn/gwt/client/experiment/forms/HrMinConverter.java):

public class HrMinConverter implements Converter<Long, String> {
private static final String RE_STR = "^(-?)(\\d+)(:([0-5]?)(\\d))?$";
public static final RegExp RE = RegExp.compile(RE_STR);
public static final String RE_MSG = "Must be in the form '-h:m', '-' and ':m' are optional";
public static final HrMinConverter INSTANCE = new HrMinConverter();
public static final RegExValidator VALIDATOR = new RegExValidator(RE_STR, RE_MSG);
...


For what it's worth I'm trying to publish the bean builder generator tool (b-generation (http://www.assembla.com/spaces/b-generation/wiki/)) so I can use it in various places.