Search in sources :

Example 31 with TextBox

use of com.google.gwt.user.client.ui.TextBox in project gerrit by GerritCodeReview.

the class CopyableLabel method showTextBox.

private void showTextBox() {
    if (textBox == null) {
        textBox = new TextBox();
        textBox.setText(getText());
        textBox.setVisibleLength(visibleLen);
        textBox.setReadOnly(true);
        textBox.addKeyPressHandler(new KeyPressHandler() {

            @Override
            public void onKeyPress(final KeyPressEvent event) {
                if (event.isControlKeyDown() || event.isMetaKeyDown()) {
                    switch(event.getCharCode()) {
                        case 'c':
                        case 'x':
                            textBox.addKeyUpHandler(new KeyUpHandler() {

                                @Override
                                public void onKeyUp(final KeyUpEvent event) {
                                    Scheduler.get().scheduleDeferred(new Command() {

                                        @Override
                                        public void execute() {
                                            hideTextBox();
                                        }
                                    });
                                }
                            });
                            break;
                    }
                }
            }
        });
        textBox.addBlurHandler(new BlurHandler() {

            @Override
            public void onBlur(final BlurEvent event) {
                hideTextBox();
            }
        });
        content.insert(textBox, 1);
    }
    textLabel.setVisible(false);
    textBox.setVisible(true);
    Scheduler.get().scheduleDeferred(new Command() {

        @Override
        public void execute() {
            textBox.selectAll();
            textBox.setFocus(true);
        }
    });
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Command(com.google.gwt.user.client.Command) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) TextBox(com.google.gwt.user.client.ui.TextBox) BlurEvent(com.google.gwt.event.dom.client.BlurEvent) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler)

Aggregations

TextBox (com.google.gwt.user.client.ui.TextBox)31 Test (org.junit.Test)10 Label (com.google.gwt.user.client.ui.Label)9 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)7 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)6 Grid (com.google.gwt.user.client.ui.Grid)4 HashMap (java.util.HashMap)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 KeyPressEvent (com.google.gwt.event.dom.client.KeyPressEvent)2 KeyPressHandler (com.google.gwt.event.dom.client.KeyPressHandler)2 CheckBox (com.google.gwt.user.client.ui.CheckBox)2 FlexTable (com.google.gwt.user.client.ui.FlexTable)2 HTML (com.google.gwt.user.client.ui.HTML)2 AttributeDefinition (cz.metacentrum.perun.webgui.model.AttributeDefinition)2 ThemedButton (org.rstudio.core.client.widget.ThemedButton)2 StringListPanel (com.google.gerrit.client.StringListPanel)1 AccessMap (com.google.gerrit.client.access.AccessMap)1