ref #9114 adapt some classes with URI to wrapper in taxeditor (cont.)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / e4 / in / 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 package eu.etaxonomy.taxeditor.io.e4.in;
10
11 import java.io.File;
12
13 import javax.inject.Inject;
14
15 import org.eclipse.jface.wizard.WizardPage;
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.URI;
28 import eu.etaxonomy.cdm.common.CdmUtils;
29
30 /**
31 * @author pplitzner
32 * @since Oct 5, 2017
33 */
34 public class ImportFromFileDataSourceWizardPage extends WizardPage {
35
36 public static final String PAGE_NAME = "ImportDataSourceWizardPage";
37
38 private String[] extensions = {"*.xml"};
39
40 private FileDialog fileDialog;
41
42 protected Text text_source;
43
44 protected Composite composite;
45
46 @Inject
47 public ImportFromFileDataSourceWizardPage() {
48 super(PAGE_NAME);
49
50 setTitle("Xml File");
51
52 setDescription("Select XML file.");
53
54 setExtensions(new String[]{"*.xml","*.*"});
55 }
56
57 public void setExtensions(String[] extensions) {
58 this.extensions = extensions;
59 }
60
61 @Override
62 public void createControl(Composite parent) {
63 composite = new Composite(parent, SWT.NULL);
64
65 setPageComplete(false);
66
67 GridLayout gridLayout = new GridLayout();
68 gridLayout.numColumns = 2;
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 new Label(composite, SWT.NONE);
78
79 text_source = new Text(composite, SWT.BORDER);
80 text_source.setEditable(false);
81 text_source.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_source.setText(path);
94 setPageComplete(isPageComplete());
95 }
96 }
97 });
98
99 setControl(composite);
100 }
101
102 public File getFile() {
103 return new File(text_source.getText());
104 }
105
106 public URI getUri() {
107 return URI.fromFile(getFile());
108 }
109
110 @Override
111 public boolean isPageComplete() {
112 return CdmUtils.isNotBlank(text_source.getText());
113 }
114 }