Example usage for com.google.gwt.user.client.ui SuggestBox SuggestBox

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

Introduction

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

Prototype

public SuggestBox(SuggestOracle oracle, ValueBoxBase<String> box) 

Source Link

Document

Constructor for SuggestBox .

Usage

From source file:cc.kune.core.client.sitebar.search.MultivalueSuggestBox.java

License:GNU Affero Public License

/**
 * Constructor./*  w  w  w. java  2s.  c o m*/
 * 
 * @param i18n
 * 
 * @param the
 *          URL for the REST endpoint. This URL should accept the parameters q
 *          (for query), indexFrom and indexTo
 * @param isMultivalued
 *          - true for allowing multiple values
 * @param onExactMatch
 * @param showNoResult
 *          if we have to show noResult message when the search is empty or
 *          not
 */
public MultivalueSuggestBox(final I18nTranslationService i18n, final boolean showNoResult,
        final String restEndpointUrl, final boolean isMultivalued, final OnExactMatch onExactMatch) {
    this.i18n = i18n;
    this.showNoResult = showNoResult;
    mrestEndpointUrl = restEndpointUrl;
    misMultivalued = isMultivalued;
    // this.onExactMatch = onExactMatch;

    final FlowPanel panel = new FlowPanel();
    TextBoxBase textfield;
    if (isMultivalued) {
        panel.addStyleName("textarearow");
        textfield = new TextArea();
    } else {
        panel.addStyleName("textfieldrow");
        textfield = new TextBox();
    }

    // Create our own SuggestOracle that queries REST endpoint
    final SuggestOracle oracle = new RestSuggestOracle();
    // intialize the SuggestBox
    mfield = new SuggestBox(oracle, textfield);
    if (isMultivalued) {
        // have to do this here b/c gwt suggest box wipes
        // style name if added in previous if
        textfield.addStyleName("multivalue");
    }
    mfield.addStyleName("wideTextField");
    mfield.addSelectionHandler(this);
    mfield.addKeyUpHandler(this);

    panel.add(mfield);
    mfeedback = new FormFeedback();
    // panel.add(mfeedback);

    initWidget(panel);

    /*
     * Create a Map that holds the values that should be stored. It will be
     * keyed on "display value", so that any time a "display value" is added or
     * removed the valueMap can be updated.
     */
    mvalueMap = new HashMap<String, String>();

    resetPageIndices();
}

From source file:cl.uai.client.page.EditMarkDialog.java

License:Open Source License

/**
 * Creates a comment dialog at a specific position
 * //from   w  w w . j  av a2  s . c o  m
 * @param posx Top position for the dialog
 * @param posy Left position for the dialog
 * @param level An optional rubric level in case we are editing one
 */
