Class NatExporter

java.lang.Object
org.eclipse.nebula.widgets.nattable.export.NatExporter

public class NatExporter extends Object
This class is used to perform exports of a NatTable or ILayer in a NatTable composition. The exporter to use can be configured via IConfigRegistry or directly given as method parameter.
See Also:
  • Field Details

    • shell

      protected final org.eclipse.swt.widgets.Shell shell
      The Shell that should be used to open sub-dialogs and perform export operations in a background thread.
      Since:
      1.5
    • openResult

      protected boolean openResult
      Flag that indicates if the created export result should be opened after the export is finished.
      Since:
      1.5
    • exportSucceeded

      protected boolean exportSucceeded
      Flag that indicates that the export succeeded. Used to determine whether the export result can be opened or not.
      Since:
      1.5
    • preRender

      protected boolean preRender
      Flag to configure whether in-memory pre-rendering is enabled or not. This is necessary in case content painters are used that are configured for content based auto-resizing.
      Since:
      1.5
  • Constructor Details

    • NatExporter

      public NatExporter(org.eclipse.swt.widgets.Shell shell)
      Create a new NatExporter.
      Parameters:
      shell - The Shell that should be used to open sub-dialogs and perform export operations in a background thread. Can be null but could lead to NullPointerExceptions if IExporter are configured, that use a FileOutputStreamProvider.
    • NatExporter

      public NatExporter(org.eclipse.swt.widgets.Shell shell, boolean executeSynchronously)
      Create a new NatExporter.
      Parameters:
      shell - The Shell that should be used to open sub-dialogs and perform export operations in a background thread. Can be null but could lead to NullPointerExceptions if IExporter are configured, that use a FileOutputStreamProvider.
      executeSynchronously - Configure whether the export should be performed asynchronously or synchronously. By default the decision whether the execution should be performed synchronously or not is made based on whether a Shell is set or not. If a Shell is set and this flag is set to true the execution is performed synchronously.
      Since:
      1.6
    • NatExporter

      public NatExporter(org.eclipse.swt.widgets.Shell shell, boolean executeSynchronously, boolean useProgressDialog)
      Create a new NatExporter.
      Parameters:
      shell - The Shell that should be used to open sub-dialogs and perform export operations in a background thread. Can be null but could lead to NullPointerExceptions if IExporter are configured, that use a FileOutputStreamProvider.
      executeSynchronously - Configure whether the export should be performed asynchronously or synchronously. By default the decision whether the execution should be performed synchronously or not is made based on whether a Shell is set or not. If a Shell is set and this flag is set to true the execution is performed synchronously.
      Since:
      2.3
  • Method Details

    • exportSingleLayer

      public void exportSingleLayer(ILayer layer, IConfigRegistry configRegistry)
      Exports a single ILayer using the ILayerExporter registered in the IConfigRegistry for the key ExportConfigAttributes.EXPORTER.
      Parameters:
      layer - The ILayer to export, usually a NatTable instance.
      configRegistry - The IConfigRegistry of the NatTable instance to export, that contains the necessary export configurations.
    • exportSingleLayer

      public void exportSingleLayer(ILayerExporter exporter, ILayer layer, IConfigRegistry configRegistry)
      Exports a single ILayer using the given ILayerExporter.
      Parameters:
      exporter - The ILayerExporter to use for exporting.
      layer - The ILayer to export, usually a NatTable instance.
      configRegistry - The IConfigRegistry of the NatTable instance to export, that contains the necessary export configurations.
      Since:
      1.5
    • getProgressMonitorDialog

      protected org.eclipse.jface.dialogs.ProgressMonitorDialog getProgressMonitorDialog()
      Returns:
      The ProgressMonitorDialog that is used to report the export progress to a user, in case useProgressDialog is true.
      Since:
      2.3
      See Also:
      • useProgressDialog
    • exportSingleTable

      public void exportSingleTable(ILayer layer, IConfigRegistry configRegistry)
      Exports a single ILayer using the ILayerExporter registered in the IConfigRegistry for the key ExportConfigAttributes.EXPORTER.
      Parameters:
      layer - The ILayer to export, usually a NatTable instance.
      configRegistry - The IConfigRegistry of the NatTable instance to export, that contains the necessary export configurations.
      Since:
      1.5
    • exportSingleTable

      public void exportSingleTable(ITableExporter exporter, ILayer layer, IConfigRegistry configRegistry)
      Exports a single ILayer using the given ITableExporter.
      Parameters:
      exporter - The ITableExporter to use for exporting.
      layer - The ILayer to export, usually a NatTable instance.
      configRegistry - The IConfigRegistry of the NatTable instance to export, that contains the necessary export configurations.
      Since:
      1.5
    • exportMultipleNatTables

      public void exportMultipleNatTables(ILayerExporter exporter, Map<String,NatTable> natTablesMap)
      Export multiple NatTable instances to one file by using the given ILayerExporter.
      Parameters:
      exporter - The ILayerExporter to use for exporting.
      natTablesMap - The NatTable instances to export. They keys in the map will be used as sheet titles while the values are the instances to export.
    • exportMultipleNatTables

      public void exportMultipleNatTables(ILayerExporter exporter, Map<String,NatTable> natTablesMap, boolean exportOnSameSheet, String sheetName)
      Export multiple NatTable instances to one file by using the given ILayerExporter.
      Parameters:
      exporter - The ILayerExporter to use for exporting.
      natTablesMap - The NatTable instances to export. They keys in the map will be used as sheet titles while the values are the instances to export.
      exportOnSameSheet - Flag to configure whether multiple NatTable instances should be exported on the same sheet or not.
      sheetName - The sheet name that should be used in case of exporting multiple NatTables on a single sheet.
      Since:
      1.5
    • exportLayer

      protected void exportLayer(ILayerExporter exporter, OutputStream outputStream, String layerName, ILayer layer, IConfigRegistry configRegistry)
      Exports the given layer to the outputStream using the provided exporter. The ILayerExporter.exportBegin(OutputStream) method should be called before this method is invoked, and ILayerExporter.exportEnd(OutputStream) should be called after this method returns. If multiple layers are being exported as part of a single logical export operation, then ILayerExporter.exportBegin(OutputStream) will be called once at the very beginning, followed by n calls to this method, and finally followed by ILayerExporter.exportEnd(OutputStream).

      Note: This method calls exportLayer(ILayerExporter, OutputStream, String, ILayer, IConfigRegistry, boolean) with the parameter initExportLayer set to true.

      Parameters:
      exporter - The ILayerExporter that should be used for exporting.
      outputStream - The OutputStream that should be used to write the export to.
      layerName - The name that should be set as sheet name of the export.
      layer - The ILayer that should be exported.
      configRegistry - The IConfigRegistry needed to retrieve the export configurations.
    • exportLayer

      protected void exportLayer(ILayerExporter exporter, OutputStream outputStream, String layerName, ILayer layer, IConfigRegistry configRegistry, boolean initExportLayer)
      Exports the given layer to the outputStream using the provided exporter. The ILayerExporter.exportBegin(OutputStream) method should be called before this method is invoked, and ILayerExporter.exportEnd(OutputStream) should be called after this method returns. If multiple layers are being exported as part of a single logical export operation, then ILayerExporter.exportBegin(OutputStream) will be called once at the very beginning, followed by n calls to this method, and finally followed by ILayerExporter.exportEnd(OutputStream).
      Parameters:
      exporter - The ILayerExporter that should be used for exporting.
      outputStream - The OutputStream that should be used to write the export to.
      layerName - The name that should be set as sheet name of the export.
      layer - The ILayer that should be exported.
      configRegistry - The IConfigRegistry needed to retrieve the export configurations.
      initExportLayer - flag to configure whether ILayerExporter.exportLayerBegin(OutputStream, String) and ILayerExporter.exportLayerEnd(OutputStream, String) should be called or not. Should be set to true if multiple NatTable instances should be exported on the same sheet.
      Since:
      1.5
    • exportLayer

      protected void exportLayer(ILayerExporter exporter, OutputStream outputStream, org.eclipse.core.runtime.IProgressMonitor monitor, String layerName, ILayer layer, IConfigRegistry configRegistry, boolean initExportLayer)
      /** Exports the given layer to the outputStream using the provided exporter. The ILayerExporter.exportBegin(OutputStream) method should be called before this method is invoked, and ILayerExporter.exportEnd(OutputStream) should be called after this method returns. If multiple layers are being exported as part of a single logical export operation, then ILayerExporter.exportBegin(OutputStream) will be called once at the very beginning, followed by n calls to this method, and finally followed by ILayerExporter.exportEnd(OutputStream).
      Parameters:
      exporter - The ILayerExporter that should be used for exporting.
      outputStream - The OutputStream that should be used to write the export to.
      monitor - The IProgressMonitor used to report the export process to the user. Can be null.
      layerName - The name that should be set as sheet name of the export.
      layer - The ILayer that should be exported.
      configRegistry - The IConfigRegistry needed to retrieve the export configurations.
      initExportLayer - flag to configure whether ILayerExporter.exportLayerBegin(OutputStream, String) and ILayerExporter.exportLayerEnd(OutputStream, String) should be called or not. Should be set to true if multiple NatTable instances should be exported on the same sheet.
      Since:
      2.3
    • exportLayer

      protected void exportLayer(ITableExporter exporter, OutputStream outputStream, ILayer layer, IConfigRegistry configRegistry)
      Exports the given ILayer to the given OutputStream using the provided ITableExporter.
      Parameters:
      exporter - The ITableExporter that should be used for exporting.
      outputStream - The OutputStream that should be used to write the export to.
      layer - The ILayer that should be exported.
      configRegistry - The IConfigRegistry needed to retrieve the export configurations.
      Since:
      1.5
    • exportLayer

      protected void exportLayer(ITableExporter exporter, OutputStream outputStream, org.eclipse.core.runtime.IProgressMonitor monitor, ILayer layer, IConfigRegistry configRegistry)
      Exports the given ILayer to the given OutputStream using the provided ITableExporter.
      Parameters:
      exporter - The ITableExporter that should be used for exporting.
      outputStream - The OutputStream that should be used to write the export to.
      monitor - The IProgressMonitor used to report the export process to the user. Can be null.
      layer - The ILayer that should be exported.
      configRegistry - The IConfigRegistry needed to retrieve the export configurations.
      Since:
      2.3
    • prepareExportProcess

      protected void prepareExportProcess(ILayer layer, IConfigRegistry configRegistry)
      Prepare the table for the export process. This involves disabling the viewport for example.
      Parameters:
      layer - The ILayer that should be exported.
      configRegistry - The IConfigRegistry needed to retrieve the export configurations.
      Since:
      2.3
    • finalizeExportProcess

      protected void finalizeExportProcess(ILayer layer, IClientAreaProvider originalClientAreaProvider)
      Reset the table state. This means to set back the state that was changed in prepareExportProcess(ILayer, IConfigRegistry), e.g. enable the viewport for example.
      Parameters:
      layer - The ILayer that should be exported.
      originalClientAreaProvider - The original IClientAreaProvider, which was replaced via setClientAreaToMaximum(ILayer).
      Since:
      2.3
    • getPrepareSubTaskName

      protected String getPrepareSubTaskName()
      Returns:
      The name that should be shown for the "prepare" subtask in the ProgressMonitorDialog.
      Since:
      2.3
      See Also:
      • useProgressDialog
    • getExportSubTaskName

      protected String getExportSubTaskName()
      Returns:
      The name that should be shown for the "export data" subtask in the ProgressMonitorDialog.
      Since:
      2.3
      See Also:
      • useProgressDialog
    • setClientAreaToMaximum

      protected void setClientAreaToMaximum(ILayer layer)
      Increase the client area so it can include the whole ILayer.
      Parameters:
      layer - The ILayer for which the client area should be maximized.
      Since:
      1.5
    • openExport

      protected void openExport(IExporter exporter)
      Open the export result in the matching application.
      Parameters:
      exporter - The IExporter that was used to perform the export. Needed to access the export result.
      Since:
      1.5
    • setOpenResult

      public void setOpenResult(boolean openResult)
      Sets the behavior after finishing the export. The default is opening the created export file with the associated application. You can prevent the opening by setting openResult to false.
      Parameters:
      openResult - set to true to open the created export file, false otherwise
      Since:
      1.5
    • getOutputStream

      protected OutputStream getOutputStream(IExporter exporter)
      Method that is used to retrieve the OutputStream to write the export to in a safe way. Any occurring exception will be handled inside.
      Parameters:
      exporter - The ILayerExporter that should be used
      Returns:
      The OutputStream that is used to write the export to or null if an error occurs.
      Since:
      1.5
    • handleExportException

      protected void handleExportException(Exception e)
      Method that is used to handle exceptions that are raised while processing the export.
      Parameters:
      e - The exception that should be handled.
      Since:
      1.5
    • enablePreRendering

      public void enablePreRendering()
      Enable in-memory pre-rendering. This is necessary in case content painters are used that are configured for content based auto-resizing.
      Since:
      1.5
    • disablePreRendering

      public void disablePreRendering()
      Disable in-memory pre-rendering. You should consider to disable pre-rendering if no content painters are used that are configured for content based auto-resizing.
      Since:
      1.5
    • isUseProgressDialog

      public boolean isUseProgressDialog()
      Returns:
      true if the progress is reported via ProgressMonitorDialog, false if a custom shell with a ProgressBar will be shown.
      Since:
      2.3
    • setUseProgressDialog

      public void setUseProgressDialog(boolean useProgressDialog)
      Configure how the export progress should be visualized. Will only have an effect if the NatExporter was created with a Shell.
      Parameters:
      useProgressDialog - true if the progress should be reported via ProgressMonitorDialog, false if a custom shell with a ProgressBar should be shown.
      Since:
      2.3