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
.taxeditor
.datasource
.CdmDataSourceRepository
;
32 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSourceException
;
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 static String CSV_PRINT_EXPORT
="CSV_PRINT_EXPORT";
77 private static boolean csvPrintExport
= false;
79 private DirectoryDialog folderDialog
;
80 private Text text_exportFileName
;
82 private Text text_folder
;
84 private final String type
;
86 private final String extension
;
88 private Combo comboBox
;
94 protected ExportToFileDestinationWizardPage(String pageName
, String type
,
95 String title
, String description
, String extension
) {
99 this.extension
= extension
;
100 this.setTitle(title
);
101 this.setDescription(description
);
110 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
113 public static ExportToFileDestinationWizardPage
Jaxb() {
114 return new ExportToFileDestinationWizardPage(
118 "Exports the contents of the currently selected database into the cdm jaxb format.",
128 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
131 public static ExportToFileDestinationWizardPage
Tcs() {
132 return new ExportToFileDestinationWizardPage(
136 "Export the contents of the currently selected database into TCS format.",
146 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
149 public static ExportToFileDestinationWizardPage
Sdd() {
150 return new ExportToFileDestinationWizardPage(
154 "Export the contents of the currently selected database into SDD format.",
161 public static ExportToFileDestinationWizardPage
Dwca() {
162 return new ExportToFileDestinationWizardPage(
165 "DwC-Archive Export",
166 "Export the contents of the currently selected database into Darwin Core Archive format.",
175 public static ExportToFileDestinationWizardPage
Csv() {
177 return new ExportToFileDestinationWizardPage(
181 "Export the contents of the currently selected database into Comma Separated Value format.",
188 public static ExportToFileDestinationWizardPage
CsvNames() {
189 csvNameExport
= true;
190 return new ExportToFileDestinationWizardPage(
194 "Export the names of the currently selected database into Semicolon Separated Value format.",
201 public static ExportToFileDestinationWizardPage
CsvPrint() {
202 csvPrintExport
= true;
203 return new ExportToFileDestinationWizardPage(
207 "Export the content of the currently selected database into Semicolon Separated Value format.",
215 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
220 public void createControl(Composite parent
) {
222 setPageComplete(false);
224 Composite composite
= new Composite(parent
, SWT
.NONE
);
225 GridLayout gridLayout
= new GridLayout();
226 gridLayout
.numColumns
= 3;
227 composite
.setLayout(gridLayout
);
231 Label comboBoxLabel
= new Label(composite
, SWT
.NONE
);
232 comboBoxLabel
.setText("Classification");
233 Combo comboBox
= addComboBox(composite
);
234 comboBox
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
241 Label fileLabel
= new Label(composite
, SWT
.NONE
);
242 fileLabel
.setText("File");
244 text_exportFileName
= new Text(composite
, SWT
.BORDER
);
245 text_exportFileName
.setText(generateFilename());
246 text_exportFileName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
249 Label folderLabel
= new Label(composite
, SWT
.NONE
);
250 folderLabel
.setText("Folder");
252 folderDialog
= new DirectoryDialog(parent
.getShell());
254 text_folder
= new Text(composite
, SWT
.BORDER
);
255 text_folder
.setEditable(false);
256 text_folder
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
259 Button button
= new Button(composite
, SWT
.PUSH
);
260 button
.setText("Browse...");
262 button
.addSelectionListener(new SelectionAdapter() {
267 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
268 * .swt.events.SelectionEvent)
271 public void widgetSelected(SelectionEvent e
) {
272 super.widgetSelected(e
);
273 String path
= folderDialog
.open();
274 if (path
!= null) { // a folder was selected
275 text_folder
.setText(path
);
276 setPageComplete(true);
281 // make the composite the wizard pages control
282 setControl(composite
);
285 protected String
generateFilename() {
286 StringBuffer buffer
= new StringBuffer();
288 Calendar cal
= Calendar
.getInstance();
289 SimpleDateFormat sdf
= new SimpleDateFormat(DATE_FORMAT_NOW
);
290 buffer
.append(sdf
.format(cal
.getTime()));
294 buffer
.append(type
+ "_export-");
296 buffer
.append(CdmDataSourceRepository
.getCurrentCdmSource());
297 } catch (CdmRemoteSourceException e
) {
298 buffer
.append("Unknown");
302 buffer
.append(extension
);
304 return buffer
.toString();
312 * @return the exportFileName
314 public String
getExportFileName() {
315 return text_exportFileName
.getText();
323 * @return the folderText
325 public String
getFolderText() {
326 return text_folder
.getText();
329 private Combo
addComboBox(Composite composite
){
331 comboBox
= new Combo(composite
, SWT
.DROP_DOWN
);
332 comboBox
.setText("Choose Classification");
334 final List
<Classification
> listClassifications
= CdmStore
.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
336 for(Classification c
: listClassifications
){
337 comboBox
.add(c
.getTitleCache());
343 public Combo
getCombo(){