Example usage for com.google.gwt.user.client.ui TextBoxBase getValue

List of usage examples for com.google.gwt.user.client.ui TextBoxBase getValue

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui TextBoxBase getValue.

Prototype

@Override
public String getValue() 

Source Link

Document

Overridden to return "" from an empty text box.

Usage

From source file:com.google.gerrit.client.ui.OnEditEnabler.java

License:Apache License

private void on(final GwtEvent<?> e) {
    if (widget.isEnabled() || !(e.getSource() instanceof FocusWidget)
            || !((FocusWidget) e.getSource()).isEnabled()) {
        if (e.getSource() instanceof ValueBoxBase) {
            final TextBoxBase box = ((TextBoxBase) e.getSource());
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override/*from   w  w w  .j a  v a2 s . co  m*/
                public void execute() {
                    if (box.getValue().trim().length() == 0) {
                        widget.setEnabled(false);
                    }
                }
            });
        }
        return;
    }

    if (e.getSource() instanceof TextBoxBase) {
        onTextBoxBase((TextBoxBase) e.getSource());
    } else {
        // For many widgets, we can assume that a change is an edit. If
        // a widget does not work that way, it should be special cased
        // above.
        widget.setEnabled(true);
    }
}

From source file:com.googlesource.gerrit.plugins.emoticons.client.OnEditEnabler.java

License:Apache License

public OnEditEnabler(FocusWidget w, TextBoxBase tb) {
    this(w);
    originalValue = tb.getValue().trim();
    listenTo(tb);
}

From source file:com.googlesource.gerrit.plugins.emoticons.client.OnEditEnabler.java

License:Apache License

private void on(GwtEvent<?> e) {
    if (widget.isEnabled() || !(e.getSource() instanceof FocusWidget)
            || !((FocusWidget) e.getSource()).isEnabled()) {
        if (e.getSource() instanceof ValueBoxBase) {
            final TextBoxBase box = ((TextBoxBase) e.getSource());
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override/*  w  w w  .j av a  2 s .  co m*/
                public void execute() {
                    if (box.getValue().trim().equals(originalValue)) {
                        widget.setEnabled(false);
                    }
                }
            });
        }
        return;
    }

    if (e.getSource() instanceof TextBoxBase) {
        onTextBoxBase((TextBoxBase) e.getSource());
    } else {
        // For many widgets, we can assume that a change is an edit. If
        // a widget does not work that way, it should be special cased
        // above.
        widget.setEnabled(true);
    }
}

From source file:org.rstudio.studio.client.workbench.views.connections.ui.NewConnectionSnippetHost.java

License:Open Source License

