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

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

Introduction

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

Prototype

public SuggestOracle() 

Source Link

Document

Constructor for com.google.gwt.user.client.ui.SuggestOracle .

Usage

From source file:com.tasktop.c2c.server.tasks.client.widgets.chooser.task.ExternalTaskRelationChooser.java

License:Open Source License

/**
 * Always create a {@link ExternalTaskRelation} of type link and kind web
 *//*www .  jav  a2 s .com*/
public ExternalTaskRelationChooser() {
    super(new SuggestOracle() {

        @Override
        public void requestSuggestions(Request request, Callback callback) {

            List<Suggestion> suggestions = new ArrayList<Suggestion>();
            suggestions.add(new ExternalTaskRelationSuggestion(
                    new ExternalTaskRelation("link", "web", request.getQuery())));
            callback.onSuggestionsReady(request, new Response(suggestions));
        }
    });
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.common.client.LemmaEditorWidget.java

License:Apache License

private Widget buildOracleFor(final ValueSpecification vs) {
    SuggestOracle oracle = new SuggestOracle() {

        CommonServiceAsync service = GWT.create(CommonService.class);

        @Override//from   ww w  .ja v a 2s.c o  m
        public void requestSuggestions(final Request request, final Callback callback) {
            service.getSuggestionsForField(vs.getInternalName(), request.getQuery(), request.getLimit(),
                    new AsyncCallback<ArrayList<String>>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            // Ignore failure
                        }

                        @Override
                        public void onSuccess(ArrayList<String> result) {
                            Collection<Suggestion> suggestions = new ArrayList<Suggestion>();
                            if (result != null) {
                                for (final String string : result) {
                                    suggestions.add(new Suggestion() {

                                        @Override
                                        public String getDisplayString() {
                                            return string;
                                        }

                                        @Override
                                        public String getReplacementString() {
                                            return string;
                                        }

                                    });
                                }
                            }
                            Response response = new Response(suggestions);
                            callback.onSuggestionsReady(request, response);
                        }
                    });
        }

    };
    SuggestBox box = new SuggestBox(oracle);
    fields.put(vs.getInternalName(), box);
    return box;
}

From source file:org.apache.solr.explorer.client.plugin.terms.ui.SearchAutoCompletionPlugin.java

License:Apache License

@Override
public void init(SolrCore solrCore) {
    setActive(solrCore.getConfiguration().isActive(TermsConfig.class));

    if (!isActive()) {
        searchPane.setSearchTextBox(new TextBox());
        return;/*www  . j  a  va  2  s .  com*/
    }

    oracle = new SuggestOracle() {
        public void requestSuggestions(final Request request, final Callback callback) {
            findSuggestions(request.getQuery(),
                    new org.apache.solr.explorer.client.util.Callback<List<Suggestion>>() {
                        public void onSuccess(List<Suggestion> suggestions) {
                            callback.onSuggestionsReady(request, new Response(suggestions));
                        }
                    });

        }
    };
    suggestBox = new SuggestBox(oracle);
    suggestBox.setPopupStyleName("AutoCompletionPopup");

    suggestBox.addKeyDownHandler(new EnterKeyHandler() {
        @Override
        protected void onEnter(KeyDownEvent keyDownEvent) {
            if (!suggestBox.isSuggestionListShowing()) {
                searchPane.executeSearch();
            }
        }
    });
    suggestBox.setAutoSelectEnabled(false);
    suggestBox.setAnimationEnabled(true);

    searchPane.setSearchTextBox(suggestBox);
}

From source file:org.drools.guvnor.client.editor.QuickFindWidget.java

License:Apache License

