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