8277684dadd36a28a1b108df49492eba76d92ea3
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / ExportToFileDestinationWizardPage.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.io.wizard;
12
13 import java.text.SimpleDateFormat;
14 import java.util.Calendar;
15 import java.util.List;
16
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;
29
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;
34
35 /**
36 * <p>
37 * ExportToFileDestinationWizardPage class.
38 * </p>
39 *
40 * @author n.hoffmann
41 * @created 15.06.2009
42 * @version 1.0
43 */
44 public class ExportToFileDestinationWizardPage extends WizardPage {
45
46 /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
47 public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
48
49 /** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
50 public static final String JAXB_EXPORT = "JAXB_EXPORT";
51
52 /** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
53 public static final String TCS_EXPORT = "TCS_EXPORT";
54
55 /** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
56 public static final String SDD_EXPORT = "SDD_EXPORT";
57
58 public static final String DWCA_EXPORT = "DWCA_EXPORT";
59
60 public static final String CSV_EXPORT = "CSV_EXPORT";
61 public static final String CSV_NAME_EXPORT = "CSV_NAME_EXPORT";
62
63 public static final String XML = "xml";
64
65 public static final String CSV = "csv";
66
67
68
69 public static final String ZIP = "zip";
70
71 private static boolean csvExport = false;
72
73 private static boolean csvNameExport = false;
74
75 private DirectoryDialog folderDialog;
76 private Text text_exportFileName;
77
78 private Text text_folder;
79
80 private final String type;
81
82 private final String extension;
83
84 private Combo comboBox;
85
86 /**
87 * @param pageName
88 * @param selection
89 */
90 protected ExportToFileDestinationWizardPage(String pageName, String type,
91 String title, String description, String extension) {
92 super(pageName);
93
94 this.type = type;
95 this.extension = extension;
96 this.setTitle(title);
97 this.setDescription(description);
98 }
99
100 /**
101 * <p>
102 * Jaxb
103 * </p>
104 *
105 * @return a
106 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
107 * object.
108 */
109 public static ExportToFileDestinationWizardPage Jaxb() {
110 return new ExportToFileDestinationWizardPage(
111 JAXB_EXPORT,
112 "jaxb",
113 "JAXB Export",
114 "Exports the contents of the currently selected database into the cdm jaxb format.",
115 XML);
116 }
117
118 /**
119 * <p>
120 * Tcs
121 * </p>
122 *
123 * @return a
124 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
125 * object.
126 */
127 public static ExportToFileDestinationWizardPage Tcs() {
128 return new ExportToFileDestinationWizardPage(
129 TCS_EXPORT,
130 "tcs",
131 "Tcs Export",
132 "Export the contents of the currently selected database into TCS format.",
133 XML);
134 }
135
136 /**
137 * <p>
138 * Sdd
139 * </p>
140 *
141 * @return a
142 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
143 * object.
144 */
145 public static ExportToFileDestinationWizardPage Sdd() {
146 return new ExportToFileDestinationWizardPage(
147 SDD_EXPORT,
148 "sdd",
149 "Sdd Export",
150 "Export the contents of the currently selected database into SDD format.",
151 XML);
152 }
153
154 /**
155 * @return
156 */
157 public static ExportToFileDestinationWizardPage Dwca() {
158 return new ExportToFileDestinationWizardPage(
159 DWCA_EXPORT,
160 "dwca",
161 "DwC-Archive Export",
162 "Export the contents of the currently selected database into Darwin Core Archive format.",
163 ZIP);
164 }
165
166
167
168 /**
169 * @return
170 */
171 public static ExportToFileDestinationWizardPage Csv() {
172 csvExport = true;
173 return new ExportToFileDestinationWizardPage(
174 CSV_EXPORT,
175 "csv",
176 "CSV Export",
177 "Export the contents of the currently selected database into Comma Separated Value format.",
178 CSV);
179 }
180
181 /**
182 * @return
183 */
184 public static ExportToFileDestinationWizardPage CsvNames() {
185 csvNameExport = true;
186 return new ExportToFileDestinationWizardPage(
187 CSV_NAME_EXPORT,
188 "csvNames",
189 "CSV Name Export",
190 "Export the names of the currently selected database into Semicolon Separated Value format.",
191 CSV);
192 }
193
194 /*
195 * (non-Javadoc)
196 *
197 * @see
198 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
199 * .Composite)
200 */
201 /** {@inheritDoc} */
202 @Override
203 public void createControl(Composite parent) {
204
205 setPageComplete(false);
206
207 Composite composite = new Composite(parent, SWT.NONE);
208 GridLayout gridLayout = new GridLayout();
209 gridLayout.numColumns = 3;
210 composite.setLayout(gridLayout);
211
212
213 if(csvExport){
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,
218 true, false, 2, 1));
219 }
220
221
222
223
224 Label fileLabel = new Label(composite, SWT.NONE);
225 fileLabel.setText("File");
226
227 text_exportFileName = new Text(composite, SWT.BORDER);
228 text_exportFileName.setText(generateFilename());
229 text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
230 true, false, 2, 1));
231
232 Label folderLabel = new Label(composite, SWT.NONE);
233 folderLabel.setText("Folder");
234
235 folderDialog = new DirectoryDialog(parent.getShell());
236
237 text_folder = new Text(composite, SWT.BORDER);
238 text_folder.setEditable(false);
239 text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
240 false));
241
242 Button button = new Button(composite, SWT.PUSH);
243 button.setText("Browse...");
244
245 button.addSelectionListener(new SelectionAdapter() {
246 /*
247 * (non-Javadoc)
248 *
249 * @see
250 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
251 * .swt.events.SelectionEvent)
252 */
253 @Override
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);
260 }
261 }
262 });
263
264 // make the composite the wizard pages control
265 setControl(composite);
266 }
267
268 protected String generateFilename() {
269 StringBuffer buffer = new StringBuffer();
270
271 Calendar cal = Calendar.getInstance();
272 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
273 buffer.append(sdf.format(cal.getTime()));
274
275 buffer.append("-");
276
277 buffer.append(type + "_export-");
278 try {
279 buffer.append(CdmDataSourceRepository.getCurrentCdmSource());
280 } catch (CdmRemoteSourceException e) {
281 buffer.append("Unknown");
282 }
283
284 buffer.append(".");
285 buffer.append(extension);
286
287 return buffer.toString();
288 }
289
290 /**
291 * <p>
292 * getExportFileName
293 * </p>
294 *
295 * @return the exportFileName
296 */
297 public String getExportFileName() {
298 return text_exportFileName.getText();
299 }
300
301 /**
302 * <p>
303 * getFolderText
304 * </p>
305 *
306 * @return the folderText
307 */
308 public String getFolderText() {
309 return text_folder.getText();
310 }
311
312 private Combo addComboBox(Composite composite){
313
314 comboBox = new Combo(composite, SWT.DROP_DOWN);
315 comboBox.setText("Choose Classification");
316
317 final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
318
319 for(Classification c : listClassifications){
320 comboBox.add(c.getTitleCache());
321 }
322
323 return comboBox;
324 }
325
326 public Combo getCombo(){
327 return comboBox;
328 }
329
330 }