Search in sources :

Example 1 with IChoiceRenderer

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

the class WebComponentUtil method createEnumPanel.

public static DropDownChoicePanel createEnumPanel(final PrismPropertyDefinition def, String id, final IModel model, final Component component) {
    // final Class clazz = model.getObject().getClass();
    final Object o = model.getObject();
    final IModel<List<DisplayableValue>> enumModelValues = new AbstractReadOnlyModel<List<DisplayableValue>>() {

        @Override
        public List<DisplayableValue> getObject() {
            List<DisplayableValue> values = null;
            if (def.getAllowedValues() != null) {
                values = new ArrayList<>(def.getAllowedValues().size());
                for (Object v : def.getAllowedValues()) {
                    if (v instanceof DisplayableValue) {
                        values.add(((DisplayableValue) v));
                    }
                }
            }
            return values;
        }
    };
    return new DropDownChoicePanel(id, model, enumModelValues, new IChoiceRenderer() {

        @Override
        public Object getObject(String id, IModel choices) {
            if (StringUtils.isBlank(id)) {
                return null;
            }
            return ((List) choices.getObject()).get(Integer.parseInt(id));
        }

        @Override
        public Object getDisplayValue(Object object) {
            if (object instanceof DisplayableValue) {
                return ((DisplayableValue) object).getLabel();
            }
            for (DisplayableValue v : enumModelValues.getObject()) {
                if (object.equals(v.getValue())) {
                    return v.getLabel();
                }
            }
            return object;
        }

        @Override
        public String getIdValue(Object object, int index) {
            if (object instanceof String && enumModelValues != null && enumModelValues.getObject() != null) {
                List<DisplayableValue> enumValues = enumModelValues.getObject();
                for (DisplayableValue v : enumValues) {
                    if (object.equals(v.getValue())) {
                        return String.valueOf(enumValues.indexOf(v));
                    }
                }
            }
            return String.valueOf(index);
        }
    }, true);
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) IModel(org.apache.wicket.model.IModel) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) DisplayableValue(com.evolveum.midpoint.util.DisplayableValue) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 2 with IChoiceRenderer

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

the class AjaxPalettePanel method initialize.

