Search in sources :

Example 11 with IChoiceRenderer

use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.

the class WebComponentUtil method createTriStateCombo.

public static DropDownChoice<Boolean> createTriStateCombo(String id, IModel<Boolean> model) {
    final IChoiceRenderer<Boolean> renderer = new IChoiceRenderer<Boolean>() {

        @Override
        public Boolean getObject(String id, IModel<? extends List<? extends Boolean>> choices) {
            return id != null ? choices.getObject().get(Integer.parseInt(id)) : null;
        }

        @Override
        public String getDisplayValue(Boolean object) {
            String key;
            if (object == null) {
                key = KEY_BOOLEAN_NULL;
            } else {
                key = object ? KEY_BOOLEAN_TRUE : KEY_BOOLEAN_FALSE;
            }
            StringResourceModel model = PageBase.createStringResourceStatic(null, key);
            return model.getString();
        }

        @Override
        public String getIdValue(Boolean object, int index) {
            return Integer.toString(index);
        }
    };
    DropDownChoice<Boolean> dropDown = new DropDownChoice<Boolean>(id, model, createChoices(), renderer) {

        @Override
        protected CharSequence getDefaultChoice(String selectedValue) {
            StringResourceModel model = PageBase.createStringResourceStatic(null, KEY_BOOLEAN_NULL);
            return model.getString();
        }
    };
    dropDown.setNullValid(true);
    return dropDown;
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) IModel(org.apache.wicket.model.IModel) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 12 with IChoiceRenderer

use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.

the class SynchronizationActionEditorDialog method initLayout.

private void initLayout(WebMarkupContainer content) {
    Form form = new MidpointForm(ID_MAIN_FORM);
    form.setOutputMarkupId(true);
    content.add(form);
    TextFormGroup name = new TextFormGroup(ID_NAME, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".name"), createStringResource("SynchronizationActionEditorDialog.label.name"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    form.add(name);
    TextAreaFormGroup description = new TextAreaFormGroup(ID_DESCRIPTION, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".description"), createStringResource("SynchronizationActionEditorDialog.label.description"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    form.add(description);
    DropDownFormGroup<SynchronizationActionTypeDto.HandlerUriActions> handlerUri = new DropDownFormGroup<SynchronizationActionTypeDto.HandlerUriActions>(ID_HANDLER_URI, new PropertyModel<>(model, SynchronizationActionTypeDto.F_HANDLER_URI), WebComponentUtil.createReadonlyModelFromEnum(SynchronizationActionTypeDto.HandlerUriActions.class), new EnumChoiceRenderer<>(this), createStringResource("SynchronizationActionEditorDialog.label.handlerUri"), createStringResource("SynchronizationStep.action.tooltip.handlerUri", WebComponentUtil.getMidpointCustomSystemName((PageResourceWizard) getPage(), "midpoint.default.system.name")), ID_LABEL_SIZE, ID_INPUT_SIZE, false, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<SynchronizationActionTypeDto.HandlerUriActions>> choices, IChoiceRenderer<SynchronizationActionTypeDto.HandlerUriActions> renderer, boolean required) {
            DropDownChoice choice = new DropDownChoice<>(id, getModel(), choices, renderer);
            choice.setNullValid(true);
            return choice;
        }
    };
    form.add(handlerUri);
    DropDownFormGroup<BeforeAfterType> order = new DropDownFormGroup<BeforeAfterType>(ID_ORDER, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".order"), WebComponentUtil.createReadonlyModelFromEnum(BeforeAfterType.class), new EnumChoiceRenderer<>(this), createStringResource("SynchronizationActionEditorDialog.label.order"), createStringResource("SynchronizationStep.action.tooltip.order", WebComponentUtil.getMidpointCustomSystemName((PageResourceWizard) getPage(), "midpoint.default.system.name")), ID_LABEL_SIZE, ID_INPUT_SIZE, false, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<BeforeAfterType>> choices, IChoiceRenderer<BeforeAfterType> renderer, boolean required) {
            DropDownChoice choice = new DropDownChoice<>(id, getModel(), choices, renderer);
            choice.setNullValid(true);
            return choice;
        }
    };
    form.add(order);
    initButtons(form);
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) SynchronizationActionTypeDto(com.evolveum.midpoint.web.component.wizard.resource.dto.SynchronizationActionTypeDto) TextFormGroup(com.evolveum.midpoint.web.component.form.TextFormGroup) IModel(org.apache.wicket.model.IModel) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) Form(org.apache.wicket.markup.html.form.Form) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) BeforeAfterType(com.evolveum.midpoint.xml.ns._public.common.common_3.BeforeAfterType) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) TextAreaFormGroup(com.evolveum.midpoint.web.component.form.TextAreaFormGroup) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice)

Example 13 with IChoiceRenderer

use of org.apache.wicket.markup.html.form.IChoiceRenderer 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 14 with IChoiceRenderer

use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.

the class NameStep method createConnectorDropDown.

