public static void emptyText(HasText hasTextWidget) {
boolean changed = false;
int baseLength = hasTextWidget.getText().length();
for (int i = 0; i < baseLength; i++) {
Event keyDownEvent = EventBuilder.create(Event.ONKEYDOWN).setKeyCode(
KeyCodes.KEY_BACKSPACE).build();
dispatchEvent((IsWidget) hasTextWidget, keyDownEvent);
boolean keyDownEventPreventDefault = JavaScriptObjects.getBoolean(keyDownEvent,
JsoProperties.EVENT_PREVENTDEFAULT);
if (!keyDownEventPreventDefault) {
hasTextWidget.setText(hasTextWidget.getText().substring(0,
hasTextWidget.getText().length() - 1));
changed = true;
}
}
// don't have to check if the event can be dispatch since it's check
// before
Event keyUpEvent = EventBuilder.create(Event.ONKEYUP).setKeyCode(KeyCodes.KEY_BACKSPACE).build();
dispatchEvent((IsWidget) hasTextWidget, keyUpEvent);
dispatchEvent((IsWidget) hasTextWidget, EventBuilder.create(Event.ONBLUR).build());
if (changed) {