Search in sources :

Example 1 with AjaxDownloadBehaviorFromStream

use of com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream in project midpoint by Evolveum.

the class UploadDownloadPanel method initLayout.

private void initLayout(final boolean isReadOnly) {
    final FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE);
    Form form = this.findParent(Form.class);
    fileUpload.add(new AjaxFormSubmitBehavior(form, "change") {

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            super.onSubmit(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            super.onError(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }
    });
    fileUpload.setOutputMarkupId(true);
    add(fileUpload);
    final AjaxDownloadBehaviorFromStream downloadBehavior = new AjaxDownloadBehaviorFromStream() {

        @Override
        protected InputStream initStream() {
            return getStream();
        }
    };
    add(downloadBehavior);
    add(new AjaxSubmitButton(ID_BUTTON_DOWNLOAD) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            downloadPerformed(downloadBehavior, target);
        }
    });
    add(new AjaxSubmitButton(ID_BUTTON_DELETE) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            removeFilePerformed(target);
        }
    });
    add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) Form(org.apache.wicket.markup.html.form.Form) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 2 with AjaxDownloadBehaviorFromStream

use of com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream in project midpoint by Evolveum.

the class ReportCreateHandlerPanel method initLayout.

private void initLayout(final PageTaskEdit parentPage) {
    final AjaxDownloadBehaviorFromStream ajaxDownloadBehavior = new AjaxDownloadBehaviorFromStream() {

        @Override
        protected InputStream initStream() {
            String outputOid = getModelObject().getReportOutputOid();
            if (outputOid == null) {
                return null;
            }
            Task task = parentPage.createSimpleTask(OPERATION_LOAD_REPORT_OUTPUT);
            PrismObject<ReportOutputType> reportObject = WebModelServiceUtils.loadObject(ReportOutputType.class, outputOid, parentPage, task, task.getResult());
            if (reportObject != null) {
                return PageCreatedReports.createReport(reportObject.asObjectable(), this, parentPage);
            } else {
                return null;
            }
        }
    };
    parentPage.getForm().add(ajaxDownloadBehavior);
    WebMarkupContainer reportParametersContainer = new WebMarkupContainer(ID_REPORT_PARAMETERS_CONTAINER);
    TextArea reportParameters = new TextArea<>(ID_REPORT_PARAMETERS, new PropertyModel<>(getModel(), ReportCreateHandlerDto.F_REPORT_PARAMS));
    reportParameters.setEnabled(false);
    reportParametersContainer.add(reportParameters);
    add(reportParametersContainer);
    WebMarkupContainer downloadContainer = new WebMarkupContainer(ID_DOWNLOAD_CONTAINER);
    AjaxButton download = new AjaxButton(ID_DOWNLOAD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            ajaxDownloadBehavior.initiate(target);
        }
    };
    downloadContainer.add(download);
    downloadContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModelObject().getReportOutputOid() != null;
        }
    });
    add(downloadContainer);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Task(com.evolveum.midpoint.task.api.Task) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) TextArea(org.apache.wicket.markup.html.form.TextArea) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ReportOutputType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportOutputType) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 3 with AjaxDownloadBehaviorFromStream

use of com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream in project midpoint by Evolveum.

the class UploadDownloadPanel method initLayout.

private void initLayout() {
    final FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE) {

        private static final long serialVersionUID = 1L;

        @Override
        public String[] getInputAsArray() {
            List<String> input = new ArrayList<>();
            try {
                input.add(new String(IOUtils.toByteArray(getStream())));
            } catch (IOException e) {
                LOGGER.error("Unable to define file content type: {}", e.getLocalizedMessage());
            }
            return input.toArray(new String[0]);
        }
    };
    Form form = this.findParent(Form.class);
    fileUpload.add(new AjaxFormSubmitBehavior(form, "change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            super.onSubmit(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            super.onError(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }
    });
    fileUpload.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
    fileUpload.setOutputMarkupId(true);
    add(fileUpload);
    final AjaxDownloadBehaviorFromStream downloadBehavior = new AjaxDownloadBehaviorFromStream() {

        private static final long serialVersionUID = 1L;

        @Override
        protected InputStream initStream() {
            InputStream is = getStream();
            try {
                String newContentType = URLConnection.guessContentTypeFromStream(is);
                if (StringUtils.isNotEmpty(newContentType)) {
                    setContentType(newContentType);
                }
            } catch (IOException ex) {
                LOGGER.error("Unable to define download file content type: {}", ex.getLocalizedMessage());
            }
            return is;
        }
    };
    downloadBehavior.setContentType(getDownloadContentType());
    downloadBehavior.setFileName(getDownloadFileName());
    add(downloadBehavior);
    add(new AjaxSubmitButton(ID_BUTTON_DOWNLOAD) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            downloadPerformed(downloadBehavior, target);
        }
    });
    AjaxSubmitButton deleteButton = new AjaxSubmitButton(ID_BUTTON_DELETE) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            removeFilePerformed(target);
        }
    };
    deleteButton.add(new VisibleBehaviour(() -> !isReadOnly));
    add(deleteButton);
    add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
}
Also used : AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) Form(org.apache.wicket.markup.html.form.Form) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 4 with AjaxDownloadBehaviorFromStream

use of com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream in project midpoint by Evolveum.

the class PageTask method createDownloadReportButton.