public EditMarkDialog(int posx, int posy, int level, int regradeid) {
    super(true, false);

    this.regradeId = regradeid;

    this.levelId = level;
    Level lvl = MarkingInterface.submissionData.getLevelById(levelId);

    if (EMarkingConfiguration.getKeywords() != null && EMarkingConfiguration.getKeywords().length() > 0) {
        logger.fine("Keywords: " + EMarkingConfiguration.getKeywords());
    }
    if (!EMarkingConfiguration.getKeywords().equals("") && (level > 0 || regradeid > 0)) {
        feedbackArray = new ArrayList<FeedbackObject>();
        feedbackPanel = new FeedbackInterface();
        feedbackPanel.setParent(this);
    } else {
        simplePanel = true;
    }

    superPanel = new HorizontalPanel();
    superPanel.addStyleName(Resources.INSTANCE.css().feedbackdialog());

    feedbackForStudent = new VerticalPanel();
    feedbackForStudent.addStyleName(Resources.INSTANCE.css().feedbackforstudent());

    feedbackSummary = new ScrollPanel(feedbackForStudent);
    feedbackSummary.addStyleName(Resources.INSTANCE.css().feedbacksummary());

    mainPanel = new VerticalPanel();
    mainPanel.addStyleName(Resources.INSTANCE.css().editmarkdialog());

    // Adds the CSS style and other settings
    this.addStyleName(Resources.INSTANCE.css().commentdialog());
    this.setAnimationEnabled(true);
    this.setGlassEnabled(true);

    bonusTxt = new TextBox();
    bonusTxt.addStyleName(Resources.INSTANCE.css().bonuslist());

    this.levelsList = new ListBox();
    this.levelsList.addStyleName(Resources.INSTANCE.css().levelslist());
    this.levelsList.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            int levelid = Integer.parseInt(levelsList.getValue(levelsList.getSelectedIndex()));
            levelId = levelid;
            Level lvl = MarkingInterface.submissionData.getLevelById(levelId);
            setBonus(lvl.getBonus());
        }
    });

    // If there's a rubric level we should edit a Mark
    // otherwise we are just editing its comment
    if (this.levelId == 0) {
        this.setHTML(MarkingInterface.messages.AddEditComment());
    } else {
        this.setHTML(MarkingInterface.messages.AddEditMark() + "<br/>" + lvl.getCriterion().getDescription());
    }

    // Position the dialog
    if (simplePanel) {
        this.setPopupPosition(posx, posy);
    } else {
        // The Dialog is more big, so we need to fix the position
        this.setPopupPosition((int) (Window.getClientWidth() * 0.08), (int) (Window.getClientHeight() * 0.15));
    }

    if (this.levelId > 0) {

        loadLevelsList();

        HorizontalPanel hpanelLevels = new HorizontalPanel();
        hpanelLevels.setWidth("100%");
        Label messages = new Label(MarkingInterface.messages.Level());
        hpanelLevels.add(messages);
        hpanelLevels.add(levelsList);
        hpanelLevels.setCellHorizontalAlignment(levelsList, HasHorizontalAlignment.ALIGN_RIGHT);
        mainPanel.add(hpanelLevels);
        mainPanel.setCellHorizontalAlignment(hpanelLevels, HasHorizontalAlignment.ALIGN_RIGHT);
    }

    // Save button
    Button btnSave = new Button(MarkingInterface.messages.Save());
    btnSave.addStyleName(Resources.INSTANCE.css().btnsave());
    btnSave.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (levelId > 0 && !bonusIsValid()) {
                Window.alert(MarkingInterface.messages.InvalidBonusValue());
                return;
            }
            cancelled = false;
            hide();
        }
    });

    // Cancel button
    Button btnCancel = new Button(MarkingInterface.messages.Cancel());
    btnSave.addStyleName(Resources.INSTANCE.css().btncancel());
    btnCancel.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            cancelled = true;
            hide();
        }
    });

    // The comment text box
    TextArea txt = new TextArea();
    txt.setVisibleLines(5);
    txt.getElement().getStyle().setMarginBottom(5, Unit.PT);
    txtComment = new SuggestBox(EMarkingWeb.markingInterface.previousCommentsOracle, txt);
    txtComment.setAutoSelectEnabled(false);
    txtComment.addStyleName(Resources.INSTANCE.css().editmarksuggestbox());

    HorizontalPanel hpanelComment = new HorizontalPanel();
    hpanelComment.setWidth("100%");
    hpanelComment.add(new Label(MarkingInterface.messages.Comment()));
    hpanelComment.add(txtComment);
    hpanelComment.setCellHorizontalAlignment(txtComment, HasHorizontalAlignment.ALIGN_RIGHT);
    mainPanel.add(hpanelComment);
    mainPanel.setCellHorizontalAlignment(hpanelComment, HasHorizontalAlignment.ALIGN_RIGHT);

    // If the rubric level is not null then create the bonus list and add it to the dialog 
    if (this.levelId > 0) {
        setBonus(lvl.getBonus());

        HorizontalPanel hpanelBonus = new HorizontalPanel();
        hpanelBonus.setWidth("100%");
        hpanelBonus.add(new Label(MarkingInterface.messages.SetBonus()));
        hpanelBonus.add(bonusTxt);
        hpanelBonus.setCellHorizontalAlignment(bonusTxt, HasHorizontalAlignment.ALIGN_RIGHT);
        if (EMarkingConfiguration.isFormativeFeedbackOnly()) {
            hpanelBonus.setVisible(false);
        }
        mainPanel.add(hpanelBonus);
        mainPanel.setCellHorizontalAlignment(hpanelBonus, HasHorizontalAlignment.ALIGN_RIGHT);
    }

    // The regrade comment text box
    txt = new TextArea();
    txt.setVisibleLines(5);
    txt.getElement().getStyle().setMarginBottom(5, Unit.PT);
    txtRegradeComment = new SuggestBox(EMarkingWeb.markingInterface.previousCommentsOracle, txt);

    if (this.regradeId > 0) {

        mainPanel.add(new HTML("<hr>"));
        mainPanel.add(new Label(MarkingInterface.messages.Regrade()));

        // Add the textbox
        HorizontalPanel hpanelRegradeComment = new HorizontalPanel();
        hpanelRegradeComment.setWidth("100%");
        hpanelRegradeComment.add(new Label(MarkingInterface.messages.RegradeComment()));
        hpanelRegradeComment.add(txtRegradeComment);
        hpanelRegradeComment.setCellHorizontalAlignment(txtRegradeComment, HasHorizontalAlignment.ALIGN_RIGHT);
        mainPanel.add(hpanelRegradeComment);
        mainPanel.setCellHorizontalAlignment(hpanelRegradeComment, HasHorizontalAlignment.ALIGN_RIGHT);
    }

    // Add buttons
    HorizontalPanel hpanel = new HorizontalPanel();
    hpanel.setSpacing(2);
    hpanel.setWidth("100%");
    hpanel.add(btnSave);
    hpanel.add(btnCancel);
    hpanel.setCellWidth(btnSave, "100%");
    hpanel.setCellWidth(btnCancel, "0px");
    hpanel.setCellHorizontalAlignment(btnCancel, HasHorizontalAlignment.ALIGN_RIGHT);
    hpanel.setCellHorizontalAlignment(btnSave, HasHorizontalAlignment.ALIGN_RIGHT);
    mainPanel.add(hpanel);
    mainPanel.setCellHorizontalAlignment(hpanel, HasHorizontalAlignment.ALIGN_RIGHT);

    if (simplePanel) {
        // No feedback
        this.setWidget(mainPanel);
    } else {
        // Remove CSS Style
        mainPanel.removeStyleName(Resources.INSTANCE.css().editmarkdialog());
        mainPanel.addStyleName(Resources.INSTANCE.css().editmarkdialogWithFeedback());

        bonusTxt.removeStyleName(Resources.INSTANCE.css().bonuslist());
        bonusTxt.addStyleName(Resources.INSTANCE.css().bonuslistWithFeedback());

        this.levelsList.removeStyleName(Resources.INSTANCE.css().levelslist());
        this.levelsList.addStyleName(Resources.INSTANCE.css().levelslistWithFeedback());

        txtComment.removeStyleName(Resources.INSTANCE.css().editmarksuggestbox());
        txtComment.addStyleName(Resources.INSTANCE.css().editmarksuggestboxWithFeedback());

        // Add feedback panel
        mainPanel.add(new HTML("<h4>Feedback</h4>"));
        mainPanel.add(feedbackSummary);

        superPanel.add(mainPanel);
        superPanel.add(feedbackPanel);
        this.setWidget(superPanel);
    }
}

