Search in sources :

Example 16 with FormComponent

use of org.apache.wicket.markup.html.form.FormComponent in project oc-explorer by devgateway.

the class FileInputBootstrapFormComponentWrapper method addBootstrapFileInputComponent.

private void addBootstrapFileInputComponent() {
    // this is where the newly uploaded files are saved
    final IModel<List<FileUpload>> internalUploadModel = new ListModel<>();
    /*
         * some customization of the BootstrapFileInput Component
         */
    FileInputConfig fileInputConfig = new FileInputConfig();
    fileInputConfig.put(new Key<String>("browseLabel"), new StringResourceModel("browseLabel", FileInputBootstrapFormComponentWrapper.this, null).getString());
    fileInputConfig.put(new Key<String>("uploadClass"), "btn btn-blue");
    fileInputConfig.put(new Key<String>("browseClass"), "btn btn-blue");
    bootstrapFileInput = new BootstrapFileInput("bootstrapFileInput", internalUploadModel, fileInputConfig) {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        protected void onSubmit(final AjaxRequestTarget target) {
            super.onSubmit(target);
            List<FileUpload> fileUploads = internalUploadModel.getObject();
            if (fileUploads != null) {
                // check if we uploaded too many files
                if (maxFiles > 0 && filesModel.size() + fileUploads.size() > maxFiles) {
                    if (maxFiles == 1) {
                        FileInputBootstrapFormComponentWrapper.this.fatal(new StringResourceModel("OneUpload", FileInputBootstrapFormComponentWrapper.this, null).getString());
                    } else {
                        FileInputBootstrapFormComponentWrapper.this.fatal(new StringResourceModel("tooManyFiles", FileInputBootstrapFormComponentWrapper.this, Model.of(maxFiles)).getString());
                    }
                    FileInputBootstrapFormComponentWrapper.this.invalid();
                } else {
                    // and update the model
                    for (FileUpload upload : fileUploads) {
                        FileMetadata fileMetadata = new FileMetadata();
                        fileMetadata.setName(upload.getClientFileName());
                        fileMetadata.setContentType(upload.getContentType());
                        fileMetadata.setSize(upload.getSize());
                        FileContent fileContent = new FileContent();
                        fileContent.setBytes(upload.getBytes());
                        fileMetadata.setContent(fileContent);
                        filesModel.add(fileMetadata);
                    // don't display the success notification
                    // FileInputBootstrapFormComponentWrapper.this.success(new
                    // StringResourceModel("successUpload",
                    // FileInputBootstrapFormComponentWrapper.this,
                    // null, new
                    // Model(upload.getClientFileName())).getString());
                    }
                }
            }
            FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
            target.add(fileUploadFeedback);
            target.add(pendingFiles);
        }
    };
    add(bootstrapFileInput);
    /**
     * due to an upgrade of FormGroup in wicket7/wicket-bootrap-0.10, the
     * visitor that finds inner FormComponentS, will now find two instead of
     * one: the FileInputBootstrapFormComponentWrapper and also the
     * BootstrapFileInputField. This is the RIGHT result, previously in
     * wicket 6.x it only got the first level of children, hence only one
     * FormComponent (the FileInputBootstrapFormComponentWrapper). It would
     * then read the label from FileInputBootstrapFormComponentWrapper and
     * use it for displaying the label of the FormGroup. In
     * wicket7/wicket-bootstrap-0.10 this will result in reading the label
     * of BootstrapFileInputField which is null. So you will notice no
     * labels for FormGroupS. We fix this by forcing the label of the
     * underlying fileInput element to the same model as the label used by
     * FileInputBootstrapFormComponentWrapper
     */
    FormComponent<?> fileInput = (FormComponent<?>) bootstrapFileInput.get("fileInputForm").get("fileInput");
    fileInput.setLabel(this.getLabel());
    // only to admins
    if (visibleOnlyToAdmin) {
        MetaDataRoleAuthorizationStrategy.authorize(bootstrapFileInput, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    }
    // want to read only
    if (disableDeleteButton) {
        MetaDataRoleAuthorizationStrategy.authorize(bootstrapFileInput, Component.RENDER, MetaDataRoleAuthorizationStrategy.NO_ROLE);
    }
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) FileMetadata(org.devgateway.toolkit.persistence.dao.FileMetadata) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) FileContent(org.devgateway.toolkit.persistence.dao.FileContent) ListModel(org.apache.wicket.model.util.ListModel) BootstrapFileInput(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.BootstrapFileInput) ArrayList(java.util.ArrayList) List(java.util.List) FileInputConfig(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.FileInputConfig) StringResourceModel(org.apache.wicket.model.StringResourceModel) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 17 with FormComponent

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

the class SearchPropertyPanel method initSearchItemField.

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

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

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

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

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

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

Example 18 with FormComponent

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

the class AbstractInputGuiComponentFactory method configure.

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

Example 19 with FormComponent

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

the class ACAttributeValuePanel method initLayout.

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

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

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

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

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

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

Aggregations

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