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";
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 DirectoryDialog folderDialog
;
85 private Text text_exportFileName
;
87 private Text text_folder
;
89 private final String type
;
91 private final String extension
;
93 private Combo classificationSelectionCombo
;
95 private List
<Classification
> classifications
;
97 private Classification selectedClassification
;
103 protected ExportToFileDestinationWizardPage(String pageName
, String type
,
104 String title
, String description
, String extension
) {
108 this.extension
= extension
;
109 this.setTitle(title
);
110 this.setDescription(description
);
119 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
122 public static ExportToFileDestinationWizardPage
Jaxb() {
123 return new ExportToFileDestinationWizardPage(
127 "Exports the contents of the currently selected database into the cdm jaxb format.",
137 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
140 public static ExportToFileDestinationWizardPage
Tcs() {
141 return new ExportToFileDestinationWizardPage(
145 "Export the contents of the currently selected database into TCS format.",
155 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
158 public static ExportToFileDestinationWizardPage
Sdd() {
159 return new ExportToFileDestinationWizardPage(
163 "Export the contents of the currently selected database into SDD format.",
170 public static ExportToFileDestinationWizardPage
Dwca() {
171 return new ExportToFileDestinationWizardPage(
174 "DwC-Archive Export",
175 "Export the contents of the currently selected database into Darwin Core Archive format.",
184 public static ExportToFileDestinationWizardPage
Csv() {
186 return new ExportToFileDestinationWizardPage(
190 "Export the contents of the currently selected database into Comma Separated Value format.",
197 public static ExportToFileDestinationWizardPage
CsvNames() {
198 csvNameExport
= true;
199 return new ExportToFileDestinationWizardPage(
203 "Export the names of the currently selected database into Semicolon Separated Value format.",
210 public static ExportToFileDestinationWizardPage
CsvPrint() {
211 csvPrintExport
= true;
212 return new ExportToFileDestinationWizardPage(
216 "Export the content of the currently selected database into Semicolon Separated Value format.",
224 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
229 public void createControl(Composite parent
) {
231 setPageComplete(false);
233 Composite composite
= new Composite(parent
, SWT
.NONE
);
234 GridLayout gridLayout
= new GridLayout();
235 gridLayout
.numColumns
= 3;
236 composite
.setLayout(gridLayout
);
237 if(classifications
== null){
238 classifications
= CdmStore
.getService(IClassificationService
.class).list(null, null, null, null, null);
239 Collections
.sort(classifications
, new Comparator
<Classification
>() {
242 public int compare(Classification o1
, Classification o2
) {
246 int result
= o1
.getTitleCache().compareTo(o2
.getTitleCache());
248 return o1
.getUuid().compareTo(o2
.getUuid());
254 selectedClassification
= classifications
.iterator().next();
258 if(csvExport
|| csvPrintExport
){
259 Label comboBoxLabel
= new Label(composite
, SWT
.NONE
);
260 comboBoxLabel
.setText("Classification");
262 createClassificationSelectionCombo(composite
);
263 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
270 Label fileLabel
= new Label(composite
, SWT
.NONE
);
271 fileLabel
.setText("File");
273 text_exportFileName
= new Text(composite
, SWT
.BORDER
);
274 text_exportFileName
.setText(generateFilename());
275 text_exportFileName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
278 Label folderLabel
= new Label(composite
, SWT
.NONE
);
279 folderLabel
.setText("Folder");
281 folderDialog
= new DirectoryDialog(parent
.getShell());
283 text_folder
= new Text(composite
, SWT
.BORDER
);
284 text_folder
.setEditable(false);
285 text_folder
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
288 Button button
= new Button(composite
, SWT
.PUSH
);
289 button
.setText("Browse...");
291 button
.addSelectionListener(new SelectionAdapter() {
296 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
297 * .swt.events.SelectionEvent)
300 public void widgetSelected(SelectionEvent e
) {
301 super.widgetSelected(e
);
302 String path
= folderDialog
.open();
303 if (path
!= null) { // a folder was selected
304 text_folder
.setText(path
);
305 setPageComplete(true);
310 // make the composite the wizard pages control
311 setControl(composite
);
314 protected String
generateFilename() {
315 StringBuffer buffer
= new StringBuffer();
317 Calendar cal
= Calendar
.getInstance();
318 SimpleDateFormat sdf
= new SimpleDateFormat(DATE_FORMAT_NOW
);
319 buffer
.append(sdf
.format(cal
.getTime()));
323 buffer
.append(type
+ "_export-");
325 buffer
.append(CdmDataSourceRepository
.getCurrentCdmSource());
326 } catch (CdmRemoteSourceException e
) {
327 buffer
.append("Unknown");
331 buffer
.append(extension
);
333 return buffer
.toString();
341 * @return the exportFileName
343 public String
getExportFileName() {
344 return text_exportFileName
.getText();
352 * @return the folderText
354 public String
getFolderText() {
355 return text_folder
.getText();
358 private Control
createClassificationSelectionCombo(Composite parent
){
359 // classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
361 Composite classificationSelection
= new Composite(parent
, SWT
.NULL
);
362 classificationSelection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
364 GridLayout layout
= new GridLayout();
365 classificationSelection
.setLayout(layout
);
367 Label label
= new Label(classificationSelection
, SWT
.NULL
);
368 // TODO not working is not really true but leave it here to remind everyone that this is under construction
369 label
.setText("Select Classification");
370 classificationSelectionCombo
= new Combo(classificationSelection
, SWT
.BORDER
| SWT
.READ_ONLY
);
371 classificationSelectionCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
373 for(Classification tree
: classifications
){
374 classificationSelectionCombo
.add(tree
.getName().getText(), classifications
.indexOf(tree
));
378 classificationSelectionCombo
.select(classifications
.indexOf(selectedClassification
));
380 // TODO remember last selection
381 classificationSelectionCombo
.addSelectionListener(this);
385 return classificationSelection
;
388 public Combo
getCombo(){
389 return classificationSelectionCombo
;
393 public void widgetSelected(SelectionEvent e
) {
394 selectedClassification
= classifications
.get(classificationSelectionCombo
.getSelectionIndex());
399 public void widgetDefaultSelected(SelectionEvent e
) {
404 public UUID
getSelectedClassificationUUID() {
406 return selectedClassification
.getUuid();