Search in sources :

Example 1 with LookupTableConverter

use of com.evolveum.midpoint.gui.api.component.autocomplete.LookupTableConverter in project midpoint by Evolveum.

the class TextPopupPanel method initTextField.

private TextField initTextField() {
    if (lookup == null) {
        return new TextField(ID_TEXT_INPUT, new PropertyModel(getModel(), SearchValue.F_VALUE));
    }
    // TODO: displayName
    // LookupPropertyModel<String> lookupPropertyModel = new LookupPropertyModel<String>(getModel(), SearchValue.F_VALUE, lookup.asObjectable()) {
    // 
    // private static final long serialVersionUID = 1L;
    // 
    // @Override
    // public boolean isSupportsDisplayName() {
    // return true;
    // }
    // };
    AutoCompleteSettings settings = new AutoCompleteSettings();
    settings.setShowListOnEmptyInput(true);
    AutoCompleteTextField<String> textField = new AutoCompleteTextField<String>(ID_TEXT_INPUT, new PropertyModel<>(getModel(), SearchValue.F_VALUE), settings) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            return prepareAutoCompleteList(input).iterator();
        }

        @Override
        public <C> IConverter<C> getConverter(Class<C> type) {
            IConverter<C> converter = super.getConverter(type);
            if (lookup == null) {
                return converter;
            }
            return new LookupTableConverter(converter, lookup.asObjectable(), this, false) {

                @Override
                public Object convertToObject(String value, Locale locale) throws ConversionException {
                    PropertyModel<Object> label = new PropertyModel<>(TextPopupPanel.this.getModelObject(), SearchValue.F_LABEL);
                    label.setObject(value);
                    return super.convertToObject(value, locale);
                }
            };
        }
    };
    return textField;
}
Also used : Locale(java.util.Locale) PropertyModel(org.apache.wicket.model.PropertyModel) AutoCompleteSettings(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) TextField(org.apache.wicket.markup.html.form.TextField) PrismObject(com.evolveum.midpoint.prism.PrismObject) LookupTableConverter(com.evolveum.midpoint.gui.api.component.autocomplete.LookupTableConverter)

Aggregations

LookupTableConverter (com.evolveum.midpoint.gui.api.component.autocomplete.LookupTableConverter)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 Locale (java.util.Locale)1 AutoCompleteSettings (org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings)1 AutoCompleteTextField (org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField)1 TextField (org.apache.wicket.markup.html.form.TextField)1 PropertyModel (org.apache.wicket.model.PropertyModel)1