ref #10448 rename WFO classification -> WFO Backbone
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / ExportToFileDestinationWizardPage.java
index 01543b75b8c91246b224f90d0cc329b93b57cc90..c1822da2400378996c4a6ead51db41cbcc49b08c 100644 (file)
@@ -6,18 +6,18 @@
  * The content of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
-
 package eu.etaxonomy.taxeditor.io.wizard;
 
-import java.awt.Checkbox;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
-import java.util.Comparator;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
-import org.apache.commons.lang.StringUtils;
+import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -28,8 +28,8 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Listener;
@@ -37,519 +37,623 @@ import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.filter.LogicFilter;
 import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
+import eu.etaxonomy.cdm.io.coldp.ColDpExportConfigurator;
 import eu.etaxonomy.cdm.io.common.ExportConfiguratorBase;
 import eu.etaxonomy.cdm.io.csv.caryophyllales.out.CsvNameExportConfigurator;
 import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
-import eu.etaxonomy.cdm.io.csv.redlist.out.CsvTaxExportConfiguratorRedlist;
 import eu.etaxonomy.cdm.io.dwca.out.DwcaTaxExportConfigurator;
 import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
 import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
 import eu.etaxonomy.cdm.io.tcsxml.out.TcsXmlExportConfigurator;
+import eu.etaxonomy.cdm.io.wfo.out.WfoExportConfigurator;
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByNameComparator;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByRankAndNameComparator;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoNaturalComparator;
+import eu.etaxonomy.taxeditor.preference.NavigatorOrderEnum;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
+import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
- * <p>
  * ExportToFileDestinationWizardPage class.
- * </p>
  *
  * @author n.hoffmann
  * @created 15.06.2009
