Java 类com.google.gwt.user.client.ui.KeyboardListenerAdapter 实例源码

项目:ephesoft    文件:ValidatePanel.java   
public ValidatePanel() {
    super();
    initWidget(BINDER.createAndBindUi(this));
    scrollPanel.addStyleName(ReviewValidateConstants.OVERFLOW_SCROLL);
    scrollValidationTableFocusPanel.add(validationTable);
    scrollValidationTableFocusPanel.setHeight("98%");
    scrollValidationTableFocusPanel.setWidth("99%");
    scrollPanel.setHeight("100%");
    scrollPanel.add(scrollValidationTableFocusPanel);
    fuzzySearchBtn = new Button();
    showTableViewBtn = new Button();
    showTableViewBtn.setStyleName("tableViewButton");
    showTableViewBtn.setTitle(LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_TABLE_VIEW_TOOLTIP));
    fuzzySearchText = new TextBox();
    fuzzySearchBtn.setText(LocaleDictionary.get().getConstantValue(ReviewValidateConstants.FUZZY_SEARCH_GO_BTN));
    fuzzySearchBtn.setTitle(LocaleDictionary.get().getConstantValue(ReviewValidateConstants.FUZZY_SEARCH_TOOLTIP));
    fuzzySearchBtn.setStyleName("fuzzySearchButton");

    fuzzySearchTextBox = new ValidatableWidget<TextBox>(fuzzySearchText);
    fuzzySearchTextBox.getWidget().addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            fuzzySearchTextBox.toggleValidDateBox();
            fuzzySearchTextBox.getWidget().addStyleName("validatePanelListBox");
        }
    });
    // fuzzySearchTextBox.addValidator(new EmptyStringValidator(fuzzySearchText));
    fuzzySearchTextBox.getWidget().addStyleName("validatePanelListBox");
    fuzzySearchText.addKeyboardListener(new KeyboardListenerAdapter() {

        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            if (keyCode == (char) KEY_ENTER) {
                fuzzySearchBtn.click();
            }
        }
    });

    showTableViewBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent arg0) {
            presenter.setTableView(Boolean.TRUE);
            presenter.onTableViewButtonClicked();
        }
    });

    fuzzySearchBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            ScreenMaskUtility.maskScreen();
            String value = fuzzySearchText.getValue();
            if (null == value || value.trim().isEmpty()) {
                final ConfirmationDialog confirmationDialog = ConfirmationDialogUtil.showConfirmationDialog(LocaleDictionary.get()
                        .getMessageValue(ReviewValidateMessages.MSG_FUZZY_SEARCH_INVALID_ENTRY), LocaleDictionary.get()
                        .getConstantValue(ReviewValidateConstants.FUZZY_SEARCH_TOOLTIP), Boolean.TRUE);
                confirmationDialog.addDialogListener(new DialogListener() {

                    @Override
                    public void onOkClick() {
                        confirmationDialog.hide();
                        ScreenMaskUtility.unmaskScreen();
                        presenter.setFocus();
                    }

                    @Override
                    public void onCancelClick() {
                        ScreenMaskUtility.unmaskScreen();
                        presenter.setFocus();
                    }
                });

            } else {
                performFuzzySearch(value);
            }
            fuzzySearchText.setText("");
        }
    });

}
项目:onecmdb    文件:NewMaskTextFieldWidget.java   
public NewMaskTextFieldWidget(String labelText, String textMask) {
    super(labelText);
    mask = textMask;

    textBox.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            String text = ((TextBox) sender).getText();

            int length = text.length();
            if ((keyCode == (char) KEY_BACKSPACE) && length > 0) {
                //((TextBox) sender).setText(text.substring(0, length - 1));
                setText(text.substring(0, length - 1));
            }
            if ((keyCode == (char) KEY_TAB || keyCode == (char) KEY_ENTER))
                return;
            if (length >= mask.length()) {
                ((TextBox) sender).cancelKey();
                return;
            }
            int nextIndex = mask.indexOf('#', length);

            String currentMask = "";
            if (nextIndex >= 0)
                currentMask = mask.substring(length, nextIndex);
            else
                currentMask = mask.substring(length);
            String newText;
            if (Character.isDigit(keyCode)) {
                if (!currentMask.equals("#"))
                    newText = text + currentMask + String.valueOf(keyCode);
                else
                    newText = text + keyCode;
                //((TextBox) sender).setText(newText);
                setText(newText);
                ((TextBox) sender).setCursorPos(newText.length());
            }
            ((TextBox) sender).cancelKey();
        }

    });
}
项目:OneCMDBwithMaven    文件:NewMaskTextFieldWidget.java   
public NewMaskTextFieldWidget(String labelText, String textMask) {
    super(labelText);
    mask = textMask;

    textBox.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            String text = ((TextBox) sender).getText();

            int length = text.length();
            if ((keyCode == (char) KEY_BACKSPACE) && length > 0) {
                //((TextBox) sender).setText(text.substring(0, length - 1));
                setText(text.substring(0, length - 1));
            }
            if ((keyCode == (char) KEY_TAB || keyCode == (char) KEY_ENTER))
                return;
            if (length >= mask.length()) {
                ((TextBox) sender).cancelKey();
                return;
            }
            int nextIndex = mask.indexOf('#', length);

            String currentMask = "";
            if (nextIndex >= 0)
                currentMask = mask.substring(length, nextIndex);
            else
                currentMask = mask.substring(length);
            String newText;
            if (Character.isDigit(keyCode)) {
                if (!currentMask.equals("#"))
                    newText = text + currentMask + String.valueOf(keyCode);
                else
                    newText = text + keyCode;
                //((TextBox) sender).setText(newText);
                setText(newText);
                ((TextBox) sender).setCursorPos(newText.length());
            }
            ((TextBox) sender).cancelKey();
        }

    });
}