Search in sources :

Example 1 with AutoCompleteTextField

use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.

the class AutoCompleteQNamePanel method initLayout.

private void initLayout(final IModel<QName> model) {
    setOutputMarkupId(true);
    AutoCompleteSettings autoCompleteSettings = createAutoCompleteSettings();
    final IModel<String> stringModel = new Model<String>() {

        @Override
        public void setObject(String object) {
            super.setObject(object);
            model.setObject(convertToQname(object));
        }
    };
    // The inner autocomplete field is always String. Non-string auto-complete fields are problematic
    final AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, stringModel, String.class, autoCompleteSettings) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            return getIterator(input);
        }
    };
    input.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String inputString = stringModel.getObject();
            if (StringUtils.isBlank(inputString)) {
                QName modelObject = model.getObject();
                if (modelObject != null) {
                    model.setObject(null);
                    AutoCompleteQNamePanel.this.onChange(target);
                }
            } else {
                QName inputQName = convertToQname(stringModel.getObject());
                if (inputQName == null) {
                // We have some input, but it does not match any QName. Just do nothing.
                } else {
                    QName modelObject = model.getObject();
                    if (inputQName.equals(modelObject)) {
                        model.setObject(inputQName);
                        AutoCompleteQNamePanel.this.onChange(target);
                    }
                }
            }
        }
    });
    add(input);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AutoCompleteSettings(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) QName(javax.xml.namespace.QName) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior)

Example 2 with AutoCompleteTextField

use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.

the class PageAccounts method initSearchForm.

private void initSearchForm(Form searchForm) {
    BasicSearchPanel<AccountDetailsSearchDto> basicSearch = new BasicSearchPanel<AccountDetailsSearchDto>(ID_SEARCH_BASIC) {

        @Override
        protected IModel<String> createSearchTextModel() {
            return new PropertyModel<>(searchModel, AccountDetailsSearchDto.F_SEARCH_TEXT);
        }

        @Override
        protected void searchPerformed(AjaxRequestTarget target) {
            PageAccounts.this.searchPerformed(target);
        }

        @Override
        protected void clearSearchPerformed(AjaxRequestTarget target) {
            PageAccounts.this.clearSearchPerformed(target);
        }
    };
    basicSearch.setOutputMarkupId(true);
    searchForm.add(basicSearch);
    DropDownChoice failedOperationType = new DropDownChoice<>(ID_SEARCH_FAILED_OPERATION_TYPE, new PropertyModel<FailedOperationTypeType>(searchModel, AccountDetailsSearchDto.F_FAILED_OPERATION_TYPE), WebComponentUtil.createReadonlyModelFromEnum(FailedOperationTypeType.class), new EnumChoiceRenderer<FailedOperationTypeType>(this));
    failedOperationType.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            searchPerformed(target);
        }
    });
    failedOperationType.setOutputMarkupId(true);
    failedOperationType.setNullValid(true);
    searchForm.add(failedOperationType);
    DropDownChoice kind = new DropDownChoice<>(ID_SEARCH_KIND, new PropertyModel<ShadowKindType>(searchModel, AccountDetailsSearchDto.F_KIND), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>(this));
    kind.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            searchPerformed(target);
        }
    });
    kind.setOutputMarkupId(true);
    kind.setNullValid(true);
    searchForm.add(kind);
    DropDownChoice intent = new DropDownChoice<>(ID_SEARCH_INTENT, new PropertyModel<String>(searchModel, AccountDetailsSearchDto.F_INTENT), createIntentChoices(), new StringChoiceRenderer(null));
    intent.setNullValid(true);
    intent.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            searchPerformed(target);
        }
    });
    intent.setOutputMarkupId(true);
    searchForm.add(intent);
    AutoCompleteTextField<String> objectClass = new AutoCompleteTextField<String>(ID_SEARCH_OBJECT_CLASS, new PropertyModel<String>(searchModel, AccountDetailsSearchDto.F_OBJECT_CLASS)) {

        @Override
        protected Iterator<String> getChoices(String input) {
            if (Strings.isEmpty(input)) {
                List<String> emptyList = Collections.emptyList();
                return emptyList.iterator();
            }
            AccountDetailsSearchDto dto = searchModel.getObject();
            List<QName> accountObjectClassList = dto.getObjectClassList();
            List<String> choices = new ArrayList<>(AUTO_COMPLETE_LIST_SIZE);
            for (QName s : accountObjectClassList) {
                if (s.getLocalPart().toLowerCase().startsWith(input.toLowerCase())) {
                    choices.add(s.getLocalPart());
                    if (choices.size() == AUTO_COMPLETE_LIST_SIZE) {
                        break;
                    }
                }
            }
            return choices.iterator();
        }
    };
    objectClass.add(AttributeModifier.replace("placeholder", createStringResource("PageAccounts.accounts.objectClass")));
    objectClass.setOutputMarkupId(true);
    objectClass.add(createObjectClassValidator());
    objectClass.add(new SearchFormEnterBehavior(basicSearch.getSearchButton()));
    searchForm.add(objectClass);
}
Also used : AccountDetailsSearchDto(com.evolveum.midpoint.web.page.admin.configuration.dto.AccountDetailsSearchDto) SearchFormEnterBehavior(com.evolveum.midpoint.web.util.SearchFormEnterBehavior) QName(javax.xml.namespace.QName) PropertyModel(org.apache.wicket.model.PropertyModel) ArrayList(java.util.ArrayList) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) BasicSearchPanel(com.evolveum.midpoint.web.component.BasicSearchPanel) StringChoiceRenderer(com.evolveum.midpoint.web.component.input.StringChoiceRenderer) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) FailedOperationTypeType(com.evolveum.midpoint.xml.ns._public.common.common_3.FailedOperationTypeType)

