Search in sources :

Example 26 with DropDownChoice

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

the class ConstructionDetailsPanelChainedModel method initLayout.

private void initLayout() {
    CompoundPropertyModel constrModel = new CompoundPropertyModel(getModel()) {

        @Override
        public Object getObject() {
            Object o = super.getObject();
            return o;
        }

        @Override
        public void setObject(Object o) {
            super.setObject(o);
        }
    };
    Form<ConstructionType> form = new Form<ConstructionType>(ID_FORM, constrModel);
    form.setOutputMarkupId(true);
    DropDownChoice kindChoice = new DropDownChoice<>("kind", Model.ofList(Arrays.asList(ShadowKindType.values())));
    kindChoice.setOutputMarkupId(true);
    kindChoice.add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

        @Override
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
        // ajaxRequestTarget.add(form);
        }
    });
    // kindChoice.add(new AjaxEventBehavior("blur") {
    // @Override
    // protected void onEvent(AjaxRequestTarget ajaxRequestTarget) {
    // ajaxRequestTarget.add(form);
    // }
    // });
    form.add(kindChoice);
    DropDownChoice intentDropdown = new DropDownChoice<>("intent", new IModel<List<String>>() {

        @Override
        public List<String> getObject() {
            List<String> availableIntentValues = new ArrayList<>();
            try {
                if (resourceModel.getObject() == null) {
                    return availableIntentValues;
                }
                ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resourceModel.getObject());
                if (refinedSchema != null) {
                    ConstructionType m = (ConstructionType) constrModel.getObject();
                    ShadowKindType kind = m.getKind();
                    List<? extends ResourceObjectTypeDefinition> definitions = refinedSchema.getObjectTypeDefinitions(kind);
                    for (ResourceObjectTypeDefinition def : definitions) {
                        if (def.getIntent() != null) {
                            availableIntentValues.add(def.getIntent());
                        }
                    }
                }
            } catch (SchemaException ex) {
                LOGGER.error("Cannot get refined resource schema for resource {}. {}", resourceModel.getObject().getName().getOrig(), ex.getLocalizedMessage());
            }
            return availableIntentValues;
        }

        @Override
        public void setObject(List<String> o) {
        // 
        }

        @Override
        public void detach() {
        }
    });
    intentDropdown.setOutputMarkupId(true);
    form.add(intentDropdown);
    add(form);
// DropDownChoice kindDropDown = new DropDownChoice<ShadowKindType>(ID_KIND_FIELD, kindModel, Model.ofList(Arrays.asList(ShadowKindType.values()))){
// @Override
// protected void onSelectionChanged(ShadowKindType newSelection) {
// if (newSelection == null){
// ConstructionDetailsPanelChainedModel.this.getModelObject().setKind(null);
// return;
// }
// if (newSelection instanceof ShadowKindType){
// ConstructionDetailsPanelChainedModel.this.getModelObject().setKind((ShadowKindType) newSelection);
// }
// }
// };
// kindDropDown.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// 
// kindDropDown.setOutputMarkupId(true);
// add(kindDropDown);
// 
// TextField intentDropDown = new TextField(ID_INTENT_FIELD, intentChoicesModel);
// DropDownChoicePanel intentDropDown = new DropDownChoicePanel(ID_INTENT_FIELD,
// PropertyModel.of(getModel(), ConstructionType.F_INTENT.getLocalPart()), intentChoicesModel);
// intentDropDown.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// intentDropDown.setOutputMarkupId(true);
// add(intentDropDown);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Form(org.apache.wicket.markup.html.form.Form) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) PrismObject(com.evolveum.midpoint.prism.PrismObject) ArrayList(java.util.ArrayList) List(java.util.List) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 27 with DropDownChoice

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

the class PageEvaluateMapping method initLayout.