private void initialize(final IModel<List<T>> model, final Builder<T> builder) {
    setOutputMarkupId(true);
    this.palette = new NonI18nPalette<T>("paletteField", model, choicesModel, builder.renderer, 8, builder.allowOrder, builder.allowMoveAll) {

        private static final long serialVersionUID = -3074655279011678437L;

        @Override
        protected Component newAvailableHeader(final String componentId) {
            return new Label(componentId, new ResourceModel("palette.available", builder.availableLabel));
        }

        @Override
        protected Component newSelectedHeader(final String componentId) {
            return new Label(componentId, new ResourceModel("palette.selected", builder.selectedLabel));
        }

        @Override
        protected Recorder<T> newRecorderComponent() {
            return new Recorder<T>("recorder", this) {

                private static final long serialVersionUID = -9169109967480083523L;

                @Override
                public List<T> getUnselectedList() {
                    final IChoiceRenderer<? super T> renderer = getPalette().getChoiceRenderer();
                    final Collection<? extends T> choices = getPalette().getChoices();
                    final List<T> unselected = new ArrayList<>(choices.size());
                    final List<String> ids = Arrays.asList(getValue().split(","));
                    choices.forEach(choice -> {
                        final String choiceId = renderer.getIdValue(choice, 0);
                        if (!ids.contains(choiceId)) {
                            unselected.add(choice);
                        }
                    });
                    return unselected;
                }

                @Override
                public List<T> getSelectedList() {
                    final IChoiceRenderer<? super T> renderer = getPalette().getChoiceRenderer();
                    final Collection<? extends T> choices = getPalette().getChoices();
                    final List<T> selected = new ArrayList<>(choices.size());
                    // reduce number of method calls by building a lookup table
                    final Map<T, String> idForChoice = new HashMap<>(choices.size());
                    choices.forEach(choice -> {
                        idForChoice.put(choice, renderer.getIdValue(choice, 0));
                    });
                    final String value = getValue();
                    int start = value.indexOf(';') + 1;
                    for (final String id : Strings.split(value.substring(start), ',')) {
                        for (final T choice : choices) {
                            final String idValue = idForChoice.get(choice);
                            if (id.equals(idValue)) {
                                selected.add(choice);
                                break;
                            }
                        }
                    }
                    return selected;
                }
            };
        }
    };
    add(palette.setOutputMarkupId(true));
    final Form<?> form = new Form<>("form");
    add(form.setEnabled(builder.filtered).setVisible(builder.filtered));
    final AjaxTextFieldPanel filter = new AjaxTextFieldPanel("filter", "filter", queryFilter, false);
    filter.hideLabel().setOutputMarkupId(true);
    form.add(filter);
    form.add(new AjaxSubmitLink("search") {

        private static final long serialVersionUID = -1765773642975892072L;

        @Override
        protected void onAfterSubmit(final AjaxRequestTarget target, final Form<?> form) {
            super.onAfterSubmit(target, form);
            target.add(palette);
        }
    });
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) Label(org.apache.wicket.markup.html.basic.Label) Form(org.apache.wicket.markup.html.form.Form) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Palette(org.apache.wicket.extensions.markup.html.form.palette.Palette) Recorder(org.apache.wicket.extensions.markup.html.form.palette.component.Recorder) Collection(java.util.Collection) Model(org.apache.wicket.model.Model) Component(org.apache.wicket.Component) HashMap(java.util.HashMap) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) StringUtils(org.apache.commons.lang3.StringUtils) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Strings(org.apache.wicket.util.string.Strings) Pattern(java.util.regex.Pattern) IModel(org.apache.wicket.model.IModel) ResourceModel(org.apache.wicket.model.ResourceModel) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) Recorder(org.apache.wicket.extensions.markup.html.form.palette.component.Recorder) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResourceModel(org.apache.wicket.model.ResourceModel) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.apache.wicket.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with IChoiceRenderer

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

the class MappingEditorDialog method initLayout.