Example 3 with AutoCompleteTextField

use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.

the class ResourceRelatedHandlerPanel method initLayout.

private void initLayout() {
    final VisibleEnableBehaviour visibleIfEdit = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return parentPage.isEdit();
        }
    };
    final VisibleEnableBehaviour visibleIfView = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !parentPage.isEdit();
        }
    };
    enabledIfEdit = new VisibleEnableBehaviour() {

        @Override
        public boolean isEnabled() {
            return parentPage.isEdit();
        }
    };
    final VisibleEnableBehaviour visibleForResourceCoordinates = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getTaskDto().configuresResourceCoordinates();
        }
    };
    final WebMarkupContainer resourceRefContainer = new WebMarkupContainer(ID_RESOURCE_REF_CONTAINER);
    resourceRefContainer.add(visibleForResourceCoordinates);
    resourceRefContainer.setOutputMarkupId(true);
    add(resourceRefContainer);
    final DropDownChoice<TaskAddResourcesDto> resourceRef = new DropDownChoice<>(ID_RESOURCE_REF, new PropertyModel<TaskAddResourcesDto>(getModel(), ResourceRelatedHandlerDto.F_RESOURCE_REFERENCE), new AbstractReadOnlyModel<List<TaskAddResourcesDto>>() {

        @Override
        public List<TaskAddResourcesDto> getObject() {
            return createResourceList();
        }
    }, new ChoiceableChoiceRenderer<TaskAddResourcesDto>());
    resourceRef.setOutputMarkupId(true);
    resourceRef.add(enabledIfEdit);
    resourceRef.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            Task task = parentPage.createSimpleTask(OPERATION_LOAD_RESOURCE);
            OperationResult result = task.getResult();
            List<QName> objectClassList = new ArrayList<>();
            TaskAddResourcesDto resourcesDto = getModelObject().getResourceRef();
            if (resourcesDto != null) {
                PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(ResourceType.class, resourcesDto.getOid(), parentPage, task, result);
                try {
                    ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resource, parentPage.getPrismContext());
                    schema.getObjectClassDefinitions();
                    for (Definition def : schema.getDefinitions()) {
                        objectClassList.add(def.getTypeName());
                    }
                    getModelObject().setObjectClassList(objectClassList);
                } catch (Exception e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object class list from resource.", e);
                    error("Couldn't load object class list from resource.");
                }
            }
            target.add(resourceRefContainer);
        }
    });
    resourceRefContainer.add(resourceRef);
    WebMarkupContainer kindContainer = new WebMarkupContainer(ID_KIND_CONTAINER);
    kindContainer.add(visibleForResourceCoordinates);
    add(kindContainer);
    final DropDownChoice kind = new DropDownChoice<>(ID_KIND, new PropertyModel<ShadowKindType>(getModel(), ResourceRelatedHandlerDto.F_KIND), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>());
    kind.setOutputMarkupId(true);
    kind.setNullValid(true);
    kindContainer.add(kind);
    WebMarkupContainer intentContainer = new WebMarkupContainer(ID_INTENT_CONTAINER);
    intentContainer.add(visibleForResourceCoordinates);
    add(intentContainer);
    final TextField<String> intent = new TextField<>(ID_INTENT, new PropertyModel<String>(getModel(), ResourceRelatedHandlerDto.F_INTENT));
    intentContainer.add(intent);
    intent.setOutputMarkupId(true);
    intent.add(enabledIfEdit);
    WebMarkupContainer objectClassContainer = new WebMarkupContainer(ID_OBJECT_CLASS_CONTAINER);
    objectClassContainer.add(visibleForResourceCoordinates);
    add(objectClassContainer);
    AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
    autoCompleteSettings.setShowListOnEmptyInput(true);
    final AutoCompleteTextField<String> objectClass = new AutoCompleteTextField<String>(ID_OBJECT_CLASS, new PropertyModel<String>(getModel(), ResourceRelatedHandlerDto.F_OBJECT_CLASS), autoCompleteSettings) {

        @Override
        protected Iterator<String> getChoices(String input) {
            return prepareObjectClassChoiceList(input);
        }
    };
    objectClass.add(enabledIfEdit);
    objectClassContainer.add(objectClass);
    WebMarkupContainer optionsContainer = new WebMarkupContainer(ID_OPTIONS_CONTAINER);
    optionsContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getTaskDto().configuresDryRun();
        }
    });
    add(optionsContainer);
    WebMarkupContainer dryRunContainer = new WebMarkupContainer(ID_DRY_RUN_CONTAINER);
    dryRunContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getTaskDto().configuresDryRun();
        }
    });
    optionsContainer.add(dryRunContainer);
    CheckBox dryRun = new CheckBox(ID_DRY_RUN, new PropertyModel<Boolean>(getModel(), ResourceRelatedHandlerDto.F_DRY_RUN));
    dryRun.add(enabledIfEdit);
    dryRunContainer.add(dryRun);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) TextField(org.apache.wicket.markup.html.form.TextField) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) ArrayList(java.util.ArrayList) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) Definition(com.evolveum.midpoint.prism.Definition) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AutoCompleteSettings(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) CheckBox(org.apache.wicket.markup.html.form.CheckBox) TaskAddResourcesDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskAddResourcesDto) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 4 with AutoCompleteTextField

