Merge branch 'develop' into featureTreeEditor
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / ImportFromFileDataSourceWizardPage.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.io.wizard;
11
12 import java.io.File;
13 import java.net.URI;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
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 import eu.etaxonomy.cdm.common.CdmUtils;
27
28 /**
29 *
30 * @author n.hoffmann
31 * @created 04.08.2009
32 * @version 1.0
33 */
34 public class ImportFromFileDataSourceWizardPage extends AbcdSourceSelectionPage {
35
36 /** Constant <code>PAGE_NAME="CdmXmlDataSourceWizardPage"</code> */
37 public static final String PAGE_NAME = "CdmXmlDataSourceWizardPage";
38
39 private String[] extensions = {"*.xml"};
40
41 private FileDialog fileDialog;
42 private Text textReferenceString;
43
44 protected ImportFromFileDataSourceWizardPage(String title, String description, String[] extensions) {
45 super(PAGE_NAME);
46
47 setTitle(title);
48
49 setDescription(description);
50
51 this.extensions = extensions;
52 }
53
54 protected static ImportFromFileDataSourceWizardPage XML(){
55 return new ImportFromFileDataSourceWizardPage("Xml File", "Select XML file.", new String[]{"*.xml","*.*"});
56 }
57
58 /** {@inheritDoc} */
59 @Override
60 public void createControl(Composite parent) {
61 final Composite composite = new Composite(parent, SWT.NULL);
62
63 setPageComplete(false);
64
65 GridLayout gridLayout = new GridLayout();
66 gridLayout.numColumns = 3;
67 composite.setLayout(gridLayout);
68
69 Label folderLabel = new Label(composite, SWT.NONE);
70 folderLabel.setText("File");
71
72 fileDialog = new FileDialog(parent.getShell());
73
74 fileDialog.setFilterExtensions(extensions);
75
76 text_source = new Text(composite, SWT.BORDER);
77 text_source.setEditable(false);
78 text_source.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
79
80
81 Button button = new Button(composite, SWT.PUSH);
82 button.setText("Browse...");
83
84 button.addSelectionListener(new SelectionAdapter(){
85
86 @Override
87 public void widgetSelected(SelectionEvent e) {
88 String path = fileDialog.open();
89 if(path!=null){
90 text_source.setText(path);
91 setPageComplete(isPageComplete());
92 }
93 }
94
95 });
96
97 Label labelRef = new Label(composite, SWT.NONE);
98 labelRef.setText("Default import souce reference");
99 labelRef.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
100 textReferenceString = new Text(composite, SWT.NONE);
101 textReferenceString.setEnabled(true);
102 GridData gd_textReferenceString = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
103 gd_textReferenceString.widthHint = 229;
104 textReferenceString.setLayoutData(gd_textReferenceString);
105 setControl(composite);
106 }
107
108 public File getFile() {
109 return new File(text_source.getText());
110 }
111
112 public Text getTextReferenceString() {
113 return textReferenceString;
114 }
115
116 public void setTextReferenceString(Text textReferenceString) {
117 this.textReferenceString = textReferenceString;
118 }
119
120
121 @Override
122 public URI getUri() {
123 return getFile().toURI();
124 }
125
126 @Override
127 public boolean isPageComplete() {
128 return CdmUtils.isNotBlank(text_source.getText());
129 }
130
131 }