public 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, MappingTypeDto.F_MAPPING + ".name"), createStringResource("MappingEditorDialog.label.name"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    name.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(name);
    TextAreaFormGroup description = new TextAreaFormGroup(ID_DESCRIPTION, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".description"), createStringResource("MappingEditorDialog.label.description"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    description.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(description);
    CheckFormGroup authoritative = new CheckFormGroup(ID_AUTHORITATIVE, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".authoritative"), createStringResource("MappingEditorDialog.label.authoritative"), "SchemaHandlingStep.mapping.tooltip.authoritative", ID_LABEL_SIZE, ID_INPUT_SIZE);
    authoritative.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(authoritative);
    CheckFormGroup exclusive = new CheckFormGroup(ID_EXCLUSIVE, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".exclusive"), createStringResource("MappingEditorDialog.label.exclusive"), "SchemaHandlingStep.mapping.tooltip.exclusive", ID_LABEL_SIZE, ID_INPUT_SIZE);
    exclusive.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(exclusive);
    DropDownFormGroup strength = new DropDownFormGroup<>(ID_STRENGTH, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".strength"), WebComponentUtil.createReadonlyModelFromEnum(MappingStrengthType.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.strength"), "SchemaHandlingStep.mapping.tooltip.strength", ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    strength.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(strength);
    MultiValueDropDownPanel channel = new MultiValueDropDownPanel<String>(ID_CHANNEL, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".channel"), true, readOnlyModel) {

        @Override
        protected String createNewEmptyItem() {
            return "";
        }

        @Override
        protected IModel<List<String>> createChoiceList() {
            return new IModel<List<String>>() {

                @Override
                public List<String> getObject() {
                    return WebComponentUtil.getChannelList();
                }
            };
        }

        @Override
        protected IChoiceRenderer<String> createRenderer() {
            return CHANNEL_RENDERER;
        }
    };
    form.add(channel);
    MultiValueDropDownPanel exceptChannel = new MultiValueDropDownPanel<String>(ID_EXCEPT_CHANNEL, new PropertyModel<>(model, MappingTypeDto.F_MAPPING + ".exceptChannel"), true, readOnlyModel) {

        @Override
        protected String createNewEmptyItem() {
            return "";
        }

        @Override
        protected IModel<List<String>> createChoiceList() {
            return new IModel<List<String>>() {

                @Override
                public List<String> getObject() {
                    return WebComponentUtil.getChannelList();
                }
            };
        }

        @Override
        protected IChoiceRenderer<String> createRenderer() {
            return CHANNEL_RENDERER;
        }
    };
    form.add(exceptChannel);
    // TODO - create some nice ItemPathType editor in near future
    MultiValueTextPanel source = new MultiValueTextPanel<>(ID_SOURCE, new PropertyModel<List<String>>(model, MappingTypeDto.F_SOURCE), readOnlyModel, true);
    form.add(source);
    // TODO - create some nice ItemPathType editor in near future
    TextFormGroup target = new TextFormGroup(ID_TARGET, new PropertyModel<>(model, MappingTypeDto.F_TARGET), createStringResource("MappingEditorDialog.label.target"), "SchemaHandlingStep.mapping.tooltip.target", ID_LABEL_SIZE, ID_INPUT_SIZE, false, isTargetRequired);
    target.setOutputMarkupId(true);
    target.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(target);
    DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType> expressionType = new DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType>(ID_EXPRESSION_TYPE, new PropertyModel<>(model, MappingTypeDto.F_EXPRESSION_TYPE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.expressionType"), "SchemaHandlingStep.mapping.tooltip.expressionType", ID_LABEL_SIZE, ID_INPUT_SIZE, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<ExpressionUtil.ExpressionEvaluatorType>> choices, IChoiceRenderer<ExpressionUtil.ExpressionEvaluatorType> renderer, boolean required) {
            return new DropDownChoice<>(id, getModel(), choices, renderer);
        }
    };
    expressionType.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateExpression();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION));
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION_LANG));
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION_POLICY_REF));
        }
    });
    expressionType.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(expressionType);
    DropDownFormGroup expressionLanguage = new DropDownFormGroup<>(ID_EXPRESSION_LANG, new PropertyModel<>(model, MappingTypeDto.F_EXPRESSION_LANG), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.language"), "SchemaHandlingStep.mapping.tooltip.expressionLanguage", ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    expressionLanguage.setOutputMarkupId(true);
    expressionLanguage.setOutputMarkupPlaceholderTag(true);
    expressionLanguage.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(model.getObject().getExpressionType());
        }

        @Override
        public boolean isEnabled() {
            return !readOnlyModel.getObject();
        }
    });
    form.add(expressionLanguage);
    expressionLanguage.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateExpressionLanguage();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION));
        }
    });
    DropDownFormGroup<ObjectReferenceType> expressionGeneratePolicy = new DropDownFormGroup<ObjectReferenceType>(ID_EXPRESSION_POLICY_REF, new PropertyModel<>(model, MappingTypeDto.F_EXPRESSION_POLICY_REF), new IModel<List<ObjectReferenceType>>() {

        @Override
        public List<ObjectReferenceType> getObject() {
            return WebModelServiceUtils.createObjectReferenceList(ValuePolicyType.class, getPageBase(), policyMap);
        }
    }, new ObjectReferenceChoiceRenderer(policyMap), createStringResource("MappingEditorDialog.label.passPolicyRef"), "SchemaHandlingStep.mapping.tooltip.expressionValuePolicyRef", ID_LABEL_SIZE, ID_INPUT_SIZE, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<ObjectReferenceType>> choices, IChoiceRenderer<ObjectReferenceType> renderer, boolean required) {
            return new DropDownChoice<>(id, getModel(), choices, renderer);
        }
    };
    expressionGeneratePolicy.setOutputMarkupId(true);
    expressionGeneratePolicy.setOutputMarkupPlaceholderTag(true);
    expressionGeneratePolicy.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(model.getObject().getExpressionType());
        }

        @Override
        public boolean isEnabled() {
            return !readOnlyModel.getObject();
        }
    });
    expressionGeneratePolicy.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateExpressionGeneratePolicy();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_EXPRESSION));
        }
    });
    form.add(expressionGeneratePolicy);
    AceEditorFormGroup expression = new AceEditorFormGroup(ID_EXPRESSION, new PropertyModel<>(model, MappingTypeDto.F_EXPRESSION), createStringResource("MappingEditorDialog.label.expression"), "SchemaHandlingStep.mapping.tooltip.expression", ID_LABEL_SIZE, ID_INPUT_SIZE, false, CODE_ROW_COUNT);
    expression.setOutputMarkupId(true);
    expression.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(expression);
    DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType> conditionType = new DropDownFormGroup<ExpressionUtil.ExpressionEvaluatorType>(ID_CONDITION_TYPE, new PropertyModel<>(model, MappingTypeDto.F_CONDITION_TYPE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.conditionType"), "SchemaHandlingStep.mapping.tooltip.conditionType", ID_LABEL_SIZE, ID_INPUT_SIZE, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<ExpressionUtil.ExpressionEvaluatorType>> choices, IChoiceRenderer<ExpressionUtil.ExpressionEvaluatorType> renderer, boolean required) {
            return new DropDownChoice<>(id, getModel(), choices, renderer);
        }
    };
    conditionType.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateCondition();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION));
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION_LANG));
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION_POLICY_REF));
        }
    });
    form.add(conditionType);
    conditionType.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    DropDownFormGroup conditionLanguage = new DropDownFormGroup<>(ID_CONDITION_LANG, new PropertyModel<>(model, MappingTypeDto.F_CONDITION_LANG), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class), new EnumChoiceRenderer<>(this), createStringResource("MappingEditorDialog.label.language"), "SchemaHandlingStep.mapping.tooltip.conditionLanguage", ID_LABEL_SIZE, ID_INPUT_SIZE, false);
    conditionLanguage.setOutputMarkupId(true);
    conditionLanguage.setOutputMarkupPlaceholderTag(true);
    conditionLanguage.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(model.getObject().getConditionType());
        }

        @Override
        public boolean isEnabled() {
            return !readOnlyModel.getObject();
        }
    });
    conditionLanguage.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateConditionLanguage();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION));
        }
    });
    form.add(conditionLanguage);
    DropDownFormGroup<ObjectReferenceType> conditionGeneratePolicy = new DropDownFormGroup<ObjectReferenceType>(ID_CONDITION_POLICY_REF, new PropertyModel<>(model, MappingTypeDto.F_CONDITION_POLICY_REF), new IModel<List<ObjectReferenceType>>() {

        @Override
        public List<ObjectReferenceType> getObject() {
            return WebModelServiceUtils.createObjectReferenceList(ValuePolicyType.class, getPageBase(), policyMap);
        }
    }, new ObjectReferenceChoiceRenderer(policyMap), createStringResource("MappingEditorDialog.label.passPolicyRef"), "SchemaHandlingStep.mapping.tooltip.conditionValuePolicyRef", ID_LABEL_SIZE, ID_INPUT_SIZE, false) {

        @Override
        protected DropDownChoice createDropDown(String id, IModel<List<ObjectReferenceType>> choices, IChoiceRenderer<ObjectReferenceType> renderer, boolean required) {
            return new DropDownChoice<>(id, getModel(), choices, renderer);
        }
    };
    conditionGeneratePolicy.setOutputMarkupId(true);
    conditionGeneratePolicy.setOutputMarkupPlaceholderTag(true);
    conditionGeneratePolicy.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(model.getObject().getConditionType());
        }

        @Override
        public boolean isEnabled() {
            return !readOnlyModel.getObject();
        }
    });
    conditionGeneratePolicy.getInput().add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            model.getObject().updateConditionGeneratePolicy();
            target.add(get(getContentId() + ":" + ID_MAIN_FORM + ":" + ID_CONDITION));
        }
    });
    form.add(conditionGeneratePolicy);
    AceEditorFormGroup condition = new AceEditorFormGroup(ID_CONDITION, new PropertyModel<>(model, MappingTypeDto.F_CONDITION), createStringResource("MappingEditorDialog.label.condition"), "SchemaHandlingStep.mapping.tooltip.condition", ID_LABEL_SIZE, ID_INPUT_SIZE, false, CODE_ROW_COUNT);
    condition.setOutputMarkupId(true);
    condition.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    form.add(condition);
    Label channelTooltip = new Label(ID_T_CHANNEL);
    channelTooltip.add(new InfoTooltipBehavior());
    form.add(channelTooltip);
    Label exceptChannelTooltip = new Label(ID_T_EXCEPT_CHANNEL);
    exceptChannelTooltip.add(new InfoTooltipBehavior());
    form.add(exceptChannelTooltip);
    Label sourceTooltip = new Label(ID_T_SOURCE);
    sourceTooltip.add(new InfoTooltipBehavior());
    form.add(sourceTooltip);
    AjaxButton cancel = new AjaxButton(ID_BUTTON_CANCEL, createStringResource("MappingEditorDialog.button.cancel")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            cancelPerformed(target);
        }
    };
    form.add(cancel);
    AjaxSubmitButton save = new AjaxSubmitButton(ID_BUTTON_SAVE, createStringResource("MappingEditorDialog.button.apply")) {

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            savePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getPageBase().getFeedbackPanel(), getContent());
        }
    };
    save.add(WebComponentUtil.visibleIfFalse(readOnlyModel));
    form.add(save);
    setCloseButtonCallback(new CloseButtonCallback() {

        @Override
        public boolean onCloseButtonClicked(AjaxRequestTarget target) {
            cancelPerformed(target);
            return true;
        }
    });
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) ObjectReferenceChoiceRenderer(com.evolveum.midpoint.web.component.input.ObjectReferenceChoiceRenderer) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) MultiValueDropDownPanel(com.evolveum.midpoint.web.component.form.multivalue.MultiValueDropDownPanel) ArrayList(java.util.ArrayList) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) MultiValueTextPanel(com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextPanel) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) IModel(org.apache.wicket.model.IModel) MappingStrengthType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingStrengthType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) ExpressionUtil(com.evolveum.midpoint.web.util.ExpressionUtil)