From source file:com.google.api.explorer.client.FullView.java

License:Apache License

public FullView(URLManipulator urlManipulator, AuthManager authManager, AnalyticsManager analytics,
        SuggestOracle searchKeywords) {//from ww w  .  j a  v a 2s. c  om

    this.analytics = analytics;
    this.presenter = new FullViewPresenter(urlManipulator, this);
    this.authManager = authManager;
    PlaceholderTextBox searchBackingTextBox = new PlaceholderTextBox(
            "Search for services, methods, and recent requests...");
    this.searchBox = new SuggestBox(searchKeywords, searchBackingTextBox);

    searchBox.setAutoSelectEnabled(false);
    initWidget(uiBinder.createAndBindUi(this));
    setMenuActions();

    // Add a fixed css class name that I can use to be able to style the menu.
    settingsMenu.setStyleName(SETTINGS_MENU_CSS_RULE + " " + settingsMenu.getStyleName());

    // Set the style of the search box.
    searchBackingTextBox.setPlaceholderTextStyleName(style.searchPlaceholderText());
}

From source file:com.google.gerrit.client.account.MyWatchedProjectsScreen.java

License:Apache License

protected void createWidgets() {
    nameBox = new HintTextBox();
    nameTxt = new SuggestBox(new ProjectNameSuggestOracle(), nameBox);
    nameBox.setVisibleLength(50);// ww  w.  j av  a  2  s  .  c o m
    nameBox.setHintText(Util.C.defaultProjectName());
    nameBox.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            submitOnSelection = false;

            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                if (((DefaultSuggestionDisplay) nameTxt.getSuggestionDisplay()).isSuggestionListShowing()) {
                    submitOnSelection = true;
                } else {
                    doAddNew();
                }
            }
        }
    });
    nameTxt.addSelectionHandler(new SelectionHandler<Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            if (submitOnSelection) {
                submitOnSelection = false;
                doAddNew();
            }
        }
    });

    filterTxt = new HintTextBox();
    filterTxt.setVisibleLength(50);
    filterTxt.setHintText(Util.C.defaultFilter());
    filterTxt.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                doAddNew();
            }
        }
    });

    addNew = new Button(Util.C.buttonWatchProject());
    addNew.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            doAddNew();
        }
    });

    browse = new Button(Util.C.buttonBrowseProjects());
    browse.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            int top = grid.getAbsoluteTop() - 50; // under page header
            // Try to place it to the right of everything else, but not
            // right justified
            int left = 5 + Math.max(grid.getAbsoluteLeft() + grid.getOffsetWidth(),
                    watchesTab.getAbsoluteLeft() + watchesTab.getOffsetWidth());
            projectsPopup.setPreferredCoordinates(top, left);
            projectsPopup.displayPopup();
        }
    });

    watchesTab = new MyWatchesTable();

    delSel = new Button(Util.C.buttonDeleteSshKey());
    delSel.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            watchesTab.deleteChecked();
        }
    });
}

