Example usage for com.google.gwt.event.dom.client FocusHandler FocusHandler

List of usage examples for com.google.gwt.event.dom.client FocusHandler FocusHandler

Introduction

In this page you can find the example usage for com.google.gwt.event.dom.client FocusHandler FocusHandler.

Prototype

FocusHandler

Source Link

Usage

From source file:com.ephesoft.gxt.rv.client.widget.ValidatableCheckBox.java

License:Open Source License

private void addFocusHandler() {

    this.addFocusHandler(new FocusHandler() {

        @Override//w  w w .  j a va  2  s.c  o  m
        public void onFocus(final FocusEvent event) {
            addStyleName("checkBoxFocus");
            if (ReviewValidateNavigator.isPageSelectionEnable()) {
                ReviewValidateEventBus.fireEvent(new PageSelectionEvent(bindedField.getPage()));
            }
            Validatable lastSelectedWidget = ReviewValidateNavigator.getLastSelectedWidget();
            boolean valueChanged = false;
            if (ReviewValidateNavigator.getCurrentSelectedDocField() != null && lastSelectedWidget != null) {
                if (lastSelectedWidget instanceof DLFSuggestionBox) {
                    valueChanged = DLFSuggestionBox.isValueChanged();
                }
            }
            ReviewValidateNavigator.setCurrentSelectedDocField(bindedField, valueChanged);
        }
    });

    this.addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(final BlurEvent event) {
            removeStyleName("checkBoxFocus");
        }
    });
}

From source file:com.explicatis.ext_token_field.client.ExtTokenFieldWidget.java

License:Apache License

protected TokenWidget buildTokenWidget(final Token token) {
    final TokenWidget widget = new TokenWidget(this, token, tokenActions) {

        @Override//  www .ja va2s.  c o  m
        protected void onTokenActionClicked(TokenAction tokenAction) {
            tokenActionClicked(this, tokenAction);
        }

        @Override
        protected void buildIcon(final TokenAction action, final Anchor actionAnchor) {
            if (icons != null && icons.containsKey(action)) {
                Icon icon = applicationConnection.getIcon(icons.get(action));
                actionAnchor.getElement().insertBefore(icon.getElement(), null);
            }
        }
    };
    widget.addFocusHandler(new FocusHandler() {

        @Override
        public void onFocus(FocusEvent event) {
            widget.getElement().addClassName(TokenWidget.FOCUS_CLASS_NAME);
        }
    });

    widget.addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(BlurEvent event) {
            widget.getElement().removeClassName(TokenWidget.FOCUS_CLASS_NAME);
        }
    });

    widget.addKeyDownHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_LEFT) {
                leftKeyDown(widget);
            } else if (event.getNativeKeyCode() == KeyCodes.KEY_RIGHT) {
                rightKeyDown(widget);
            } else if (event.getNativeKeyCode() == KeyCodes.KEY_DELETE) {
                TokenAction deleteTokenAction = findTokenAction(TokenAction.DELETE_TOKEN_ACTION_IDENTIFIER);
                if (deleteTokenAction != null) {
                    if (isEnabled() && !isReadOnly()) {
                        tokenActionClicked(widget, deleteTokenAction);
                    }
                }
            }
        }
    });
    return widget;
}

From source file:com.gafactory.core.client.ui.suggestions.SuggestedEditor.java

License:Open Source License

public SuggestedEditor(Renderer<T> renderer, BaseDataProxy<T> dataProxy, ValueProvider<T, String> searchField) {
    this.renderer = renderer;

    if (dataProxy == null) {
        oracle = new MultiWordSuggestOracle();
    } else {/*  w  ww.ja v  a  2 s  .  c  om*/
        oracle = new BaseSuggestOracle<T>(dataProxy, renderer, searchField);

    }

    final TextBox box = new TextBox();
    suggestBox = new SuggestBox(oracle, box, new SuggestionDisplayImpl());
    box.setStyleName("form-control");

    box.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            scheduleShowSuggestList();

        }
    });

    box.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) {
                if (getValue() != null) {
                    setValue(null);
                    scheduleShowSuggestList();
                }
            }
        }
    });

    suggestBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) {
            if (event.getSelectedItem() instanceof Suggestion) {
                Suggestion<T> selectedItem = (Suggestion) event.getSelectedItem();
                setValue(selectedItem.getValue(), true);
            } else {
                final String replacementString = event.getSelectedItem().getReplacementString();
                setValue(replacementMap.get(replacementString), true);
            }

            SelectionEvent.fire(SuggestedEditor.this, value);

        }
    });

    InputGroup inputGroup = createGroup(suggestBox);

    initWidget(inputGroup);
}

