Example usage for org.apache.wicket.extensions.ajax.markup.html.autocomplete AutoCompleteSettings setAdjustInputWidth

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.autocomplete AutoCompleteSettings setAdjustInputWidth

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.autocomplete AutoCompleteSettings setAdjustInputWidth.

Prototype

public AutoCompleteSettings setAdjustInputWidth(final boolean adjustInputWidth) 

Source Link

Document

Adjust the width of the autocompleter selection window to the width of the related input field.

Usage

From source file:com.servoy.j2db.server.headlessclient.dataui.WebDataLookupField.java

License:Open Source License

private void init() {

    add(new HeaderContributor(new IHeaderContributor() {
        private static final long serialVersionUID = 1L;

        public void renderHead(IHeaderResponse response) {
            response.renderCSSReference(
                    new CompressedResourceReference(WebDataLookupField.class, "servoy_lookupfield.css")); //$NON-NLS-1$
        }//from  ww w.java  2s.  c  om
    }) {
        @Override
        public boolean isEnabled(Component component) {
            return !getScriptObject().isReadOnly() && getScriptObject().isEnabled();
        }
    });

    setOutputMarkupPlaceholderTag(true);

    AutoCompleteSettings behSettings = new AutoCompleteSettings();
    behSettings.setMaxHeightInPx(200);
    behSettings.setPreselect(true);
    behSettings.setShowCompleteListOnFocusGain(true);
    behSettings.setAdjustInputWidth(false);

    ClientProperties clp = (application.getApplicationType() != IApplication.HEADLESS_CLIENT
            ? ((WebClientInfo) Session.get().getClientInfo()).getProperties()
            : null); // in case of batch processors/jsp, we can't get browser info because UI is not given by web client components
    if (clp != null && (!clp.isBrowserInternetExplorer() || clp.getBrowserVersionMajor() >= 8)) {
        // smart positioning doesn't work on IE < 8 (probably because of unreliable clientWidth/clientHeight browser element js properties)
        behSettings.setUseSmartPositioning(true);
        behSettings.setUseHideShowCoveredIEFix(false); // don't know if the problem this setting is for can still be reproduced (I couldn't reproduce it)... this is true by default and makes fields in IE and Opera appear/dissapear if they would be covered by type-ahead popup
    } else {
        behSettings.setUseSmartPositioning(false);
        behSettings.setUseHideShowCoveredIEFix(true);
    }
    behSettings.setThrottleDelay(500);

    IAutoCompleteRenderer<Object> renderer = new IAutoCompleteRenderer<Object>() {
        protected String getTextValue(Object object) {
            String str = ""; //$NON-NLS-1$
            if (object instanceof DisplayString) {
                str = object.toString();
            } else if (object != null && !(object instanceof String)) {
                IConverter con = getConverter(object.getClass());
                if (con != null) {
                    str = con.convertToString(object, getLocale());
                } else {
                    str = object.toString();
                }
            } else if (object != null) {
                str = object.toString();
            }
            if (str == null || str.trim().equals("")) //$NON-NLS-1$
                str = "&nbsp;"; //$NON-NLS-1$
            return str;
        }

        protected void renderChoice(Object object, Response response, String criteria) {
            if (IValueList.SEPARATOR_DESIGN_VALUE.equals(object))
                return;
            String renderedObject = getTextValue(object);
            // escape the markup if it is not html or not just an empty none breaking space (null or empty string object)
            if (!renderedObject.equals("&nbsp;") && !HtmlUtils.hasHtmlTag(renderedObject)) //$NON-NLS-1$
                renderedObject = HtmlUtils.escapeMarkup(renderedObject, true, false).toString();
            response.write(renderedObject);
        }

        /*
         * (non-Javadoc)
         *
         * @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#render(java.lang.Object, org.apache.wicket.Response,
         * java.lang.String)
         */
        public void render(Object object, Response response, String criteria) {
            String textValue = getTextValue(object);
            if (textValue == null) {
                throw new IllegalStateException(
                        "A call to textValue(Object) returned an illegal value: null for object: "
                                + object.toString());
            }
            textValue = textValue.replaceAll("\\\"", "&quot;");

            response.write("<li textvalue=\"" + textValue + "\"");
            response.write(">");
            renderChoice(object, response, criteria);
            response.write("</li>");
        }

        /*
         * (non-Javadoc)
         *
         * @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#renderHeader(org.apache.wicket.Response)
         */
        @SuppressWarnings("nls")
        public void renderHeader(Response response) {
            StringBuffer listStyle = new StringBuffer();
            listStyle.append("style=\"");

            String fFamily = "Tahoma, Arial, Helvetica, sans-serif";
            String bgColor = "#ffffff";
            String fgColor = "#000000";
            String fSize = TemplateGenerator.DEFAULT_FONT_SIZE + "px";
            String padding = "2px";
            String margin = "0px";
            if (getFont() != null) {
                Font f = getFont();
                if (f != null) {
                    if (f.getFamily() != null) {
                        fFamily = f.getFamily();
                        if (fFamily.contains(" "))
                            fFamily = "'" + fFamily + "'";
                    }
                    if (f.getName() != null) {
                        String fName = f.getName();
                        if (fName.contains(" "))
                            fName = "'" + fName + "'";
                        fFamily = fName + "," + fFamily;
                    }
                    if (f.isBold())
                        listStyle.append("font-weight:bold; ");
                    if (f.isItalic())
                        listStyle.append("font-style:italic; ");

                    fSize = Integer.toString(f.getSize()) + "px";
                }
            }

            if (getListColor() != null && getListColor().getAlpha() == 255) {
                // background shouldn't be transparent
                bgColor = getWebColor(getListColor().getRGB());
            }
            if (getForeground() != null) {
                fgColor = getWebColor(getForeground().getRGB());
            }
            Insets _padding = getPadding();
            if (getPadding() != null)
                padding = _padding.top + "px " + _padding.right + "px " + _padding.bottom + "px "
                        + _padding.left + "px";

            listStyle.append("font-family:" + fFamily + "; ");
            listStyle.append("background-color: " + bgColor + "; ");
            listStyle.append("color: " + fgColor + "; ");
            listStyle.append("font-size:" + fSize + "; ");
            listStyle.append("min-width:" + (getSize().width - 6) + "px; "); // extract padding and border
            listStyle.append("margin: " + margin + "; ");
            listStyle.append("padding: " + padding + "; ");
            listStyle.append(
                    "text-align:" + TemplateGenerator.getHorizontalAlignValue(getHorizontalAlignment()));
            listStyle.append("\"");

            response.write("<ul " + listStyle + ">");
        }

        /*
         * (non-Javadoc)
         *
         * @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#renderFooter(org.apache.wicket.Response)
         */
        public void renderFooter(Response response) {
            response.write("</ul>"); //$NON-NLS-1$
        }

        /**
         * Returns web color representation of int rgba color by
         * removing the alpha value
         *
         * @param color int representation of rgba color
         * @return web color of form #rrggbb
         */
        private String getWebColor(int color) {
            String webColor = Integer.toHexString(color);
            int startIdx = webColor.length() - 6;
            if (startIdx < 0)
                startIdx = 0;
            webColor = webColor.substring(startIdx);

            StringBuilder sb = new StringBuilder();
            sb.append('#');
            int nrMissing0 = 6 - webColor.length();
            for (int i = 0; i < nrMissing0; i++) {
                sb.append('0');
            }
            sb.append(webColor);

            return sb.toString();
        }
    };

    AutoCompleteBehavior<Object> beh = new AutoCompleteBehavior<Object>(renderer, behSettings) {
        private static final long serialVersionUID = 1L;

        /**
         * @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteBehavior#getChoices(java.lang.String)
         */
        @Override
        protected Iterator<Object> getChoices(String input) {
            String filteredInput = filterInput(input);
            if (changeListener != null)
                dlm.getValueList().removeListDataListener(changeListener);
            try {
                dlm.fill(parentState, getDataProviderID(), filteredInput, false);
                return dlm.iterator();
            } catch (Exception ex) {
                Debug.error(ex);
            } finally {
                if (changeListener != null)
                    dlm.getValueList().addListDataListener(changeListener);
            }
            return Collections.emptyList().iterator();
        }

        /**
         * filters the input in case of masked input (removes the mask)
         */
        private String filterInput(String input) {
            String displayFormat = WebDataLookupField.this.parsedFormat.getDisplayFormat();
            if (displayFormat != null && displayFormat.length() > 0
                    && input.length() == displayFormat.length()) {
                int index = firstBlankSpacePosition(input, displayFormat);
                if (index == -1)
                    return input;
                return input.substring(0, index);
            }
            return input;
        }

        /**
         * Computes the index of the first space char found in the input and is not ' ' nor '*' in the format
         * Example:
         * input  '12 - 3  -  '
         * format '## - ## - #'
         * returns 6
         * @param input
         * @param displayFormat
         * @return The index of the first space char found in the input and is not ' ' nor '*' in the format
         */
        private int firstBlankSpacePosition(String input, String displayFormat) {
            for (int i = 0; i < input.length(); i++) {
                if ((input.charAt(i) == ' ') && (displayFormat.charAt(i) != ' ')
                        && (displayFormat.charAt(i) != '*'))
                    return i;
            }
            return 0;
        }

        /**
         * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#getFailureScript()
         */
        @Override
        protected CharSequence getFailureScript() {
            return "onAjaxError();"; //$NON-NLS-1$
        }

        /**
         * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#getPreconditionScript()
         */
        @Override
        protected CharSequence getPreconditionScript() {
            return "onAjaxCall();" + super.getPreconditionScript(); //$NON-NLS-1$
        }

        // need to set this behavior to true (enterHidesWithNoSelection) because otherwise the onKeyDown events
        // or other events for the component with type ahead would be null in Firefox, and would not execute as
        // expected on the other browsers...
        @Override
        public void renderHead(IHeaderResponse response) {
            settings.setShowListOnEmptyInput(Boolean.TRUE.equals(UIUtils.getUIProperty(getScriptObject(),
                    application, IApplication.TYPE_AHEAD_SHOW_POPUP_WHEN_EMPTY, Boolean.TRUE)));
            settings.setShowListOnFocusGain(Boolean.TRUE.equals(UIUtils.getUIProperty(getScriptObject(),
                    application, IApplication.TYPE_AHEAD_SHOW_POPUP_ON_FOCUS_GAIN, Boolean.TRUE)));
            if (!getScriptObject().isReadOnly() && getScriptObject().isEnabled()) {
                super.renderHead(response);
                response.renderJavascript("Wicket.AutoCompleteSettings.enterHidesWithNoSelection = true;", //$NON-NLS-1$
                        "AutocompleteSettingsID"); //$NON-NLS-1$
            }
        }

        /**
         * @see org.apache.wicket.behavior.AbstractBehavior#isEnabled(org.apache.wicket.Component)
         */
        @Override
        public boolean isEnabled(Component component) {
            IFormUIInternal<?> formui = findParent(IFormUIInternal.class);
            if (formui != null && formui.isDesignMode()) {
                return false;
            }
            return super.isEnabled(component) && WebClientSession.get().useAjax();
        }
    };
    add(beh);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.administration.AdminManagePersonPage.java

License:Apache License

private AutoCompleteSettings prepareAutoCompleteSettings() {

    AutoCompleteSettings settings = new AutoCompleteSettings();
    settings.setShowListOnEmptyInput(true);
    settings.setShowCompleteListOnFocusGain(true);
    settings.setUseHideShowCoveredIEFix(false);
    settings.setMaxHeightInPx(200);/*from   w  w  w.j a  va  2  s .  co  m*/
    settings.setAdjustInputWidth(false);
    return settings;
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.forms.wizard.AddExperimentScenarioForm.java

License:Apache License

private AutoCompleteSettings prepareAutoCompleteSettings() {
    AutoCompleteSettings settings = new AutoCompleteSettings();
    settings.setShowListOnEmptyInput(true);
    settings.setShowCompleteListOnFocusGain(true);
    settings.setUseHideShowCoveredIEFix(false);
    settings.setMaxHeightInPx(200);//ww w  . j ava  2 s . c  om
    settings.setAdjustInputWidth(false);
    return settings;
}

From source file:it.av.eatt.web.page.RistoranteSearchPanel.java

License:Apache License

/**
 * Constructor//from  ww  w  .jav  a  2  s . co m
 * 
 * @param id
 * @param dataProvider
 * @param dataTable
 * @param feedbackPanel
 */
public RistoranteSearchPanel(String id, final RistoranteSortableDataProvider dataProvider,
        final RistoranteDataTable<Ristorante> dataTable, final FeedbackPanel feedbackPanel) {
    super(id);
    Form<String> form = new Form<String>("searchForm", new CompoundPropertyModel(searchBean));
    add(form);
    form.setOutputMarkupId(true);
    FormComponent<String> fc;
    // fc = new TextField<String>("searchData");
    AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
    autoCompleteSettings.setCssClassName("autocomplete-risto");
    autoCompleteSettings.setAdjustInputWidth(false);
    fc = new searchBox("searchData", autoCompleteSettings, dataProvider.getRistoranteService());
    form.add(fc);
    // event and throttle it down to once per second
    AjaxFormValidatingBehavior.addToAllFormComponents(form, "onkeyup", Duration.ONE_SECOND);

    form.add(new AjaxButton("ajax-button", form) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            try {
                String pattern = getRequest().getParameter("searchData");
                dataProvider.fetchResults(pattern);
            } catch (JackWicketException e) {
                feedbackPanel.error(e.getMessage());
            }
            target.addComponent(dataTable);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form form) {
            target.addComponent(dataTable);
        }
    });
}