public QuickFindWidget() {

    VerticalPanel container = new VerticalPanel();
    VerticalPanel criteria = new VerticalPanel();

    FormStyleLayout layout = new FormStyleLayout(images.systemSearch(), "");

    searchBox = new SuggestBox(new SuggestOracle() {
        public void requestSuggestions(Request r, Callback cb) {
            loadShortList(r.getQuery(), archiveBox.getValue(), caseSensitiveBox.getValue(), r, cb);

        }/*from ww w  . j av  a  2s.c  om*/
    });

    HorizontalPanel srch = new HorizontalPanel();

    final SimplePanel resultsP = new SimplePanel();
    final ClickHandler cl = new ClickHandler() {
        public void onClick(ClickEvent event) {
            resultsP.clear();
            /*                QueryPagedTable table = new QueryPagedTable(
                searchBox.getValue(),
                archiveBox.getValue(),
                caseSensitiveBox.getValue(),
                clientFactory );
                            resultsP.add( table );*/
        }
    };
    searchBox.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                cl.onClick(null);
            }
        }
    });
    srch.add(searchBox);
    layout.addAttribute(constants.FindItemsWithANameMatching(), srch);

    archiveBox = new CheckBox();
    archiveBox.setValue(false);
    layout.addAttribute(constants.IncludeArchivedAssetsInResults(), archiveBox);

    caseSensitiveBox = new CheckBox();
    caseSensitiveBox.setValue(false);
    layout.addAttribute(constants.IsSearchCaseSensitive(), caseSensitiveBox);

    Button go = new Button(constants.Search());
    go.addClickHandler(cl);
    layout.addAttribute("", go);

    HorizontalPanel searchTitle = new HorizontalPanel();
    searchTitle.add(new Image(images.information()));
    searchTitle.add(new Label(constants.EnterSearchString()));
    FlexTable listPanel = new FlexTable();
    listPanel.setWidget(0, 0, searchTitle);

    PrettyFormLayout pfl = new PrettyFormLayout();
    pfl.startSection();
    pfl.addRow(listPanel);
    pfl.endSection();

    criteria.add(pfl);
    criteria.add(layout);
    container.add(criteria);
    container.add(resultsP);

    initWidget(container);
}

From source file:org.drools.guvnor.client.rulelist.QuickFindWidget.java

License:Apache License

public QuickFindWidget(EditItemEvent editEvent) {
    layout = new FormStyleLayout("images/system_search.png", "");

    searchBox = new SuggestBox(new SuggestOracle() {
        public void requestSuggestions(Request r, Callback cb) {
            loadShortList(r.getQuery(), r, cb);

        }//from   w  w  w  .j  av a 2 s.co m
    });

    this.editEvent = editEvent;
    HorizontalPanel srch = new HorizontalPanel();
    Button go = new Button("Search");
    go.addClickListener(new ClickListener() {
        public void onClick(Widget w) {
            updateList();
        }
    });

    srch.add(searchBox);

    archiveBox = new CheckBox();

    archiveBox.setChecked(false);

    layout.addAttribute("Find items with a name matching:", srch);
    layout.addAttribute("Include archived assets in results:", archiveBox);
    layout.addAttribute("", go);

    listPanel = new FlexTable();
    listPanel.setWidget(0, 0, new HTML(
            "<img src='images/information.gif'/>&nbsp;Enter the name or part of a name. Alternatively, use the categories to browse."));

    PrettyFormLayout pfl = new PrettyFormLayout();
    pfl.startSection();
    pfl.addRow(listPanel);

    pfl.endSection();
    layout.addRow(pfl);

    initWidget(layout);
}

From source file:org.drools.guvnor.client.widgets.query.QuickFindWidget.java

License:Apache License

