b832068fb76adc7a4a748e65676a5ceeb533c9cb
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / ImportFromFileDataSourceWizardPage.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 org.apache.log4j.Logger;
14 import org.eclipse.jface.wizard.WizardPage;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.MouseAdapter;
17 import org.eclipse.swt.events.MouseEvent;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.FileDialog;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.swt.widgets.Text;
25
26 /**
27 * @author n.hoffmann
28 * @created 04.08.2009
29 * @version 1.0
30 */
31 public class ImportFromFileDataSourceWizardPage extends WizardPage {
32 private static final Logger logger = Logger
33 .getLogger(ImportFromFileDataSourceWizardPage.class);
34
35 public static final String PAGE_NAME = "CdmXmlDataSourceWizardPage";
36
37 private String[] extensions = {"*.xml"};
38
39 private FileDialog fileDialog;
40
41 private Text text_file;
42
43
44 /**
45 * @param pageName
46 */
47 protected ImportFromFileDataSourceWizardPage(String title, String description, String[] extensions) {
48 super(PAGE_NAME);
49
50 setTitle(title);
51
52 setDescription(description);
53
54 this.extensions = extensions;
55 }
56
57 protected static ImportFromFileDataSourceWizardPage XML(){
58 return new ImportFromFileDataSourceWizardPage("Xml File", "Select XML file.", new String[]{"*.xml"});
59 }
60
61
62
63 /* (non-Javadoc)
64 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
65 */
66 public void createControl(Composite parent) {
67 final Composite composite = new Composite(parent, SWT.NULL);
68
69 setPageComplete(false);
70
71 GridLayout gridLayout = new GridLayout();
72 gridLayout.numColumns = 3;
73 composite.setLayout(gridLayout);
74
75 Label folderLabel = new Label(composite, SWT.NONE);
76 folderLabel.setText("File");
77
78 fileDialog = new FileDialog(parent.getShell());
79
80 fileDialog.setFilterExtensions(extensions);
81
82 text_file = new Text(composite, SWT.BORDER);
83 text_file.setEditable(false);
84 text_file.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
85
86
87 Button button = new Button(composite, SWT.PUSH);
88 button.setText("Browse...");
89
90 button.addMouseListener(new MouseAdapter(){
91
92 /* (non-Javadoc)
93 * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
94 */
95 @Override
96 public void mouseUp(MouseEvent e) {
97 String path = fileDialog.open();
98 text_file.setText(path);
99 setPageComplete(true);
100 }
101
102 });
103
104 setControl(composite);
105 }
106
107 /**
108 * @return
109 */
110 public String getFile() {
111 return text_file.getText();
112 }
113 }