From source file:it.av.youeat.web.page.manager.CommentsSearchPanel.java

License:Apache License

/**
 * Constructor//from ww w .  j  ava  2s  .com
 * 
 * @param id
 * @param dataProvider
 * @param dataTable
 * @param feedbackPanel
 */
public CommentsSearchPanel(String id, final CommentsSortableDataProvider dataProvider,
        final RistoranteDataTable<Comment> dataTable, final FeedbackPanel feedbackPanel) {
    super(id);
    Form<String> form = new Form<String>("searchForm", new CompoundPropertyModel(searchBean));
    add(form);
    form.setOutputMarkupId(true);
    FormComponent<String> fc;
    // fc = new TextField<String>("searchData");
    AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
    autoCompleteSettings.setCssClassName("autocomplete-risto");
    autoCompleteSettings.setAdjustInputWidth(false);
    fc = new SearchBox("searchData", autoCompleteSettings);
    form.add(fc);
    // event and throttle it down to once per second
    AjaxFormValidatingBehavior.addToAllFormComponents(form, "onkeyup", Duration.ONE_SECOND);

    form.add(new AjaxButton("ajax-button", form) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            try {
                String pattern = getRequest().getPostParameters().getParameterValue("searchData").toString();
                dataProvider.fetchResults(pattern);
            } catch (YoueatException e) {
                feedbackPanel.error(e.getMessage());
            }
            target.addComponent(dataTable);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form form) {
            target.addComponent(dataTable);
        }
    });
}

