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