private Grid createParameterizedUI(final NewConnectionInfo info) {
    final ArrayList<NewConnectionSnippetParts> snippetParts = parseSnippet(info.getSnippet());
    int visibleRows = snippetParts.size();
    int visibleParams = Math.min(visibleRows, maxRows_);

    // If we have a field that shares the first row, usually port:
    boolean hasSecondaryHeaderField = false;
    if (visibleParams >= 2 && snippetParts.get(0).getOrder() == snippetParts.get(1).getOrder()) {
        visibleRows--;/*from ww  w.j av  a2 s . com*/
        visibleParams++;
        hasSecondaryHeaderField = true;
    }

    boolean showAdvancedButton = visibleRows > maxRows_;
    visibleRows = Math.min(visibleRows, maxRows_);

    final ArrayList<NewConnectionSnippetParts> secondarySnippetParts = new ArrayList<NewConnectionSnippetParts>(
            snippetParts.subList(visibleParams, snippetParts.size()));

    final Grid connGrid = new Grid(visibleRows + 1, 4);
    connGrid.addStyleName(RES.styles().grid());

    connGrid.getCellFormatter().setWidth(0, 0, "150px");
    connGrid.getCellFormatter().setWidth(0, 1, "180px");
    connGrid.getCellFormatter().setWidth(0, 2, "60px");
    connGrid.getCellFormatter().setWidth(0, 3, "74px");

    for (int idxParams = 0, idxRow = 0; idxRow < visibleRows; idxParams++, idxRow++) {
        connGrid.getRowFormatter().setStyleName(idxRow, RES.styles().gridRow());

        final String key = snippetParts.get(idxParams).getKey();
        Label label = new Label(key + ":");
        label.addStyleName(RES.styles().label());
        connGrid.setWidget(idxRow, 0, label);
        connGrid.getRowFormatter().setVerticalAlign(idxRow, HasVerticalAlignment.ALIGN_TOP);

        String textboxStyle = RES.styles().textbox();

        if (idxRow == 0 && hasSecondaryHeaderField) {
            textboxStyle = RES.styles().firstTextbox();
        } else {
            connGrid.getCellFormatter().getElement(idxRow, 1).setAttribute("colspan", "4");
        }

        final TextBoxBase textboxBase;

        if (visibleRows == 1) {
            TextArea textarea = new TextArea();
            textarea.setVisibleLines(7);
            textarea.addStyleName(RES.styles().textarea());
            textarea.setText(snippetParts.get(idxParams).getValue());
            connGrid.setWidget(idxRow, 1, textarea);
            textboxBase = textarea;
        } else {
            TextBox textbox = new TextBox();
            textbox.setText(snippetParts.get(idxParams).getValue());
            textbox.addStyleName(textboxStyle);
            textboxBase = textbox;
        }

        connGrid.setWidget(idxRow, 1, textboxBase);

        textboxBase.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent arg0) {
                partsKeyValues_.put(key, textboxBase.getValue());
                updateCodePanel();
            }
        });

        if (idxRow == 0 && hasSecondaryHeaderField) {
            idxParams++;

            final String secondKey = snippetParts.get(idxParams).getKey();
            Label secondLabel = new Label(secondKey + ":");
            secondLabel.addStyleName(RES.styles().secondLabel());
            connGrid.setWidget(idxRow, 2, secondLabel);
            connGrid.getRowFormatter().setVerticalAlign(idxRow, HasVerticalAlignment.ALIGN_TOP);

            final TextBox secondTextbox = new TextBox();
            secondTextbox.setText(snippetParts.get(idxParams).getValue());
            secondTextbox.addStyleName(RES.styles().secondTextbox());
            connGrid.setWidget(idxRow, 3, secondTextbox);
            connGrid.getCellFormatter().getElement(idxRow, 3).setAttribute("colspan", "2");

            secondTextbox.addChangeHandler(new ChangeHandler() {
                @Override
                public void onChange(ChangeEvent arg0) {
                    partsKeyValues_.put(secondKey, secondTextbox.getValue());
                    updateCodePanel();
                }
            });
        }
    }

    HorizontalPanel buttonsPanel = new HorizontalPanel();
    buttonsPanel.addStyleName(RES.styles().buttonsPanel());

    final ThemedButton testButton = new ThemedButton("Test");
    testButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            testButton.setEnabled(false);
            server_.connectionTest(codePanel_.getCode(),
                    new DelayedProgressRequestCallback<String>("Testing Connection...") {
                        @Override
                        protected void onSuccess(String error) {
                            testButton.setEnabled(true);
                            if (StringUtil.isNullOrEmpty(error)) {
                                showSuccess();
                            } else {
                                showFailure(error);
                            }
                        }

                        @Override
                        public void onError(ServerError error) {
                            testButton.setEnabled(true);
                        }
                    });
        }
    });

    buttonsPanel.add(testButton);

    if (showAdvancedButton) {
        ThemedButton optionsButton = new ThemedButton("Advanced Options...", new ClickHandler() {
            public void onClick(ClickEvent event) {
                new NewConnectionSnippetDialog(new OperationWithInput<HashMap<String, String>>() {
                    @Override
                    public void execute(final HashMap<String, String> result) {
                        for (String key : result.keySet()) {
                            partsKeyValues_.put(key, result.get(key));
                        }
                        updateCodePanel();
                    }
                }, secondarySnippetParts, info).showModal();
            }
        });

        buttonsPanel.add(optionsButton);
    }

    connGrid.getRowFormatter().setStyleName(visibleRows, RES.styles().lastRow());
    connGrid.getCellFormatter().getElement(visibleRows, 1).setAttribute("colspan", "4");
    connGrid.setWidget(visibleRows, 1, buttonsPanel);

    return connGrid;
}