use of com.evolveum.midpoint.web.component.dialog.ExportingPanel in project midpoint by Evolveum.
the class CsvDownloadButtonPanel method initLayout.
private void initLayout() {
CSVDataExporter csvDataExporter = new CSVDataExporter() {
private static final long serialVersionUID = 1L;
@Override
public <T> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T, ?>> columns, OutputStream outputStream) {
if (dataProvider instanceof SelectableBeanContainerDataProvider) {
// TODO implement more nicely
((SelectableBeanContainerDataProvider) dataProvider).setExport(true);
}
try {
((BaseSortableDataProvider) dataProvider).setExportSize(true);
super.exportData(dataProvider, getExportableColumns(), outputStream);
((BaseSortableDataProvider) dataProvider).setExportSize(false);
} catch (Exception ex) {
LOGGER.error("Unable to export data,", ex);
} finally {
if (dataProvider instanceof SelectableBeanContainerDataProvider) {
((SelectableBeanContainerDataProvider) dataProvider).setExport(false);
}
}
}
@Override
protected <T> IModel<T> wrapModel(IModel<T> model) {
if (model.getObject() == null) {
return () -> (T) "";
}
if (model.getObject() instanceof Referencable) {
return () -> {
String value = WebModelServiceUtils.resolveReferenceName((Referencable) model.getObject(), getPageBase());
return (T) (value == null ? "" : value);
};
}
return super.wrapModel(model);
}
};
IModel<String> name = Model.of("");
final AbstractAjaxDownloadBehavior ajaxDownloadBehavior = new AbstractAjaxDownloadBehavior() {
private static final long serialVersionUID = 1L;
@Override
public IResourceStream getResourceStream() {
return new ExportToolbar.DataExportResourceStreamWriter(csvDataExporter, getDataTable());
}
public String getFileName() {
if (StringUtils.isEmpty(name.getObject())) {
return CsvDownloadButtonPanel.this.getFilename();
}
return name.getObject();
}
};
add(ajaxDownloadBehavior);
AjaxIconButton exportDataLink = new AjaxIconButton(ID_EXPORT_DATA, new Model<>("fa fa-download"), createStringResource("CsvDownloadButtonPanel.export")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
long exportSizeLimit = -1;
try {
CompiledGuiProfile adminGuiConfig = getPageBase().getCompiledGuiProfile();
if (adminGuiConfig.getDefaultExportSettings() != null && adminGuiConfig.getDefaultExportSettings().getSizeLimit() != null) {
exportSizeLimit = adminGuiConfig.getDefaultExportSettings().getSizeLimit();
}
} catch (Exception ex) {
LOGGER.error("Unable to get csv export size limit,", ex);
}
boolean askForSizeLimitConfirmation;
if (exportSizeLimit < 0) {
askForSizeLimitConfirmation = false;
} else {
if (canCountBeforeExporting) {
IDataProvider<?> dataProvider = getDataTable().getDataProvider();
long size = dataProvider.size();
askForSizeLimitConfirmation = size > exportSizeLimit;
} else {
// size is unknown
askForSizeLimitConfirmation = true;
}
}
Long useExportSizeLimit = null;
if (askForSizeLimitConfirmation) {
useExportSizeLimit = exportSizeLimit;
}
exportableColumnsIndex.clear();
ExportingPanel exportingPanel = new ExportingPanel(getPageBase().getMainPopupBodyId(), getDataTable(), exportableColumnsIndex, useExportSizeLimit, name) {
private static final long serialVersionUID = 1L;
@Override
public void exportPerformed(AjaxRequestTarget target) {
ajaxDownloadBehavior.initiate(target);
}
};
getPageBase().showMainPopup(exportingPanel, target);
}
};
add(exportDataLink);
}
Aggregations