From source file:it.av.youeat.web.panel.RistoranteSearchPanel.java

License:Apache License

/**
 * Constructor/* w  w w  . j a  v  a 2  s .c  o  m*/
 * 
 * @param id
 * @param dataProvider
 * @param dataTable
 * @param feedbackPanel
 */
public RistoranteSearchPanel(String id, final RistoranteSortableDataProvider dataProvider,
        final RistoranteDataTable<Ristorante> dataTable, final FeedbackPanel feedbackPanel) {
    super(id);
    Form<String> form = new Form<String>("searchForm", new CompoundPropertyModel(searchBean));
    add(form);
    form.setOutputMarkupId(true);
    FormComponent<String> fc;
    // fc = new TextField<String>("searchData");
    AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
    autoCompleteSettings.setCssClassName("autocomplete-risto");
    autoCompleteSettings.setAdjustInputWidth(false);
    fc = new SearchBox("searchData", autoCompleteSettings);
    form.add(fc);
    // event and throttle it down to once per second
    AjaxFormValidatingBehavior.addToAllFormComponents(form, "onkeyup", Duration.ONE_SECOND);

    form.add(new AjaxButton("ajax-button", form) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            try {
                String pattern = getRequest().getPostParameters().getParameterValue("searchData").toString("");
                dataProvider.fetchResults(pattern, dataTable.getItemsPerPage());
            } catch (YoueatException e) {
                feedbackPanel.error(e.getMessage());
            }
            target.addComponent(dataTable);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form form) {
            target.addComponent(dataTable);
        }
    });
}

