Search in sources :

Example 1 with FileMetadata

use of org.devgateway.toolkit.persistence.dao.FileMetadata in project ocvn by devgateway.

the class FileInputBootstrapFormComponentWrapper method addPendingFilesComponent.

/**
 * pending files section
 */
private void addPendingFilesComponent() {
    pendingFiles = new WebMarkupContainer("pendingFiles") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onConfigure() {
            if (filesModel != null && filesModel.size() > 0) {
                for (FileMetadata file : filesModel) {
                    if (file.isNew()) {
                        setVisibilityAllowed(true);
                        return;
                    }
                }
            }
            setVisibilityAllowed(false);
        }
    };
    pendingFiles.setOutputMarkupPlaceholderTag(true);
    pendingFiles.setOutputMarkupId(true);
    add(pendingFiles);
    pendingFiles.add(new Label("pendingFilesTitle", new StringResourceModel("pendingFilesTitle", this, null)));
    AbstractReadOnlyModel<List<FileMetadata>> pendingFilesModel = new AbstractReadOnlyModel<List<FileMetadata>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public List<FileMetadata> getObject() {
            List<FileMetadata> fileObject = new ArrayList<>();
            // upload)
            for (FileMetadata file : filesModel) {
                if (file.isNew()) {
                    fileObject.add(file);
                }
            }
            return fileObject;
        }
    };
    ListView<FileMetadata> list = new ListView<FileMetadata>("list", pendingFilesModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<FileMetadata> item) {
            item.add(new Label("fileTitle", item.getModelObject().getName()));
            IndicatingAjaxLink<Void> delete = new IndicatingAjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                public void onClick(final AjaxRequestTarget target) {
                    filesModel.remove(item.getModelObject());
                    FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
                    target.add(pendingFiles);
                }
            };
            delete.add(new IconBehavior(GlyphIconType.remove));
            delete.add(new TooltipBehavior(new StringResourceModel("removeUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            delete.setVisible(true);
            item.add(delete);
        }
    };
    pendingFiles.add(list);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) FileMetadata(org.devgateway.toolkit.persistence.dao.FileMetadata) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) IconBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) TooltipBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior) ListView(org.apache.wicket.markup.html.list.ListView) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 2 with FileMetadata

use of org.devgateway.toolkit.persistence.dao.FileMetadata in project ocvn 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 3 with FileMetadata

use of org.devgateway.toolkit.persistence.dao.FileMetadata in project oc-explorer by devgateway.

the class FileInputBootstrapFormComponentWrapper method addAlreadyUploadedFilesComponent.

/**
 * already uploaded files section
 */