From source file:com.google.gerrit.client.admin.AccessRightEditor.java

License:Apache License

protected void initWidgets() {
    catBox = new ListBox();
    catBox.addChangeHandler(new ChangeHandler() {
        @Override/*  ww w. j a va  2s  . com*/
        public void onChange(final ChangeEvent event) {
            updateCategorySelection();
        }
    });

    nameTxt = new HintTextBox();
    nameSug = new SuggestBox(new RPCSuggestOracle(new AccountGroupSuggestOracle()), nameTxt);
    nameTxt.setVisibleLength(50);
    nameTxt.setHintText(Util.C.defaultAccountGroupName());

    referenceTxt = new HintTextBox();
    referenceTxt.setVisibleLength(50);
    referenceTxt.setText("");
    referenceTxt.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
                doAddNewRight();
            }
        }
    });

    topBox = new ListBox();
    botBox = new ListBox();

    addBut = new Button(Util.C.buttonAddProjectRight());
    addBut.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            doAddNewRight();
        }
    });

    clearBut = new Button(Util.C.buttonClearProjectRight());
    clearBut.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            clear();
        }
    });
}

From source file:com.google.gerrit.client.admin.AccountGroupInfoScreen.java

License:Apache License

private void initOwner() {
    final VerticalPanel ownerPanel = new VerticalPanel();
    ownerPanel.setStyleName(Gerrit.RESOURCES.css().groupOwnerPanel());
    ownerPanel.add(new SmallHeading(Util.C.headingOwner()));

    ownerTxtBox = new NpTextBox();
    ownerTxtBox.setVisibleLength(60);/* w w  w  .ja  va2 s.com*/
    ownerTxt = new SuggestBox(new RPCSuggestOracle(new AccountGroupSuggestOracle()), ownerTxtBox);
    ownerTxt.setStyleName(Gerrit.RESOURCES.css().groupOwnerTextBox());
    ownerPanel.add(ownerTxt);

    saveOwner = new Button(Util.C.buttonChangeGroupOwner());
    saveOwner.setEnabled(false);
    saveOwner.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            final String newOwner = ownerTxt.getText().trim();
            if (newOwner.length() > 0) {
                GroupApi.setGroupOwner(getGroupUUID(), newOwner, new GerritCallback<GroupInfo>() {
                    public void onSuccess(final GroupInfo result) {
                        updateOwnerGroup(result);
                        saveOwner.setEnabled(false);
                    }
                });
            }
        }
    });
    ownerPanel.add(saveOwner);
    add(ownerPanel);

    new OnEditEnabler(saveOwner, ownerTxtBox);
}