From source file:it.av.youeat.web.panel.SearchFriendPanel.java

License:Apache License

/**
 * Constructor// w  ww .  j  a  v  a 2s  .c o m
 * 
 * @param dataProvider
 * @param dataTable
 * @param id
 * @param feedbackPanel
 * @param loggedUser
 */
public SearchFriendPanel(final SearchUserFriendSortableDataProvider dataProvider,
        final AjaxFallbackDefaultDataTable dataTable, String id, final FeedbackPanel feedbackPanel,
        Eater loggedUser) {
    super(id);
    Form<String> form = new Form<String>("searchForm", new CompoundPropertyModel(searchBean));
    add(form);
    form.setOutputMarkupId(true);
    FormComponent<String> fc;
    AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
    autoCompleteSettings.setCssClassName("autocomplete-risto");
    autoCompleteSettings.setAdjustInputWidth(false);
    fc = new SearchBox("searchData", loggedUser, autoCompleteSettings);
    //fc = new TextField<String>();
    form.add(fc);
    // event and throttle it down to once per second
    AjaxFormValidatingBehavior.addToAllFormComponents(form, "onkeyup", Duration.ONE_SECOND);

    form.add(new AjaxButton("ajax-button", form) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            String pattern = getRequest().getPostParameters().getParameterValue("searchData").toString("");
            try {
                dataProvider.fetchResults(pattern);
            } catch (YoueatException e) {
                feedbackPanel.error(e.getMessage());
            }
            target.addComponent(dataTable);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form form) {
            target.addComponent(dataTable);
        }
    });
}

