Class GridExporter<T>
- java.lang.Object
-
- com.flowingcode.vaadin.addons.gridexporter.GridExporter<T>
-
- All Implemented Interfaces:
Serializable
public class GridExporter<T> extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
GridExporter.GridExporterStreamResource
-
Field Summary
Fields Modifier and Type Field Description static float
DEFAULT_COST
The standard unit of resource usage for concurrent downloads.static float
MAX_COST
Represents all the permits available to the semaphore.static float
MIN_COST
A fractional cost that acquires only one permit.int
totalcells
Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Registration
addConcurrentDownloadTimeoutEvent(SerializableConsumer<ConcurrentDownloadTimeoutEvent> listener)
Adds a listener for concurrent download timeout events specific to this instance.static <T> GridExporter<T>
createFor(Grid<T> grid)
static <T> GridExporter<T>
createFor(Grid<T> grid, String excelCustomTemplate, String docxCustomTemplate)
Map<String,String>
getAdditionalPlaceHolders()
List<Grid.Column<T>>
getColumns()
List<Grid.Column<T>>
getColumnsOrdered()
Get columns in the positions specified bysetColumnPosition(Column, int)
Charset
getCsvCharset()
Charset to use when exporting the CSV file.StreamResource
getCsvStreamResource()
GridExporter.GridExporterStreamResource
getDocxStreamResource()
GridExporter.GridExporterStreamResource
getDocxStreamResource(String template)
GridExporter.GridExporterStreamResource
getExcelStreamResource()
GridExporter.GridExporterStreamResource
getExcelStreamResource(String template)
String
getFileName()
GridExporter.GridExporterStreamResource
getPdfStreamResource()
GridExporter.GridExporterStreamResource
getPdfStreamResource(String template)
int
getSheetNumber()
String
getTitle()
boolean
isAutoAttachExportButtons()
boolean
isAutoMergeTitle()
boolean
isAutoSizeColumns()
boolean
isCsvExportEnabled()
boolean
isDocxExportEnabled()
boolean
isExcelExportEnabled()
boolean
isPdfExportEnabled()
void
setAdditionalPlaceHolders(Map<String,String> additionalPlaceHolders)
Sets a map that will contain additional place holders that will be replaced with values when processing the exported filevoid
setAutoAttachExportButtons(boolean autoAttachExportButtons)
If true, it will automatically generate export buttons in the asociated gridvoid
setAutoMergeTitle(boolean autoMergeTitle)
If true the title cell will be merged with the next ones to create a single title cell that will span across the columnsvoid
setAutoSizeColumns(boolean autoSizeColumns)
void
setButtonsAlignment(ButtonsAlignment buttonsAlignment)
void
setColumnPosition(Grid.Column<T> column, int position)
Assigns the position of the column in the exported file.void
setColumns(List<Grid.Column<T>> columns)
void
setConcurrentDownloadCost(float concurrentDownloadCost)
Sets the cost for concurrent downloads.void
setCsvCharset(SerializableSupplier<Charset> charset)
void
setCsvExportEnabled(boolean csvExportEnabled)
void
setCustomFooter(Grid.Column<T> column, String header)
Configures the exporter to use a custom string for a specific column's footer.void
setCustomHeader(Grid.Column<T> column, String header)
Configures the exporter to use a custom string for a specific column's header.void
setDateColumnFormat(Grid.Column<T> column, String excelFormat)
If the column is based on a LocalDate attribute of the item, rendered with a LocalDateRenderer, it configures the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.void
setDateColumnFormat(Grid.Column<T> column, DateFormat dateFormat, String excelFormat)
If the column is based on a String, it configures a DateFormat to parse a date from the value of the column so it can be converted to a java.util.Date, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.void
setDateColumnFormatProvider(Grid.Column<T> column, DateFormat dateFormat, ValueProvider<T,String> excelFormatProvider)
If the column is based on a String, it configures a DateFormat to parse a date from the value of the column so it can be converted to a java.util.Date, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.void
setDisableOnClick(boolean disableOnClick)
Configures the behavior of the system when a download is in progress.void
setDocxExportEnabled(boolean docxExportEnabled)
void
setExcelExportEnabled(boolean excelExportEnabled)
void
setExportColumn(Grid.Column<T> column, boolean export)
Configure if the column is exported or notvoid
setExportValue(Grid.Column<T> column, ValueProvider<T,?> vp)
Configure a value provider for a given column.void
setFileName(SerializableSupplier<String> fileNameSupplier)
Sets a dynamic filename for the exported file.void
setFileName(String fileName)
Sets the filename of the exported filevoid
setFooterToolbarItems(List<FooterToolbarItem> footerToolbarItems)
void
setNullValueHandler(SerializableSupplier<String> nullValueSupplier)
void
setNumberColumnFormat(Grid.Column<T> column, String excelFormat)
If the column is based on a number attribute of the item, rendered with a NumberRenderer, it configures the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a number that can be used in formulas.void
setNumberColumnFormat(Grid.Column<T> column, DecimalFormat decimalFormat, String excelFormat)
If the column is based on a String, it configures a DecimalFormat to parse a number from the value of the column so it can be converted to a Double, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a number that can be used in formulas.void
setNumberColumnFormatProvider(Grid.Column<T> column, DecimalFormat decimalFormat, ValueProvider<T,String> excelFormatProvider)
If the column is based on a String, it configures a DecimalFormat to parse a number from the value of the column so it can be converted to a Double, and then allows to specify the excel format to be applied to the cell when exported to excel with a provider, so the resulting cell is not a string but a number that can be used in formulas.void
setPdfExportEnabled(boolean pdfExportEnabled)
void
setSheetNumber(int sheetNumber)
Configures the excel sheet that will be inspected for placeholders to export the datavoid
setTitle(String title)
Sets the title of the exported file
-
-
-
Field Detail
-
MAX_COST
public static final float MAX_COST
Represents all the permits available to the semaphore.- See Also:
- Constant Field Values
-
MIN_COST
public static final float MIN_COST
A fractional cost that acquires only one permit.- See Also:
- Constant Field Values
-
DEFAULT_COST
public static final float DEFAULT_COST
The standard unit of resource usage for concurrent downloads.- See Also:
- Constant Field Values
-
totalcells
@Deprecated(since="2.5.0", forRemoval=true) public int totalcells
Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Detail
-
createFor
public static <T> GridExporter<T> createFor(Grid<T> grid)
-
createFor
public static <T> GridExporter<T> createFor(Grid<T> grid, String excelCustomTemplate, String docxCustomTemplate)
-
setButtonsAlignment
public void setButtonsAlignment(ButtonsAlignment buttonsAlignment)
-
getDocxStreamResource
public GridExporter.GridExporterStreamResource getDocxStreamResource()
-
getDocxStreamResource
public GridExporter.GridExporterStreamResource getDocxStreamResource(String template)
-
getPdfStreamResource
public GridExporter.GridExporterStreamResource getPdfStreamResource()
-
getPdfStreamResource
public GridExporter.GridExporterStreamResource getPdfStreamResource(String template)
-
getCsvStreamResource
public StreamResource getCsvStreamResource()
-
getExcelStreamResource
public GridExporter.GridExporterStreamResource getExcelStreamResource()
-
getExcelStreamResource
public GridExporter.GridExporterStreamResource getExcelStreamResource(String template)
-
addConcurrentDownloadTimeoutEvent
public Registration addConcurrentDownloadTimeoutEvent(SerializableConsumer<ConcurrentDownloadTimeoutEvent> listener)
Adds a listener for concurrent download timeout events specific to this instance.The listener will be called whenever a concurrent download timeout event occurs.
- Parameters:
listener
- the listener to be added- Returns:
- a
Registration
object that can be used to remove the listener
-
setDisableOnClick
public void setDisableOnClick(boolean disableOnClick)
Configures the behavior of the system when a download is in progress.When
disableOnClick
is set totrue
, the system prevents the UI from starting an additional download of the same kind while one is already in progress. Downloads from other UIs are still allowed. When set tofalse
, concurrent downloads are permitted.- Parameters:
disableOnClick
- Whether to prevent additional downloads during an ongoing download.
-
setConcurrentDownloadCost
public void setConcurrentDownloadCost(float concurrentDownloadCost)
Sets the cost for concurrent downloads. This cost is used to determine the number of permits required for downloads to proceed, thereby controlling the concurrency level. At any given time, the sum of the costs of all concurrent downloads will not exceed the limit set byGridExporterConcurrentSettings.setConcurrentDownloadLimit(float)
.The cost is represented as a float to allow for more granular control over resource usage. By using a floating-point number, fractional costs can be expressed, providing flexibility in determining the resource consumption for different downloads.
The cost is converted to a number of permits by capping it to stay within the limit. A cost of 1.0 (
DEFAULT_COST
) represents a standard unit of resource usage, while a cost of 0.5 represents half a unit, and a cost above 1.0 indicates higher than normal resource usage.If the cost is zero or negative, no permits are needed. However, any positive cost, no matter how small, will require at least one permit to prevent downloads with very low costs from bypassing the semaphore.
MIN_COST
represents the minimal fractional cost that acquires only one permit (hence2*MIN_COST
acquires two permits and so on). A cost ofMAX_COST
prevents any other downloads from acquiring permits simultaneously.- Parameters:
concurrentDownloadCost
- the cost associated with concurrent downloads for this instance.
-
getTitle
public String getTitle()
-
setTitle
public void setTitle(String title)
Sets the title of the exported file- Parameters:
title
-
-
getFileName
public String getFileName()
-
setFileName
public void setFileName(String fileName)
Sets the filename of the exported file- Parameters:
fileName
-
-
setFileName
public void setFileName(SerializableSupplier<String> fileNameSupplier)
Sets a dynamic filename for the exported file.- Parameters:
fileNameSupplier
- a supplier that returns the name of the exported file, without extension.
-
isAutoAttachExportButtons
public boolean isAutoAttachExportButtons()
-
setAutoAttachExportButtons
public void setAutoAttachExportButtons(boolean autoAttachExportButtons)
If true, it will automatically generate export buttons in the asociated grid- Parameters:
autoAttachExportButtons
-
-
setAdditionalPlaceHolders
public void setAdditionalPlaceHolders(Map<String,String> additionalPlaceHolders)
Sets a map that will contain additional place holders that will be replaced with values when processing the exported file- Parameters:
additionalPlaceHolders
-
-
getSheetNumber
public int getSheetNumber()
-
setSheetNumber
public void setSheetNumber(int sheetNumber)
Configures the excel sheet that will be inspected for placeholders to export the data- Parameters:
sheetNumber
-
-
isAutoMergeTitle
public boolean isAutoMergeTitle()
-
setAutoMergeTitle
public void setAutoMergeTitle(boolean autoMergeTitle)
If true the title cell will be merged with the next ones to create a single title cell that will span across the columns- Parameters:
autoMergeTitle
-
-
isExcelExportEnabled
public boolean isExcelExportEnabled()
-
setExcelExportEnabled
public void setExcelExportEnabled(boolean excelExportEnabled)
-
isDocxExportEnabled
public boolean isDocxExportEnabled()
-
setDocxExportEnabled
public void setDocxExportEnabled(boolean docxExportEnabled)
-
isPdfExportEnabled
public boolean isPdfExportEnabled()
-
setPdfExportEnabled
public void setPdfExportEnabled(boolean pdfExportEnabled)
-
isCsvExportEnabled
public boolean isCsvExportEnabled()
-
setCsvExportEnabled
public void setCsvExportEnabled(boolean csvExportEnabled)
-
isAutoSizeColumns
public boolean isAutoSizeColumns()
-
setAutoSizeColumns
public void setAutoSizeColumns(boolean autoSizeColumns)
-
setExportValue
public void setExportValue(Grid.Column<T> column, ValueProvider<T,?> vp)
Configure a value provider for a given column. If there is a value provider, that will be taken into account when exporting the column- Parameters:
column
-vp
-
-
setExportColumn
public void setExportColumn(Grid.Column<T> column, boolean export)
Configure if the column is exported or not- Parameters:
column
-export
- true will be included in the exported file, false will not be included
-
setNullValueHandler
public void setNullValueHandler(SerializableSupplier<String> nullValueSupplier)
-
setNumberColumnFormat
public void setNumberColumnFormat(Grid.Column<T> column, DecimalFormat decimalFormat, String excelFormat)
If the column is based on a String, it configures a DecimalFormat to parse a number from the value of the column so it can be converted to a Double, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a number that can be used in formulas.- Parameters:
column
-decimalFormat
-excelFormat
-
-
setNumberColumnFormatProvider
public void setNumberColumnFormatProvider(Grid.Column<T> column, DecimalFormat decimalFormat, ValueProvider<T,String> excelFormatProvider)
If the column is based on a String, it configures a DecimalFormat to parse a number from the value of the column so it can be converted to a Double, and then allows to specify the excel format to be applied to the cell when exported to excel with a provider, so the resulting cell is not a string but a number that can be used in formulas.- Parameters:
column
-decimalFormat
-excelFormatProvider
-
-
setDateColumnFormat
public void setDateColumnFormat(Grid.Column<T> column, DateFormat dateFormat, String excelFormat)
If the column is based on a String, it configures a DateFormat to parse a date from the value of the column so it can be converted to a java.util.Date, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.- Parameters:
column
-dateFormat
-excelFormat
-
-
setDateColumnFormatProvider
public void setDateColumnFormatProvider(Grid.Column<T> column, DateFormat dateFormat, ValueProvider<T,String> excelFormatProvider)
If the column is based on a String, it configures a DateFormat to parse a date from the value of the column so it can be converted to a java.util.Date, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.- Parameters:
column
-dateFormat
-excelFormatProvider
-
-
setNumberColumnFormat
public void setNumberColumnFormat(Grid.Column<T> column, String excelFormat)
If the column is based on a number attribute of the item, rendered with a NumberRenderer, it configures the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a number that can be used in formulas.- Parameters:
column
-excelFormat
-
-
setDateColumnFormat
public void setDateColumnFormat(Grid.Column<T> column, String excelFormat)
If the column is based on a LocalDate attribute of the item, rendered with a LocalDateRenderer, it configures the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.- Parameters:
column
-excelFormat
-
-
setCustomHeader
public void setCustomHeader(Grid.Column<T> column, String header)
Configures the exporter to use a custom string for a specific column's header. Usefull when the header is a custom component.- Parameters:
column
-header
-
-
setCustomFooter
public void setCustomFooter(Grid.Column<T> column, String header)
Configures the exporter to use a custom string for a specific column's footer. Usefull when the footer is a custom component.- Parameters:
column
-header
-
-
setColumnPosition
public void setColumnPosition(Grid.Column<T> column, int position)
Assigns the position of the column in the exported file.- Parameters:
column
-position
-
-
setColumns
public void setColumns(List<Grid.Column<T>> columns)
-
getColumns
public List<Grid.Column<T>> getColumns()
-
getColumnsOrdered
public List<Grid.Column<T>> getColumnsOrdered()
Get columns in the positions specified bysetColumnPosition(Column, int)
-
setFooterToolbarItems
public void setFooterToolbarItems(List<FooterToolbarItem> footerToolbarItems)
-
getCsvCharset
public Charset getCsvCharset()
Charset to use when exporting the CSV file.- Returns:
- CSV file charset or default one.
-
setCsvCharset
public void setCsvCharset(SerializableSupplier<Charset> charset)
-
-