Search in sources :

Example 1 with MutablePrismReferenceDefinition

use of com.evolveum.midpoint.prism.MutablePrismReferenceDefinition in project midpoint by Evolveum.

the class SearchFilterPanel method initSearchItemField.

protected void initSearchItemField(WebMarkupContainer searchItemContainer) {
    CheckPanel checkPanel = new CheckPanel(ID_CHECK_DISABLE_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_APPLY_FILTER));
    (checkPanel).getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
            searchPerformed(ajaxRequestTarget);
        }
    });
    checkPanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    checkPanel.add(new VisibleBehaviour(this::canRemoveSearchItem));
    checkPanel.setOutputMarkupId(true);
    searchItemContainer.add(checkPanel);
    ParameterType functionParameter = getModelObject().getPredefinedFilter().getParameter();
    QName returnType = functionParameter != null ? functionParameter.getType() : null;
    Component inputPanel;
    if (returnType == null) {
        inputPanel = new WebMarkupContainer(ID_SEARCH_ITEM_FIELD);
    } else {
        Class<?> inputClass = getPrismContext().getSchemaRegistry().determineClassForType(returnType);
        Validate.notNull(inputClass, "Couldn't find class for type " + returnType);
        SearchItem.Type inputType = getModelObject().getInputType(inputClass, getPageBase());
        IModel<List<DisplayableValue<?>>> choices = null;
        switch(inputType) {
            case REFERENCE:
                SearchFilterParameterType parameter = getModelObject().getPredefinedFilter().getParameter();
                MutablePrismReferenceDefinition def = null;
                if (parameter != null) {
                    Class<?> clazz = getPrismContext().getSchemaRegistry().determineClassForType(parameter.getType());
                    QName type = getPrismContext().getSchemaRegistry().determineTypeForClass(clazz);
                    def = getPrismContext().definitionFactory().createReferenceDefinition(new QName(parameter.getName()), type);
                    def.setTargetTypeName(parameter.getTargetType());
                }
                inputPanel = new ReferenceValueSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE), def);
                break;
            case BOOLEAN:
                choices = (IModel) createBooleanChoices();
            case ENUM:
                if (choices == null) {
                    choices = CollectionUtils.isEmpty(getModelObject().getAllowedValues(getPageBase())) ? createEnumChoices((Class<? extends Enum>) inputClass) : Model.ofList(getModelObject().getAllowedValues(getPageBase()));
                }
                if (choices != null) {
                    inputPanel = WebComponentUtil.createDropDownChoices(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), FilterSearchItem.F_INPUT), (IModel) choices, true, getPageBase());
                    break;
                }
            case DATE:
                inputPanel = new DateSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), FilterSearchItem.F_INPUT_VALUE));
                break;
            case ITEM_PATH:
                inputPanel = new ItemPathSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), FilterSearchItem.F_INPUT_VALUE));
                break;
            case TEXT:
                LookupTableType lookupTable = getModelObject().getLookupTable(getPageBase());
                if (lookupTable != null) {
                    inputPanel = createAutoCompetePanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE), lookupTable);
                    break;
                }
            default:
                inputPanel = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE));
        }
        if (inputPanel instanceof InputPanel && !(inputPanel instanceof AutoCompleteTextPanel)) {
            ((InputPanel) inputPanel).getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
            ((InputPanel) inputPanel).getBaseFormComponent().add(AttributeAppender.append("style", "width: 140px; max-width: 400px !important;"));
            ((InputPanel) inputPanel).getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
        }
        inputPanel.setOutputMarkupId(true);
        searchItemContainer.add(inputPanel);
    }
    searchItemContainer.add(inputPanel);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) SearchFilterParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.SearchFilterParameterType) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) List(java.util.List) Component(org.apache.wicket.Component) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) ParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ParameterType) SearchFilterParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.SearchFilterParameterType) IModel(org.apache.wicket.model.IModel) QName(javax.xml.namespace.QName) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) CheckPanel(com.evolveum.midpoint.web.component.input.CheckPanel) MutablePrismReferenceDefinition(com.evolveum.midpoint.prism.MutablePrismReferenceDefinition) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget)

Aggregations

AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)1 MutablePrismReferenceDefinition (com.evolveum.midpoint.prism.MutablePrismReferenceDefinition)1 CheckPanel (com.evolveum.midpoint.web.component.input.CheckPanel)1 InputPanel (com.evolveum.midpoint.web.component.prism.InputPanel)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 EmptyOnBlurAjaxFormUpdatingBehaviour (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour)1 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)1 ParameterType (com.evolveum.midpoint.xml.ns._public.common.common_3.ParameterType)1 SearchFilterParameterType (com.evolveum.midpoint.xml.ns._public.common.common_3.SearchFilterParameterType)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 Component (org.apache.wicket.Component)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 OnChangeAjaxBehavior (org.apache.wicket.ajax.form.OnChangeAjaxBehavior)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 IModel (org.apache.wicket.model.IModel)1 PropertyModel (org.apache.wicket.model.PropertyModel)1