From source file:ontopoly.components.AssociationFieldAutoCompleteTextField.java

License:Apache License

public AssociationFieldAutoCompleteTextField(String id, IModel<Topic> model,
        final RoleFieldModel valueFieldModel) {
    super(id);/*from   w w w .jav a2 s.  c o m*/

    AutoCompleteSettings opts = new AutoCompleteSettings();
    opts.setCssClassName("ontopoly-autocompleter");
    opts.setAdjustInputWidth(false);
    opts.setPreselect(true);

    this.textField = new AutoCompleteTextField<Topic>("autoComplete", model, Topic.class,
            new AbstractAutoCompleteRenderer<Topic>() {
                @Override
                protected String getTextValue(Topic o) {
                    return TOPIC_CONVERTER.convertToString(o);
                }

                @Override
                protected void renderChoice(Topic o, Response response, String criteria) {
                    response.write(o.getName());
                }
            }, opts) {

        @Override
        public IConverter getConverter(Class<?> type) {
            if (Topic.class.equals(type)) {
                return new TopicConverter();
            } else {
                return super.getConverter(type);
            }
        }

        @Override
        protected Iterator<Topic> getChoices(String input) {
            List<Topic> result = new ArrayList<Topic>(
                    valueFieldModel.getRoleField().searchAllowedPlayers(input));
            filterPlayers(result);
            Collections.sort(result, TopicComparator.INSTANCE);
            return result.iterator();
        }

        @Override
        protected void onModelChanged() {
            super.onModelChanged();
            Topic topic = getModelObject();
            if (topic != null) {
                AssociationFieldAutoCompleteTextField.this.onTopicSelected(topic);
            }
        }
    };
    add(textField);
}

From source file:org.hippoecm.frontend.plugins.console.menu.node.NodeDialog.java

License:Apache License