private DropDownFormGroup<PrismObject<ConnectorType>> createConnectorDropDown() {
    return new DropDownFormGroup<PrismObject<ConnectorType>>(ID_CONNECTOR, selectedConnectorModel, relevantConnectorsModel, new IChoiceRenderer<PrismObject<ConnectorType>>() {

        @Override
        public PrismObject<ConnectorType> getObject(String id, IModel<? extends List<? extends PrismObject<ConnectorType>>> choices) {
            return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
        }

        @Override
        public Object getDisplayValue(PrismObject<ConnectorType> object) {
            return WebComponentUtil.getName(object);
        }

        @Override
        public String getIdValue(PrismObject<ConnectorType> object, int index) {
            if (index < 0) {
                // noinspection unchecked
                List<PrismObject<ConnectorType>> connectors = (List<PrismObject<ConnectorType>>) getConnectorDropDown().getInput().getChoices();
                for (PrismObject<ConnectorType> connector : connectors) {
                    if (connector.getOid().equals(selectedConnectorModel.getObject().getOid())) {
                        return Integer.toString(connectors.indexOf(connector));
                    }
                }
            }
            return Integer.toString(index);
        }
    }, createStringResource("NameStep.connectorType"), "col-md-3", "col-md-6", true) {

        @Override
        protected DropDownChoice<PrismObject<ConnectorType>> createDropDown(String id, IModel<List<PrismObject<ConnectorType>>> choices, IChoiceRenderer<PrismObject<ConnectorType>> renderer, boolean required) {
            DropDownChoice<PrismObject<ConnectorType>> choice = super.createDropDown(id, choices, renderer, required);
            choice.add(new AjaxFormComponentUpdatingBehavior("change") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(getConnectorDropDown().getAdditionalInfoComponent());
                }
            });
            choice.setOutputMarkupId(true);
            return choice;
        }

        @Override
        protected Component createAdditionalInfoComponent(String id) {
            Label l = new Label(id, schemaChangeWarningModel);
            l.add(new AttributeAppender("class", "text-danger"));
            l.setOutputMarkupId(true);
            return l;
        }
    };
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IModel(org.apache.wicket.model.IModel) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) Label(org.apache.wicket.markup.html.basic.Label) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) List(java.util.List) ArrayList(java.util.ArrayList) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 15 with IChoiceRenderer

use of org.apache.wicket.markup.html.form.IChoiceRenderer in project midpoint by Evolveum.

the class NameStep method createHostDropDown.

@NotNull
private DropDownFormGroup<PrismObject<ConnectorHostType>> createHostDropDown() {
    return new DropDownFormGroup<PrismObject<ConnectorHostType>>(ID_CONNECTOR_HOST, selectedHostModel, allHostsModel, new IChoiceRenderer<PrismObject<ConnectorHostType>>() {

        @Override
        public PrismObject<ConnectorHostType> getObject(String id, IModel<? extends List<? extends PrismObject<ConnectorHostType>>> choices) {
            if (StringUtils.isBlank(id)) {
                return null;
            }
            return choices.getObject().get(Integer.parseInt(id));
        }

        @Override
        public Object getDisplayValue(PrismObject<ConnectorHostType> object) {
            if (object == null) {
                return NameStep.this.getString("NameStep.hostNotUsed");
            }
            return ConnectorHostTypeComparator.getUserFriendlyName(object);
        }

        @Override
        public String getIdValue(PrismObject<ConnectorHostType> object, int index) {
            return Integer.toString(index);
        }
    }, createStringResource("NameStep.connectorHost"), "col-md-3", "col-md-6", false) {

        @Override
        protected DropDownChoice<PrismObject<ConnectorHostType>> createDropDown(String id, IModel<List<PrismObject<ConnectorHostType>>> choices, IChoiceRenderer<PrismObject<ConnectorHostType>> renderer, boolean required) {
            DropDownChoice<PrismObject<ConnectorHostType>> choice = super.createDropDown(id, choices, renderer, required);
            choice.add(new AjaxFormComponentUpdatingBehavior("change") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    discoverConnectorsPerformed(target);
                }
            });
            return choice;
        }
    };
}
Also used : ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IModel(org.apache.wicket.model.IModel) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IChoiceRenderer (org.apache.wicket.markup.html.form.IChoiceRenderer)15 IModel (org.apache.wicket.model.IModel)14 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 DropDownFormGroup (com.evolveum.midpoint.web.component.form.DropDownFormGroup)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)4 Form (org.apache.wicket.markup.html.form.Form)4 TextFormGroup (com.evolveum.midpoint.web.component.form.TextFormGroup)3 Label (org.apache.wicket.markup.html.basic.Label)3 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)3 PropertyModel (org.apache.wicket.model.PropertyModel)3 DisplayableValue (com.evolveum.midpoint.util.DisplayableValue)2 TextAreaFormGroup (com.evolveum.midpoint.web.component.form.TextAreaFormGroup)2 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)2 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)2 ExportType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExportType)2 EnumChoiceRenderer (org.apache.wicket.markup.html.form.EnumChoiceRenderer)2