Search in sources :

Example 6 with FormComponent

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

the class PrismValuePanel method createInputComponent.

private Panel createInputComponent(String id, IModel<String> labelModel, Form form) {
    ValueWrapper valueWrapper = valueWrapperModel.getObject();
    ObjectWrapper objectWrapper = null;
    if (valueWrapper.getItem().getContainer() != null) {
        objectWrapper = valueWrapper.getItem().getContainer().getObject();
    }
    Item property = valueWrapper.getItem().getItem();
    boolean required = property.getDefinition().getMinOccurs() > 0;
    Panel component = createTypedInputComponent(id);
    if (component instanceof InputPanel) {
        InputPanel inputPanel = (InputPanel) component;
        //adding valid from/to date range validator, if necessary
        ItemPath activation = new ItemPath(UserType.F_ACTIVATION);
        if (ActivationType.F_VALID_FROM.equals(property.getElementName())) {
            DateValidator validator = WebComponentUtil.getRangeValidator(form, activation);
            validator.setDateFrom((DateTimeField) inputPanel.getBaseFormComponent());
        } else if (ActivationType.F_VALID_TO.equals(property.getElementName())) {
            DateValidator validator = WebComponentUtil.getRangeValidator(form, activation);
            validator.setDateTo((DateTimeField) inputPanel.getBaseFormComponent());
        }
        final List<FormComponent> formComponents = inputPanel.getFormComponents();
        for (FormComponent formComponent : formComponents) {
            formComponent.setLabel(labelModel);
            formComponent.setRequired(required);
            if (formComponent instanceof TextField) {
                formComponent.add(new AttributeModifier("size", "42"));
            }
            formComponent.add(new AjaxFormComponentUpdatingBehavior("blur") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            });
        // Validation occurs when submitting the form
        //            if (form != null) {
        //                AjaxFormValidatingBehavior validator = new AjaxFormValidatingBehavior(form, "Blur"); 
        //                 
        //                formComponent.add(validator);
        //            }
        }
    }
    if (component == null) {
        throw new RuntimeException("Cannot create input component for item " + property + " (" + valueWrapper + ") in " + objectWrapper);
    }
    return component;
}
Also used : DateValidator(com.evolveum.midpoint.web.util.DateValidator) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) FormComponent(org.apache.wicket.markup.html.form.FormComponent) DateTimeField(org.apache.wicket.extensions.yui.calendar.DateTimeField) AttributeModifier(org.apache.wicket.AttributeModifier) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) LockoutStatusPanel(com.evolveum.midpoint.web.component.LockoutStatusPanel) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) ValueChoosePanel(com.evolveum.midpoint.web.component.form.ValueChoosePanel) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) ModificationsPanel(com.evolveum.midpoint.web.component.model.delta.ModificationsPanel) Panel(org.apache.wicket.markup.html.panel.Panel) AssociationValueChoicePanel(com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel) TextField(org.apache.wicket.markup.html.form.TextField) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with FormComponent

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

the class RunReportPopupPanel method createTypedInputPanel.

private InputPanel createTypedInputPanel(String componentId, IModel<JasperReportValueDto> model, String expression, JasperReportParameterDto param) {
    InputPanel panel;
    Class<?> type;
    try {
        if (param.isMultiValue()) {
            type = param.getNestedType();
        } else {
            type = param.getType();
        }
    } catch (ClassNotFoundException e) {
        getSession().error("Could not find parameter type definition. Check the configuration.");
        throw new RestartResponseException(getPageBase());
    }
    if (type.isEnum()) {
        panel = WebComponentUtil.createEnumPanel(type, componentId, new PropertyModel<>(model, expression), this);
    } else if (XMLGregorianCalendar.class.isAssignableFrom(type)) {
        panel = new DatePanel(componentId, new PropertyModel<>(model, expression));
    } else if (param.getProperties() != null && param.getProperties().getTargetType() != null) {
        // render autocomplete box
        LookupTableType lookup = new LookupTableType();
        panel = new AutoCompleteTextPanel<String>(componentId, new LookupPropertyModel<>(model, expression, lookup, false), String.class) {

            @Override
            public Iterator<String> getIterator(String input) {
                return prepareAutoCompleteList(input, lookup, param).iterator();
            }
        };
    } else {
        panel = new TextPanel<>(componentId, new PropertyModel<>(model, expression), type);
    }
    List<FormComponent> components = panel.getFormComponents();
    for (FormComponent component : components) {
        component.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    }
    panel.setOutputMarkupId(true);
    return panel;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) LookupPropertyModel(com.evolveum.midpoint.web.model.LookupPropertyModel) PropertyModel(org.apache.wicket.model.PropertyModel) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) RestartResponseException(org.apache.wicket.RestartResponseException) DatePanel(com.evolveum.midpoint.web.component.input.DatePanel) Iterator(java.util.Iterator) LookupPropertyModel(com.evolveum.midpoint.web.model.LookupPropertyModel) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)

