protected Widget createGotoWidget() {
final TextBox gotoPage = new TextBox();
int maxlen = String.valueOf(computeNumPages()).length();
gotoPage.setMaxLength(maxlen);
gotoPage.setVisibleLength(maxlen);
final PushButton go = new PushButton();
go.setStylePrimaryName(STYLE_GOTO_BUTTON);
go.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
setPage(Integer.parseInt(gotoPage.getText()) - 1);
gotoPage.setText("");
go.setEnabled(false);
fireChange();
}
});
go.setEnabled(false);
gotoPage.addKeyDownHandler(new KeyDownHandler() {
public void onKeyDown(final KeyDownEvent event) {
final int keyCode = event.getNativeKeyCode();
DeferredCommand.addCommand(new Command() {
public void execute() {
int page = -1;
try {
page = Integer.parseInt(gotoPage.getText()) - 1;
} catch(NumberFormatException e) {
}
go.setEnabled(page >= 0 && page < computeNumPages());
if(keyCode == KeyCodes.KEY_ENTER && go.isEnabled()) {
setPage(Integer.parseInt(gotoPage.getText()) - 1);
gotoPage.setText("");
go.setEnabled(false);
fireChange();
}
}
});
}