public QuickFindWidget(final ClientFactory clientFactory) {

    VerticalPanel container = new VerticalPanel();
    VerticalPanel criteria = new VerticalPanel();

    Image image = new Image(images.systemSearch());
    image.setAltText(constants.SystemSearch());
    FormStyleLayout layout = new FormStyleLayout(image, "");

    searchBox = new SuggestBox(new SuggestOracle() {
        public void requestSuggestions(Request r, Callback cb) {
            loadShortList(r.getQuery(), archiveBox.getValue(), caseSensitiveBox.getValue(), r, cb);

        }//from w  w w  .  j  a v a  2 s.  c om
    });

    HorizontalPanel srch = new HorizontalPanel();

    final SimplePanel resultsP = new SimplePanel();
    final ClickHandler cl = new ClickHandler() {
        public void onClick(ClickEvent event) {
            resultsP.clear();
            QueryPagedTable table = new QueryPagedTable(searchBox.getValue(), archiveBox.getValue(),
                    caseSensitiveBox.getValue(), clientFactory);
            resultsP.add(table);
        }
    };
    searchBox.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                cl.onClick(null);
            }
        }
    });
    srch.add(searchBox);
    layout.addAttribute(constants.FindItemsWithANameMatching(), srch);

    archiveBox = new CheckBox();
    archiveBox.setValue(false);
    layout.addAttribute(constants.IncludeArchivedAssetsInResults(), archiveBox);

    caseSensitiveBox = new CheckBox();
    caseSensitiveBox.setValue(false);
    layout.addAttribute(constants.IsSearchCaseSensitive(), caseSensitiveBox);

    Button go = new Button(constants.Search());
    go.addClickHandler(cl);
    layout.addAttribute("", go);

    HorizontalPanel searchTitle = new HorizontalPanel();
    searchTitle.add(new Image(images.information()));
    searchTitle.add(new Label(constants.EnterSearchString()));
    FlexTable listPanel = new FlexTable();
    listPanel.setWidget(0, 0, searchTitle);

    PrettyFormLayout pfl = new PrettyFormLayout();
    pfl.startSection();
    pfl.addRow(listPanel);
    pfl.endSection();

    criteria.add(pfl);
    criteria.add(layout);
    container.add(criteria);
    container.add(resultsP);

    initWidget(container);
}

From source file:org.eclipse.che.ide.ext.svn.client.property.PropertyEditorViewImpl.java

License:Open Source License

@Inject
public PropertyEditorViewImpl(SubversionExtensionResources resources,
        SubversionExtensionLocalizationConstants constants, PropertyEditorViewImplUiBinder uiBinder) {
    this.resources = resources;
    this.constants = constants;

    this.ensureDebugId("svn-property-edit-window");
    this.setTitle("Properties");

    existingProperties = new ArrayList<String>();

    btnCancel = createButton(constants.buttonCancel(), "svn-property-edit-cancel", new ClickHandler() {
        @Override/* w ww . j  a  v  a2s. c om*/
        public void onClick(ClickEvent event) {
            delegate.onCancelClicked();
        }
    });
    btnCancel.setTabIndex(6);
    getFooter().add(btnCancel);

    btnOk = createButton("Ok", "svn-property-edit-ok", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            delegate.onOkClicked();
        }
    });
    btnOk.setTabIndex(5);
    getFooter().add(btnOk);

    final String[] props = new String[] { "svn:ignore", "svn:keywords", "svn:mime-type", "svn:mergeinfo" };

    propertyList = new SuggestBox(new SuggestOracle() {
        @Override
        public void requestSuggestions(final Request request, Callback callback) {
            final List<Suggestion> suggestions = new ArrayList<>();
            for (final String prop : props) {
                if (!prop.startsWith(request.getQuery())) {
                    continue;
                }

                suggestions.add(new SuggestOracle.Suggestion() {
                    /** {@inheritDoc} */
                    @Override
                    public String getDisplayString() {
                        return prop;
                    }

                    /** {@inheritDoc} */
                    @Override
                    public String getReplacementString() {
                        return prop;
                    }
                });
            }

            callback.onSuggestionsReady(request, new Response(suggestions));
        }
    });

    propertyList.getValueBox().addKeyUpHandler(new KeyUpHandler() {
        /** {@inheritDoc} */
        @Override
        public void onKeyUp(KeyUpEvent event) {

            String propertyListValue = propertyList.getValue();

            int keyCode = event.getNativeKeyCode();
            if (keyCode >= KeyCodes.KEY_A && keyCode <= KeyCodes.KEY_Z
                    || keyCode >= KeyCodes.KEY_ZERO && keyCode <= KeyCodes.KEY_NINE
                    || keyCode >= KeyCodes.KEY_NUM_ZERO && keyCode <= KeyCodes.KEY_NUM_NINE
                    || keyCode == KeyCodes.KEY_ENTER || keyCode == KeyCodes.KEY_BACKSPACE) {

                setPropertyCurrentValue(Arrays.asList(""));

                if (!Strings.isNullOrEmpty(propertyListValue)
                        && existingProperties.contains(propertyListValue)) {

                    btnOk.setEnabled(editProperty.getValue() && !Strings.isNullOrEmpty(propertyValue.getText())
                            || deleteProperty.getValue());
                    delegate.onPropertyNameChanged(propertyListValue);
                }
            }
        }
    });

    this.setWidget(uiBinder.createAndBindUi(this));

    for (Depth depth : Depth.values()) {
        this.depth.addItem(depth.getDescription(), depth.getValue());
    }

    propertyCurrentValue.setReadOnly(true);
    propertyCurrentValue.getElement().setAttribute("placeHolder", "(current value of property)");
    propertyCurrentValue.getElement().setAttribute("resize", "none");
}

