, , submit on enter, , enter , . , . , , FocusWidget, .
protected final KeyPressHandler submitOnEnterHandler = new KeyPressHandler()
{
@Override
public void onKeyPress(KeyPressEvent event)
{
char charCode = event.getCharCode();
if (submitOnEnter && (charCode == '\n' || charCode == '\r'))
{
final Object source = event.getSource();
final String beforeText;
if (source instanceof TextBoxBase)
beforeText = ((TextBoxBase) source).getText();
else
beforeText = null;
Scheduler.get().scheduleDeferred(new ScheduledCommand()
{
@Override
public void execute()
{
String afterText;
if (source instanceof TextBoxBase)
afterText = ((TextBoxBase) source).getText();
else
afterText = null;
if (beforeText.equals(afterText))
submit();
}
});
}
}
};