Merge remote-tracking branch 'origin/master'

This commit is contained in:
kozyaikin 2017-04-14 14:38:14 +04:00
commit 4835cc5b60
2 changed files with 31 additions and 6 deletions

View File

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

View File

@ -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 {