automated build configuration is on its way
[taxeditor.git] / 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
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;
27
28 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
29
30 /**
31 * <p>ExportToFileDestinationWizardPage class.</p>
32 *
33 * @author n.hoffmann
34 * @created 15.06.2009
35 * @version 1.0
36 */
37 public class ExportToFileDestinationWizardPage extends WizardPage{
38
39 /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
40 public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
41
42 /** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
43 public static final String JAXB_EXPORT = "JAXB_EXPORT";
44
45 /** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
46 public static final String TCS_EXPORT = "TCS_EXPORT";
47
48 /** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
49 public static final String SDD_EXPORT = "SDD_EXPORT";
50
51 private DirectoryDialog folderDialog;
52 private Text text_exportFileName;
53
54 private Text text_folder;
55
56 private String type;
57
58
59 /**
60 * @param pageName
61 * @param selection
62 */
63 private ExportToFileDestinationWizardPage(String pageName, String type, String title, String description) {
64 super(pageName);
65
66 this.type = type;
67
68 this.setTitle(title);
69 this.setDescription("Exports the contents of the currently selected database into the cdm jaxb format.");
70 }
71
72 /**
73 * <p>Jaxb</p>
74 *
75 * @return a {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage} object.
76 */
77 public static ExportToFileDestinationWizardPage Jaxb(){
78 return new ExportToFileDestinationWizardPage(JAXB_EXPORT, "jaxb", "JAXB Export", "Exports the contents of the currently selected database into the cdm jaxb format.");
79 }
80
81 /**
82 * <p>Tcs</p>
83 *
84 * @return a {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage} object.
85 */
86 public static ExportToFileDestinationWizardPage Tcs(){
87 return new ExportToFileDestinationWizardPage(TCS_EXPORT, "tcs", "Tcs Export", "Export the contents of the currently selected database into TCS format.");
88 }
89
90 /**
91 * <p>Sdd</p>
92 *
93 * @return a {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage} object.
94 */
95 public static ExportToFileDestinationWizardPage Sdd(){
96 return new ExportToFileDestinationWizardPage(SDD_EXPORT, "sdd", "Sdd Export", "Export the contents of the currently selected database into SDD format.");
97 }
98
99
100 /* (non-Javadoc)
101 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
102 */
103 /** {@inheritDoc} */
104 public void createControl(Composite parent) {
105
106 setPageComplete(false);
107
108 Composite composite = new Composite(parent, SWT.NONE);
109 GridLayout gridLayout = new GridLayout();
110 gridLayout.numColumns = 3;
111 composite.setLayout(gridLayout);
112
113 Label fileLabel = new Label(composite, SWT.NONE);
114 fileLabel.setText("File");
115
116 text_exportFileName = new Text(composite, SWT.BORDER);
117 text_exportFileName.setText(generateFilename());
118 text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
119
120
121 Label folderLabel = new Label(composite, SWT.NONE);
122 folderLabel.setText("Folder");
123
124 folderDialog = new DirectoryDialog(parent.getShell());
125
126 text_folder = new Text(composite, SWT.BORDER);
127 text_folder.setEditable(false);
128 text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
129
130
131 Button button = new Button(composite, SWT.PUSH);
132 button.setText("Browse...");
133
134 button.addSelectionListener(new SelectionAdapter(){
135 /* (non-Javadoc)
136 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
137 */
138 @Override
139 public void widgetSelected(SelectionEvent e) {
140 super.widgetSelected(e);
141 String path = folderDialog.open();
142 if(path != null){ // a folder was selected
143 text_folder.setText(path);
144 setPageComplete(true);
145 }
146 }
147 });
148
149 // make the composite the wizard pages control
150 setControl(composite);
151 }
152
153 private String generateFilename(){
154 StringBuffer buffer = new StringBuffer();
155
156 Calendar cal = Calendar.getInstance();
157 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
158 buffer.append(sdf.format(cal.getTime()));
159
160 buffer.append("-");
161
162 buffer.append(type + "_export-");
163 buffer.append(CdmDataSourceRepository.getCurrentDataSource());
164
165 buffer.append(".xml");
166
167 return buffer.toString();
168 }
169
170
171 /**
172 * <p>getExportFileName</p>
173 *
174 * @return the exportFileName
175 */
176 public String getExportFileName() {
177 return text_exportFileName.getText();
178 }
179
180
181 /**
182 * <p>getFolderText</p>
183 *
184 * @return the folderText
185 */
186 public String getFolderText() {
187 return text_folder.getText();
188 }
189 }