private void initLayout() {
    Form mainForm = new MidpointForm(ID_MAIN_FORM);
    add(mainForm);
    AceEditor editorMapping = new AceEditor(ID_EDITOR_MAPPING, new PropertyModel<>(model, ExecuteMappingDto.F_MAPPING));
    editorMapping.setHeight(400);
    editorMapping.setResizeToMaxHeight(false);
    mainForm.add(editorMapping);
    AceEditor editorRequest = new AceEditor(ID_EDITOR_REQUEST, new PropertyModel<>(model, ExecuteMappingDto.F_REQUEST));
    editorRequest.setHeight(430);
    editorRequest.setResizeToMaxHeight(false);
    mainForm.add(editorRequest);
    AjaxSubmitButton evaluateMapping = new AjaxSubmitButton(ID_EXECUTE, createStringResource("PageEvaluateMapping.button.evaluateMapping")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            executeMappingPerformed(target);
        }
    };
    mainForm.add(evaluateMapping);
    final DropDownChoice<String> sampleChoice = new DropDownChoice<>(ID_MAPPING_SAMPLE, Model.of(""), (IModel<List<String>>) () -> SAMPLES, new StringResourceChoiceRenderer("PageEvaluateMapping.sample"));
    sampleChoice.setNullValid(true);
    sampleChoice.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String sampleName = sampleChoice.getModelObject();
            if (StringUtils.isEmpty(sampleName)) {
                return;
            }
            model.getObject().setMapping(readResource(SAMPLES_DIR + "/" + sampleName + ".map.xml.data"));
            model.getObject().setRequest(readResource(SAMPLES_DIR + "/" + sampleName + ".req.xml.data"));
            model.getObject().setResultText("");
            target.add(PageEvaluateMapping.this);
        }

        private String readResource(String name) {
            try (InputStream is = PageEvaluateMapping.class.getResourceAsStream(name)) {
                if (is != null) {
                    return IOUtils.toString(is, StandardCharsets.UTF_8);
                } else {
                    LOGGER.warn("Resource {} containing sample couldn't be found", name);
                }
            } catch (IOException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't read sample from resource {}", e, name);
            }
            return null;
        }
    });
    mainForm.add(sampleChoice);
    AceEditor resultText = new AceEditor(ID_RESULT_TEXT, new PropertyModel<>(model, ExecuteMappingDto.F_RESULT_TEXT));
    resultText.setReadonly(true);
    resultText.setHeight(300);
    resultText.setResizeToMaxHeight(false);
    resultText.setMode(null);
    mainForm.add(resultText);
}
Also used : AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) StringResourceChoiceRenderer(com.evolveum.midpoint.web.util.StringResourceChoiceRenderer) Form(org.apache.wicket.markup.html.form.Form) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) InputStream(java.io.InputStream) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AceEditor(com.evolveum.midpoint.web.component.AceEditor) IOException(java.io.IOException) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) List(java.util.List)

Example 28 with DropDownChoice

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

the class DateInput method computeDateTime.

public Date computeDateTime() {
    Date dateFieldInputValue = getDateTextField().getModelObject();
    if (dateFieldInputValue == null) {
        return null;
    }
    Integer hoursInput = ((TextField<Integer>) get(HOURS)).getModelObject();
    Integer minutesInput = ((TextField<Integer>) get(MINUTES)).getModelObject();
    AM_PM amOrPmInput = ((DropDownChoice<DateTimeField.AM_PM>) get(AM_OR_PM_CHOICE)).getModelObject();
    // Get year, month and day ignoring any timezone of the Date object
    Calendar cal = Calendar.getInstance();
    cal.setTime(dateFieldInputValue);
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int hours = (hoursInput == null ? 0 : hoursInput % 24);
    int minutes = (minutesInput == null ? 0 : minutesInput);
    // Use the input to create a date object with proper timezone
    MutableDateTime date = new MutableDateTime(year, month, day, hours, minutes, 0, 0, DateTimeZone.forTimeZone(getClientTimeZone()));
    // Adjust for halfday if needed
    if (use12HourFormat()) {
        int halfday = (amOrPmInput == AM_PM.PM ? 1 : 0);
        date.set(DateTimeFieldType.halfdayOfDay(), halfday);
        date.set(DateTimeFieldType.hourOfHalfday(), hours % 12);
    }
    // The date will be in the server's timezone
    Date convertedDateValue = newDateInstance(date.getMillis());
    setConvertedInput(convertedDateValue);
    return convertedDateValue;
}
Also used : DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) TextField(org.apache.wicket.markup.html.form.TextField) DateTextField(org.apache.wicket.datetime.markup.html.form.DateTextField) MutableDateTime(org.joda.time.MutableDateTime) DateTimeField(org.apache.wicket.extensions.yui.calendar.DateTimeField) Date(java.util.Date)

Example 29 with DropDownChoice

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

the class ExpressionEditorPanel method initLayout.

