Project

General

Profile

Revision 0b4f079d

ID0b4f079d634835a6274a7f12d4439193660f06ce
Parent cfbd89d6
Child dd665bef

Added by Katja Luther almost 3 years ago

cdmLight Export create zip is configurable and save last export folder

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java
315 315
                         } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
316 316
                             Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
317 317
                             Set<String> keySet = resultMap.keySet();
318
                             for (String key: keySet){
319
                                 byte[] fileData = resultMap.get(key);
320
                                 String fileEnding ="";
321
                                 if (configurator instanceof CdmLightExportConfigurator){
322
                                     fileEnding  = ".csv";
323
                                 }
324

  
325
                                 File file = new File(urlString+File.separator + key + fileEnding);
318
                             SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
319
                             Calendar cal = Calendar.getInstance();
320
                             String fileEnding = ".csv";
321
                             
322
                             if (configurator.isCreateZipFile()){      
323
                        		 File file = new File(urlString+File.separator + "csv_light_" + sdf.format(cal.getTime())+ ".zip");                              
326 324
                                 FileOutputStream stream = new FileOutputStream(file);
327
                                 Writer out = new BufferedWriter(new OutputStreamWriter(
328
                             			stream, "UTF8"));
329
                                 stream.write(fileData);
330
                                 stream.close();
331
                             }
332
                        
333

  
334
                         }else{
325
                                 ZipOutputStream zos = new ZipOutputStream(stream);
326
                                 for (String key: keySet){
327
                                	byte[] fileData = resultMap.get(key);
328
                                	ZipEntry entry = new ZipEntry( key + fileEnding); 
329
     								zos.putNextEntry(entry);
330
     								zos.write(fileData);
331
     								zos.closeEntry();
332
                                 }
333
                                 zos.close();
334
                        	 }else{
335
                        		 for (String key: keySet){
336
                        			 byte[] fileData = resultMap.get(key);
337
                        			 File file = new File(urlString+File.separator + key + fileEnding);
338
                                     FileOutputStream stream = new FileOutputStream(file);
339
                                     Writer out = new BufferedWriter(new OutputStreamWriter(
340
                                 			stream, "UTF8"));
341
                                     stream.write(fileData);
342
                                     stream.close();
343
                                 }
344
                        	 }
345
                        }else{
335 346
                             logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
336 347
                         }
