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