public NodeDialog(IModelReference<Node> modelReference) {
    this.modelReference = modelReference;
    final IModel<Node> nodeModel = modelReference.getModel();
    setModel(nodeModel);// w  w w .  j  a  va2 s.  c om

    getParent().add(CssClass.append("node-dialog"));

    // list defined child node names and types for automatic completion
    final Node node = nodeModel.getObject();
    try {
        NodeType pnt = node.getPrimaryNodeType();
        for (NodeDefinition nd : pnt.getChildNodeDefinitions()) {
            if (!nd.isProtected()) {
                for (NodeType nt : nd.getRequiredPrimaryTypes()) {
                    if (!nt.isAbstract()) {
                        addNodeType(nd, nt);
                    }
                    for (NodeType subnt : getDescendantNodeTypes(nt)) {
                        addNodeType(nd, subnt);
                    }
                }
            }
        }
        for (NodeType nt : node.getMixinNodeTypes()) {
            for (NodeDefinition nd : nt.getChildNodeDefinitions()) {
                if (!nd.isProtected()) {
                    for (NodeType cnt : nd.getRequiredPrimaryTypes()) {
                        if (!cnt.isAbstract()) {
                            addNodeType(nd, cnt);
                        }
                        for (NodeType subnt : getDescendantNodeTypes(cnt)) {
                            addNodeType(nd, subnt);
                        }
                    }
                }
            }
        }
    } catch (RepositoryException e) {
        log.warn("Unable to populate autocomplete list for child node names", e);
    }

    AutoCompleteSettings settings = new AutoCompleteSettings();
    settings.setAdjustInputWidth(false);
    settings.setUseSmartPositioning(true);
    settings.setShowCompleteListOnFocusGain(true);
    settings.setShowListOnEmptyInput(true);
    // Setting a max height will trigger a correct recalculation of the height when the list of items is filtered
    settings.setMaxHeightInPx(400);

    final Model<String> typeModel = new Model<String>() {
        @Override
        public String getObject() {
            if (name != null && namesToTypes.containsKey(name)) {
                Collection<String> types = namesToTypes.get(name);
                if (types.size() == 1) {
                    type = types.iterator().next();
                }
            } else if (namesToTypes.size() == 1) {
                Collection<String> types = namesToTypes.values().iterator().next();
                if (types.size() == 1) {
                    type = types.iterator().next();
                }
            }
            return type;
        }

        @Override
        public void setObject(String s) {
            type = s;
        }
    };
    typeField = new AutoCompleteTextFieldWidget<String>("type", typeModel, settings) {
        @Override
        protected Iterator<String> getChoices(final String input) {
            Collection<String> result = new TreeSet<>();
            if (!Strings.isEmpty(name)) {
                if (namesToTypes.get(name) != null) {
                    result.addAll(namesToTypes.get(name));
                }
                if (namesToTypes.get("*") != null) {
                    result.addAll(namesToTypes.get("*"));
                }
            } else {
                namesToTypes.values().forEach(result::addAll);
            }
            Iterator<String> resultIter = result.iterator();
            while (resultIter.hasNext()) {
                if (!resultIter.next().contains(input)) {
                    resultIter.remove();
                }
            }
            return result.iterator();
        }

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            if (isVisibleInHierarchy()) {
                target.add(nameField);
            }
        }
    };
    typeField.setRequired(true);
    add(typeField);

    final Model<String> nameModel = new Model<String>() {
        @Override
        public String getObject() {
            if (type != null && typesToNames.containsKey(type)) {
                if (name == null) {
                    Collection<String> names = typesToNames.get(type);
                    if (names.size() == 1) {
                        String _name = names.iterator().next();
                        if (!_name.equals("*")) {
                            name = _name;
                        }
                    }
                }
            } else if (typesToNames.size() == 1) {
                Collection<String> names = typesToNames.values().iterator().next();
                if (names.size() == 1) {
                    String _name = names.iterator().next();
                    if (!_name.equals("*")) {
                        name = _name;
                    }
                }
            }
            return name;
        }

        @Override
        public void setObject(String s) {
            name = s;
        }
    };
    nameField = new AutoCompleteTextFieldWidget<String>("name", nameModel, settings) {
        @Override
        protected Iterator<String> getChoices(String input) {
            Collection<String> result = new TreeSet<>();
            if (type != null && !type.isEmpty()) {
                if (typesToNames.get(type) != null) {
                    result.addAll(typesToNames.get(type));
                }
            } else {
                for (String nodeName : namesToTypes.keySet()) {
                    if (!nodeName.equals("*") && nodeName.contains(input)) {
                        result.add(nodeName);
                    }
                }
            }
            return result.iterator();
        }

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            if (isVisibleInHierarchy()) {
                target.add(typeField);
            }
        }
    };
    nameField.setRequired(true);

    add(setFocus(nameField));
}

From source file:org.hippoecm.frontend.plugins.console.menu.open.OpenDialog.java

License:Apache License

private AutoCompleteSettings getAutoCompleteSettings() {
    AutoCompleteSettings settings = new AutoCompleteSettings();
    settings.setAdjustInputWidth(false).setUseSmartPositioning(true).setShowCompleteListOnFocusGain(true)
            .setShowListOnEmptyInput(true);
    return settings;
}