88895ebeb0cf23e374819182c4b6eabf99411004
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / io / JaxbExportDestinationWizardPage.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;
12
13 import java.text.SimpleDateFormat;
14 import java.util.Calendar;
15
16 import org.apache.log4j.Logger;
17 import org.eclipse.jface.wizard.WizardPage;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.MouseAdapter;
20 import org.eclipse.swt.events.MouseEvent;
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.Composite;
25 import org.eclipse.swt.widgets.DirectoryDialog;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Text;
28
29 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
30
31 /**
32 * @author n.hoffmann
33 * @created 15.06.2009
34 * @version 1.0
35 */
36 public class JaxbExportDestinationWizardPage extends WizardPage{
37
38 public static final String DATE_FORMAT_NOW = "yyyyMMdd-HHmm";
39
40 private static final Logger logger = Logger
41 .getLogger(JaxbExportDestinationWizardPage.class);
42 private DirectoryDialog folderDialog;
43 private Text text_exportFileName;
44
45 private Text text_folder;
46
47
48 /**
49 * @param pageName
50 * @param selection
51 */
52 protected JaxbExportDestinationWizardPage(String pageName) {
53 super(pageName);
54 this.setTitle("JAXB Export");
55
56 this.setDescription("Exports the contents of the currently selected database into the cdm jaxb format.");
57 }
58
59
60 /* (non-Javadoc)
61 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
62 */
63 public void createControl(Composite parent) {
64
65 setPageComplete(false);
66
67 Composite composite = new Composite(parent, SWT.NONE);
68 GridLayout gridLayout = new GridLayout();
69 gridLayout.numColumns = 3;
70 composite.setLayout(gridLayout);
71
72 Label fileLabel = new Label(composite, SWT.NONE);
73 fileLabel.setText("File");
74
75 text_exportFileName = new Text(composite, SWT.BORDER);
76 text_exportFileName.setText(generateFilename());
77 text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
78
79
80 Label folderLabel = new Label(composite, SWT.NONE);
81 folderLabel.setText("Folder");
82
83 folderDialog = new DirectoryDialog(parent.getShell());
84
85 text_folder = new Text(composite, SWT.BORDER);
86 text_folder.setEditable(false);
87 text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
88
89
90 Button button = new Button(composite, SWT.PUSH);
91 button.setText("Browse...");
92
93 button.addMouseListener(new MouseAdapter(){
94
95 /* (non-Javadoc)
96 * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
97 */
98 @Override
99 public void mouseUp(MouseEvent e) {
100 String path = folderDialog.open();
101 text_folder.setText(path);
102 setPageComplete(true);
103 }
104
105 });
106
107 // make the composite the wizard pages control
108 setControl(composite);
109 }
110
111 private String generateFilename(){
112 StringBuffer buffer = new StringBuffer();
113 buffer.append("jaxb_export_");
114 buffer.append(CdmDataSourceRepository.getDefault().getCurrentDataSource());
115 buffer.append("-");
116
117 Calendar cal = Calendar.getInstance();
118 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
119 buffer.append(sdf.format(cal.getTime()));
120
121 buffer.append(".xml");
122
123 return buffer.toString();
124 }
125
126
127 /**
128 * @return the exportFileName
129 */
130 public Text getExportFileName() {
131 return text_exportFileName;
132 }
133
134
135 /**
136 * @return the folderText
137 */
138 public Text getFolderText() {
139 return text_folder;
140 }
141 }