337 348
                     } catch(Exception e){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CdmLightExportWizard.java
23 23

  
24 24
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
25 25
import eu.etaxonomy.cdm.model.taxon.Classification;
26
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
26 27
import eu.etaxonomy.taxeditor.store.CdmStore;
27 28

  
28 29
/**
......
98 99
            job.setUser(true);
99 100
            // schedule job
100 101
            job.schedule();
101
            
102
            PreferencesUtil.getPreferenceStore().setValue("exportFolder", page.getFolderText());
102 103
            return true;
103 104
        }
104 105

  
......
114 115

  
115 116

  
116 117
            //standard page
117
            page =  ExportToFileDestinationWizardPage.OutputModel();
118
            page =  ExportToFileDestinationWizardPage.OutputModel(configurator);
118 119

  
119 120
            addPage(page);
120 121
        }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvExportWizard.java
116 116

  
117 117

  
118 118
		//standard page
119
		page =  ExportToFileDestinationWizardPage.Csv();
119
		page =  ExportToFileDestinationWizardPage.Csv(configurator);
120 120

  
121 121
		addPage(page);
122 122
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvNameExportWizard.java
90 90

  
91 91

  
92 92
		//standard page
93
		page =  ExportToFileDestinationWizardPage.CsvNames();
93
		page =  ExportToFileDestinationWizardPage.CsvNames(configurator);
94 94

  
95 95
		addPage(page);
96 96
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvPrintExportWizard.java
45 45

  
46 46

  
47 47
		//standard page
48
		page =  ExportToFileDestinationWizardPage.CsvPrint();
48
		page =  ExportToFileDestinationWizardPage.CsvPrint(configurator);
49 49

  
50 50
		addPage(page);
51 51
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/DarwinCoreArchiveExportWizard.java
82 82
	public void addPages() {
83 83
		super.addPages();
84 84

  
85
		page = ExportToFileDestinationWizardPage.Dwca();
85
		page = ExportToFileDestinationWizardPage.Dwca(configurator);
86 86
		addPage(page);
87 87
	}
88 88
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java
33 33
import org.eclipse.swt.widgets.Text;
34 34

  
35 35
import eu.etaxonomy.cdm.api.service.IClassificationService;
36
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
37
import eu.etaxonomy.cdm.io.common.ExportConfiguratorBase;
38
import eu.etaxonomy.cdm.io.csv.caryophyllales.out.CsvNameExportConfigurator;
39
import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
40
import eu.etaxonomy.cdm.io.csv.redlist.out.CsvTaxExportConfiguratorRedlist;
41
import eu.etaxonomy.cdm.io.dwca.out.DwcaTaxExportConfigurator;
42
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
43
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
44
import eu.etaxonomy.cdm.io.tcsxml.out.TcsXmlExportConfigurator;
36 45
import eu.etaxonomy.cdm.model.taxon.Classification;
37 46
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
47
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
38 48
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
39 49
import eu.etaxonomy.taxeditor.store.CdmStore;
40 50

  
......
66 76
	public static final String CSV_EXPORT = "CSV_EXPORT";
67 77
	public static final String CSV_NAME_EXPORT = "CSV_NAME_EXPORT";
68 78
	private static final String CSV_PRINT_EXPORT ="CSV_PRINT_EXPORT";
69

  
79
	private static final String EXPORT_FOLDER ="EXPORT_FOLDER";
70 80
	public static final String XML = "xml";
71 81

  
72 82
	public static final String CSV = "csv";
......
99 109
    private List<Classification> classifications;
100 110

  
101 111
    private Classification selectedClassification;
102
    private String lastDirectory;
112
    
113
    private ExportConfiguratorBase configurator;
103 114

  
104 115
	/**
105 116
	 * @param pageName
106 117
	 * @param selection
107 118
	 */
108 119
	protected ExportToFileDestinationWizardPage(String pageName, String type,
109
			String title, String description, String extension) {
120
			String title, String description, String extension, ExportConfiguratorBase configurator) {
110 121
		super(pageName);
111

  
122
		this.configurator = configurator;
112 123
		this.type = type;
113 124
		switch(type) {
114 125
		   case CSV_EXPORT :
......
139 150
	 *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
140 151
	 *         object.
141 152
	 */
142
	public static ExportToFileDestinationWizardPage Jaxb() {
153
	public static ExportToFileDestinationWizardPage Jaxb(JaxbExportConfigurator configurator) {
143 154
		return new ExportToFileDestinationWizardPage(
144 155
				JAXB_EXPORT,
145 156
				"jaxb",
146 157
				"JAXB Export",
147 158
				"Exports the contents of the currently selected database into the cdm jaxb format.",
148
				XML);
159
				XML, configurator);
149 160
	}
150 161

  
151 162
	/**
......
157 168
	 *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
158 169
	 *         object.
159 170
	 */
160
	public static ExportToFileDestinationWizardPage Tcs() {
171
	public static ExportToFileDestinationWizardPage Tcs(TcsXmlExportConfigurator config) {
161 172
		return new ExportToFileDestinationWizardPage(
162 173
				TCS_EXPORT,
163 174
				"tcs",
164 175
				"Tcs Export",
165 176
				"Export the contents of the currently selected database into TCS format.",
166
				XML);
177
				XML, config);
167 178
	}
168 179

  
169 180
	/**
......
175 186
	 *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
176 187
	 *         object.
177 188
	 */
178
	public static ExportToFileDestinationWizardPage Sdd() {
189
	public static ExportToFileDestinationWizardPage Sdd(SDDExportConfigurator config) {
179 190
		return new ExportToFileDestinationWizardPage(
180 191
				SDD_EXPORT,
181 192
				"sdd",
182 193
				"Sdd Export",
183 194
				"Export the contents of the currently selected database into SDD format.",
184
				XML);
195
				XML, config);
185 196
	}
186 197

  
187 198
	/**
188 199
	 * @return
189 200
	 */
190
	public static ExportToFileDestinationWizardPage Dwca() {
201
	public static ExportToFileDestinationWizardPage Dwca(DwcaTaxExportConfigurator config) {
191 202
		return new ExportToFileDestinationWizardPage(
192 203
				DWCA_EXPORT,
193 204
				DWCA_EXPORT,
194 205
				"DwC-Archive Export",
195 206
				"Export the contents of the currently selected database into Darwin Core Archive format.",
196
				ZIP);
207
				ZIP, config);
197 208
	}
198 209

  
199 210
	/**
200 211
     * @return
201 212
     */
202
    public static ExportToFileDestinationWizardPage OutputModel() {
213
    public static ExportToFileDestinationWizardPage OutputModel(CdmLightExportConfigurator config) {
203 214
        
204 215
        return new ExportToFileDestinationWizardPage(
205 216
                OUTPUT_MODEL_EXPORT,
206 217
                OUTPUT_MODEL_EXPORT,
207 218
                "Output Model Export",
208 219
                "Export the contents of the currently selected database into the output model format.",
209
                CSV);
220
                CSV,config);
210 221
    }
211 222

  
212 223

  
213 224
    /**
214 225
     * @return
215 226
     */
216
    public static ExportToFileDestinationWizardPage Csv() {
227
    public static ExportToFileDestinationWizardPage Csv(CsvDemoExportConfigurator config) {
217 228
        
218 229
        return new ExportToFileDestinationWizardPage(
219 230
                CSV_EXPORT,
220 231
                CSV_EXPORT,
221 232
                "CSV Export",
222 233
                "Export the contents of the currently selected database into Comma Separated Value format.",
223
                CSV);
234
                CSV, config);
224 235
    }
225 236

  
226 237
    /**
227 238
     * @return
228 239
     */
229
    public static ExportToFileDestinationWizardPage CsvNames() {
240
    public static ExportToFileDestinationWizardPage CsvNames(CsvNameExportConfigurator config) {
230 241
    	
231 242
        return new ExportToFileDestinationWizardPage(
232 243
                CSV_NAME_EXPORT,
233 244
                CSV_NAME_EXPORT,
234 245
                "CSV Name Export",
235 246
                "Export the names of the currently selected database into Semicolon Separated Value format.",
236
                CSV);
247
                CSV, config);
237 248
    }
238 249

  
239 250
    /**
240 251
     * @return
241 252
     */
242
    public static ExportToFileDestinationWizardPage CsvPrint() {
253
    public static ExportToFileDestinationWizardPage CsvPrint(CsvNameExportConfigurator config) {
243 254
    	
244 255
        return new ExportToFileDestinationWizardPage(
245 256
                CSV_PRINT_EXPORT,
246 257
                CSV_NAME_EXPORT,
247 258
                "CSV Print Export",
248 259
                "Export the content of the currently selected database into Semicolon Separated Value format.",
249
                CSV);
260
                CSV, config);
250 261
    }
251 262

  
252 263
	/*
......
298 309
		    classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
299 310
		                true, false, 2, 1));
300 311
		}
301
		if (!outputModelExport){
302
		    Label fileLabel = new Label(composite, SWT.NONE);
303
	        fileLabel.setText("File");
304
    		text_exportFileName = new Text(composite, SWT.BORDER);
305
    		text_exportFileName.setText(generateFilename());
306
    		text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
307
    				true, false));
312
		if (outputModelExport){
313
			 Label zipLabel = new Label(composite, SWT.NONE);
314
		        zipLabel.setText("Create zip-File");
315
		   Button zip = new Button(composite, SWT.CHECK);
316
		   zip.addSelectionListener(new SelectionAdapter() {
317
				/*
318
				 * (non-Javadoc)
319
				 *
320
				 * @see
321
				 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
322
				 * .swt.events.SelectionEvent)
323
				 */
324
				@Override
325
				public void widgetSelected(SelectionEvent e) {
326
					super.widgetSelected(e);
327
					((CdmLightExportConfigurator)configurator).setCreateZipFile(zip.getSelection());
328
				}
329
			});
330
		}else {
331
			 Label fileLabel = new Label(composite, SWT.NONE);
332
		        fileLabel.setText("File");
333
	    		text_exportFileName = new Text(composite, SWT.BORDER);
334
	    		text_exportFileName.setText(generateFilename());
335
	    		text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
336
	    				true, false));