- * @version 1.0
  */
 public class ExportToFileDestinationWizardPage extends WizardPage implements SelectionListener {
 
-       /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
-       public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
-
-       /** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
-       public static final String JAXB_EXPORT = "JAXB_EXPORT";
+    /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
+    public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
 
-       /** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
-       public static final String TCS_EXPORT = "TCS_EXPORT";
+    /** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
+    public static final String JAXB_EXPORT = "JAXB_EXPORT";
 
-       /** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
-       public static final String SDD_EXPORT = "SDD_EXPORT";
+    /** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
+    public static final String TCS_EXPORT = "TCS_EXPORT";
 
-       public static final String DWCA_EXPORT = "DWCA_EXPORT";
-       public static final String OUTPUT_MODEL_EXPORT = "CDM_LIGHT(CSV)";
-       public static final String CSV_EXPORT = "CSV_EXPORT";
-       public static final String CSV_NAME_EXPORT = "CSV_NAME_EXPORT";
-       private static final String CSV_PRINT_EXPORT ="CSV_PRINT_EXPORT";
-       private static final String EXPORT_FOLDER ="EXPORT_FOLDER";
-       public static final String XML = "xml";
+    /** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
+    public static final String SDD_EXPORT = "SDD_EXPORT";
 
-       public static final String CSV = "csv";
+    public static final String DWCA_EXPORT = "DWCA_EXPORT";
+    public static final String WFO_EXPORT = "WFO_EXPORT";
+    public static final String CDM_LIGHT_EXPORT = "CDM_LIGHT(CSV)";
+    public static final String COL_DP_EXPORT = "COL DP";
+    public static final String CSV_EXPORT = "CSV_EXPORT";
+    public static final String CSV_NAME_EXPORT = "CSV_NAME_EXPORT";
+    private static final String CSV_PRINT_EXPORT = "CSV_PRINT_EXPORT";
+    private static final String EXPORT_FOLDER = "EXPORT_FOLDER";
+    public static final String XML = "xml";
 
+    public static final String CSV = "csv";
 
-
-       public static final String ZIP = "zip";
+    public static final String ZIP = "zip";
 
     private boolean csvExport = false;
 
     private boolean csvNameExport = false;
 
-       
+    private boolean csvPrintExport = false;
 
-       private boolean csvPrintExport = false;
+    private boolean cdmLightExport = false;
 
-       private boolean outputModelExport = false;
-       private boolean dwcaExport = false;
+    private boolean colDPExport = false;
+    private boolean dwcaExport = false;
+    private boolean wfoExport = false;
 
-       private DirectoryDialog folderDialog;
-       private Text text_exportFileName;
+    private DirectoryDialog folderDialog;
+    private Text text_exportFileName;
 
-       private Text text_folder;
+    private Text text_folder;
 
-       private final String type;
+    private final String type;
 
-       private final String extension;
+    private final String extension;
 
     private Combo classificationSelectionCombo;
 
     private List<Classification> classifications;
 
     private Classification selectedClassification;
-    private Label classificationLabel;
-    
-    private ExportConfiguratorBase configurator;
-    private Button checkUseSelectedtaxonNode;
+
+    private ExportConfiguratorBase<?, ?, ?> configurator;
+    private Button checkUseSelectedTaxonNode;
 
     private Button checkUseSelectedClassification;
+    private Button checkUseAllClassification;
+
+    private Button checkExportUnpublished;
+    private Button checkExportFactualData;
+    private Button checkExportUnpublishedFactualData;
+
+    private Combo orderSelectionCombo;
+
+    private Text text_familyString;
+
+    protected ExportToFileDestinationWizardPage(String pageName, String type, String title, String description,
+            String extension, ExportConfiguratorBase<?, ?, ?> configurator) {
+        super(pageName);
+        this.configurator = configurator;
+        this.type = type;
+        switch (type) {
+        case CSV_EXPORT:
+            csvExport = true;
+            break;
+        case CSV_NAME_EXPORT:
+            csvNameExport = true;
+            break;
+        case CDM_LIGHT_EXPORT:
+            cdmLightExport = true;
+            break;
+        case COL_DP_EXPORT:
+            colDPExport = true;
+            break;
+        case CSV_PRINT_EXPORT:
+            csvPrintExport = true;
+            break;
+        case DWCA_EXPORT:
+            dwcaExport = true;
+            break;
+        case WFO_EXPORT:
+            wfoExport = true;
+            break;
+        default:
+            throw new RuntimeException("Export type not yet handeled: " + type);
+        }
+        this.extension = extension;
+        this.setTitle(title);
+        this.setDescription(description);
+    }
 
-       /**
-        * @param pageName
-        * @param selection
-        */
-       protected ExportToFileDestinationWizardPage(String pageName, String type,
-                       String title, String description, String extension, ExportConfiguratorBase configurator) {
-               super(pageName);
-               this.configurator = configurator;
-               this.type = type;
-               switch(type) {
-                  case CSV_EXPORT :
-                          csvExport = true;
-                          break;
-                  case CSV_NAME_EXPORT:
-                          csvNameExport = true;
-                          break;
-                  case OUTPUT_MODEL_EXPORT:
-                          outputModelExport = true;
-                          break;
-                  case CSV_PRINT_EXPORT:
-                          csvPrintExport = true;
-                          break;
-                  case DWCA_EXPORT:
-                          dwcaExport = true;
-                          break;
-                         
-               }
-               this.extension = extension;
-               this.setTitle(title);
-               this.setDescription(description);
-       }
-
-       /**
-        * <p>
-        * Jaxb
-        * </p>
-        *
-        * @return a
-        *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
-        *         object.
-        */
-       public static ExportToFileDestinationWizardPage Jaxb(JaxbExportConfigurator configurator) {
-               return new ExportToFileDestinationWizardPage(
-                               JAXB_EXPORT,
-                               "jaxb",
-                               "JAXB Export",
-                               "Exports the content of the currently selected database into the cdm jaxb format.",
-                               XML, configurator);
-       }
-
-       /**
-        * <p>
-        * Tcs
-        * </p>
-        *
-        * @return a
-        *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
-        *         object.
-        */
-       public static ExportToFileDestinationWizardPage Tcs(TcsXmlExportConfigurator config) {
-               return new ExportToFileDestinationWizardPage(
-                               TCS_EXPORT,
-                               "tcs",
-                               "Tcs Export",
-                               "Export the content of the currently selected database into TCS format.",
-                               XML, config);
-       }
-
-       /**
-        * <p>
-        * Sdd
-        * </p>
-        *
-        * @return a
-        *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
-        *         object.
-        */
-       public static ExportToFileDestinationWizardPage Sdd(SDDExportConfigurator config) {
-               return new ExportToFileDestinationWizardPage(
-                               SDD_EXPORT,
-                               "sdd",
-                               "Sdd Export",
-                               "Export the content of the currently selected database into SDD format.",
-                               XML, config);
-       }
-
-       /**
-        * @return
-        */
-       public static ExportToFileDestinationWizardPage Dwca(DwcaTaxExportConfigurator config) {
-               return new ExportToFileDestinationWizardPage(
-                               DWCA_EXPORT,
-                               DWCA_EXPORT,
-                               "DwC-Archive Export",
-                               "Export the content of the currently selected database into Darwin Core Archive format.",
-                               ZIP, config);
-       }
-
-       /**
-     * @return
-     */
-    public static ExportToFileDestinationWizardPage OutputModel(CdmLightExportConfigurator config) {
-        
-        return new ExportToFileDestinationWizardPage(
-                OUTPUT_MODEL_EXPORT,
-                OUTPUT_MODEL_EXPORT,
-                "Cdm Light Export (csv)",
-                "Export the content of the currently selected database into the cdm light (csv) format.",
-                CSV,config);
+    public static ExportToFileDestinationWizardPage Jaxb(JaxbExportConfigurator configurator) {
+        return new ExportToFileDestinationWizardPage(JAXB_EXPORT, "jaxb", "JAXB Export",
+                "Exports the content of the currently selected database into the cdm jaxb format.", XML, configurator);
     }
 
+    public static ExportToFileDestinationWizardPage Tcs(TcsXmlExportConfigurator config) {
+        return new ExportToFileDestinationWizardPage(TCS_EXPORT, "tcs", "Tcs Export",
+                "Export the content of the currently selected database into TCS format.", XML, config);
+    }
+
+    public static ExportToFileDestinationWizardPage Sdd(SDDExportConfigurator config) {
+        return new ExportToFileDestinationWizardPage(SDD_EXPORT, "sdd", "Sdd Export",
+                "Export the content of the currently selected database into SDD format.", XML, config);
+    }
+
+    public static ExportToFileDestinationWizardPage Dwca(DwcaTaxExportConfigurator config) {
+        return new ExportToFileDestinationWizardPage(DWCA_EXPORT, DWCA_EXPORT, "DwC-Archive Export",
+                "Export the content of the currently selected database into Darwin Core Archive format.", ZIP, config);
+    }
+    public static ExportToFileDestinationWizardPage WFO(WfoExportConfigurator config) {
+        return new ExportToFileDestinationWizardPage(WFO_EXPORT, WFO_EXPORT, "WFO Backbone Export",
+                "Export the content of the currently selected database into WFO Backbone format."
+                , ZIP, config);
+    }
+
+    public static ExportToFileDestinationWizardPage CdmLight(CdmLightExportConfigurator config) {
+
+        return new ExportToFileDestinationWizardPage(CDM_LIGHT_EXPORT, CDM_LIGHT_EXPORT, "CDM Light Export (csv)",
+                "Export the content of the currently selected database into the CDM light (csv) format.", CSV, config);
+    }
+
+    public static ExportToFileDestinationWizardPage ColDp(ColDpExportConfigurator config) {
+
+        return new ExportToFileDestinationWizardPage(COL_DP_EXPORT, COL_DP_EXPORT, "Col DP Export (zip)",
+                "Export the content of the currently selected database into the Catalogue of Life Data Package (Col DP) format.", ZIP, config);
+    }
 
-    /**
-     * @return
-     */
     public static ExportToFileDestinationWizardPage Csv(CsvDemoExportConfigurator config) {
-        
-        return new ExportToFileDestinationWizardPage(
-                CSV_EXPORT,
-                CSV_EXPORT,
-                "CSV Export",
-                "Export the content of the currently selected database into Comma Separated Value format.",
-                CSV, config);
+
+        return new ExportToFileDestinationWizardPage(CSV_EXPORT, CSV_EXPORT, "CSV Export",
+                "Export the content of the currently selected database into Comma Separated Value format.", CSV,
+                config);
     }
 
-    /**
-     * @return
-     */
     public static ExportToFileDestinationWizardPage CsvNames(CsvNameExportConfigurator config) {
-       
-        return new ExportToFileDestinationWizardPage(
-                CSV_NAME_EXPORT,
-                CSV_NAME_EXPORT,
-                "CSV Name Export",
-                "Export the names of the currently selected database into Semicolon Separated Value format.",
-                CSV, config);
+
+        return new ExportToFileDestinationWizardPage(CSV_NAME_EXPORT, CSV_NAME_EXPORT, "CSV Name Export",
+                "Export the names of the currently selected database into Semicolon Separated Value format.", CSV,
+                config);
     }
 
-    /**
-     * @return
-     */
     public static ExportToFileDestinationWizardPage CsvPrint(CsvNameExportConfigurator config) {
-       
-        return new ExportToFileDestinationWizardPage(
-                CSV_PRINT_EXPORT,
-                CSV_NAME_EXPORT,
-                "CSV Print Export",
-                "Export the content of the currently selected database into Semicolon Separated Value format.",
-                CSV, config);
-    }
-
-       /*
-        * (non-Javadoc)
-        *
-        * @see
-        * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
-        * .Composite)
-        */
-       /** {@inheritDoc} */
-       @Override
+
+        return new ExportToFileDestinationWizardPage(CSV_PRINT_EXPORT, CSV_NAME_EXPORT, "CSV Print Export",
+                "Export the content of the currently selected database into Semicolon Separated Value format.", CSV,
+                config);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public void createControl(Composite parent) {
 
-               setPageComplete(false);
-
-               Composite composite = new Composite(parent, SWT.NONE);
-               GridLayout gridLayout = new GridLayout();
-               
-               gridLayout.numColumns = 2;
-               TaxonNode node = null;
-               
-               composite.setLayout(gridLayout);
-               if(classifications == null){
-                       classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
-                       Collections.sort(classifications, new Comparator<Classification>() {
-
-                @Override
-                public int compare(Classification o1, Classification o2) {
-                    if (o1.equals(o2)){
-                        return 0;
+        setPageComplete(false);
+
+        Composite composite = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+
+        gridLayout.numColumns = 2;
+        TaxonNode node = null;
+
+        composite.setLayout(gridLayout);
+        if (cdmLightExport || dwcaExport || colDPExport) {
+            checkExportUnpublished = new Button(composite, SWT.CHECK);
+            checkExportUnpublished.setText("Export unpublished taxa");
+            Label emptyLabel = new Label(composite, SWT.NONE);
+            checkExportFactualData = new Button(composite, SWT.CHECK);
+            checkExportFactualData.setText("Export factual data");
+            checkExportFactualData.setSelection(true);
+            checkExportFactualData.addListener(SWT.Selection, e -> {
+                Button b = (Button) e.widget;
+                GridData data = (GridData) checkExportUnpublishedFactualData.getLayoutData();
+                data.exclude = b.getSelection();
+                checkExportUnpublishedFactualData.setEnabled(data.exclude);
+            });
+            if (cdmLightExport || colDPExport) {
+                emptyLabel = new Label(composite, SWT.NONE);
+
+                checkExportUnpublishedFactualData = new Button(composite, SWT.CHECK);
+                checkExportUnpublishedFactualData.setText("Export unpublished factual data");
+                checkExportUnpublishedFactualData.setSelection(false);
+                GridData gridData = new GridData();
+                gridData.horizontalIndent = 20;
+                checkExportUnpublishedFactualData.setLayoutData(gridData);
+            }
+
+            @SuppressWarnings("unused")
+            Label nope = new Label(composite, SWT.NONE);
+
+            Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
+            GridData gridDataSep = new GridData(GridData.FILL_HORIZONTAL);
+            gridDataSep.horizontalSpan = 2;
+            separator.setLayoutData(gridDataSep);
+        }
+        if (classifications == null && !wfoExport) {
+            classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
+            Collections.sort(classifications, (o1, o2) -> {
+                if (o1.equals(o2)) {
+                    return 0;
+                }
+                int result = o1.getTitleCache().compareTo(o2.getTitleCache());
+                if (result == 0) {
+                    return o1.getUuid().compareTo(o2.getUuid());
+                }
+                return result;
+            });
+            if (!configurator.getTaxonNodeFilter().getClassificationFilter().isEmpty()) {
+                selectedClassification = CdmStore.getService(IClassificationService.class)
+                        .load(configurator.getTaxonNodeFilter().getClassificationFilter().get(0).getUuid());
+            } else {
+
+                selectedClassification = classifications.iterator().next();
+            }
+        }
+
+        if (csvExport || csvPrintExport || cdmLightExport || csvNameExport || dwcaExport || colDPExport || wfoExport) {
+
+            // Label comboBoxLabel = new Label(composite, SWT.NONE);
+            // comboBoxLabel.setText("Classification");
+            Composite selectNodeOrClassification = new Composite(composite, SWT.NONE);
+            GridLayout grid = new GridLayout();
+            grid.numColumns = 1;
+            selectNodeOrClassification.setLayout(grid);
+            if ((cdmLightExport || dwcaExport || colDPExport || wfoExport) && !configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty()) {
+                if (!wfoExport) {
+                    checkUseSelectedTaxonNode = new Button(selectNodeOrClassification, SWT.RADIO);
+                }
+                String taxonStr = "";
+                int count = configurator.getTaxonNodeFilter().getSubtreeFilter().size();
+                List<TaxonNode> selectedNodes = new ArrayList<>();
+                for (LogicFilter<TaxonNode> filter : configurator.getTaxonNodeFilter().getSubtreeFilter()) {
+                    node = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(filter.getUuid());
+                    selectedNodes.add(node);
+                    count--;
+                    if (node.hasTaxon()) {
+                        taxonStr += node.getTaxon().getName().getTitleCache();
+                        if (count > 0) {
+                            taxonStr += ", ";
+                        }
                     }
-                    int result = o1.getTitleCache().compareTo(o2.getTitleCache());
-                    if (result == 0){
-                        return o1.getUuid().compareTo(o2.getUuid());
+                }
+                if (!wfoExport) {
+                    checkUseSelectedTaxonNode.setText("Export all selected subtree(s) (" + taxonStr + ")");
+                    checkUseSelectedTaxonNode.addListener(SWT.Selection, e -> {
+                        Button b = (Button) e.widget;
+                        GridData data = (GridData) classificationSelectionCombo.getLayoutData();
+                        data.exclude = b.getSelection();
+                        if (classificationSelectionCombo != null) {
+                            classificationSelectionCombo.setEnabled(!data.exclude);
+                        }
+                    });
+                    checkUseSelectedTaxonNode.setSelection(true);
+                }else {
+                    Composite wfoComp = new Composite(selectNodeOrClassification, SWT.NONE);
+                    grid = new GridLayout();
+                    grid.numColumns = 2;
+                    wfoComp.setLayout(grid);
+
+                    Label label = new Label(wfoComp, SWT.NONE);
+                    label.setText("Export all selected subtree(s) (" + taxonStr + ")");
+                    GridData gridData = new GridData();
+                    gridData.horizontalSpan = 2;
+                    gridData.grabExcessHorizontalSpace = true;
+                    label.setLayoutData(gridData);
+
+                    Label familyString = new Label(wfoComp, SWT.NONE);
+                    familyString.setText("Family");
+                    text_familyString = new Text(wfoComp, SWT.BORDER);
+                    text_familyString.setText(generateFamilyName(selectedNodes));
+                    text_familyString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+                }
+            }else if (wfoExport) {
+
+                Label label = new Label(composite, SWT.NONE);
+                label.setText("WFO Backbone export is only available for subtrees, not for classifications");
+                GridData gridData = new GridData();
+                gridData.horizontalSpan = 2;
+                gridData.grabExcessHorizontalSpace = true;
+                label.setLayoutData(gridData);
+                label.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+            }
+
+            if (cdmLightExport || dwcaExport || colDPExport ) {
+                if (dwcaExport) {
+                    checkUseAllClassification = new Button(selectNodeOrClassification, SWT.RADIO);
+                    checkUseAllClassification.setText("Export all classifications");
+                    checkUseAllClassification.addListener(SWT.Selection, new Listener() {
+                        @Override
+                        public void handleEvent(Event e) {
+                            Button b = (Button) e.widget;
+                            GridData data = (GridData) classificationSelectionCombo.getLayoutData();
+                            data.exclude = b.getSelection();
+                            classificationSelectionCombo.setEnabled(!data.exclude);
+
+                        }
+                    });
+                }
+                checkUseSelectedClassification = new Button(selectNodeOrClassification, SWT.RADIO);
+                checkUseSelectedClassification.setText("Export selected classification");
+                checkUseSelectedClassification.addListener(SWT.Selection, e -> {
+                    Button b = (Button) e.widget;
+                    GridData data = (GridData) classificationSelectionCombo.getLayoutData();
+                    data.exclude = b.getSelection();
+                    classificationSelectionCombo.setEnabled(data.exclude);
+                });
+            }
+
+            if (node != null && !wfoExport) {
+                selectedClassification = node.getClassification();
+            }
+            if (!wfoExport) {
+                createClassificationSelectionCombo(selectNodeOrClassification);
+            }
+            if (cdmLightExport) {
+                Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
+                GridData gridDataSep = new GridData();
+                gridDataSep = new GridData(GridData.BEGINNING, GridData.CENTER, true, true);
+                gridDataSep.horizontalSpan = 2;
+                separator.setLayoutData(gridDataSep);
+
+                Composite comp = new Composite(composite, SWT.NONE);
+
+                GridData gridData = new GridData();
+                gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
+                gridData.horizontalSpan = 2;
+                comp.setLayoutData(gridData);
+
+                Label label = new Label(comp, SWT.NONE);
+                label.setText("Sorting of taxa");
+
+                orderSelectionCombo = new Combo(comp, SWT.BORDER | SWT.READ_ONLY);
+
+                GridLayoutFactory.fillDefaults().applyTo(comp);
+                for (NavigatorOrderEnum display : NavigatorOrderEnum.values()) {
+                    orderSelectionCombo.add(display.getLabel());
+                }
+
+                int index = 0;
+                if (PreferencesUtil.getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()) != null) {
+                    NavigatorOrderEnum orderInNavigator = NavigatorOrderEnum
+                            .valueOf(PreferencesUtil.getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
+
+                    for (String itemLabel : orderSelectionCombo.getItems()) {
+                        if (itemLabel.equalsIgnoreCase(orderInNavigator.getLabel())) {
+                            orderSelectionCombo.select(index);
+                            setComparatorToConfig();
+                            break;
+                        }
+                        index++;
                     }
-                    return result;
                 }
-            });
-                       if (!configurator.getTaxonNodeFilter().getClassificationFilter().isEmpty()){
-                               selectedClassification = CdmStore.getService(IClassificationService.class).load(configurator.getTaxonNodeFilter().getClassificationFilter().get(0).getUuid());
-                       }else{
-                               
-                               selectedClassification = classifications.iterator().next();
-                       }
-               }
-
-
-               if(csvExport || csvPrintExport || outputModelExport|| csvNameExport || dwcaExport){
-//                 Label comboBoxLabel = new Label(composite, SWT.NONE);
-//                 comboBoxLabel.setText("Classification");
-                       
-                       if ((outputModelExport || dwcaExport)&& !configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty()){
-                               Composite selectNodeOrClassification = new Composite(composite, SWT.NONE);
-                               GridLayout grid = new GridLayout();
-                               grid.numColumns = 1;
-                               selectNodeOrClassification.setLayout(grid);
-                               checkUseSelectedtaxonNode= new Button(selectNodeOrClassification,  SWT.RADIO);
-                               String taxonStr = "";
-                               node = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(configurator.getTaxonNodeFilter().getSubtreeFilter().get(0).getUuid());
-                               if (node.hasTaxon()){
-                                       taxonStr = node.getTaxon().getName().getTitleCache();
-                               }
-                               checkUseSelectedtaxonNode.setText("Export selected subtree ("+  taxonStr+")");
-                               checkUseSelectedtaxonNode.addListener(SWT.Selection, new Listener() {
-                                       @Override
-                                       public void handleEvent(Event e) {
-                                               Button b = (Button) e.widget;
-                               GridData data = (GridData)  classificationSelectionCombo.getLayoutData();
-                               data.exclude = b.getSelection();
-                               classificationSelectionCombo.setVisible(!data.exclude);
-                               classificationLabel.setVisible(!data.exclude);
-                               }
-                               });
-                                 checkUseSelectedtaxonNode.setSelection(true);
-                                 checkUseSelectedClassification= new Button(selectNodeOrClassification,  SWT.RADIO);
-                                 checkUseSelectedClassification.setText("Export complete classification");
-                                 checkUseSelectedClassification.addListener(SWT.Selection, new Listener() {
-                              @Override
-                              public void handleEvent(Event e) {
-                                  Button b = (Button) e.widget;
-                                  GridData data = (GridData)  classificationSelectionCombo.getLayoutData();
-                                  data.exclude = b.getSelection();
-                                  classificationSelectionCombo.setVisible(data.exclude);
-                                  classificationLabel.setVisible(data.exclude);
-                                 }
-                                       });
-                       }
-                       if (node!= null){
-                               selectedClassification = node.getClassification();
-                       }
-                       createClassificationSelectionCombo(composite);
-                       
-                       classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
-                                       true, false, 2, 1));
-                       if (checkUseSelectedtaxonNode != null){
-                               
-                               if (checkUseSelectedtaxonNode.getSelection()){
-                                        classificationSelectionCombo.setVisible(false);
-                        classificationLabel.setVisible(false);
-                               }
-                       }
-                       
-                       
-               }
-               
-
-               Label folderLabel = new Label(composite, SWT.NONE);
-               folderLabel.setText("Select Folder for exported files");
-               folderLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
-        true, false, 2, 1));
-               folderDialog = new DirectoryDialog(parent.getShell());
-               folderDialog.setFilterPath(PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER));
-
-               text_folder = new Text(composite, SWT.BORDER);
-               text_folder.setEditable(false);
-               text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
-                               false));
-               if (PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER) != null){
-                       text_folder.setText(PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER));
-                       setPageComplete(true);
-               }
-
-               Button button = new Button(composite, SWT.PUSH);
-               button.setText("Browse...");
-
-               button.addSelectionListener(new SelectionAdapter() {
-                       /*
-                        * (non-Javadoc)
-                        *
-                        * @see
-                        * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
-                        * .swt.events.SelectionEvent)
-                        */
-                       @Override
-                       public void widgetSelected(SelectionEvent e) {
-                               super.widgetSelected(e);
-
-                               String path = folderDialog.open();
-                               if (path != null) { // a folder was selected
-                                       text_folder.setText(path);
-                                       PreferencesUtil.getPreferenceStore().setValue(EXPORT_FOLDER, path);
-                                       setPageComplete(true);
-                               }
-                       }
-               });
-               if (!outputModelExport){
-                       
-                        Label fileLabel = new Label(composite, SWT.NONE);
-                       fileLabel.setText("File");
-                       text_exportFileName = new Text(composite, SWT.BORDER);
-                       text_exportFileName.setText(generateFilename());
-                       text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
-                                       true, false));
-               }
-               // make the composite the wizard pages control
-               setControl(composite);
-       }
-
-       protected String generateFilename() {
-               StringBuffer buffer = new StringBuffer();
-
-               Calendar cal = Calendar.getInstance();
-               SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
-               buffer.append(sdf.format(cal.getTime()));
-
-               buffer.append("-");
-
-               buffer.append(type + "_export-");
-               try {
-                       buffer.append(CdmDataSourceRepository.getCurrentCdmSource());
-               } catch (CdmRemoteSourceException e) {
-                       buffer.append("Unknown");
-               }
-
-               buffer.append(".");
-               buffer.append(extension);
-
-               return buffer.toString();
-       }
-
-       /**
-        * <p>
-        * getExportFileName
-        * </p>
-        *
-        * @return the exportFileName
-        */
-       public String getExportFileName() {
-               return text_exportFileName.getText();
-       }
-
-       /**
-        * <p>
-        * getFolderText
-        * </p>
-        *
-        * @return the folderText
-        */
-       public String getFolderText() {
-               return text_folder.getText();
-       }
-       
-       /**
-        * <p>
-        * getFolderComposite
-        * </p>
-        *
-        * @return the folderText
-        */
-       public Text getFolderComposite() {
-               return text_folder;
-       }
-
-       private void createClassificationSelectionCombo(Composite parent){
-//             classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
-
-               Composite classificationSelection = new Composite(parent, SWT.NULL);
-               classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
-
-               GridLayout layout = new GridLayout();
-               classificationSelection.setLayout(layout);
-
-               classificationLabel = new Label(classificationSelection, SWT.NULL);
-               // TODO not working is not really true but leave it here to remind everyone that this is under construction
-               classificationLabel.setText("Export complete classification");
-               
-               classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
-               classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 2,1));
-
-               for(Classification tree : classifications){
-                       classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
-
-               }
-
-               classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
-
-               // TODO remember last selection
-               classificationSelectionCombo.addSelectionListener(this);
-
-
-
-               //return classificationSelection;
-       }
-
-       public Combo getCombo(){
-           return classificationSelectionCombo;
-       }
-
-       @Override
-       public void widgetSelected(SelectionEvent e) {
-               selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
-
-       }
-
-       @Override
-       public void widgetDefaultSelected(SelectionEvent e) {
-               //not needed here
 
-       }
+                orderSelectionCombo.addSelectionListener(new SelectionListener() {
 
-       public UUID getSelectedClassificationUUID() {
-
-               return selectedClassification.getUuid();
-       }
+                    @Override
+                    public void widgetSelected(SelectionEvent e) {
+                        setComparatorToConfig();
+                    }
 
-       public boolean getCheckUseSelectedTaxonNode() {
-               if (checkUseSelectedtaxonNode== null){
-                       return false;
-               }
-               return checkUseSelectedtaxonNode.getSelection();
-       }
+                    @Override
+                    public void widgetDefaultSelected(SelectionEvent e) {
+                        // TODO Auto-generated method stub
+                    }
+                });
+            }
 