protected void initLayout(PageResourceWizard parentPage) {
    parentPage.addEditingEnabledBehavior(this);
    setOutputMarkupId(true);
    loadDtoModel();
    Label descriptionLabel = new Label(ID_LABEL_DESCRIPTION, createStringResource(getDescriptionLabelKey()));
    add(descriptionLabel);
    TextArea description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_DESCRIPTION));
    description.setOutputMarkupId(true);
    //parentPage.addEditingEnabledBehavior(description);
    add(description);
    Label typeLabel = new Label(ID_LABEL_TYPE, createStringResource(getTypeLabelKey()));
    add(typeLabel);
    DropDownChoice type = new DropDownChoice<>(ID_TYPE, new PropertyModel<ExpressionUtil.ExpressionEvaluatorType>(dtoModel, ExpressionTypeDto.F_TYPE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class), new EnumChoiceRenderer<ExpressionUtil.ExpressionEvaluatorType>(this));
    //parentPage.addEditingEnabledBehavior(type);
    type.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionType();
            //target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
            // because of ACE editor
            target.add(ExpressionEditorPanel.this);
        }
    });
    type.setOutputMarkupId(true);
    type.setOutputMarkupPlaceholderTag(true);
    type.setNullValid(true);
    add(type);
    WebMarkupContainer languageContainer = new WebMarkupContainer(ID_LANGUAGE_CONTAINER);
    languageContainer.setOutputMarkupId(true);
    languageContainer.setOutputMarkupPlaceholderTag(true);
    languageContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(dtoModel.getObject().getType());
        }
    });
    //parentPage.addEditingEnabledBehavior(languageContainer);
    add(languageContainer);
    DropDownChoice language = new DropDownChoice<>(ID_LANGUAGE, new PropertyModel<ExpressionUtil.Language>(dtoModel, ExpressionTypeDto.F_LANGUAGE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class), new EnumChoiceRenderer<ExpressionUtil.Language>(this));
    //parentPage.addEditingEnabledBehavior(language);
    language.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionLanguage();
            //target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
            // because of ACE editor
            target.add(ExpressionEditorPanel.this);
        }
    });
    language.setNullValid(false);
    languageContainer.add(language);
    WebMarkupContainer policyContainer = new WebMarkupContainer(ID_POLICY_CONTAINER);
    policyContainer.setOutputMarkupId(true);
    policyContainer.setOutputMarkupPlaceholderTag(true);
    policyContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(dtoModel.getObject().getType());
        }
    });
    add(policyContainer);
    DropDownChoice policyRef = new DropDownChoice<>(ID_POLICY_REF, new PropertyModel<ObjectReferenceType>(dtoModel, ExpressionTypeDto.F_POLICY_REF), new AbstractReadOnlyModel<List<ObjectReferenceType>>() {

        @Override
        public List<ObjectReferenceType> getObject() {
            return WebModelServiceUtils.createObjectReferenceList(ValuePolicyType.class, getPageBase(), policyMap);
        }
    }, new ObjectReferenceChoiceRenderer(policyMap));
    //parentPage.addEditingEnabledBehavior(policyRef);
    policyRef.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionValuePolicyRef();
            target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
        }
    });
    policyRef.setNullValid(true);
    policyContainer.add(policyRef);
    Label expressionLabel = new Label(ID_LABEL_EXPRESSION, createStringResource(getExpressionLabelKey()));
    add(expressionLabel);
    AceEditor expression = new AceEditor(ID_EXPRESSION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_EXPRESSION));
    expression.setOutputMarkupId(true);
    //parentPage.addEditingEnabledBehavior(expression);
    add(expression);
    AjaxSubmitLink update = new AjaxSubmitLink(ID_BUTTON_UPDATE) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            updateExpressionPerformed(target);
        }
    };
    Label updateLabel = new Label(ID_LABEL_UPDATE, createStringResource(getUpdateLabelKey()));
    updateLabel.setRenderBodyOnly(true);
    update.add(updateLabel);
    parentPage.addEditingVisibleBehavior(update);
    add(update);
    add(WebComponentUtil.createHelp(ID_T_TYPE));
    languageContainer.add(WebComponentUtil.createHelp(ID_T_LANGUAGE));
    policyContainer.add(WebComponentUtil.createHelp(ID_T_POLICY));
    add(WebComponentUtil.createHelp(ID_T_EXPRESSION));
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) TextArea(org.apache.wicket.markup.html.form.TextArea) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AceEditor(com.evolveum.midpoint.web.component.AceEditor) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice)

Example 30 with DropDownChoice

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

the class ChooseFocusTypeDialogPanel method initLayout.

private void initLayout() {
    DropDownChoice<QName> type = new DropDownChoice<QName>(ID_OBJECT_TYPE, Model.of(UserType.COMPLEX_TYPE), WebComponentUtil.createFocusTypeList(), new QNameChoiceRenderer());
    type.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    type.setOutputMarkupId(true);
    add(type);
    AjaxButton confirmButton = new AjaxButton(ID_BUTTON_OK, createStringResource("Button.ok")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            DropDownChoice<QName> type = (DropDownChoice<QName>) getParent().get(ID_OBJECT_TYPE);
            QName typeChosen = type.getModelObject();
            ChooseFocusTypeDialogPanel.this.okPerformed(typeChosen, target);
        }
    };
    add(confirmButton);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) QNameChoiceRenderer(com.evolveum.midpoint.web.component.input.QNameChoiceRenderer) EmptyOnChangeAjaxFormUpdatingBehavior(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) QName(javax.xml.namespace.QName)

Aggregations

DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)52 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)30 List (java.util.List)18 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)17 Label (org.apache.wicket.markup.html.basic.Label)17 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)16 CheckBox (org.apache.wicket.markup.html.form.CheckBox)14 IModel (org.apache.wicket.model.IModel)14 ArrayList (java.util.ArrayList)12 OnChangeAjaxBehavior (org.apache.wicket.ajax.form.OnChangeAjaxBehavior)11 Form (org.apache.wicket.markup.html.form.Form)11 TextField (org.apache.wicket.markup.html.form.TextField)11 PropertyModel (org.apache.wicket.model.PropertyModel)11 QName (javax.xml.namespace.QName)10 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)8 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)7 QNameChoiceRenderer (com.evolveum.midpoint.web.component.input.QNameChoiceRenderer)6 ListItem (org.apache.wicket.markup.html.list.ListItem)6 ListView (org.apache.wicket.markup.html.list.ListView)6 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)5