Merge branch 'develop' into remoting-4.0
[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.taxeditor.datasource.CdmDataSourceRepository;
32 import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
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 static String CSV_PRINT_EXPORT ="CSV_PRINT_EXPORT";
76
77 private static boolean csvPrintExport = false;
78
79 private DirectoryDialog folderDialog;
80 private Text text_exportFileName;
81
82 private Text text_folder;
83
84 private final String type;
85
86 private final String extension;
87
88 private Combo comboBox;
89
90 /**
91 * @param pageName
92 * @param selection
93 */
94 protected ExportToFileDestinationWizardPage(String pageName, String type,
95 String title, String description, String extension) {
96 super(pageName);
97
98 this.type = type;
99 this.extension = extension;
100 this.setTitle(title);
101 this.setDescription(description);
102 }
103
104 /**
105 * <p>
106 * Jaxb
107 * </p>
108 *
109 * @return a
110 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
111 * object.
112 */
113 public static ExportToFileDestinationWizardPage Jaxb() {
114 return new ExportToFileDestinationWizardPage(
115 JAXB_EXPORT,
116 "jaxb",
117 "JAXB Export",
118 "Exports the contents of the currently selected database into the cdm jaxb format.",
119 XML);
120 }
121
122 /**
123 * <p>
124 * Tcs
125 * </p>
126 *
127 * @return a
128 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
129 * object.
130 */
131 public static ExportToFileDestinationWizardPage Tcs() {
132 return new ExportToFileDestinationWizardPage(
133 TCS_EXPORT,
134 "tcs",
135 "Tcs Export",
136 "Export the contents of the currently selected database into TCS format.",
137 XML);
138 }
139
140 /**
141 * <p>
142 * Sdd
143 * </p>
144 *
145 * @return a
146 * {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
147 * object.
148 */
149 public static ExportToFileDestinationWizardPage Sdd() {
150 return new ExportToFileDestinationWizardPage(
151 SDD_EXPORT,
152 "sdd",
153 "Sdd Export",
154 "Export the contents of the currently selected database into SDD format.",
155 XML);
156 }
157
158 /**
159 * @return
160 */
161 public static ExportToFileDestinationWizardPage Dwca() {
162 return new ExportToFileDestinationWizardPage(
163 DWCA_EXPORT,
164 "dwca",
165 "DwC-Archive Export",
166 "Export the contents of the currently selected database into Darwin Core Archive format.",
167 ZIP);
168 }
169
170
171
172 /**
173 * @return
174 */
175 public static ExportToFileDestinationWizardPage Csv() {
176 csvExport = true;
177 return new ExportToFileDestinationWizardPage(
178 CSV_EXPORT,
179 "csv",
180 "CSV Export",
181 "Export the contents of the currently selected database into Comma Separated Value format.",
182 CSV);
183 }
184
185 /**
186 * @return
187 */
188 public static ExportToFileDestinationWizardPage CsvNames() {
189 csvNameExport = true;
190 return new ExportToFileDestinationWizardPage(
191 CSV_NAME_EXPORT,
192 "csvNames",
193 "CSV Name Export",
194 "Export the names of the currently selected database into Semicolon Separated Value format.",
195 CSV);
196 }
197
198 /**
199 * @return
200 */
201 public static ExportToFileDestinationWizardPage CsvPrint() {
202 csvPrintExport = true;
203 return new ExportToFileDestinationWizardPage(
204 CSV_PRINT_EXPORT,
205 "csvPrint",
206 "CSV Print Export",
207 "Export the content of the currently selected database into Semicolon Separated Value format.",
208 CSV);
209 }
210
211 /*
212 * (non-Javadoc)
213 *
214 * @see
215 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
216 * .Composite)
217 */
218 /** {@inheritDoc} */
219 @Override
220 public void createControl(Composite parent) {
221
222 setPageComplete(false);
223
224 Composite composite = new Composite(parent, SWT.NONE);
225 GridLayout gridLayout = new GridLayout();
226 gridLayout.numColumns = 3;
227 composite.setLayout(gridLayout);
228
229
230 if(csvExport){
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,
235 true, false, 2, 1));
236 }
237
238
239
240
241 Label fileLabel = new Label(composite, SWT.NONE);
242 fileLabel.setText("File");
243
244 text_exportFileName = new Text(composite, SWT.BORDER);
245 text_exportFileName.setText(generateFilename());
246 text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
247 true, false, 2, 1));
248
249 Label folderLabel = new Label(composite, SWT.NONE);
250 folderLabel.setText("Folder");
251
252 folderDialog = new DirectoryDialog(parent.getShell());
253
254 text_folder = new Text(composite, SWT.BORDER);
255 text_folder.setEditable(false);
256 text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
257 false));
258
259 Button button = new Button(composite, SWT.PUSH);
260 button.setText("Browse...");
261
262 button.addSelectionListener(new SelectionAdapter() {
263 /*
264 * (non-Javadoc)
265 *
266 * @see
267 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
268 * .swt.events.SelectionEvent)
269 */
270 @Override
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);
277 }
278 }
279 });
280
281 // make the composite the wizard pages control
282 setControl(composite);
283 }
284
285 protected String generateFilename() {
286 StringBuffer buffer = new StringBuffer();
287
288 Calendar cal = Calendar.getInstance();
289 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
290 buffer.append(sdf.format(cal.getTime()));
291
292 buffer.append("-");
293
294 buffer.append(type + "_export-");
295 try {
296 buffer.append(CdmDataSourceRepository.getCurrentCdmSource());
297 } catch (CdmRemoteSourceException e) {
298 buffer.append("Unknown");
299 }
300
301 buffer.append(".");
302 buffer.append(extension);
303
304 return buffer.toString();
305 }
306
307 /**
308 * <p>
309 * getExportFileName
310 * </p>
311 *
312 * @return the exportFileName
313 */
314 public String getExportFileName() {
315 return text_exportFileName.getText();
316 }
317
318 /**
319 * <p>
320 * getFolderText
321 * </p>
322 *
323 * @return the folderText
324 */
325 public String getFolderText() {
326 return text_folder.getText();
327 }
328
329 private Combo addComboBox(Composite composite){
330
331 comboBox = new Combo(composite, SWT.DROP_DOWN);
332 comboBox.setText("Choose Classification");
333
334 final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
335
336 for(Classification c : listClassifications){
337 comboBox.add(c.getTitleCache());
338 }
339
340 return comboBox;
341 }
342
343 public Combo getCombo(){
344 return comboBox;
345 }
346
347 }