Friday, February 21, 2014

Composite widget that behaves as a single Editor

I have a composite widget composed by 3 TextBoxes that acts as a "date mask" field, like:[dd]/[mm]/[yyy] (dont ask why I am doing this :), I dont like DateBox and I have to force the user to keep given  format, so I wrote my own widget). Here is the java code:

import com.google.gwt.core.client.GWT;  import com.google.gwt.event.dom.client.KeyUpEvent;  import com.google.gwt.uibinder.client.UiBinder;  import com.google.gwt.uibinder.client.UiField;  import com.google.gwt.uibinder.client.UiHandler;  import com.google.gwt.user.client.ui.Composite;`enter code here`  import com.google.gwt.user.client.ui.TextBox;  import com.google.gwt.user.client.ui.Widget;    public class DateMaskWidget extends Composite {    private static DateMaskWidgetUiBinder uiBinder = GWT          .create(DateMaskWidgetUiBinder.class);    interface DateMaskWidgetUiBinder extends UiBinder<Widget, DateMaskWidget> {  }    @UiField  TextBox daysTextbox;  @UiField  TextBox monthsTextbox;  @UiField  TextBox yearsTextbox;    public DateMaskWidget() {      initWidget(uiBinder.createAndBindUi(this));        daysTextbox.setMaxLength(2);      monthsTextbox.setMaxLength(2);      yearsTextbox.setMaxLength(4);  }    @UiHandler("daysTextbox")   void onKeyUp(KeyUpEvent event)  {      //if 2 chars were entered focus the next box      if(daysTextbox.getText().length()==daysTextbox.getMaxLength())          monthsTextbox.setFocus(true);  }  @UiHandler("monthsTextbox")   void onKeyUp2(KeyUpEvent event)  {      //if 2 chars were entered focus the next box      if(monthsTextbox.getText().length()==monthsTextbox.getMaxLength())          yearsTextbox.setFocus(true);  }      }

Now I'd like this widget to behave as a single Editor (like a single TextBox), so i can set a value to it by passing a string like xx/xx/xxxx .

The Question is: which interface do I need to implement and which methods do I need to override to achive this?? Which methods are used in the editor framework to set/get the value of an editor??

In the background, I will need to take the given string (probably passed in a method like setValue() ), split it in 3 parts, and assign each part to the right text box. And same thing for a getValue() method.

Thanks for your help

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment