2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The content of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.io
.wizard
;
12 import java
.text
.SimpleDateFormat
;
13 import java
.util
.Calendar
;
14 import java
.util
.Collections
;
15 import java
.util
.Comparator
;
16 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.eclipse
.jface
.wizard
.WizardPage
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.events
.SelectionAdapter
;
22 import org
.eclipse
.swt
.events
.SelectionEvent
;
23 import org
.eclipse
.swt
.events
.SelectionListener
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Button
;
27 import org
.eclipse
.swt
.widgets
.Combo
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
30 import org
.eclipse
.swt
.widgets
.Event
;
31 import org
.eclipse
.swt
.widgets
.Label
;
32 import org
.eclipse
.swt
.widgets
.Listener
;
33 import org
.eclipse
.swt
.widgets
.Text
;
35 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
36 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
37 import eu
.etaxonomy
.cdm
.io
.cdmLight
.CdmLightExportConfigurator
;
38 import eu
.etaxonomy
.cdm
.io
.common
.ExportConfiguratorBase
;
39 import eu
.etaxonomy
.cdm
.io
.csv
.caryophyllales
.out
.CsvNameExportConfigurator
;
40 import eu
.etaxonomy
.cdm
.io
.csv
.redlist
.demo
.CsvDemoExportConfigurator
;
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
;
45 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
47 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
48 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
49 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSourceException
;
50 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
54 * ExportToFileDestinationWizardPage class.
61 public class ExportToFileDestinationWizardPage
extends WizardPage
implements SelectionListener
{
63 /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
64 public static final String DATE_FORMAT_NOW
= "yyyyMMddHHmm";
66 /** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
67 public static final String JAXB_EXPORT
= "JAXB_EXPORT";
69 /** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
70 public static final String TCS_EXPORT
= "TCS_EXPORT";
72 /** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
73 public static final String SDD_EXPORT
= "SDD_EXPORT";
75 public static final String DWCA_EXPORT
= "DWCA_EXPORT";
76 public static final String OUTPUT_MODEL_EXPORT
= "CDM_LIGHT(CSV)";
77 public static final String CSV_EXPORT
= "CSV_EXPORT";
78 public static final String CSV_NAME_EXPORT
= "CSV_NAME_EXPORT";
79 private static final String CSV_PRINT_EXPORT
="CSV_PRINT_EXPORT";
80 private static final String EXPORT_FOLDER
="EXPORT_FOLDER";
81 public static final String XML
= "xml";
83 public static final String CSV
= "csv";
85 public static final String ZIP
= "zip";
87 private boolean csvExport
= false;
89 private boolean csvNameExport
= false;
91 private boolean csvPrintExport
= false;
93 private boolean outputModelExport
= false;
94 private boolean dwcaExport
= false;
96 private DirectoryDialog folderDialog
;
97 private Text text_exportFileName
;
99 private Text text_folder
;
101 private final String type
;
103 private final String extension
;
105 private Combo classificationSelectionCombo
;
107 private List
<Classification
> classifications
;
109 private Classification selectedClassification
;
111 private Label classificationLabel
;
113 private ExportConfiguratorBase configurator
;
114 private Button checkUseSelectedtaxonNode
;
116 private Button checkUseSelectedClassification
;
118 protected ExportToFileDestinationWizardPage(String pageName
, String type
,
119 String title
, String description
, String extension
, ExportConfiguratorBase configurator
) {
121 this.configurator
= configurator
;
127 case CSV_NAME_EXPORT
:
128 csvNameExport
= true;
130 case OUTPUT_MODEL_EXPORT
:
131 outputModelExport
= true;
133 case CSV_PRINT_EXPORT
:
134 csvPrintExport
= true;
141 this.extension
= extension
;
142 this.setTitle(title
);
143 this.setDescription(description
);
146 public static ExportToFileDestinationWizardPage
Jaxb(JaxbExportConfigurator configurator
) {
147 return new ExportToFileDestinationWizardPage(
151 "Exports the content of the currently selected database into the cdm jaxb format.",
155 public static ExportToFileDestinationWizardPage
Tcs(TcsXmlExportConfigurator config
) {
156 return new ExportToFileDestinationWizardPage(
160 "Export the content of the currently selected database into TCS format.",
164 public static ExportToFileDestinationWizardPage
Sdd(SDDExportConfigurator config
) {
165 return new ExportToFileDestinationWizardPage(
169 "Export the content of the currently selected database into SDD format.",
173 public static ExportToFileDestinationWizardPage
Dwca(DwcaTaxExportConfigurator config
) {
174 return new ExportToFileDestinationWizardPage(
177 "DwC-Archive Export",
178 "Export the content of the currently selected database into Darwin Core Archive format.",
182 public static ExportToFileDestinationWizardPage
OutputModel(CdmLightExportConfigurator config
) {
184 return new ExportToFileDestinationWizardPage(
187 "CDM Light Export (csv)",
188 "Export the content of the currently selected database into the CDM light (csv) format.",
192 public static ExportToFileDestinationWizardPage
Csv(CsvDemoExportConfigurator config
) {
194 return new ExportToFileDestinationWizardPage(
198 "Export the content of the currently selected database into Comma Separated Value format.",
202 public static ExportToFileDestinationWizardPage
CsvNames(CsvNameExportConfigurator config
) {
204 return new ExportToFileDestinationWizardPage(
208 "Export the names of the currently selected database into Semicolon Separated Value format.",
212 public static ExportToFileDestinationWizardPage
CsvPrint(CsvNameExportConfigurator config
) {
214 return new ExportToFileDestinationWizardPage(
218 "Export the content of the currently selected database into Semicolon Separated Value format.",
224 public void createControl(Composite parent
) {
226 setPageComplete(false);
228 Composite composite
= new Composite(parent
, SWT
.NONE
);
229 GridLayout gridLayout
= new GridLayout();
231 gridLayout
.numColumns
= 2;
232 TaxonNode node
= null;
234 composite
.setLayout(gridLayout
);
235 if(classifications
== null){
236 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
237 Collections
.sort(classifications
, new Comparator
<Classification
>() {
240 public int compare(Classification o1
, Classification o2
) {
244 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
246 return o1
.getUuid().compareTo(o2
.getUuid());
251 if (!configurator
.getTaxonNodeFilter().getClassificationFilter().isEmpty()){
252 selectedClassification
= CdmStore
.getService(IClassificationService
.class).load(configurator
.getTaxonNodeFilter().getClassificationFilter().get(0).getUuid());
255 selectedClassification
= classifications
.iterator().next();
260 if(csvExport
|| csvPrintExport
|| outputModelExport
|| csvNameExport
|| dwcaExport
){
262 // Label comboBoxLabel = new Label(composite, SWT.NONE);
263 // comboBoxLabel.setText("Classification");
264 Composite selectNodeOrClassification
= new Composite(composite
, SWT
.NONE
);
265 GridLayout grid
= new GridLayout();
267 selectNodeOrClassification
.setLayout(grid
);
268 if ((outputModelExport
|| dwcaExport
)&& !configurator
.getTaxonNodeFilter().getSubtreeFilter().isEmpty()){
269 checkUseSelectedtaxonNode
= new Button(selectNodeOrClassification
, SWT
.RADIO
);
270 String taxonStr
= "";
271 node
= CdmApplicationState
.getCurrentAppConfig().getTaxonNodeService().load(configurator
.getTaxonNodeFilter().getSubtreeFilter().get(0).getUuid());
272 if (node
.hasTaxon()){
273 taxonStr
= node
.getTaxon().getName().getTitleCache();
275 checkUseSelectedtaxonNode
.setText("Export selected subtree ("+ taxonStr
+")");
276 checkUseSelectedtaxonNode
.addListener(SWT
.Selection
, new Listener() {
278 public void handleEvent(Event e
) {
279 Button b
= (Button
) e
.widget
;
280 GridData data
= (GridData
) classificationSelectionCombo
.getLayoutData();
281 data
.exclude
= b
.getSelection();
282 classificationSelectionCombo
.setVisible(!data
.exclude
);
286 checkUseSelectedtaxonNode
.setSelection(true);
287 checkUseSelectedClassification
= new Button(selectNodeOrClassification
, SWT
.RADIO
);
288 checkUseSelectedClassification
.setText("Export complete classification");
289 checkUseSelectedClassification
.addListener(SWT
.Selection
, new Listener() {
291 public void handleEvent(Event e
) {
292 Button b
= (Button
) e
.widget
;
293 GridData data
= (GridData
) classificationSelectionCombo
.getLayoutData();
294 data
.exclude
= b
.getSelection();
295 classificationSelectionCombo
.setVisible(data
.exclude
);
301 selectedClassification
= node
.getClassification();
303 createClassificationSelectionCombo(selectNodeOrClassification
);
307 if (checkUseSelectedtaxonNode
!= null){
309 if (checkUseSelectedtaxonNode
.getSelection()){
310 classificationSelectionCombo
.setVisible(false);
314 classificationSelectionCombo
.setVisible(true);
315 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
321 Label folderLabel
= new Label(composite
, SWT
.NONE
);
322 folderLabel
.setText("Select Folder for exported files");
323 folderLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
325 folderDialog
= new DirectoryDialog(parent
.getShell());
326 folderDialog
.setFilterPath(PreferencesUtil
.getPreferenceStore().getString(EXPORT_FOLDER
));
328 text_folder
= new Text(composite
, SWT
.BORDER
);
329 text_folder
.setEditable(false);
330 text_folder
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
332 if (PreferencesUtil
.getPreferenceStore().getString(EXPORT_FOLDER
) != null){
333 text_folder
.setText(PreferencesUtil
.getPreferenceStore().getString(EXPORT_FOLDER
));
334 setPageComplete(true);
337 Button button
= new Button(composite
, SWT
.PUSH
);
338 button
.setText("Browse...");
340 button
.addSelectionListener(new SelectionAdapter() {
342 public void widgetSelected(SelectionEvent e
) {
343 super.widgetSelected(e
);
345 String path
= folderDialog
.open();
346 if (path
!= null) { // a folder was selected
347 text_folder
.setText(path
);
348 PreferencesUtil
.getPreferenceStore().setValue(EXPORT_FOLDER
, path
);
349 setPageComplete(true);
353 if (!outputModelExport
){
355 Label fileLabel
= new Label(composite
, SWT
.NONE
);
356 fileLabel
.setText("File");
357 text_exportFileName
= new Text(composite
, SWT
.BORDER
);
358 text_exportFileName
.setText(generateFilename());
359 text_exportFileName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
362 // make the composite the wizard pages control
363 setControl(composite
);
366 protected String
generateFilename() {
367 StringBuffer buffer
= new StringBuffer();
369 Calendar cal
= Calendar
.getInstance();
370 SimpleDateFormat sdf
= new SimpleDateFormat(DATE_FORMAT_NOW
);
371 buffer
.append(sdf
.format(cal
.getTime()));
375 buffer
.append(type
+ "_export-");
377 buffer
.append(CdmDataSourceRepository
.getCurrentCdmSource());
378 } catch (CdmRemoteSourceException e
) {
379 buffer
.append("Unknown");
383 buffer
.append(extension
);
385 return buffer
.toString();
388 public String
getExportFileName() {
389 return text_exportFileName
.getText();
392 public String
getFolderText() {
393 return text_folder
.getText();
396 public Text
getFolderComposite() {
400 private void createClassificationSelectionCombo(Composite parent
){
402 // Composite classificationSelection = new Composite(parent, SWT.NULL);
403 // classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
405 // GridLayout layout = new GridLayout();
406 // classificationSelection.setLayout(layout);
407 GridData gridData
= new GridData();
408 gridData
= new GridData(GridData
.BEGINNING
, GridData
.CENTER
, true, false);
409 gridData
.horizontalIndent
= 5;
410 // classificationSelection.setLayoutData(gridData);
412 classificationSelectionCombo
= new Combo(parent
, SWT
.BORDER
| SWT
.READ_ONLY
);
413 classificationSelectionCombo
.setLayoutData(gridData
);
414 for(Classification tree
: classifications
){
415 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
419 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
421 // TODO remember last selection
422 classificationSelectionCombo
.addSelectionListener(this);
426 //return classificationSelection;
429 public Combo
getCombo(){
430 return classificationSelectionCombo
;
434 public void widgetSelected(SelectionEvent e
) {
435 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
440 public void widgetDefaultSelected(SelectionEvent e
) {
445 public UUID
getSelectedClassificationUUID() {
447 return selectedClassification
.getUuid();
450 public boolean getCheckUseSelectedTaxonNode() {
451 if (checkUseSelectedtaxonNode
== null){
454 return checkUseSelectedtaxonNode
.getSelection();
458 public boolean canFlipToNextPage() {
459 return getFolderText() != null;