ref #8248 Split import wizard page
[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
10 package eu.etaxonomy.taxeditor.io.e4.in;
11
12 import java.io.File;
13 import java.net.URI;
14
15 import javax.inject.Inject;
16
17 import org.eclipse.jface.wizard.WizardPage;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.FileDialog;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Text;
28
29 import eu.etaxonomy.cdm.common.CdmUtils;
30
31 /**
32 *
33 * @author pplitzner
34 * @since Oct 5, 2017
35 *
36 */
37 public class ImportFromFileDataSourceWizardPage extends WizardPage {
38
39 public static final String PAGE_NAME = "ImportDataSourceWizardPage";
40
41 private String[] extensions = {"*.xml"};
42
43 private FileDialog fileDialog;
44
45 protected Text text_source;
46
47 protected Composite composite;
48
49 @Inject
50 public ImportFromFileDataSourceWizardPage() {
51 super(PAGE_NAME);
52
53 setTitle("Xml File");
54
55 setDescription("Select XML file.");
56
57 setExtensions(new String[]{"*.xml","*.*"});
58 }
59
60 public void setExtensions(String[] extensions) {
61 this.extensions = extensions;
62 }
63
64 /** {@inheritDoc} */
65 @Override
66 public void createControl(Composite parent) {
67 composite = new Composite(parent, SWT.NULL);
68
69 setPageComplete(false);
70
71 GridLayout gridLayout = new GridLayout();
72 gridLayout.numColumns = 2;
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 new Label(composite, SWT.NONE);
82
83 text_source = new Text(composite, SWT.BORDER);
84 text_source.setEditable(false);
85 text_source.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
86
87
88 Button button = new Button(composite, SWT.PUSH);
89 button.setText("Browse...");
90
91 button.addSelectionListener(new SelectionAdapter(){
92
93 @Override
94 public void widgetSelected(SelectionEvent e) {
95 String path = fileDialog.open();
96 if(path!=null){
97 text_source.setText(path);
98 setPageComplete(isPageComplete());
99 }
100 }
101
102 });
103
104
105 setControl(composite);
106 }
107
108 public File getFile() {
109 return new File(text_source.getText());
110 }
111
112 public URI getUri() {
113 return getFile().toURI();
114 }
115
116 @Override
117 public boolean isPageComplete() {
118 return CdmUtils.isNotBlank(text_source.getText());
119 }
120
121 }