From source file:org.eclipse.che.plugin.svn.ide.property.PropertyEditorViewImpl.java

License:Open Source License

@Inject
public PropertyEditorViewImpl(SubversionExtensionResources resources,
        SubversionExtensionLocalizationConstants constants, PropertyEditorViewImplUiBinder uiBinder) {
    this.resources = resources;
    this.constants = constants;

    this.ensureDebugId("svn-property-edit-window");
    this.setTitle("Properties");

    existingProperties = new ArrayList<String>();

    btnCancel = createButton(constants.buttonCancel(), "svn-property-edit-cancel", new ClickHandler() {
        @Override/*ww  w  . j  av  a2  s.  co  m*/
        public void onClick(ClickEvent event) {
            delegate.onCancelClicked();
        }
    });
    btnCancel.setTabIndex(6);
    addButtonToFooter(btnCancel);

    btnOk = createButton("Ok", "svn-property-edit-ok", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            delegate.onOkClicked();
        }
    });
    btnOk.setTabIndex(5);
    addButtonToFooter(btnOk);

    final String[] props = new String[] { "svn:ignore", "svn:keywords", "svn:mime-type", "svn:mergeinfo" };

    propertyList = new SuggestBox(new SuggestOracle() {
        @Override
        public void requestSuggestions(final Request request, Callback callback) {
            final List<Suggestion> suggestions = new ArrayList<>();
            for (final String prop : props) {
                if (!prop.startsWith(request.getQuery())) {
                    continue;
                }

                suggestions.add(new SuggestOracle.Suggestion() {
                    /** {@inheritDoc} */
                    @Override
                    public String getDisplayString() {
                        return prop;
                    }

                    /** {@inheritDoc} */
                    @Override
                    public String getReplacementString() {
                        return prop;
                    }
                });
            }

            callback.onSuggestionsReady(request, new Response(suggestions));
        }
    });

    propertyList.getValueBox().addKeyUpHandler(new KeyUpHandler() {
        /** {@inheritDoc} */
        @Override
        public void onKeyUp(KeyUpEvent event) {

            String propertyListValue = propertyList.getValue();

            int keyCode = event.getNativeKeyCode();
            if (keyCode >= KeyCodes.KEY_A && keyCode <= KeyCodes.KEY_Z
                    || keyCode >= KeyCodes.KEY_ZERO && keyCode <= KeyCodes.KEY_NINE
                    || keyCode >= KeyCodes.KEY_NUM_ZERO && keyCode <= KeyCodes.KEY_NUM_NINE
                    || keyCode == KeyCodes.KEY_ENTER || keyCode == KeyCodes.KEY_BACKSPACE) {

                setPropertyCurrentValue(Arrays.asList(""));

                if (!Strings.isNullOrEmpty(propertyListValue)
                        && existingProperties.contains(propertyListValue)) {

                    btnOk.setEnabled(editProperty.getValue() && !Strings.isNullOrEmpty(propertyValue.getText())
                            || deleteProperty.getValue());
                    delegate.onPropertyNameChanged(propertyListValue);
                }
            }
        }
    });

    this.setWidget(uiBinder.createAndBindUi(this));

    for (Depth depth : Depth.values()) {
        this.depth.addItem(depth.getDescription(), depth.getValue());
    }

    propertyCurrentValue.setReadOnly(true);
    propertyCurrentValue.getElement().setAttribute("placeHolder", "(current value of property)");
    propertyCurrentValue.getElement().setAttribute("resize", "none");
}