-       
-       @Override
-       public boolean canFlipToNextPage() {
-        return  getFolderText() != null;
+            if (classificationSelectionCombo != null) {
+                if (checkUseSelectedTaxonNode != null) {
+                    if (checkUseSelectedTaxonNode.getSelection()) {
+                        classificationSelectionCombo.setEnabled(false);
+                    }
+                } else {
+                    classificationSelectionCombo.setEnabled(true);
+                    classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+                }
+            }
+            Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
+            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+            gridData.horizontalSpan = 2;
+            separator.setLayoutData(gridData);
+
+        }
+
+        Label folderLabel = new Label(composite, SWT.NONE);
+        folderLabel.setText("Select Folder for exported files");
+        folderLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+        folderDialog = new DirectoryDialog(parent.getShell());
+        String exportFolder = PreferencesUtil.getStringValue(EXPORT_FOLDER, true);
+        folderDialog.setFilterPath(exportFolder);
+
+        text_folder = new Text(composite, SWT.BORDER);
+        text_folder.setEditable(false);
+        text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+        if (exportFolder != null) {
+            text_folder.setText(exportFolder);
+            setPageComplete(true);
+        }
+
+        Button button = new Button(composite, SWT.PUSH);
+        button.setText("Browse...");
+
+        button.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                super.widgetSelected(e);
+
+                String path = folderDialog.open();
+                if (path != null) { // a folder was selected
+                    text_folder.setText(path);
+                    PreferencesUtil.setStringValue(EXPORT_FOLDER, path);
+                    setPageComplete(true);
+                }
+            }
+        });
+        if (!cdmLightExport) {
+
+            Label fileLabel = new Label(composite, SWT.NONE);
+            fileLabel.setText("Filename");
+            text_exportFileName = new Text(composite, SWT.BORDER);
+            text_exportFileName.setText(generateFilename());
+            text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+        }
+
+        // make the composite the wizard pages control
+        setControl(composite);
     }