Example 8 with FormComponent

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

the class JasperReportConfigurationPanel method createTextPanel.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <J> Component createTextPanel(String componentId, final IModel<J> model, String expression, final Boolean mandatory) {
    TextPanel<String> textPanel = new TextPanel<String>(componentId, new PropertyModel<String>(model, expression));
    FormComponent input = textPanel.getBaseFormComponent();
    input.add(new AttributeAppender("style", "width: 100%"));
    input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    input.add(new IValidator() {

        private static final long serialVersionUID = 1L;

        @Override
        public void validate(IValidatable validatable) {
            if (!mandatory) {
                return;
            }
            if (validatable.getValue() == null) {
                validatable.error(new ValidationError("JasperReportConfigurationPanel.errormsg"));
            }
        }
    });
    return textPanel;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) IValidator(org.apache.wicket.validation.IValidator) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) ValidationError(org.apache.wicket.validation.ValidationError) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) IValidatable(org.apache.wicket.validation.IValidatable)

Example 9 with FormComponent

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

the class LoggingConfigPanel method initLoggerColumns.

private List<IColumn<LoggerConfiguration, String>> initLoggerColumns() {
    List<IColumn<LoggerConfiguration, String>> columns = new ArrayList<>();
    IColumn column = new CheckBoxHeaderColumn<LoggerConfiguration>();
    columns.add(column);
    //name editing column
    columns.add(new EditableLinkColumn<LoggerConfiguration>(createStringResource("LoggingConfigPanel.logger"), "name") {

        @Override
        protected Component createInputPanel(String componentId, final IModel<LoggerConfiguration> model) {
            if (model.getObject() instanceof StandardLogger) {
                DropDownChoicePanel dropDownChoicePanel = new DropDownChoicePanel(componentId, new PropertyModel(model, "logger"), WebComponentUtil.createReadonlyModelFromEnum(StandardLoggerType.class), new EnumChoiceRenderer<StandardLoggerType>());
                FormComponent<StandardLoggerType> input = dropDownChoicePanel.getBaseFormComponent();
                input.add(new NotNullValidator<StandardLoggerType>("logger.emptyLogger"));
                input.add(new AttributeAppender("style", "width: 100%"));
                input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
                addAjaxFormComponentUpdatingBehavior(input);
                return dropDownChoicePanel;
            } else if (model.getObject() instanceof ComponentLogger) {
                DropDownChoicePanel dropDownChoicePanel = new DropDownChoicePanel(componentId, new PropertyModel(model, "component"), WebComponentUtil.createReadonlyModelFromEnum(LoggingComponentType.class), new EnumChoiceRenderer<LoggingComponentType>());
                FormComponent<LoggingComponentType> input = dropDownChoicePanel.getBaseFormComponent();
                input.add(new NotNullValidator<LoggingComponentType>("logger.emptyLogger"));
                input.add(new AttributeAppender("style", "width: 100%"));
                input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
                addAjaxFormComponentUpdatingBehavior(input);
                return dropDownChoicePanel;
            } else {
                TextPanel textPanel = new TextPanel<>(componentId, new PropertyModel<String>(model, getPropertyExpression()));
                FormComponent input = textPanel.getBaseFormComponent();
                addAjaxFormComponentUpdatingBehavior(input);
                input.add(new AttributeAppender("style", "width: 100%"));
                input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
                input.add(new NotNullValidator<StandardLoggerType>("message.emptyString"));
                return textPanel;
            }
        }

        @Override
        public void onClick(AjaxRequestTarget target, IModel<LoggerConfiguration> rowModel) {
            loggerEditPerformed(target, rowModel);
        }
    });
    //level editing column
    columns.add(new EditableLinkColumn<LoggerConfiguration>(createStringResource("LoggingConfigPanel.loggersLevel"), "level") {

        @Override
        protected Component createInputPanel(String componentId, IModel<LoggerConfiguration> model) {
            DropDownChoicePanel dropDownChoicePanel = new DropDownChoicePanel(componentId, new PropertyModel(model, getPropertyExpression()), WebComponentUtil.createReadonlyModelFromEnum(LoggingLevelType.class));
            FormComponent<LoggingLevelType> input = dropDownChoicePanel.getBaseFormComponent();
            input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            input.add(new NotNullValidator<LoggingLevelType>("message.emptyLevel"));
            addAjaxFormComponentUpdatingBehavior(input);
            return dropDownChoicePanel;
        }

        @Override
        public void onClick(AjaxRequestTarget target, IModel<LoggerConfiguration> rowModel) {
            loggerEditPerformed(target, rowModel);
        }

        @Override
        protected IModel<String> createLinkModel(IModel<LoggerConfiguration> rowModel) {
            LoggerConfiguration configuration = rowModel.getObject();
            return WebComponentUtil.createLocalizedModelForEnum(configuration.getLevel(), getPageBase());
        }
    });
    //appender editing column
    columns.add(new EditableLinkColumn<LoggerConfiguration>(createStringResource("LoggingConfigPanel.loggersAppender"), "appenders") {

        @Override
        protected IModel<String> createLinkModel(IModel<LoggerConfiguration> rowModel) {
            final LoggerConfiguration configuration = rowModel.getObject();
            if (configuration.getAppenders().isEmpty()) {
                return createStringResource("LoggingConfigPanel.appenders.Inherit");
            } else {
                return new LoadableModel<String>() {

                    @Override
                    protected String load() {
                        StringBuilder builder = new StringBuilder();
                        for (String appender : configuration.getAppenders()) {
                            if (configuration.getAppenders().indexOf(appender) != 0) {
                                builder.append(", ");
                            }
                            builder.append(appender);
                        }
                        return builder.toString();
                    }
                };
            }
        }

        @Override
        protected InputPanel createInputPanel(String componentId, IModel<LoggerConfiguration> model) {
            IModel<Map<String, String>> options = new Model(null);
            Map<String, String> optionsMap = new HashMap<String, String>();
            optionsMap.put("nonSelectedText", createStringResource("LoggingConfigPanel.appenders.Inherit").getString());
            options.setObject(optionsMap);
            ListMultipleChoicePanel panel = new ListMultipleChoicePanel<>(componentId, new PropertyModel<List<String>>(model, getPropertyExpression()), createNewLoggerAppendersListModel(), new StringChoiceRenderer(null), options);
            FormComponent<AppenderConfigurationType> input = panel.getBaseFormComponent();
            input.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
            addAjaxFormComponentUpdatingBehavior(input);
            return panel;
        }

        public void onClick(AjaxRequestTarget target, IModel<LoggerConfiguration> rowModel) {
            loggerEditPerformed(target, rowModel);
        }
    });
    return columns;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) EnumChoiceRenderer(org.apache.wicket.markup.html.form.EnumChoiceRenderer) ArrayList(java.util.ArrayList) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) ListMultipleChoicePanel(com.evolveum.midpoint.web.component.input.ListMultipleChoicePanel) CheckBoxHeaderColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) LoggerConfiguration(com.evolveum.midpoint.web.page.admin.configuration.dto.LoggerConfiguration) StandardLoggerType(com.evolveum.midpoint.web.page.admin.configuration.dto.StandardLoggerType) StandardLogger(com.evolveum.midpoint.web.page.admin.configuration.dto.StandardLogger) IModel(org.apache.wicket.model.IModel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) NotNullValidator(com.evolveum.midpoint.web.component.input.validator.NotNullValidator) ComponentLogger(com.evolveum.midpoint.web.page.admin.configuration.dto.ComponentLogger) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) StringChoiceRenderer(com.evolveum.midpoint.web.component.input.StringChoiceRenderer) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) IModel(org.apache.wicket.model.IModel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) LoggingComponentType(com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingComponentType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with FormComponent

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

the class LoggingConfigPanel method initAppenderColumns.

private List<IColumn<AppenderConfiguration, String>> initAppenderColumns() {
    List<IColumn<AppenderConfiguration, String>> columns = new ArrayList<>();
    IColumn column = new CheckBoxHeaderColumn<AppenderConfiguration>();
    columns.add(column);
    //name columns (editable)
    column = new EditableLinkColumn<AppenderConfiguration>(createStringResource("LoggingConfigPanel.appenders.name"), "name") {

        @Override
        public void onClick(AjaxRequestTarget target, IModel<AppenderConfiguration> rowModel) {
            appenderEditPerformed(target, rowModel);
        }

        @Override
        protected Component createInputPanel(String componentId, IModel<AppenderConfiguration> model) {
            TextPanel<String> panel = new TextPanel<String>(componentId, new PropertyModel(model, getPropertyExpression()));
            panel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            panel.getBaseFormComponent().add(new NotNullValidator<String>("message.emptyString"));
            addAjaxFormComponentUpdatingBehavior(panel.getBaseFormComponent());
            return panel;
        }
    };
    columns.add(column);
    //pattern column (editable)
    column = new EditablePropertyColumn(createStringResource("LoggingConfigPanel.appenders.pattern"), "pattern") {

        @Override
        protected InputPanel createInputPanel(String componentId, IModel model) {
            InputPanel panel = super.createInputPanel(componentId, model);
            panel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            panel.getBaseFormComponent().add(new NotNullValidator<String>("message.emptyString"));
            addAjaxFormComponentUpdatingBehavior(panel.getBaseFormComponent());
            return panel;
        }
    };
    columns.add(column);
    //file path column (editable)
    column = new FileAppenderColumn(createStringResource("LoggingConfigPanel.appenders.filePath"), "filePath");
    columns.add(column);
    //file pattern column (editable)                                                                               jj
    column = new FileAppenderColumn(createStringResource("LoggingConfigPanel.appenders.filePattern"), "filePattern");
    columns.add(column);
    //max history column (editable)
    column = new FileAppenderColumn(createStringResource("LoggingConfigPanel.appenders.maxHistory"), "maxHistory") {

        @Override
        protected InputPanel createInputPanel(String componentId, IModel model) {
            TextPanel panel = new TextPanel<>(componentId, new PropertyModel<String>(model, getPropertyExpression()));
            FormComponent component = panel.getBaseFormComponent();
            component.add(new AttributeModifier("size", 5));
            component.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            addAjaxFormComponentUpdatingBehavior(component);
            return panel;
        }
    };
    columns.add(column);
    //max file size column (editable)
    column = new FileAppenderColumn(createStringResource("LoggingConfigPanel.appenders.maxFileSize"), "maxFileSize") {

        @Override
        protected InputPanel createInputPanel(String componentId, IModel model) {
            TextPanel<String> panel = new TextPanel<>(componentId, new PropertyModel<String>(model, getPropertyExpression()));
            FormComponent component = panel.getBaseFormComponent();
            component.add(new AttributeModifier("size", 5));
            component.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            component.add(new NotNullValidator<String>("message.emptyString"));
            addAjaxFormComponentUpdatingBehavior(component);
            return panel;
        }
    };
    columns.add(column);
    CheckBoxColumn check = new EditableCheckboxColumn(createStringResource("LoggingConfigPanel.appenders.appending"), "appending") {

        @Override
        protected InputPanel createInputPanel(String componentId, IModel model) {
            InputPanel panel = super.createInputPanel(componentId, model);
            panel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            panel.getBaseFormComponent().add(new NotNullValidator<String>("message.emptyString"));
            addAjaxFormComponentUpdatingBehavior(panel.getBaseFormComponent());
            return panel;
        }
    };
    check.setEnabled(false);
    columns.add(check);
    return columns;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) ArrayList(java.util.ArrayList) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) AppenderConfiguration(com.evolveum.midpoint.web.page.admin.configuration.dto.AppenderConfiguration) CheckBoxHeaderColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn) EditablePropertyColumn(com.evolveum.midpoint.web.component.data.column.EditablePropertyColumn) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IModel(org.apache.wicket.model.IModel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) NotNullValidator(com.evolveum.midpoint.web.component.input.validator.NotNullValidator) AttributeModifier(org.apache.wicket.AttributeModifier) CheckBoxColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxColumn) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) EditableCheckboxColumn(com.evolveum.midpoint.web.component.data.column.EditableCheckboxColumn) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)

Aggregations

FormComponent (org.apache.wicket.markup.html.form.FormComponent)19 InputPanel (com.evolveum.midpoint.web.component.prism.InputPanel)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 Component (org.apache.wicket.Component)5 ArrayList (java.util.ArrayList)4 AttributeModifier (org.apache.wicket.AttributeModifier)4 PropertyModel (org.apache.wicket.model.PropertyModel)4 TextPanel (com.evolveum.midpoint.web.component.input.TextPanel)3 List (java.util.List)3 IModel (org.apache.wicket.model.IModel)3 ListModel (org.apache.wicket.model.util.ListModel)3 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)2 CheckBoxHeaderColumn (com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn)2 NotNullValidator (com.evolveum.midpoint.web.component.input.validator.NotNullValidator)2 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)2 EmptyOnBlurAjaxFormUpdatingBehaviour (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour)2 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)2 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)2 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)2 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)2