From source file:org.freemedsoftware.gwt.client.widget.AsyncPicklistWidgetBase.java

License:Open Source License

public AsyncPicklistWidgetBase() {
    // Log.setUncaughtExceptionHandler();

    map = new HashMap<String, String>();

    layout = new VerticalPanel();

    textBox = new TextBox();

    searchBox = new SuggestBox(new SuggestOracle() {
        public void requestSuggestions(Request r, Callback cb) {
            loadSuggestions(r.getQuery(), r, cb);
        }//w ww .j  ava  2  s . c om
    }, textBox);
    searchBox.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            // Window.alert("Here be the new value:" + event.getValue());
        }
    });
    searchBox.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            int keyCode = event.getNativeKeyCode();
            switch (keyCode) {
            case KeyCodes.KEY_ESCAPE:
            case KeyCodes.KEY_BACKSPACE:
                // Clear any current values
                searchBox.setText("");
                searchBox.setTitle("");
                setValue(0);
                textBox.cancelKey();
                break;

            default:
                // Ignore any other keystroke
                break;
            }
        }
    });
    searchBox.addSelectionHandler(new SelectionHandler<Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            Suggestion s = (Suggestion) event.getSelectedItem();
            value = getValueFromText(s.getDisplayString());
            setTitle(s.getDisplayString());
            onSelected();
        }
    });
    searchBox.setLimit(10);
    searchBox.setAnimationEnabled(true);
    layout.add(searchBox);

    initWidget(layout);
}

From source file:org.freemedsoftware.gwt.client.widget.AsyncPicklistWidgetBaseSearch.java

License:Open Source License

public AsyncPicklistWidgetBaseSearch() {
    // Log.setUncaughtExceptionHandler();

    map = new HashMap<String, String>();

    layout = new VerticalPanel();

    textBox = new TextBox();

    searchBox = new SuggestBox(new SuggestOracle() {
        public void requestSuggestions(Request r, Callback cb) {
            loadSuggestions(r.getQuery(), r, cb);
        }/*from w  ww . j av a  2  s  . co  m*/
    }, textBox);
    searchBox.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            // Window.alert("Here be the new value:" + event.getValue());
        }
    });
    searchBox.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            int keyCode = event.getNativeKeyCode();
            switch (keyCode) {
            case KeyCodes.KEY_ESCAPE:
            case KeyCodes.KEY_BACKSPACE:
                // Clear any current values
                searchBox.setText("");
                searchBox.setTitle("");
                setValue("");
                textBox.cancelKey();
                break;

            default:
                // Ignore any other keystroke
                break;
            }
        }
    });
    searchBox.addSelectionHandler(new SelectionHandler<Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            Suggestion s = (Suggestion) event.getSelectedItem();
            value = getValueFromText(s.getDisplayString());
            setTitle(s.getDisplayString());
            onSelected();
        }
    });
    searchBox.setLimit(10);
    searchBox.setAnimationEnabled(true);
    layout.add(searchBox);

    initWidget(layout);
}