2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents 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
.Control
;
30 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
31 import org
.eclipse
.swt
.widgets
.Label
;
32 import org
.eclipse
.swt
.widgets
.Text
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
36 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
37 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSourceException
;
38 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
42 * ExportToFileDestinationWizardPage class.
49 public class ExportToFileDestinationWizardPage
extends WizardPage
implements SelectionListener
{
51 /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
52 public static final String DATE_FORMAT_NOW
= "yyyyMMddHHmm";
54 /** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
55 public static final String JAXB_EXPORT
= "JAXB_EXPORT";
57 /** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
58 public static final String TCS_EXPORT
= "TCS_EXPORT";
60 /** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
61 public static final String SDD_EXPORT
= "SDD_EXPORT";
63 public static final String DWCA_EXPORT
= "DWCA_EXPORT";
64 public static final String OUTPUT_MODEL_EXPORT
= "OUTPUT_MODEL_EXPORT";
65 public static final String CSV_EXPORT
= "CSV_EXPORT";
66 public static final String CSV_NAME_EXPORT
= "CSV_NAME_EXPORT";
68 public static final String XML
= "xml";
70 public static final String CSV
= "csv";
74 public static final String ZIP
= "zip";
76 private static boolean csvExport
= false;
78 private static boolean csvNameExport
= false;
80 private static String CSV_PRINT_EXPORT
="CSV_PRINT_EXPORT";
82 private static boolean csvPrintExport
= false;
84 private static boolean outputModelExport
= false;
86 private DirectoryDialog folderDialog
;
87 private Text text_exportFileName
;
89 private Text text_folder
;
91 private final String type
;
93 private final String extension
;
95 private Combo classificationSelectionCombo
;
97 private List
<Classification
> classifications
;
99 private Classification selectedClassification
;
105 protected ExportToFileDestinationWizardPage(String pageName
, String type
,
106 String title
, String description
, String extension
) {
110 this.extension
= extension
;
111 this.setTitle(title
);
112 this.setDescription(description
);
121 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
124 public static ExportToFileDestinationWizardPage
Jaxb() {
125 return new ExportToFileDestinationWizardPage(
129 "Exports the contents of the currently selected database into the cdm jaxb format.",
139 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
142 public static ExportToFileDestinationWizardPage
Tcs() {
143 return new ExportToFileDestinationWizardPage(
147 "Export the contents of the currently selected database into TCS format.",
157 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
160 public static ExportToFileDestinationWizardPage
Sdd() {
161 return new ExportToFileDestinationWizardPage(
165 "Export the contents of the currently selected database into SDD format.",
172 public static ExportToFileDestinationWizardPage
Dwca() {
173 return new ExportToFileDestinationWizardPage(
176 "DwC-Archive Export",
177 "Export the contents of the currently selected database into Darwin Core Archive format.",
184 public static ExportToFileDestinationWizardPage
OutputModel() {
185 outputModelExport
= true;
186 return new ExportToFileDestinationWizardPage(
189 "Output Model Export",
190 "Export the contents of the currently selected database into the output model format.",
198 public static ExportToFileDestinationWizardPage
Csv() {
200 return new ExportToFileDestinationWizardPage(
204 "Export the contents of the currently selected database into Comma Separated Value format.",
211 public static ExportToFileDestinationWizardPage
CsvNames() {
212 csvNameExport
= true;
213 return new ExportToFileDestinationWizardPage(
217 "Export the names of the currently selected database into Semicolon Separated Value format.",
224 public static ExportToFileDestinationWizardPage
CsvPrint() {
225 csvPrintExport
= true;
226 return new ExportToFileDestinationWizardPage(
230 "Export the content of the currently selected database into Semicolon Separated Value format.",
238 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
243 public void createControl(Composite parent
) {
245 setPageComplete(false);
247 Composite composite
= new Composite(parent
, SWT
.NONE
);
248 GridLayout gridLayout
= new GridLayout();
249 gridLayout
.numColumns
= 3;
250 composite
.setLayout(gridLayout
);
251 if(classifications
== null){
252 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
253 Collections
.sort(classifications
, new Comparator
<Classification
>() {
256 public int compare(Classification o1
, Classification o2
) {
260 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
262 return o1
.getUuid().compareTo(o2
.getUuid());
268 selectedClassification
= classifications
.iterator().next();
272 if(csvExport
|| csvPrintExport
|| outputModelExport
){
273 Label comboBoxLabel
= new Label(composite
, SWT
.NONE
);
274 comboBoxLabel
.setText("Classification");
276 createClassificationSelectionCombo(composite
);
277 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
280 if (!outputModelExport
){
281 Label fileLabel
= new Label(composite
, SWT
.NONE
);
282 fileLabel
.setText("File");
283 text_exportFileName
= new Text(composite
, SWT
.BORDER
);
284 text_exportFileName
.setText(generateFilename());
285 text_exportFileName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
289 Label folderLabel
= new Label(composite
, SWT
.NONE
);
290 folderLabel
.setText("Folder");
292 folderDialog
= new DirectoryDialog(parent
.getShell());
294 text_folder
= new Text(composite
, SWT
.BORDER
);
295 text_folder
.setEditable(false);
296 text_folder
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
299 Button button
= new Button(composite
, SWT
.PUSH
);
300 button
.setText("Browse...");
302 button
.addSelectionListener(new SelectionAdapter() {
307 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
308 * .swt.events.SelectionEvent)
311 public void widgetSelected(SelectionEvent e
) {
312 super.widgetSelected(e
);
313 String path
= folderDialog
.open();
314 if (path
!= null) { // a folder was selected
315 text_folder
.setText(path
);
316 setPageComplete(true);
321 // make the composite the wizard pages control
322 setControl(composite
);
325 protected String
generateFilename() {
326 StringBuffer buffer
= new StringBuffer();
328 Calendar cal
= Calendar
.getInstance();
329 SimpleDateFormat sdf
= new SimpleDateFormat(DATE_FORMAT_NOW
);
330 buffer
.append(sdf
.format(cal
.getTime()));
334 buffer
.append(type
+ "_export-");
336 buffer
.append(CdmDataSourceRepository
.getCurrentCdmSource());
337 } catch (CdmRemoteSourceException e
) {
338 buffer
.append("Unknown");
342 buffer
.append(extension
);
344 return buffer
.toString();
352 * @return the exportFileName
354 public String
getExportFileName() {
355 return text_exportFileName
.getText();
363 * @return the folderText
365 public String
getFolderText() {
366 return text_folder
.getText();
369 private Control
createClassificationSelectionCombo(Composite parent
){
370 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
372 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
373 classificationSelection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
375 GridLayout layout
= new GridLayout();
376 classificationSelection
.setLayout(layout
);
378 Label label
= new Label(classificationSelection
, SWT
.NULL
);
379 // TODO not working is not really true but leave it here to remind everyone that this is under construction
380 label
.setText("Select Classification");
381 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
382 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
384 for(Classification tree
: classifications
){
385 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
389 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
391 // TODO remember last selection
392 classificationSelectionCombo
.addSelectionListener(this);
396 return classificationSelection
;
399 public Combo
getCombo(){
400 return classificationSelectionCombo
;
404 public void widgetSelected(SelectionEvent e
) {
405 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
410 public void widgetDefaultSelected(SelectionEvent e
) {
415 public UUID
getSelectedClassificationUUID() {
417 return selectedClassification
.getUuid();