308 337
		}
309 338

  
310 339
		Label folderLabel = new Label(composite, SWT.NONE);
......
317 346
		text_folder.setEditable(false);
318 347
		text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
319 348
				false));
349
		if (PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER) != null){
350
			text_folder.setText(PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER));
351
			setPageComplete(true);
352
		}
320 353

  
321 354
		Button button = new Button(composite, SWT.PUSH);
322 355
		button.setText("Browse...");
......
335 368
				String path = folderDialog.open();
336 369
				if (path != null) { // a folder was selected
337 370
					text_folder.setText(path);
371
					PreferencesUtil.getPreferenceStore().setValue(EXPORT_FOLDER, path);
338 372
					setPageComplete(true);
339 373
				}
340 374
			}
......
453 487
	
454 488
	
455 489

  
456
    private void loadLastState() {
457
        if(lastDirectory!=null){
458
            Text text = this.getFolderComposite();
459
            Listener[] listeners = text.getListeners(SWT.Modify);
460
            for (int i = 0; i < listeners.length; i++) {
461
                text.removeListener(SWT.Modify, listeners[i]);
462
            }
463
            text.setText(lastDirectory);
464
            for (int i = 0; i < listeners.length; i++) {
465
                text.addListener(SWT.Modify, listeners[i]);
466
            }
467

  
468
        }
469
    }
470
    
471
    public void saveLastState() {
472
    	lastDirectory = this.getFolderText();
473
    }
490
   
474 491

  
475 492
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/JaxbExportWizard.java
75 75
	public void addPages() {
76 76
		super.addPages();
77 77

  
78
		page = ExportToFileDestinationWizardPage.Jaxb();
78
		page = ExportToFileDestinationWizardPage.Jaxb(configurator);
79 79
		addPage(page);
80 80
	}
81 81

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/SddExportWizard.java
68 68
	public void addPages() {
69 69
		super.addPages();
70 70

  
71
		page = ExportToFileDestinationWizardPage.Sdd();
71
		page = ExportToFileDestinationWizardPage.Sdd(configurator);
72 72
		addPage(page);
73 73
	}
74 74

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/TcsExportWizard.java
81 81
	public void addPages() {
82 82
		super.addPages();
83 83

  
84
		page = ExportToFileDestinationWizardPage.Tcs();
84
		page = ExportToFileDestinationWizardPage.Tcs(configurator);
85 85
		addPage(page);
86 86
	}
87 87

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)