-       
 
-   
+    /**
+     * @return
+     */
+    private String generateFamilyName(List<TaxonNode> nodes) {
+        if (nodes.size() == 1){
+            TaxonNode node = nodes.get(0);
+            if (node.getTaxon() != null) {
+                if(node.getTaxon().getName().getRank().getOrderIndex() >= Rank.FAMILY().getOrderIndex()) {
+                    TaxonNode familyNode = node.getAncestorOfRank(Rank.FAMILY());
+                    if (familyNode != null && familyNode.getTaxon() != null) {
+                        return familyNode.getTaxon().getName().getNameCache();
+                    }
 
+                }
+            }
+
+        }
+        return "";
+    }
+
+    protected void setComparatorToConfig() {
+        if (orderSelectionCombo.getText().equals(NavigatorOrderEnum.NaturalOrder.getLabel())) {
+            ((CdmLightExportConfigurator) configurator).setTaxonNodeComparator(new TaxonNodeDtoNaturalComparator());
+        } else if (orderSelectionCombo.getText().equals(NavigatorOrderEnum.AlphabeticalOrder.getLabel())) {
+            ((CdmLightExportConfigurator) configurator).setTaxonNodeComparator(new TaxonNodeDtoByNameComparator());
+        } else {
+            ((CdmLightExportConfigurator) configurator)
+                    .setTaxonNodeComparator(new TaxonNodeDtoByRankAndNameComparator());
+        }
+    }
+
+    protected String generateFilename() {
+        StringBuffer buffer = new StringBuffer();
+
+        Calendar cal = Calendar.getInstance();
+        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
+        buffer.append(sdf.format(cal.getTime()));
+
+        buffer.append("-");
+        buffer.append(type + "_");
+
+        String source = ((ICdmRemoteSource) CdmStore.getActiveCdmSource()).toString();
+        source = source.substring(source.indexOf("/") + 1);
+        buffer.append(source);
+
+        buffer.append(".");
+        buffer.append(extension);
+
+        return buffer.toString();
+    }
+
+    public String getExportFileName() {
+        return text_exportFileName.getText();
+    }
+
+    /**
+     * @return the familyString
+     */
+    public String getFamilyString() {
+        return text_familyString.getText();
+    }
+
+    public String getFolderText() {
+        return text_folder.getText();
+    }
+
+    public Text getFolderComposite() {
+        return text_folder;
+    }
+
+    public boolean isExportUnpublishedData() {
+        return checkExportUnpublished.getSelection();
+    }
+
+    public boolean isExportFactualData() {
+        return checkExportFactualData.getSelection();
+    }
+
+    public boolean isExportUnpublishedFactualData() {
+        return checkExportUnpublishedFactualData.getSelection();
+    }
+
+    private void createClassificationSelectionCombo(Composite parent) {
+
+        GridData gridData = new GridData();
+        gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
+        gridData.horizontalIndent = 5;
+
+        classificationSelectionCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
+        classificationSelectionCombo.setLayoutData(gridData);
+        for (Classification tree : classifications) {
+            classificationSelectionCombo.add(tree.getTitleCache(), classifications.indexOf(tree));
+        }
+
+        classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
+
+        // TODO remember last selection
+        classificationSelectionCombo.addSelectionListener(this);
+
+    }
+
+    public Combo getCombo() {
+        return classificationSelectionCombo;
+    }
+
+    @Override
+    public void widgetSelected(SelectionEvent e) {
+        selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
+    }
+
+    public Classification getSelectedClassification() {
+        return selectedClassification;
+    }
+
+    @Override
+    public void widgetDefaultSelected(SelectionEvent e) {
+        // not needed here
+    }
+
+    public UUID getSelectedClassificationUUID() {
+        return selectedClassification.getUuid();
+    }
+
+    public boolean getCheckUseSelectedTaxonNode() {
+        if (checkUseSelectedTaxonNode == null) {
+            return false;
+        }
+        return checkUseSelectedTaxonNode.getSelection();
+    }
+
+    public boolean getCheckUseAllClassifications() {
+        if (checkUseAllClassification == null) {
+            return false;
+        }
+        return checkUseAllClassification.getSelection();
+    }
+
+    public Set<UUID> getAllClassificationUuids() {
+        Set<UUID> allClassificationUuids = new HashSet<>();
+        for (Classification classification : this.classifications) {
+            allClassificationUuids.add(classification.getUuid());
+        }
+        return allClassificationUuids;
+    }
+
+    @Override
+    public boolean canFlipToNextPage() {
+        return getFolderText() != null && !(wfoExport && configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty());
+    }
 }