use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.

the class AutoCompleteItemDefinitionPanel method initLayout.

private void initLayout(final IModel<ItemDefinition<?>> model) {
    final Model<String> itemDefinitionAsStringModel = new Model<>(null);
    AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, itemDefinitionAsStringModel, String.class, createAutoCompleteSettings()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            List<String> defsAsString = new ArrayList<>();
            for (ItemDefinition<?> def : listChoices(input).values()) {
                defsAsString.add(def.getItemName().getLocalPart());
            }
            return defsAsString.iterator();
        }
    };
    input.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            onUpdateAutoComplete(target, itemDefinitionAsStringModel, model);
        }
    });
    add(input);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) ArrayList(java.util.ArrayList) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior)

Example 5 with AutoCompleteTextField

use of org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField in project midpoint by Evolveum.

the class AutoCompleteQNamePanel method initLayout.

private void initLayout(final IModel<T> model) {
    setOutputMarkupId(true);
    AutoCompleteSettings autoCompleteSettings = createAutoCompleteSettings();
    final IModel<String> stringModel = new Model<String>() {

        @Override
        public void setObject(String object) {
            super.setObject(object);
            model.setObject(convertToQname(object));
        }

        @Override
        public String getObject() {
            return (model.getObject() != null) ? model.getObject().getLocalPart() : null;
        }
    };
    // The inner autocomplete field is always String. Non-string auto-complete fields are problematic
    final AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, stringModel, String.class, autoCompleteSettings) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            return getIterator(input);
        }
    };
    input.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String inputString = stringModel.getObject();
            if (StringUtils.isBlank(inputString)) {
                T modelObject = model.getObject();
                if (modelObject != null) {
                    model.setObject(null);
                    AutoCompleteQNamePanel.this.onChange(target);
                }
            } else {
                T inputQName = convertToQname(stringModel.getObject());
                if (inputQName == null) {
                // We have some input, but it does not match any QName. Just do nothing.
                } else {
                    T modelObject = model.getObject();
                    if (inputQName.equals(modelObject)) {
                        model.setObject(inputQName);
                        AutoCompleteQNamePanel.this.onChange(target);
                    }
                }
            }
        }
    });
    add(input);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AutoCompleteSettings(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior)

Aggregations

AutoCompleteTextField (org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField)10 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)9 AutoCompleteSettings (org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings)7 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 IModel (org.apache.wicket.model.IModel)5 OnChangeAjaxBehavior (org.apache.wicket.ajax.form.OnChangeAjaxBehavior)4 PropertyModel (org.apache.wicket.model.PropertyModel)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)3 List (java.util.List)3 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)3 Model (org.apache.wicket.model.Model)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 StringChoiceRenderer (com.evolveum.midpoint.web.component.input.StringChoiceRenderer)2 TaskAddResourcesDto (com.evolveum.midpoint.web.page.admin.server.dto.TaskAddResourcesDto)2 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)2 TextField (org.apache.wicket.markup.html.form.TextField)2