mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 04:07:42 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
4835cc5b60
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components.actions;
|
||||
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.gui.AppConfig;
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
@ -51,6 +52,7 @@ public class ExcelAction extends BaseAction implements Action.HasBeforeActionPer
|
||||
|
||||
protected final ListComponent listComponent;
|
||||
protected final ExportDisplay display;
|
||||
protected String fileName = null;
|
||||
|
||||
protected BeforeActionPerformedHandler beforeActionPerformedHandler;
|
||||
|
||||
@ -148,6 +150,20 @@ public class ExcelAction extends BaseAction implements Action.HasBeforeActionPer
|
||||
this.icon = thCM.getThemeValue("actions.Excel.icon");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return excel file name without extension
|
||||
*/
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName excel file name without extension
|
||||
*/
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is invoked by action owner component.
|
||||
* @param component component invoking action
|
||||
@ -197,16 +213,16 @@ public class ExcelAction extends BaseAction implements Action.HasBeforeActionPer
|
||||
protected void export(ExportMode exportMode) {
|
||||
ExcelExporter exporter = new ExcelExporter();
|
||||
if (listComponent instanceof Table) {
|
||||
Table<?> table = (Table) listComponent;
|
||||
exporter.exportTable(table, table.getNotCollapsedColumns(), display, exportMode);
|
||||
Table<Entity> table = (Table<Entity>) listComponent;
|
||||
exporter.exportTable(table, table.getNotCollapsedColumns(), false, display, null, fileName, exportMode);
|
||||
}
|
||||
|
||||
if (listComponent instanceof DataGrid) {
|
||||
DataGrid<?> dataGrid = (DataGrid) listComponent;
|
||||
DataGrid<Entity> dataGrid = (DataGrid<Entity>) listComponent;
|
||||
List<DataGrid.Column> columns = dataGrid.getVisibleColumns().stream()
|
||||
.filter(col -> !col.isCollapsed())
|
||||
.collect(Collectors.toList());
|
||||
exporter.exportDataGrid(dataGrid, columns, display, exportMode);
|
||||
exporter.exportDataGrid(dataGrid, columns, display, null, fileName, exportMode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Use this class to export {@link com.haulmont.cuba.gui.components.Table} into Excel format
|
||||
@ -197,7 +198,11 @@ public class ExcelExporter {
|
||||
|
||||
CollectionDatasource datasource = table.getDatasource();
|
||||
if (exportMode == ExportMode.SELECTED_ROWS && table.getSelected().size() > 0) {
|
||||
for (Entity item : table.getSelected()) {
|
||||
Set<Entity> selected = table.getSelected();
|
||||
List<Entity> ordered = ((Collection<Entity>) datasource.getItems()).stream()
|
||||
.filter(selected::contains)
|
||||
.collect(Collectors.toList());
|
||||
for (Entity item : ordered) {
|
||||
createRow(table, columns, 0, ++r, item.getId());
|
||||
}
|
||||
} else {
|
||||
@ -327,7 +332,11 @@ public class ExcelExporter {
|
||||
|
||||
CollectionDatasource datasource = dataGrid.getDatasource();
|
||||
if (exportMode == ExportMode.SELECTED_ROWS && dataGrid.getSelected().size() > 0) {
|
||||
for (Entity item : dataGrid.getSelected()) {
|
||||
Set<Entity> selected = dataGrid.getSelected();
|
||||
List<Entity> ordered = ((Collection<Entity>) datasource.getItems()).stream()
|
||||
.filter(selected::contains)
|
||||
.collect(Collectors.toList());
|
||||
for (Entity item : ordered) {
|
||||
createDataGridRow(dataGrid, columns, 0, ++r, item.getId());
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user