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
;
16 import org
.eclipse
.jface
.wizard
.WizardPage
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.SelectionAdapter
;
19 import org
.eclipse
.swt
.events
.SelectionEvent
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Button
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
25 import org
.eclipse
.swt
.widgets
.Label
;
26 import org
.eclipse
.swt
.widgets
.Text
;
28 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
32 * ExportToFileDestinationWizardPage class.
39 public class ExportToFileDestinationWizardPage
extends WizardPage
{
41 /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
42 public static final String DATE_FORMAT_NOW
= "yyyyMMddHHmm";
44 /** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
45 public static final String JAXB_EXPORT
= "JAXB_EXPORT";
47 /** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
48 public static final String TCS_EXPORT
= "TCS_EXPORT";
50 /** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
51 public static final String SDD_EXPORT
= "SDD_EXPORT";
53 public static final String DWCA_EXPORT
= "DWCA_EXPORT";
55 public static final String XML
= "xml";
57 public static final String ZIP
= "zip";
59 private DirectoryDialog folderDialog
;
60 private Text text_exportFileName
;
62 private Text text_folder
;
64 private final String type
;
66 private final String extension
;
72 private ExportToFileDestinationWizardPage(String pageName
, String type
,
73 String title
, String description
, String extension
) {
77 this.extension
= extension
;
79 this.setDescription(description
);
88 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
91 public static ExportToFileDestinationWizardPage
Jaxb() {
92 return new ExportToFileDestinationWizardPage(
96 "Exports the contents of the currently selected database into the cdm jaxb format.",
106 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
109 public static ExportToFileDestinationWizardPage
Tcs() {
110 return new ExportToFileDestinationWizardPage(
114 "Export the contents of the currently selected database into TCS format.",
124 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
127 public static ExportToFileDestinationWizardPage
Sdd() {
128 return new ExportToFileDestinationWizardPage(
132 "Export the contents of the currently selected database into SDD format.",
139 public static ExportToFileDestinationWizardPage
Dwca() {
140 return new ExportToFileDestinationWizardPage(
143 "DwC-Archive Export",
144 "Export the contents of the currently selected database into Darwin Core Archive format.",
152 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
156 public void createControl(Composite parent
) {
158 setPageComplete(false);
160 Composite composite
= new Composite(parent
, SWT
.NONE
);
161 GridLayout gridLayout
= new GridLayout();
162 gridLayout
.numColumns
= 3;
163 composite
.setLayout(gridLayout
);
165 Label fileLabel
= new Label(composite
, SWT
.NONE
);
166 fileLabel
.setText("File");
168 text_exportFileName
= new Text(composite
, SWT
.BORDER
);
169 text_exportFileName
.setText(generateFilename());
170 text_exportFileName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
173 Label folderLabel
= new Label(composite
, SWT
.NONE
);
174 folderLabel
.setText("Folder");
176 folderDialog
= new DirectoryDialog(parent
.getShell());
178 text_folder
= new Text(composite
, SWT
.BORDER
);
179 text_folder
.setEditable(false);
180 text_folder
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
183 Button button
= new Button(composite
, SWT
.PUSH
);
184 button
.setText("Browse...");
186 button
.addSelectionListener(new SelectionAdapter() {
191 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
192 * .swt.events.SelectionEvent)
195 public void widgetSelected(SelectionEvent e
) {
196 super.widgetSelected(e
);
197 String path
= folderDialog
.open();
198 if (path
!= null) { // a folder was selected
199 text_folder
.setText(path
);
200 setPageComplete(true);
205 // make the composite the wizard pages control
206 setControl(composite
);
209 private String
generateFilename() {
210 StringBuffer buffer
= new StringBuffer();
212 Calendar cal
= Calendar
.getInstance();
213 SimpleDateFormat sdf
= new SimpleDateFormat(DATE_FORMAT_NOW
);
214 buffer
.append(sdf
.format(cal
.getTime()));
218 buffer
.append(type
+ "_export-");
219 buffer
.append(CdmDataSourceRepository
.getCurrentDataSource());
222 buffer
.append(extension
);
224 return buffer
.toString();
232 * @return the exportFileName
234 public String
getExportFileName() {
235 return text_exportFileName
.getText();
243 * @return the folderText
245 public String
getFolderText() {
246 return text_folder
.getText();