Trim code
[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.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.FileDialog;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Text;
27
28 import eu.etaxonomy.cdm.common.CdmUtils;
29
30 /**
31 *
32 * @author n.hoffmann
33 * @created 04.08.2009
34 * @version 1.0
35 */
36 public class ImportFromFileDataSourceWizardPage extends WizardPage {
37
38 /** Constant <code>PAGE_NAME="CdmXmlDataSourceWizardPage"</code> */
39 public static final String PAGE_NAME = "CdmXmlDataSourceWizardPage";
40
41 private String[] extensions = {"*.xml"};
42
43 private FileDialog fileDialog;
44
45 private Text text_file;
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 /** {@inheritDoc} */
62 @Override
63 public void createControl(Composite parent) {
64 final Composite composite = new Composite(parent, SWT.NULL);
65
66 setPageComplete(false);
67
68 GridLayout gridLayout = new GridLayout();
69 gridLayout.numColumns = 3;
70 composite.setLayout(gridLayout);
71
72 Label folderLabel = new Label(composite, SWT.NONE);
73 folderLabel.setText("File");
74
75 fileDialog = new FileDialog(parent.getShell());
76
77 fileDialog.setFilterExtensions(extensions);
78
79 text_file = new Text(composite, SWT.BORDER);
80 text_file.setEditable(false);
81 text_file.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
82
83
84 Button button = new Button(composite, SWT.PUSH);
85 button.setText("Browse...");
86
87 button.addSelectionListener(new SelectionAdapter(){
88
89 @Override
90 public void widgetSelected(SelectionEvent e) {
91 String path = fileDialog.open();
92 if(path!=null){
93 text_file.setText(path);
94 setPageComplete(true);
95 }
96 }
97
98 });
99
100
101 setControl(composite);
102 }
103
104 public File getFile() {
105 return new File(text_file.getText());
106 }
107
108 public URI getUri() {
109 return getFile().toURI();
110 }
111
112 @Override
113 public boolean isPageComplete() {
114 return CdmUtils.isNotBlank(text_file.getText());
115 }
116
117 }