Search in sources :

Example 11 with InputPanel

use of com.evolveum.midpoint.web.component.prism.InputPanel in project midpoint by Evolveum.

the class SwitchablePropertyValuePanel method getValueField.

private <T> Component getValueField(String id) {
    Component searchItemField = null;
    ItemDefinition propertyDef = getPropertyItemDefinition();
    if (propertyDef != null) {
        PrismObject<LookupTableType> lookupTable = WebComponentUtil.findLookupTable(propertyDef, getPageBase());
        if (propertyDef instanceof PrismReferenceDefinition) {
            searchItemField = new ReferenceValueSearchPanel(id, new PropertyModel<>(getModel(), "value.value"), (PrismReferenceDefinition) propertyDef) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void referenceValueUpdated(ObjectReferenceType ort, AjaxRequestTarget target) {
                    SwitchablePropertyValuePanel.this.getModelObject().getValue().setValue(ort);
                }
            };
        } else if (propertyDef instanceof PrismPropertyDefinition) {
            List<DisplayableValue> allowedValues = new ArrayList<>();
            if (((PrismPropertyDefinition) propertyDef).getAllowedValues() != null) {
                allowedValues.addAll(((PrismPropertyDefinition) propertyDef).getAllowedValues());
            } else if (propertyDef.getTypeClass().equals(boolean.class) || Boolean.class.isAssignableFrom(propertyDef.getTypeClass())) {
                allowedValues.add(new SearchValue<>(Boolean.TRUE, getString("Boolean.TRUE")));
                allowedValues.add(new SearchValue<>(Boolean.FALSE, getString("Boolean.FALSE")));
            }
            if (lookupTable != null) {
                searchItemField = new AutoCompleteTextPanel<String>(id, new PropertyModel<>(getModel(), "value." + ValueSearchFilterItem.F_VALUE), String.class, true, lookupTable.asObjectable()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public Iterator<String> getIterator(String input) {
                        return WebComponentUtil.prepareAutoCompleteList(lookupTable.asObjectable(), input, ((PageBase) getPage()).getLocalizationService()).iterator();
                    }
                };
            } else if (CollectionUtils.isNotEmpty(allowedValues)) {
                List<T> allowedValuesList = new ArrayList<>();
                allowedValues.forEach(val -> allowedValuesList.add((T) val.getValue()));
                searchItemField = new DropDownChoicePanel<T>(id, new PropertyModel<>(getModel(), "value." + ValueSearchFilterItem.F_VALUE), Model.ofList(allowedValuesList), new IChoiceRenderer<T>() {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public Object getDisplayValue(T val) {
                        if (val instanceof DisplayableValue) {
                            return ((DisplayableValue) val).getLabel();
                        }
                        return val;
                    }

                    @Override
                    public String getIdValue(T val, int index) {
                        return Integer.toString(index);
                    }

                    @Override
                    public T getObject(String id, IModel<? extends List<? extends T>> choices) {
                        return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
                    }
                }, true);
            } else {
                searchItemField = new TextPanel<String>(id, new PropertyModel<>(getModel(), "value." + ValueSearchFilterItem.F_VALUE));
            }
        }
    }
    if (searchItemField instanceof InputPanel) {
        ((InputPanel) searchItemField).getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    }
    return searchItemField != null ? searchItemField : new WebMarkupContainer(id);
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) ArrayList(java.util.ArrayList) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) DisplayableValue(com.evolveum.midpoint.util.DisplayableValue) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.apache.wicket.Component) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) IModel(org.apache.wicket.model.IModel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)

Example 12 with InputPanel

use of com.evolveum.midpoint.web.component.prism.InputPanel in project midpoint by Evolveum.

the class SearchPropertyPanel method initSearchItemField.