private void createDownloadReportButton(RepeatingView repeatingView) {
    final AjaxDownloadBehaviorFromStream ajaxDownloadBehavior = new AjaxDownloadBehaviorFromStream() {

        private static final long serialVersionUID = 1L;

        @Override
        protected InputStream initStream() {
            ReportDataType reportObject = getReportData();
            if (reportObject != null) {
                return PageCreatedReports.createReport(reportObject, this, PageTask.this);
            } else {
                return null;
            }
        }

        @Override
        public String getFileName() {
            ReportDataType reportObject = getReportData();
            return PageCreatedReports.getReportFileName(reportObject);
        }
    };
    add(ajaxDownloadBehavior);
    AjaxButton download = new AjaxButton(repeatingView.newChildId(), createStringResource("PageTask.download.report")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            ajaxDownloadBehavior.initiate(target);
        }
    };
    download.add(new VisibleBehaviour(this::isDownloadReportVisible));
    download.add(AttributeAppender.append("class", "btn-primary btn-sm"));
    repeatingView.add(download);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour)

Example 5 with AjaxDownloadBehaviorFromStream

use of com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream in project midpoint by Evolveum.

the class PageCreatedReports method initLayout.

private void initLayout() {
    Form mainForm = new MidpointForm(ID_MAIN_FORM);
    add(mainForm);
    MainObjectListPanel<ReportDataType> table = new MainObjectListPanel<ReportDataType>(ID_TABLE, ReportDataType.class) {

        @Override
        protected void objectDetailsPerformed(AjaxRequestTarget target, ReportDataType object) {
        }

        @Override
        protected UserProfileStorage.TableId getTableId() {
            return UserProfileStorage.TableId.PAGE_CREATED_REPORTS_PANEL;
        }

        @Override
        protected ISelectableDataProvider<ReportDataType, SelectableBean<ReportDataType>> createProvider() {
            return createSelectableBeanObjectDataProvider(() -> appendTypeFilter(), (sortParam) -> PageCreatedReports.this.createCustomOrdering(sortParam));
        }

        // @Override
        // protected ObjectQuery getCustomizeContentQuery() {
        // return appendTypeFilter();
        // }
        // 
        // @Override
        // protected List<ObjectOrdering> createObjectOrderings(SortParam<String> sortParam) {
        // return PageCreatedReports.this.createCustomOrdering(sortParam);
        // }
        // @Override
        // protected ISelectableDataProvider<ReportDataType, SelectableBean<ReportDataType>> createProvider() {
        // PageStorage storage = getObjectListPanel().getPageStorage();
        // SelectableBeanObjectDataProvider<ReportDataType> provider = new SelectableBeanObjectDataProvider<ReportDataType>(
        // getPageBase(), getSearchModel(), null) {
        // private static final long serialVersionUID = 1L;
        // 
        // @Override
        // protected PageStorage getPageStorage() {
        // return storage;
        // }
        // 
        // @NotNull
        // @Override
        // protected List<ObjectOrdering> createObjectOrderings(SortParam<String> sortParam) {
        // return PageCreatedReports.this.createCustomOrdering(sortParam);
        // }
        // 
        // @Override
        // protected ObjectQuery getCustomizeContentQuery() {
        // return appendTypeFilter();
        // }
        // };
        // provider.setCompiledObjectCollectionView(getObjectCollectionView());
        // provider.setOptions(createOptions());
        // return provider;
        // }
        @Override
        protected List<InlineMenuItem> createInlineMenu() {
            return initInlineMenu();
        }

        @Override
        protected boolean isCreateNewObjectEnabled() {
            return false;
        }

        @Override
        protected boolean isObjectDetailsEnabled(IModel<SelectableBean<ReportDataType>> rowModel) {
            return false;
        }

        @Override
        protected List<IColumn<SelectableBean<ReportDataType>, String>> createDefaultColumns() {
            return PageCreatedReports.this.initColumns();
        }
    };
    table.setOutputMarkupId(true);
    mainForm.add(table);
    String reportName = reportTypeMal.get(getReportType());
    List<String> values = new ArrayList<>(reportTypeMal.values());
    DropDownChoicePanel<String> reportTypeSelect = new DropDownChoicePanel<>(ID_REPORT_TYPE_SELECT, Model.of(reportName), Model.ofList(values), StringChoiceRenderer.simple(), true);
    reportTypeSelect.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            table.refreshTable(target);
        }
    });
    reportTypeSelect.setOutputMarkupId(true);
    mainForm.add(reportTypeSelect);
    ajaxDownloadBehavior = new AjaxDownloadBehaviorFromStream() {

        private static final long serialVersionUID = 1L;

        @Override
        protected InputStream initStream() {
            return createReport();
        }

        @Override
        public String getFileName() {
            return getReportFileName();
        }
    };
    mainForm.add(ajaxDownloadBehavior);
}
Also used : MainObjectListPanel(com.evolveum.midpoint.gui.api.component.MainObjectListPanel) IModel(org.apache.wicket.model.IModel) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) Form(org.apache.wicket.markup.html.form.Form) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) InputStream(java.io.InputStream) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)

Aggregations

AjaxDownloadBehaviorFromStream (com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)3 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 Form (org.apache.wicket.markup.html.form.Form)3 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)2 InputStream (java.io.InputStream)2 AjaxFormSubmitBehavior (org.apache.wicket.ajax.form.AjaxFormSubmitBehavior)2 FileUploadField (org.apache.wicket.markup.html.form.upload.FileUploadField)2 MainObjectListPanel (com.evolveum.midpoint.gui.api.component.MainObjectListPanel)1 Task (com.evolveum.midpoint.task.api.Task)1 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)1 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)1 ButtonInlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)1 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)1 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)1 UserProfileStorage (com.evolveum.midpoint.web.session.UserProfileStorage)1 ReportOutputType (com.evolveum.midpoint.xml.ns._public.common.common_3.ReportOutputType)1 IOException (java.io.IOException)1