3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.io
.wizard
;
13 import java
.text
.SimpleDateFormat
;
14 import java
.util
.Calendar
;
15 import java
.util
.List
;
17 import org
.eclipse
.jface
.wizard
.WizardPage
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Button
;
24 import org
.eclipse
.swt
.widgets
.Combo
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
27 import org
.eclipse
.swt
.widgets
.Label
;
28 import org
.eclipse
.swt
.widgets
.Text
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
31 import eu
.etaxonomy
.cdm
.remote
.CdmRemoteSourceException
;
32 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 * ExportToFileDestinationWizardPage class.
44 public class ExportToFileDestinationWizardPage
extends WizardPage
{
46 /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
47 public static final String DATE_FORMAT_NOW
= "yyyyMMddHHmm";
49 /** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
50 public static final String JAXB_EXPORT
= "JAXB_EXPORT";
52 /** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
53 public static final String TCS_EXPORT
= "TCS_EXPORT";
55 /** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
56 public static final String SDD_EXPORT
= "SDD_EXPORT";
58 public static final String DWCA_EXPORT
= "DWCA_EXPORT";
60 public static final String CSV_EXPORT
= "CSV_EXPORT";
61 public static final String CSV_NAME_EXPORT
= "CSV_NAME_EXPORT";
63 public static final String XML
= "xml";
65 public static final String CSV
= "csv";
69 public static final String ZIP
= "zip";
71 private static boolean csvExport
= false;
73 private static boolean csvNameExport
= false;
75 private DirectoryDialog folderDialog
;
76 private Text text_exportFileName
;
78 private Text text_folder
;
80 private final String type
;
82 private final String extension
;
84 private Combo comboBox
;
90 protected ExportToFileDestinationWizardPage(String pageName
, String type
,
91 String title
, String description
, String extension
) {
95 this.extension
= extension
;
97 this.setDescription(description
);
106 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
109 public static ExportToFileDestinationWizardPage
Jaxb() {
110 return new ExportToFileDestinationWizardPage(
114 "Exports the contents of the currently selected database into the cdm jaxb format.",
124 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
127 public static ExportToFileDestinationWizardPage
Tcs() {
128 return new ExportToFileDestinationWizardPage(
132 "Export the contents of the currently selected database into TCS format.",
142 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
145 public static ExportToFileDestinationWizardPage
Sdd() {
146 return new ExportToFileDestinationWizardPage(
150 "Export the contents of the currently selected database into SDD format.",
157 public static ExportToFileDestinationWizardPage
Dwca() {
158 return new ExportToFileDestinationWizardPage(
161 "DwC-Archive Export",
162 "Export the contents of the currently selected database into Darwin Core Archive format.",
171 public static ExportToFileDestinationWizardPage
Csv() {
173 return new ExportToFileDestinationWizardPage(
177 "Export the contents of the currently selected database into Comma Separated Value format.",
184 public static ExportToFileDestinationWizardPage
CsvNames() {
185 csvNameExport
= true;
186 return new ExportToFileDestinationWizardPage(
190 "Export the names of the currently selected database into Semicolon Separated Value format.",
198 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
203 public void createControl(Composite parent
) {
205 setPageComplete(false);
207 Composite composite
= new Composite(parent
, SWT
.NONE
);
208 GridLayout gridLayout
= new GridLayout();
209 gridLayout
.numColumns
= 3;
210 composite
.setLayout(gridLayout
);
214 Label comboBoxLabel
= new Label(composite
, SWT
.NONE
);
215 comboBoxLabel
.setText("Classification");
216 Combo comboBox
= addComboBox(composite
);
217 comboBox
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
224 Label fileLabel
= new Label(composite
, SWT
.NONE
);
225 fileLabel
.setText("File");
227 text_exportFileName
= new Text(composite
, SWT
.BORDER
);
228 text_exportFileName
.setText(generateFilename());
229 text_exportFileName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
232 Label folderLabel
= new Label(composite
, SWT
.NONE
);
233 folderLabel
.setText("Folder");
235 folderDialog
= new DirectoryDialog(parent
.getShell());
237 text_folder
= new Text(composite
, SWT
.BORDER
);
238 text_folder
.setEditable(false);
239 text_folder
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
242 Button button
= new Button(composite
, SWT
.PUSH
);
243 button
.setText("Browse...");
245 button
.addSelectionListener(new SelectionAdapter() {
250 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
251 * .swt.events.SelectionEvent)
254 public void widgetSelected(SelectionEvent e
) {
255 super.widgetSelected(e
);
256 String path
= folderDialog
.open();
257 if (path
!= null) { // a folder was selected
258 text_folder
.setText(path
);
259 setPageComplete(true);
264 // make the composite the wizard pages control
265 setControl(composite
);
268 protected String
generateFilename() {
269 StringBuffer buffer
= new StringBuffer();
271 Calendar cal
= Calendar
.getInstance();
272 SimpleDateFormat sdf
= new SimpleDateFormat(DATE_FORMAT_NOW
);
273 buffer
.append(sdf
.format(cal
.getTime()));
277 buffer
.append(type
+ "_export-");
279 buffer
.append(CdmDataSourceRepository
.getCurrentCdmSource());
280 } catch (CdmRemoteSourceException e
) {
281 buffer
.append("Unknown");
285 buffer
.append(extension
);
287 return buffer
.toString();
295 * @return the exportFileName
297 public String
getExportFileName() {
298 return text_exportFileName
.getText();
306 * @return the folderText
308 public String
getFolderText() {
309 return text_folder
.getText();
312 private Combo
addComboBox(Composite composite
){
314 comboBox
= new Combo(composite
, SWT
.DROP_DOWN
);
315 comboBox
.setText("Choose Classification");
317 final List
<Classification
> listClassifications
= CdmStore
.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
319 for(Classification c
: listClassifications
){
320 comboBox
.add(c
.getTitleCache());
326 public Combo
getCombo(){