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;
}
});
}
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);
}
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;
}
});
}
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);
}
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);
}
Aggregations