Search in sources :

Example 6 with FileMetadata

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

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