protected void initSearchItemField(WebMarkupContainer searchItemContainer) {
    Component searchItemField;
    PropertySearchItem<T> item = getModelObject();
    IModel<List<DisplayableValue<?>>> choices = null;
    switch(item.getSearchItemType()) {
        case REFERENCE:
            searchItemField = new ReferenceValueSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"), (PrismReferenceDefinition) item.getDefinition().getDef()) {

                @Override
                public Boolean isItemPanelEnabled() {
                    return item.isEnabled();
                }

                @Override
                protected boolean isAllowedNotFoundObjectRef() {
                    return item.getSearch().getTypeClass().equals(AuditEventRecordType.class);
                }

                @Override
                protected List<QName> getAllowedRelations() {
                    if (item.getSearch().getTypeClass().equals(AuditEventRecordType.class)) {
                        return Collections.emptyList();
                    }
                    return super.getAllowedRelations();
                }
            };
            break;
        case BOOLEAN:
            choices = (IModel) createBooleanChoices();
        case ENUM:
            if (choices == null) {
                choices = new ListModel(item.getAllowedValues(getPageBase()));
            }
            searchItemField = WebComponentUtil.createDropDownChoices(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), "value"), (IModel) choices, true, getPageBase());
            break;
        case DATE:
            searchItemField = new DateIntervalSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), "fromDate"), new PropertyModel(getModel(), "toDate"));
            break;
        case ITEM_PATH:
            searchItemField = new ItemPathSearchPanel(ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), "value.value"));
            break;
        case TEXT:
            PrismObject<LookupTableType> lookupTable = WebComponentUtil.findLookupTable(item.getDefinition().getDef(), getPageBase());
            if (lookupTable != null) {
                searchItemField = createAutoCompetePanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"), lookupTable.asObjectable());
            } else {
                searchItemField = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"));
            }
            break;
        default:
            searchItemField = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value"));
    }
    if (searchItemField instanceof InputPanel && !(searchItemField instanceof AutoCompleteTextPanel)) {
        FormComponent<?> baseFormComponent = ((InputPanel) searchItemField).getBaseFormComponent();
        baseFormComponent.add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
        baseFormComponent.add(AttributeAppender.append("style", "width: 140px; max-width: 400px !important;"));
        baseFormComponent.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
        baseFormComponent.add(new VisibleEnableBehaviour() {

            @Override
            public boolean isEnabled() {
                return item.isEnabled();
            }

            @Override
            public boolean isVisible() {
                return item.isVisible();
            }
        });
    }
    searchItemField.setOutputMarkupId(true);
    searchItemContainer.add(searchItemField);
}
Also used : IModel(org.apache.wicket.model.IModel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) ListModel(org.apache.wicket.model.util.ListModel) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)

Example 13 with InputPanel

use of com.evolveum.midpoint.web.component.prism.InputPanel in project midpoint by Evolveum.

the class AbstractInputGuiComponentFactory method configure.

@Override
public void configure(PrismPropertyPanelContext<T> panelCtx, Component component) {
    if (!(component instanceof InputPanel)) {
        return;
    }
    InputPanel panel = (InputPanel) component;
    final List<FormComponent> formComponents = panel.getFormComponents();
    for (FormComponent<T> formComponent : formComponents) {
        PrismPropertyWrapper<T> propertyWrapper = panelCtx.unwrapWrapperModel();
        IModel<String> label = LambdaModel.of(propertyWrapper::getDisplayName);
        formComponent.setLabel(label);
        formComponent.setRequired(panelCtx.isMandatory());
        if (formComponent instanceof TextField) {
            formComponent.add(new AttributeModifier("size", "42"));
        }
        formComponent.add(panelCtx.getAjaxEventBehavior());
        formComponent.add(panelCtx.getVisibleEnableBehavior());
    }
    panel.getValidatableComponent().add(panelCtx.getExpressionValidator());
    panelCtx.getFeedback().setFilter(new ComponentFeedbackMessageFilter(panel.getValidatableComponent()));
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) ComponentFeedbackMessageFilter(org.apache.wicket.feedback.ComponentFeedbackMessageFilter) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) TextField(org.apache.wicket.markup.html.form.TextField) AttributeModifier(org.apache.wicket.AttributeModifier)

Example 14 with InputPanel

use of com.evolveum.midpoint.web.component.prism.InputPanel in project midpoint by Evolveum.

the class ACAttributeValuePanel method initLayout.

private void initLayout(Form form, boolean ignoreMandatoryAttributes) {
    ACValueConstructionDto dto = getModel().getObject();
    PrismPropertyDefinition definition = dto.getAttribute().getDefinition();
    InputPanel input = createTypedInputComponent(ID_INPUT, definition);
    for (FormComponent comp : input.getFormComponents()) {
        comp.setLabel(new PropertyModel<>(dto.getAttribute(), ACAttributeDto.F_NAME));
        if (!ignoreMandatoryAttributes) {
            comp.setRequired(definition.getMinOccurs() > 0);
        }
        comp.add(new AjaxFormComponentUpdatingBehavior("blur") {

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
            }
        });
    }
    add(input);
    AjaxLink<Void> addLink = new AjaxLink<Void>(ID_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addPerformed(target);
        }
    };
    add(addLink);
    addLink.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return isAddVisible();
        }
    });
    AjaxLink<Void> removeLink = new AjaxLink<Void>(ID_REMOVE) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            removePerformed(target);
        }
    };
    add(removeLink);
    removeLink.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return isRemoveVisible();
        }
    });
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) FormComponent(org.apache.wicket.markup.html.form.FormComponent) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Aggregations

InputPanel (com.evolveum.midpoint.web.component.prism.InputPanel)14 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)9 PropertyModel (org.apache.wicket.model.PropertyModel)9 IModel (org.apache.wicket.model.IModel)8 Component (org.apache.wicket.Component)7 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)6 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)6 FormComponent (org.apache.wicket.markup.html.form.FormComponent)6 EmptyOnBlurAjaxFormUpdatingBehaviour (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour)5 TextPanel (com.evolveum.midpoint.web.component.input.TextPanel)4 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)3 Label (org.apache.wicket.markup.html.basic.Label)3 PasswordPanel (com.evolveum.midpoint.gui.api.component.password.PasswordPanel)2 DisplayableValue (com.evolveum.midpoint.util.DisplayableValue)2