Example 4 with IChoiceRenderer

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

the class CapabilityStep method editCapabilityPerformed.

@SuppressWarnings("unchecked")
private void editCapabilityPerformed(final AjaxRequestTarget target, CapabilityDto<? extends CapabilityType> capability) {
    dtoModel.getObject().setSelected(capability);
    WebMarkupContainer config = getConfigContainer();
    WebMarkupContainer newConfig;
    CapabilityType capType = capability.getCapability();
    if (capType instanceof ActivationCapabilityType) {
        newConfig = new CapabilityActivationPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ActivationCapabilityType>) capability), parentPage) {

            @Override
            public IModel<List<QName>> createAttributeChoiceModel(final IChoiceRenderer<QName> renderer) {
                LoadableModel<List<QName>> attributeChoiceModel = new LoadableModel<List<QName>>(false) {

                    @Override
                    protected List<QName> load() {
                        List<QName> choices = new ArrayList<>();
                        PrismObject<ResourceType> resourcePrism = resourceModel.getObject();
                        try {
                            ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resourcePrism);
                            if (schema != null) {
                                // TODO is this OK?
                                ResourceObjectTypeDefinition def = schema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
                                if (def != null) {
                                    for (ResourceAttributeDefinition<?> attribute : def.getAttributeDefinitions()) {
                                        choices.add(attribute.getItemName());
                                    }
                                }
                            }
                        } catch (CommonException | RuntimeException e) {
                            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource schema attributes.", e);
                            getPageBase().error("Couldn't load resource schema attributes" + e);
                        }
                        choices.sort((o1, o2) -> {
                            String s1 = (String) renderer.getDisplayValue(o1);
                            String s2 = (String) renderer.getDisplayValue(o2);
                            return String.CASE_INSENSITIVE_ORDER.compare(s1, s2);
                        });
                        return choices;
                    }
                };
                parentPage.registerDependentModel(attributeChoiceModel);
                return attributeChoiceModel;
            }
        };
    } else if (capType instanceof ScriptCapabilityType) {
        newConfig = new CapabilityScriptPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ScriptCapabilityType>) capability), getTable(), parentPage);
    } else if (capType instanceof CredentialsCapabilityType) {
        newConfig = new CapabilityCredentialsPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CredentialsCapabilityType>) capability), getTable(), parentPage);
    } else {
        newConfig = new CapabilityValuePanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CapabilityType>) capability), getTable(), parentPage);
    }
    // TODO other specific capabilities (paged, count, ...)
    newConfig.setOutputMarkupId(true);
    config.replaceWith(newConfig);
    target.add(newConfig);
    target.add(getTable());
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchemaFactory(com.evolveum.midpoint.schema.processor.ResourceSchemaFactory) com.evolveum.midpoint.web.component.wizard.resource.component.capability(com.evolveum.midpoint.web.component.wizard.resource.component.capability) WebModelServiceUtils(com.evolveum.midpoint.gui.api.util.WebModelServiceUtils) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PageResourceWizard(com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard) IModel(org.apache.wicket.model.IModel) Method(java.lang.reflect.Method) Label(org.apache.wicket.markup.html.basic.Label) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) Model(org.apache.wicket.model.Model) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) AttributeModifier(org.apache.wicket.AttributeModifier) com.evolveum.midpoint.xml.ns._public.resource.capabilities_3(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3) InvocationTargetException(java.lang.reflect.InvocationTargetException) ModelService(com.evolveum.midpoint.model.api.ModelService) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) PropertyModel(org.apache.wicket.model.PropertyModel) Item(org.apache.wicket.markup.repeater.Item) Type(java.lang.reflect.Type) SystemException(com.evolveum.midpoint.util.exception.SystemException) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) QName(javax.xml.namespace.QName) DataView(org.apache.wicket.markup.repeater.data.DataView) NotNull(org.jetbrains.annotations.NotNull) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) java.util(java.util) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) CapabilityUtil(com.evolveum.midpoint.schema.CapabilityUtil) Capability(com.evolveum.midpoint.web.component.wizard.resource.dto.Capability) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) JAXBElement(javax.xml.bind.JAXBElement) WizardStep(com.evolveum.midpoint.web.component.wizard.WizardStep) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) CommonException(com.evolveum.midpoint.util.exception.CommonException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ParameterizedType(java.lang.reflect.ParameterizedType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) IModel(org.apache.wicket.model.IModel) QName(javax.xml.namespace.QName) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) PropertyModel(org.apache.wicket.model.PropertyModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel)

Example 5 with IChoiceRenderer

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

the class GuiComponents method createTriStateCombo.

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

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

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

        @Override
        public String getIdValue(T object, int index) {
            return Integer.toString(index);
        }
    };
    DropDownChoice dropDown = new DropDownChoice(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) ArrayList(java.util.ArrayList) List(java.util.List) StringResourceModel(org.apache.wicket.model.StringResourceModel)

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