package eu.etaxonomy.taxeditor.io.wizard;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashSet;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
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;
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.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.WfoBackboneExportConfigurator;
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.cdm.persistence.dto.TaxonNodeDtoByNameComparator;
public static final String SDD_EXPORT = "SDD_EXPORT";
public static final String DWCA_EXPORT = "DWCA_EXPORT";
+ public static final String WFO_BACKBONE_EXPORT = "WFO_BACKBONE_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 boolean csvPrintExport = false;
private boolean cdmLightExport = false;
+
+ private boolean colDPExport = false;
private boolean dwcaExport = false;
+ private boolean wfoBackboneExport = false;
private DirectoryDialog folderDialog;
private Text text_exportFileName;
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);
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_BACKBONE_EXPORT:
+ wfoBackboneExport = true;
+ break;
default:
throw new RuntimeException("Export type not yet handeled: " + type);
}
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(WfoBackboneExportConfigurator config) {
+ return new ExportToFileDestinationWizardPage(WFO_BACKBONE_EXPORT, WFO_BACKBONE_EXPORT, "WFO Backbone Export",
+ "Export the content of the currently selected database into WFO Backbone format."
+ , ZIP, config);
+ }
public static ExportToFileDestinationWizardPage CdmLight(CdmLightExportConfigurator config) {
"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);
+ }
+
public static ExportToFileDestinationWizardPage Csv(CsvDemoExportConfigurator config) {
return new ExportToFileDestinationWizardPage(CSV_EXPORT, CSV_EXPORT, "CSV Export",
TaxonNode node = null;
composite.setLayout(gridLayout);
- if (cdmLightExport || dwcaExport) {
+ 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 gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 2;
- separator.setLayoutData(gridData);
+ GridData gridDataSep = new GridData(GridData.FILL_HORIZONTAL);
+ gridDataSep.horizontalSpan = 2;
+ separator.setLayoutData(gridDataSep);
}
- if (classifications == null) {
+ if (classifications == null && !wfoBackboneExport) {
classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
Collections.sort(classifications, (o1, o2) -> {
if (o1.equals(o2)) {
}
}
- if (csvExport || csvPrintExport || cdmLightExport || csvNameExport || dwcaExport) {
+ if (csvExport || csvPrintExport || cdmLightExport || csvNameExport || dwcaExport || colDPExport || wfoBackboneExport) {
// Label comboBoxLabel = new Label(composite, SWT.NONE);
// comboBoxLabel.setText("Classification");
GridLayout grid = new GridLayout();
grid.numColumns = 1;
selectNodeOrClassification.setLayout(grid);
- if ((cdmLightExport || dwcaExport) && !configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty()) {
- checkUseSelectedTaxonNode = new Button(selectNodeOrClassification, SWT.RADIO);
+ if ((cdmLightExport || dwcaExport || colDPExport || wfoBackboneExport) && !configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty()) {
+ if (!wfoBackboneExport) {
+ 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 (!wfoBackboneExport) {
+ 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));
- checkUseSelectedTaxonNode.setText("Export selected subtree(s) (" + taxonStr + ")");
- checkUseSelectedTaxonNode.addListener(SWT.Selection, e -> {
- Button b = (Button) e.widget;
- GridData data = (GridData) classificationSelectionCombo.getLayoutData();
- data.exclude = b.getSelection();
- classificationSelectionCombo.setEnabled(!data.exclude);
- });
- checkUseSelectedTaxonNode.setSelection(true);
+ }
+ }else if (wfoBackboneExport) {
+
+ 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) {
+
+ if (cdmLightExport || dwcaExport || colDPExport ) {
if (dwcaExport) {
checkUseAllClassification = new Button(selectNodeOrClassification, SWT.RADIO);
checkUseAllClassification.setText("Export all classifications");
});
}
- if (node != null) {
+ if (node != null && !wfoBackboneExport) {
selectedClassification = node.getClassification();
}
- createClassificationSelectionCombo(selectNodeOrClassification);
+ if (!wfoBackboneExport) {
+ createClassificationSelectionCombo(selectNodeOrClassification);
+ }
if (cdmLightExport) {
Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
GridData gridDataSep = new GridData();
});
}
- if (checkUseSelectedTaxonNode != null) {
- if (checkUseSelectedTaxonNode.getSelection()) {
- classificationSelectionCombo.setEnabled(false);
+ 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));
}
- } 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);
if (!cdmLightExport) {
Label fileLabel = new Label(composite, SWT.NONE);
- fileLabel.setText("File");
+ 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));
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());
return text_exportFileName.getText();
}
+ /**
+ * @return the familyString
+ */
+ public String getFamilyString() {
+ return text_familyString.getText();
+ }
+
public String getFolderText() {
return text_folder.getText();
}
return checkExportFactualData.getSelection();
}
- private void createClassificationSelectionCombo(Composite parent) {
+ public boolean isExportUnpublishedFactualData() {
+ return checkExportUnpublishedFactualData.getSelection();
+ }
- // Composite classificationSelection = new Composite(parent, SWT.NULL);
- // classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP,
- // true, false, 1, 1));
+ private void createClassificationSelectionCombo(Composite parent) {
- // GridLayout layout = new GridLayout();
- // classificationSelection.setLayout(layout);
GridData gridData = new GridData();
gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
gridData.horizontalIndent = 5;
- // classificationSelection.setLayoutData(gridData);
classificationSelectionCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
classificationSelectionCombo.setLayoutData(gridData);
// TODO remember last selection
classificationSelectionCombo.addSelectionListener(this);
- // return classificationSelection;
}
public Combo getCombo() {
@Override
public boolean canFlipToNextPage() {
- return getFolderText() != null;
+ return getFolderText() != null && !(wfoBackboneExport && configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty());
}
}