private void addAlreadyUploadedFilesComponent() {
    alreadyUploadedFiles = new WebMarkupContainer("alreadyUploadedFiles") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onInitialize() {
            super.onInitialize();
            setVisibilityAllowed(isVisibleAlreadyUploadedFiles());
        }
    };
    alreadyUploadedFiles.setOutputMarkupPlaceholderTag(true);
    alreadyUploadedFiles.setOutputMarkupId(true);
    add(alreadyUploadedFiles);
    alreadyUploadedFiles.add(new Label("uploadedFilesTitle", new StringResourceModel("uploadedFilesTitle", this, null)));
    AbstractReadOnlyModel<List<FileMetadata>> alreadyUploadedFilesModel = new AbstractReadOnlyModel<List<FileMetadata>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public List<FileMetadata> getObject() {
            List<FileMetadata> fileObject = new ArrayList<>();
            // get only the already uploaded files
            for (FileMetadata file : filesModel) {
                if (!file.isNew()) {
                    fileObject.add(file);
                }
            }
            return fileObject;
        }
    };
    ListView<FileMetadata> list = new ListView<FileMetadata>("list", alreadyUploadedFilesModel) {

        private static final long serialVersionUID = 1L;

        private List<IndicatingAjaxLink<Void>> deleteButtons = new ArrayList<>();

        @Override
        protected void populateItem(final ListItem<FileMetadata> item) {
            // make file name clickable
            Link<FileMetadata> downloadLink = new Link<FileMetadata>("downloadLink", item.getModel()) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    final FileMetadata modelObject = getModelObject();
                    AbstractResourceStreamWriter rstream = new AbstractResourceStreamWriter() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void write(final OutputStream output) throws IOException {
                            output.write(modelObject.getContent().getBytes());
                        }

                        @Override
                        public String getContentType() {
                            return modelObject.getContentType();
                        }
                    };
                    ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(rstream, modelObject.getName());
                    handler.setContentDisposition(ContentDisposition.ATTACHMENT);
                    getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
                }
            };
            downloadLink.add(new Label("downloadText", item.getModelObject().getName()));
            downloadLink.add(new TooltipBehavior(new StringResourceModel("downloadUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            item.add(downloadLink);
            Link<FileMetadata> download = new CustomDownloadLink("download", item.getModel());
            item.add(download);
            IndicatingAjaxLink<Void> delete = new IndicatingAjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                public void onClick(final AjaxRequestTarget target) {
                    filesModel.remove(item.getModelObject());
                    FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
                    target.add(alreadyUploadedFiles);
                }
            };
            delete.add(new IconBehavior(GlyphIconType.remove));
            delete.add(new TooltipBehavior(new StringResourceModel("removeUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            delete.setVisible(true);
            item.add(delete);
            deleteButtons.add(delete);
            // only to admins
            if (visibleOnlyToAdmin) {
                MetaDataRoleAuthorizationStrategy.authorize(delete, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
            }
            if (disableDeleteButton) {
                delete.setVisibilityAllowed(false);
            }
        }

        @Override
        public void onEvent(final IEvent<?> event) {
            /*
                 * disable 'delete' buttons based on the form state
                 */
            if (event.getPayload() instanceof EditingDisabledEvent) {
                for (IndicatingAjaxLink<?> del : deleteButtons) {
                    del.setVisibilityAllowed(false);
                }
            }
            if (event.getPayload() instanceof EditingEnabledEvent) {
                for (IndicatingAjaxLink<?> del : deleteButtons) {
                    del.setVisibilityAllowed(true);
                }
            }
        }
    };
    alreadyUploadedFiles.add(list);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) IEvent(org.apache.wicket.event.IEvent) OutputStream(java.io.OutputStream) Label(org.apache.wicket.markup.html.basic.Label) FileMetadata(org.devgateway.toolkit.persistence.dao.FileMetadata) ArrayList(java.util.ArrayList) AbstractResourceStreamWriter(org.apache.wicket.util.resource.AbstractResourceStreamWriter) CustomDownloadLink(org.devgateway.toolkit.forms.wicket.components.util.CustomDownloadLink) IconBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) TooltipBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior) ListView(org.apache.wicket.markup.html.list.ListView) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ArrayList(java.util.ArrayList) List(java.util.List) EditingDisabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingDisabledEvent) StringResourceModel(org.apache.wicket.model.StringResourceModel) EditingEnabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingEnabledEvent) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListItem(org.apache.wicket.markup.html.list.ListItem) CustomDownloadLink(org.devgateway.toolkit.forms.wicket.components.util.CustomDownloadLink) Link(org.apache.wicket.markup.html.link.Link) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)

Example 4 with FileMetadata

use of org.devgateway.toolkit.persistence.dao.FileMetadata in project ocvn by devgateway.

the class FileInputBootstrapFormComponentWrapper method addAlreadyUploadedFilesComponent.

/**
 * already uploaded files section
 */
