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