-
18 Apr 2012 11:39 PM #1
Answered: Custom PropertyEditor / ValueBaseInputCell
Answered: Custom PropertyEditor / ValueBaseInputCell
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) but don't know how to wire it in. My HrMinField 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/f...lic/learn/gwt/ learn-gwt
- mvn gwt:run
- Navigate to GXT | Forms | Time Edit
Thanks in advance,
Pete
-
Best Answer Posted by p33t
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:
From my HrMinConverter:Code:@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; }
For what it's worth I'm trying to publish the bean builder generator tool (b-generation) so I can use it in various places.Code: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); ...
-
23 Apr 2012 6:07 PM #2
Converter + Validator Solution
Converter + Validator Solution
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:
From my HrMinConverter:Code:@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; }
For what it's worth I'm trying to publish the bean builder generator tool (b-generation) so I can use it in various places.Code: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); ...


Reply With Quote