private void addAlreadyUploadedFilesComponent() {
    alreadyUploadedFiles = new WebMarkupContainer("alreadyUploadedFiles") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onInitialize() {
            super.onInitialize();
            setVisibilityAllowed(isVisibleAlreadyUploadedFiles());
        }
    };
    alreadyUploadedFiles.setOutputMarkupPlaceholderTag(true);
    alreadyUploadedFiles.setOutputMarkupId(true);
    add(alreadyUploadedFiles);
    alreadyUploadedFiles.add(new Label("uploadedFilesTitle", new StringResourceModel("uploadedFilesTitle", this, null)));
    AbstractReadOnlyModel<List<FileMetadata>> alreadyUploadedFilesModel = new AbstractReadOnlyModel<List<FileMetadata>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public List<FileMetadata> getObject() {
            List<FileMetadata> fileObject = new ArrayList<>();
            // get only the already uploaded files
            for (FileMetadata file : filesModel) {
                if (!file.isNew()) {
                    fileObject.add(file);
                }
            }
            return fileObject;
        }
    };
    ListView<FileMetadata> list = new ListView<FileMetadata>("list", alreadyUploadedFilesModel) {

        private static final long serialVersionUID = 1L;

        private List<IndicatingAjaxLink<Void>> deleteButtons = new ArrayList<>();

        @Override
        protected void populateItem(final ListItem<FileMetadata> item) {
            // make file name clickable
            Link<FileMetadata> downloadLink = new Link<FileMetadata>("downloadLink", item.getModel()) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    final FileMetadata modelObject = getModelObject();
                    AbstractResourceStreamWriter rstream = new AbstractResourceStreamWriter() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void write(final OutputStream output) throws IOException {
                            output.write(modelObject.getContent().getBytes());
                        }

                        @Override
                        public String getContentType() {
                            return modelObject.getContentType();
                        }
                    };
                    ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(rstream, modelObject.getName());
                    handler.setContentDisposition(ContentDisposition.ATTACHMENT);
                    getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
                }
            };
            downloadLink.add(new Label("downloadText", item.getModelObject().getName()));
            downloadLink.add(new TooltipBehavior(new StringResourceModel("downloadUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            item.add(downloadLink);
            Link<FileMetadata> download = new CustomDownloadLink("download", item.getModel());
            item.add(download);
            IndicatingAjaxLink<Void> delete = new IndicatingAjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                public void onClick(final AjaxRequestTarget target) {
                    filesModel.remove(item.getModelObject());
                    FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
                    target.add(alreadyUploadedFiles);
                }
            };
            delete.add(new IconBehavior(GlyphIconType.remove));
            delete.add(new TooltipBehavior(new StringResourceModel("removeUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            delete.setVisible(true);
            item.add(delete);
            deleteButtons.add(delete);
            // only to admins
            if (visibleOnlyToAdmin) {
                MetaDataRoleAuthorizationStrategy.authorize(delete, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
            }
            if (disableDeleteButton) {
                delete.setVisibilityAllowed(false);
            }
        }

        @Override
        public void onEvent(final IEvent<?> event) {
            /*
                 * disable 'delete' buttons based on the form state
                 */
            if (event.getPayload() instanceof EditingDisabledEvent) {
                for (IndicatingAjaxLink<?> del : deleteButtons) {
                    del.setVisibilityAllowed(false);
                }
            }
            if (event.getPayload() instanceof EditingEnabledEvent) {
                for (IndicatingAjaxLink<?> del : deleteButtons) {
                    del.setVisibilityAllowed(true);
                }
            }
        }
    };
    alreadyUploadedFiles.add(list);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) IEvent(org.apache.wicket.event.IEvent) OutputStream(java.io.OutputStream) Label(org.apache.wicket.markup.html.basic.Label) FileMetadata(org.devgateway.toolkit.persistence.dao.FileMetadata) ArrayList(java.util.ArrayList) AbstractResourceStreamWriter(org.apache.wicket.util.resource.AbstractResourceStreamWriter) CustomDownloadLink(org.devgateway.toolkit.forms.wicket.components.util.CustomDownloadLink) IconBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) TooltipBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior) ListView(org.apache.wicket.markup.html.list.ListView) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ArrayList(java.util.ArrayList) List(java.util.List) EditingDisabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingDisabledEvent) StringResourceModel(org.apache.wicket.model.StringResourceModel) EditingEnabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingEnabledEvent) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListItem(org.apache.wicket.markup.html.list.ListItem) CustomDownloadLink(org.devgateway.toolkit.forms.wicket.components.util.CustomDownloadLink) Link(org.apache.wicket.markup.html.link.Link) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)

Example 5 with FileMetadata

use of org.devgateway.toolkit.persistence.dao.FileMetadata 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)

Aggregations

ArrayList (java.util.ArrayList)6 List (java.util.List)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 StringResourceModel (org.apache.wicket.model.StringResourceModel)6 FileMetadata (org.devgateway.toolkit.persistence.dao.FileMetadata)6 TooltipBehavior (de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior)4 IconBehavior (de.agilecoders.wicket.core.markup.html.bootstrap.image.IconBehavior)4 IndicatingAjaxLink (org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)4 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)4 Label (org.apache.wicket.markup.html.basic.Label)4 ListItem (org.apache.wicket.markup.html.list.ListItem)4 ListView (org.apache.wicket.markup.html.list.ListView)4 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)4 BootstrapFileInput (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.BootstrapFileInput)2 FileInputConfig (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.FileInputConfig)2 OutputStream (java.io.OutputStream)2 IEvent (org.apache.wicket.event.IEvent)2 FormComponent (org.apache.wicket.markup.html.form.FormComponent)2 FileUpload (org.apache.wicket.markup.html.form.upload.FileUpload)2 Link (org.apache.wicket.markup.html.link.Link)2