From source file:com.goodow.wave.client.search.SearchBox.java

License:Apache License

public SearchBox() {
    initWidget(uiBinder.createAndBindUi(this));
    textBox.addFocusHandler(new FocusHandler() {

        @Override/*from w w w  .  j av a  2  s. c o m*/
        public void onFocus(final FocusEvent arg0) {
            root.getElement().setAttribute("focused", "");
        }
    });
    textBox.addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(final BlurEvent arg0) {
            root.getElement().removeAttribute("focused");
        }
    });
}

From source file:com.google.api.explorer.client.embedded.RequestBodyForm.java

License:Apache License

/**
 * Bind the free form and schema based editors together so that when the user switches the data is
 * moved between editors.//from w ww  . ja  v a  2s  .  c  om
 */
private void setupEditorDataBinding() {
    // Add a handler to clear body error message when the user intends to edit
    // the text.
    requestBody.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            editorSwitchError.setVisible(false);
        }
    });

    requestBody.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            resizeTextArea();
        }
    });

    requestBody.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            resizeTextArea();
        }
    });

    requestBody.addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {
            resizeTextArea();
        }
    });
}

From source file:com.google.appinventor.client.widgets.properties.TextPropertyEditorBase.java

License:Open Source License

/**
 * Creates a new instance of the property editor.
 *///from  w  w  w.j  a v a  2 s .  c  o m
public TextPropertyEditorBase(final TextBoxBase widget) {

    textEdit = widget;

    textEdit.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            handleKeyPress(event.getCharCode());
        }
    });
    textEdit.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            handleKeyUp(event.getNativeKeyCode());
        }
    });
    textEdit.addValueChangeHandler(new ValueChangeHandler() {
        @Override
        public void onValueChange(ValueChangeEvent event) {
            validateText();
        }
    });

    // NOTE(lizlooney) - The following handlers for focus, blur, and click are needed to workaround
    // a bug with WebKit browsers (chrome and safari) where clicking in the TextBox causes it to
    // gain focus, but then immediately lose focus (blur). To work around the problem, we keep
    // track of whether the TextBox has focus using a FocusHandler and a BlurHandler. Then, we use
    // a ClickHandler and if we get a ClickEvent and the TextBox does not have focus, we explicitly
    // call setFocus.
    textEdit.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            hasFocus = true;
        }
    });
    textEdit.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            hasFocus = false;
            // Calling validateText here means that we will save the changed property value (if it is
            // valid) when this property editor loses focus (for example, when the user clicks on
            // another property editor).
            validateText();
        }
    });
    textEdit.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (!hasFocus) {
                textEdit.setFocus(true);
            }
        }
    });

    initWidget(textEdit); //kludge for now fix this with instanceOf?

    setHeight("2em");
}

From source file:com.google.caja.demos.playground.client.ui.PlaygroundView.java

License:Apache License

private void initSourcePanel() {
    for (Example eg : Example.values()) {
        sourceExamples.add(eg.url);/*from  ww w  . j a  v  a 2 s  .c om*/
    }
    playgroundUI.addressField.getTextBox().addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            playgroundUI.addressField.showSuggestionList();
        }
    });
    playgroundUI.addressField.setText("https://");

    playgroundUI.goButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            controller.loadSource(playgroundUI.addressField.getText());
        }
    });
    playgroundUI.cajoleButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            playgroundUI.runtimeMessages.clear();
            playgroundUI.renderPanel.setText("");
            playgroundUI.renderTime.setText("Unknown");
            controller.cajole(playgroundUI.addressField.getText(), playgroundUI.sourceText.getText(),
                    playgroundUI.policyText.getText(), true /* debug */, genId());
        }
    });
}

From source file:com.google.caja.demos.playground.client.ui.PlaygroundView.java

License:Apache License

private void initPolicyPanel() {
    policyExamples = new MultiWordSuggestOracle();
    playgroundUI.policyAddressField = new SuggestBox(policyExamples);
    playgroundUI.policyAddressField.getTextBox().addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            playgroundUI.policyAddressField.showSuggestionList();
        }/*from  w  w  w .  j a  va2  s.  c om*/
    });
    playgroundUI.policyAddressField.setText("http://");

    playgroundUI.clearButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            controller.clearPolicy();
        }
    });

    playgroundUI.loadButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            controller.loadPolicy(playgroundUI.policyAddressField.getText());
        }
    });

    playgroundUI.defaultButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            setPolicySource(defaultPolicy());
        }
    });

    setPolicySource(defaultPolicy());
}