From source file:com.google.gerrit.client.admin.AccountGroupScreen.java

License:Apache License

private void initOwner() {
    final VerticalPanel ownerPanel = new VerticalPanel();
    ownerPanel.add(new SmallHeading(Util.C.headingOwner()));

    ownerTxtBox = new NpTextBox();
    ownerTxtBox.setVisibleLength(60);//from  www  . ja va2 s  .c o m
    ownerTxt = new SuggestBox(new RPCSuggestOracle(new AccountGroupSuggestOracle()), ownerTxtBox);
    ownerPanel.add(ownerTxt);

    saveOwner = new Button(Util.C.buttonChangeGroupOwner());
    saveOwner.setEnabled(false);
    saveOwner.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            final String newOwner = ownerTxt.getText().trim();
            if (newOwner.length() > 0) {
                Util.GROUP_SVC.changeGroupOwner(groupId, newOwner, new GerritCallback<VoidResult>() {
                    public void onSuccess(final VoidResult result) {
                        saveOwner.setEnabled(false);
                    }
                });
            }
        }
    });
    ownerPanel.add(saveOwner);
    add(ownerPanel);

    new OnEditEnabler(saveOwner, ownerTxtBox);
}

From source file:com.google.gerrit.client.admin.CreateProjectScreen.java

License:Apache License

private void initParentBox() {
    parent = new HintTextBox();
    suggestParent = new SuggestBox(new ProjectNameSuggestOracle(), parent);
    parent.setVisibleLength(50);/*from  w  ww .j  ava  2  s .  com*/
}

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

License:Apache License

public AddIncludedGroupBox() {
    addPanel = new FlowPanel();
    addMember = new Button(Util.C.buttonAddIncludedGroup());
    nameTxtBox = new HintTextBox();
    nameTxt = new SuggestBox(new RPCSuggestOracle(new AccountGroupSuggestOracle()), nameTxtBox);

    nameTxtBox.setVisibleLength(50);/*from www. jav  a 2  s .c om*/
    nameTxtBox.setHintText(Util.C.defaultAccountGroupName());
    nameTxtBox.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            submitOnSelection = false;

            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                if (((DefaultSuggestionDisplay) nameTxt.getSuggestionDisplay()).isSuggestionListShowing()) {
                    submitOnSelection = true;
                } else {
                    doAdd();
                }
            }
        }
    });
    nameTxt.addSelectionHandler(new SelectionHandler<Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            if (submitOnSelection) {
                submitOnSelection = false;
                doAdd();
            }
        }
    });

    addPanel.add(nameTxt);
    addPanel.add(addMember);

    initWidget(addPanel);
}

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

License:Apache License

public AddMemberBox(final String buttonLabel, final String hint, final SuggestOracle suggestOracle) {
    addPanel = new FlowPanel();
    addMember = new Button(buttonLabel);
    nameTxtBox = new HintTextBox();
    nameTxt = new SuggestBox(new RPCSuggestOracle(suggestOracle), nameTxtBox);
    nameTxt.setStyleName(Gerrit.RESOURCES.css().addMemberTextBox());

    nameTxtBox.setVisibleLength(50);//from w  ww  .  ja va  2s  .  co  m
    nameTxtBox.setHintText(hint);
    nameTxtBox.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            submitOnSelection = false;

            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                if (((DefaultSuggestionDisplay) nameTxt.getSuggestionDisplay()).isSuggestionListShowing()) {
                    submitOnSelection = true;
                } else {
                    doAdd();
                }
            }
        }
    });
    nameTxt.addSelectionHandler(new SelectionHandler<Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            nameTxtBox.setFocus(true);
            if (submitOnSelection) {
                submitOnSelection = false;
                doAdd();
            }
        }
    });

    addPanel.add(nameTxt);
    addPanel.add(addMember);

    initWidget(addPanel);
}