} else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
Set<String> keySet = resultMap.keySet();
- for (String key: keySet){
- byte[] fileData = resultMap.get(key);
- String fileEnding ="";
- if (configurator instanceof CdmLightExportConfigurator){
- fileEnding = ".csv";
- }
-
- File file = new File(urlString+File.separator + key + fileEnding);
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
+ Calendar cal = Calendar.getInstance();
+ String fileEnding = ".csv";
+
+ if (configurator.isCreateZipFile()){
+ File file = new File(urlString+File.separator + "csv_light_" + sdf.format(cal.getTime())+ ".zip");
FileOutputStream stream = new FileOutputStream(file);
- Writer out = new BufferedWriter(new OutputStreamWriter(
- stream, "UTF8"));
- stream.write(fileData);
- stream.close();
- }
-
-
- }else{
+ ZipOutputStream zos = new ZipOutputStream(stream);
+ for (String key: keySet){
+ byte[] fileData = resultMap.get(key);
+ ZipEntry entry = new ZipEntry( key + fileEnding);
+ zos.putNextEntry(entry);
+ zos.write(fileData);
+ zos.closeEntry();
+ }
+ zos.close();
+ }else{
+ for (String key: keySet){
+ byte[] fileData = resultMap.get(key);
+ File file = new File(urlString+File.separator + key + fileEnding);
+ FileOutputStream stream = new FileOutputStream(file);
+ Writer out = new BufferedWriter(new OutputStreamWriter(
+ stream, "UTF8"));
+ stream.write(fileData);
+ stream.close();
+ }
+ }
+ }else{
logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
}
} catch(Exception e){
import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
+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.model.taxon.Classification;
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
import eu.etaxonomy.taxeditor.store.CdmStore;
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";
private List<Classification> classifications;
private Classification selectedClassification;
- private String lastDirectory;
+
+ private ExportConfiguratorBase configurator;
/**
* @param pageName
* @param selection
*/
protected ExportToFileDestinationWizardPage(String pageName, String type,
- String title, String description, String extension) {
+ String title, String description, String extension, ExportConfiguratorBase configurator) {
super(pageName);
-
+ this.configurator = configurator;
this.type = type;
switch(type) {
case CSV_EXPORT :
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
* object.
*/
- public static ExportToFileDestinationWizardPage Jaxb() {
+ public static ExportToFileDestinationWizardPage Jaxb(JaxbExportConfigurator configurator) {
return new ExportToFileDestinationWizardPage(
JAXB_EXPORT,
"jaxb",
"JAXB Export",
"Exports the contents of the currently selected database into the cdm jaxb format.",
- XML);
+ XML, configurator);
}
/**
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
* object.
*/
- public static ExportToFileDestinationWizardPage Tcs() {
+ public static ExportToFileDestinationWizardPage Tcs(TcsXmlExportConfigurator config) {
return new ExportToFileDestinationWizardPage(
TCS_EXPORT,
"tcs",
"Tcs Export",
"Export the contents of the currently selected database into TCS format.",
- XML);
+ XML, config);
}
/**
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
* object.
*/
- public static ExportToFileDestinationWizardPage Sdd() {
+ public static ExportToFileDestinationWizardPage Sdd(SDDExportConfigurator config) {
return new ExportToFileDestinationWizardPage(
SDD_EXPORT,
"sdd",
"Sdd Export",
"Export the contents of the currently selected database into SDD format.",
- XML);
+ XML, config);
}
/**
* @return
*/
- public static ExportToFileDestinationWizardPage Dwca() {
+ public static ExportToFileDestinationWizardPage Dwca(DwcaTaxExportConfigurator config) {
return new ExportToFileDestinationWizardPage(
DWCA_EXPORT,
DWCA_EXPORT,
"DwC-Archive Export",
"Export the contents of the currently selected database into Darwin Core Archive format.",
- ZIP);
+ ZIP, config);
}
/**
* @return
*/
- public static ExportToFileDestinationWizardPage OutputModel() {
+ public static ExportToFileDestinationWizardPage OutputModel(CdmLightExportConfigurator config) {
return new ExportToFileDestinationWizardPage(
OUTPUT_MODEL_EXPORT,
OUTPUT_MODEL_EXPORT,
"Output Model Export",
"Export the contents of the currently selected database into the output model format.",
- CSV);
+ CSV,config);
}
/**
* @return
*/
- public static ExportToFileDestinationWizardPage Csv() {
+ public static ExportToFileDestinationWizardPage Csv(CsvDemoExportConfigurator config) {
return new ExportToFileDestinationWizardPage(
CSV_EXPORT,
CSV_EXPORT,
"CSV Export",
"Export the contents of the currently selected database into Comma Separated Value format.",
- CSV);
+ CSV, config);
}
/**
* @return
*/
- public static ExportToFileDestinationWizardPage CsvNames() {
+ 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);
+ CSV, config);
}
/**
* @return
*/
- public static ExportToFileDestinationWizardPage CsvPrint() {
+ 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);
+ CSV, config);
}
/*
classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, false, 2, 1));
}
- 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));
+ if (outputModelExport){
+ Label zipLabel = new Label(composite, SWT.NONE);
+ zipLabel.setText("Create zip-File");
+ Button zip = new Button(composite, SWT.CHECK);
+ zip.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);
+ ((CdmLightExportConfigurator)configurator).setCreateZipFile(zip.getSelection());
+ }
+ });
+ }else {
+ 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));
}
Label folderLabel = new Label(composite, SWT.NONE);
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...");
String path = folderDialog.open();
if (path != null) { // a folder was selected
text_folder.setText(path);
+ PreferencesUtil.getPreferenceStore().setValue(EXPORT_FOLDER, path);
setPageComplete(true);
}
}
- private void loadLastState() {
- if(lastDirectory!=null){
- Text text = this.getFolderComposite();
- Listener[] listeners = text.getListeners(SWT.Modify);
- for (int i = 0; i < listeners.length; i++) {
- text.removeListener(SWT.Modify, listeners[i]);
- }
- text.setText(lastDirectory);
- for (int i = 0; i < listeners.length; i++) {
- text.addListener(SWT.Modify, listeners[i]);
- }
-
- }
- }
-
- public void saveLastState() {
- lastDirectory = this.getFolderText();
- }
+
}