From source file:com.google.gerrit.client.diff.SideBySide.java

License:Apache License

@Override
FocusHandler getFocusHandler() {/*from  w  ww.  j  a va 2 s  .  co m*/
    return new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            cmB.focus();
        }
    };
}

From source file:com.google.gerrit.client.diff.SideBySide2.java

License:Apache License

@Override
public void registerKeys() {
    super.registerKeys();

    keysNavigation.add(new UpToChangeCommand2(revision, 0, 'u'));
    keysNavigation.add(new NoOpKeyCommand(KeyCommand.M_SHIFT, KeyCodes.KEY_LEFT, PatchUtil.C.focusSideA()),
            new NoOpKeyCommand(KeyCommand.M_SHIFT, KeyCodes.KEY_RIGHT, PatchUtil.C.focusSideB()));
    keysNavigation.add(new NoOpKeyCommand(0, 'j', PatchUtil.C.lineNext()),
            new NoOpKeyCommand(0, 'k', PatchUtil.C.linePrev()));
    keysNavigation.add(new NoOpKeyCommand(0, 'n', PatchUtil.C.chunkNext2()),
            new NoOpKeyCommand(0, 'p', PatchUtil.C.chunkPrev2()));
    keysNavigation.add(new NoOpKeyCommand(KeyCommand.M_SHIFT, 'n', PatchUtil.C.commentNext()),
            new NoOpKeyCommand(KeyCommand.M_SHIFT, 'p', PatchUtil.C.commentPrev()));
    keysNavigation.add(new NoOpKeyCommand(KeyCommand.M_CTRL, 'f', Gerrit.C.keySearch()));

    keysAction = new KeyCommandSet(Gerrit.C.sectionActions());
    keysAction.add(new NoOpKeyCommand(0, KeyCodes.KEY_ENTER, PatchUtil.C.expandComment()));
    keysAction.add(new NoOpKeyCommand(0, 'o', PatchUtil.C.expandComment()));
    keysAction.add(new NoOpKeyCommand(KeyCommand.M_SHIFT, 'o', PatchUtil.C.expandAllCommentsOnCurrentLine()));
    if (Gerrit.isSignedIn()) {
        keysAction.add(new KeyCommand(0, 'r', PatchUtil.C.toggleReviewed()) {
            @Override//from   ww  w  .ja  va 2s .c  o m
            public void onKeyPress(KeyPressEvent event) {
                header.toggleReviewed().run();
            }
        });
    }
    keysAction.add(new KeyCommand(KeyCommand.M_SHIFT, 'm', PatchUtil.C.markAsReviewedAndGoToNext()) {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            header.reviewedAndNext().run();
        }
    });
    keysAction.add(new KeyCommand(0, 'a', PatchUtil.C.openReply()) {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            upToChange(true).run();
        }
    });
    keysAction.add(new KeyCommand(KeyCommand.M_SHIFT, 'a', PatchUtil.C.toggleSideA()) {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            diffTable.toggleA().run();
        }
    });
    keysAction.add(new KeyCommand(0, ',', PatchUtil.C.showPreferences()) {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            prefsAction.show();
        }
    });
    if (getIntraLineStatus() == DiffInfo.IntraLineStatus.OFF
            || getIntraLineStatus() == DiffInfo.IntraLineStatus.OK) {
        keysAction.add(new KeyCommand(0, 'i', PatchUtil.C.toggleIntraline()) {
            @Override
            public void onKeyPress(KeyPressEvent event) {
                toggleShowIntraline();
            }
        });
    }

    if (Gerrit.isSignedIn()) {
        keysAction.add(new NoOpKeyCommand(0, 'c', PatchUtil.C.commentInsert()));
        keysComment = new KeyCommandSet(PatchUtil.C.commentEditorSet());
        keysComment.add(new NoOpKeyCommand(KeyCommand.M_CTRL, 's', PatchUtil.C.commentSaveDraft()));
        keysComment.add(new NoOpKeyCommand(0, KeyCodes.KEY_ESCAPE, PatchUtil.C.commentCancelEdit()));
    } else {
        keysComment = null;
    }

    removeKeyHandlerRegistrations();
    handlers.add(GlobalKey.add(this, keysAction));
    handlers.add(GlobalKey.add(this, keysNavigation));
    if (keysComment != null) {
        handlers.add(GlobalKey.add(this, keysComment));
    }
    handlers.add(ShowHelpCommand.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            cmB.focus();
        }
    }));
}