da353112490a5cfc8acd5051a5ac75e3cb8437b7
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / ClassificationChooserWizardPage.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.Event;
25 import org.eclipse.swt.widgets.FileDialog;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Listener;
28 import org.eclipse.swt.widgets.Text;
29 import org.eclipse.wb.swt.ResourceManager;
30
31 import eu.etaxonomy.cdm.model.taxon.Classification;
32 import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
33
34 /**
35 * <p>ImportFromFileDataSourceWizardPage class.</p>
36 *
37 * @author n.hoffmann
38 * @created 04.08.2009
39 * @version 1.0
40 */
41 public class ClassificationChooserWizardPage extends WizardPage implements Listener{
42
43 public static final String PAGE_NAME = "ClassificationChooserWizardPage";
44
45 //classification
46 private Text textClassification;
47 private Classification classification;
48 private Button btnBrowseClassification;
49
50 private Button btnClear;
51
52 //report
53 private FileDialog fileDialogReport;
54 private Text textFileReport;
55
56 /**
57 * <p>Constructor for ImportFromFileDataSourceWizardPage.</p>
58 *
59 * @param title a {@link java.lang.String} object.
60 * @param description a {@link java.lang.String} object.
61 * @param extensions an array of {@link java.lang.String} objects.
62 */
63 protected ClassificationChooserWizardPage(String title, String description) {
64 super(PAGE_NAME);
65
66 setTitle(title);
67
68 setDescription(description);
69
70 }
71
72 /**
73 * <p>XML</p>
74 *
75 * @return a {@link eu.etaxonomy.taxeditor.io.wizard.ClassificationChooserWizardPage} object.
76 */
77 protected static ClassificationChooserWizardPage createPage(){
78 return new ClassificationChooserWizardPage("Configure import destinations", "Note: Selecting no classification will create a default one.");
79 }
80
81
82
83 /* (non-Javadoc)
84 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
85 */
86 /** {@inheritDoc} */
87 @Override
88 public void createControl(Composite parent) {
89 final Composite composite = new Composite(parent, SWT.NULL);
90
91 GridLayout gridLayout = new GridLayout();
92 gridLayout.numColumns = 4;
93 composite.setLayout(gridLayout);
94
95 //classification
96 Label label = new Label(composite, SWT.NONE);
97 label.setText("Classification");
98 textClassification = new Text(composite, SWT.NONE);
99 textClassification.setEnabled(false);
100 textClassification.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
101 btnBrowseClassification = new Button(composite, SWT.NONE);
102 btnBrowseClassification.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
103 btnBrowseClassification.addListener(SWT.Selection, this);
104 btnClear = new Button(composite, SWT.NONE);
105 btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
106 btnClear.addListener(SWT.Selection, this);
107
108 //report
109 Label labelReportFile = new Label(composite, SWT.NONE);
110 labelReportFile.setText("Report File");
111
112 fileDialogReport = new FileDialog(parent.getShell());
113
114 fileDialogReport.setFilterExtensions(new String[]{"*.*"});
115
116 textFileReport = new Text(composite, SWT.BORDER);
117 textFileReport.setEditable(false);
118 textFileReport.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
119
120
121 Button buttonReport = new Button(composite, SWT.PUSH);
122 buttonReport.setText("Browse...");
123
124 buttonReport.addSelectionListener(new SelectionAdapter(){
125
126 /* (non-Javadoc)
127 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
128 */
129 @Override
130 public void widgetSelected(SelectionEvent e) {
131 String path = fileDialogReport.open();
132 if(path!=null){
133 textFileReport.setText(path);
134 setPageComplete(true);
135 }
136 }
137
138 });
139
140 setControl(composite);
141 }
142
143 /* (non-Javadoc)
144 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
145 */
146 @Override
147 public void handleEvent(Event event) {
148 if(event.widget==btnBrowseClassification){
149 classification = SelectionDialogFactory.getSelectionFromDialog(Classification.class, getShell(), null, null);
150 if(classification!=null){
151 textClassification.setText(classification.getTitleCache());
152 }
153 }
154 else if(event.widget==btnClear){
155 classification = null;
156 textClassification.setText("");
157 }
158 }
159
160 /**
161 * @return the classification
162 */
163 public Classification getClassification() {
164 return classification;
165 }
166
167 public URI getReportUri(){
168 String text = textFileReport.getText();
169 if(text==null || text.isEmpty()){
170 return null;
171 }
172 return new File(text).toURI();
173 }
174 }