1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 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
|
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
14
|
import com.vaadin.data.Container;
|
15
|
import com.vaadin.data.Property;
|
16
|
import com.vaadin.data.Property.ValueChangeEvent;
|
17
|
import com.vaadin.data.Property.ValueChangeListener;
|
18
|
import com.vaadin.server.VaadinSession;
|
19
|
import com.vaadin.ui.AbstractLayout;
|
20
|
import com.vaadin.ui.Alignment;
|
21
|
import com.vaadin.ui.Button;
|
22
|
import com.vaadin.ui.Button.ClickEvent;
|
23
|
import com.vaadin.ui.Button.ClickListener;
|
24
|
import com.vaadin.ui.ComboBox;
|
25
|
import com.vaadin.ui.CustomComponent;
|
26
|
import com.vaadin.ui.HorizontalLayout;
|
27
|
import com.vaadin.ui.Label;
|
28
|
import com.vaadin.ui.ListSelect;
|
29
|
import com.vaadin.ui.Notification;
|
30
|
import com.vaadin.ui.Tree;
|
31
|
import com.vaadin.ui.VerticalLayout;
|
32
|
import com.vaadin.ui.Window;
|
33
|
|
34
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
35
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
36
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
37
|
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
|
38
|
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
|
39
|
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter;
|
40
|
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
|
41
|
|
42
|
/**
|
43
|
*
|
44
|
* @author pplitzner
|
45
|
*
|
46
|
*/
|
47
|
public class DistributionSettingsConfigWindow extends CustomComponent implements ValueChangeListener, ClickListener{
|
48
|
|
49
|
private static final long serialVersionUID = 1439411115014088780L;
|
50
|
private ComboBox classificationBox;
|
51
|
private ComboBox distAreaBox;
|
52
|
private ListSelect namedAreaList;
|
53
|
private Tree taxonTree;
|
54
|
private Label labelNoClassification;
|
55
|
private Button okButton;
|
56
|
private Button cancelButton;
|
57
|
private final SettingsPresenter presenter;
|
58
|
private Window window;
|
59
|
private HorizontalLayout mainLayout;
|
60
|
|
61
|
/**
|
62
|
* The constructor should first build the main layout, set the
|
63
|
* composition root and then do any custom initialization.
|
64
|
*
|
65
|
* The constructor will not be automatically regenerated by the
|
66
|
* visual editor.
|
67
|
* @param distributionTableView
|
68
|
*/
|
69
|
public DistributionSettingsConfigWindow(DistributionTableView distributionTableView) {
|
70
|
buildMainLayout();
|
71
|
presenter = new SettingsPresenter();
|
72
|
init();
|
73
|
}
|
74
|
|
75
|
private void init() {
|
76
|
Container distributionContainer = presenter.getDistributionContainer();
|
77
|
TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea();
|
78
|
|
79
|
classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
|
80
|
classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
|
81
|
classificationBox.setImmediate(true);
|
82
|
TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode();
|
83
|
classificationBox.addValueChangeListener(this);
|
84
|
if(chosenTaxonNode!=null){
|
85
|
classificationBox.setValue(chosenTaxonNode.getClassification().getRootNode());
|
86
|
taxonTree.setContainerDataSource(new TaxonNodeContainer((TaxonNode) classificationBox.getValue()));
|
87
|
taxonTree.setValue(chosenTaxonNode);
|
88
|
}
|
89
|
taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
|
90
|
distAreaBox.setContainerDataSource(distributionContainer);
|
91
|
distAreaBox.setValue(chosenArea);
|
92
|
distAreaBox.addValueChangeListener(this);
|
93
|
|
94
|
if(chosenArea!=null){
|
95
|
NamedAreaContainer container = new NamedAreaContainer(chosenArea);
|
96
|
namedAreaList.setContainerDataSource(container);
|
97
|
}
|
98
|
Object selectedAreas = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS);
|
99
|
namedAreaList.setValue(selectedAreas);
|
100
|
|
101
|
okButton.addClickListener(this);
|
102
|
cancelButton.addClickListener(this);
|
103
|
}
|
104
|
|
105
|
public Window createWindow(){
|
106
|
window = new Window();
|
107
|
window.setModal(true);
|
108
|
window.setWidth("60%");
|
109
|
window.setHeight("80%");
|
110
|
window.setCaption("Settings");
|
111
|
window.setContent(mainLayout);
|
112
|
return window;
|
113
|
}
|
114
|
|
115
|
private AbstractLayout buildMainLayout() {
|
116
|
|
117
|
mainLayout = new HorizontalLayout();
|
118
|
mainLayout.setImmediate(false);
|
119
|
mainLayout.setSizeFull();
|
120
|
mainLayout.setMargin(true);
|
121
|
mainLayout.setSpacing(true);
|
122
|
|
123
|
VerticalLayout leftContainer = new VerticalLayout();
|
124
|
leftContainer.setImmediate(false);
|
125
|
leftContainer.setSizeFull();
|
126
|
leftContainer.setSpacing(true);
|
127
|
|
128
|
VerticalLayout rightContainer = new VerticalLayout();
|
129
|
rightContainer.setImmediate(false);
|
130
|
rightContainer.setSizeFull();
|
131
|
rightContainer.setSpacing(true);
|
132
|
|
133
|
//classification and term
|
134
|
classificationBox = new ComboBox("Classification");
|
135
|
classificationBox.setImmediate(true);
|
136
|
classificationBox.setWidth("100%");
|
137
|
|
138
|
//distribution area box
|
139
|
distAreaBox = new ComboBox("Distribution Area:");
|
140
|
distAreaBox.setImmediate(true);
|
141
|
distAreaBox.setWidth("100%");
|
142
|
|
143
|
// named areas
|
144
|
namedAreaList = new ListSelect();
|
145
|
namedAreaList.setCaption("Areas");
|
146
|
namedAreaList.setWidth("100%");
|
147
|
namedAreaList.setMultiSelect(true);
|
148
|
|
149
|
//taxonomy
|
150
|
taxonTree = new Tree("Taxonomy");
|
151
|
taxonTree.setImmediate(false);
|
152
|
|
153
|
//no classification selected label
|
154
|
labelNoClassification = new Label(" - Please select a classification - ");
|
155
|
|
156
|
leftContainer.addComponent(classificationBox);
|
157
|
leftContainer.addComponent(distAreaBox);
|
158
|
leftContainer.addComponent(namedAreaList);
|
159
|
leftContainer.setSizeFull();
|
160
|
|
161
|
rightContainer.addComponent(taxonTree);
|
162
|
rightContainer.setExpandRatio(taxonTree, 1);
|
163
|
rightContainer.addComponent(labelNoClassification);
|
164
|
rightContainer.setComponentAlignment(labelNoClassification, Alignment.BOTTOM_RIGHT);
|
165
|
|
166
|
mainLayout.addComponent(leftContainer);
|
167
|
mainLayout.addComponent(rightContainer);
|
168
|
|
169
|
//button toolbar
|
170
|
HorizontalLayout buttonToolBar = new HorizontalLayout();
|
171
|
// cancelButton
|
172
|
cancelButton = new Button();
|
173
|
cancelButton.setCaption("Cancel");
|
174
|
cancelButton.setImmediate(true);
|
175
|
buttonToolBar.addComponent(cancelButton);
|
176
|
|
177
|
// okButton
|
178
|
okButton = new Button();
|
179
|
okButton.setCaption("OK");
|
180
|
okButton.setImmediate(true);
|
181
|
buttonToolBar.addComponent(okButton);
|
182
|
|
183
|
mainLayout.addComponent(rightContainer);
|
184
|
mainLayout.addComponent(buttonToolBar);
|
185
|
mainLayout.setComponentAlignment(buttonToolBar, Alignment.BOTTOM_RIGHT);
|
186
|
|
187
|
return mainLayout;
|
188
|
}
|
189
|
|
190
|
@Override
|
191
|
public void valueChange(ValueChangeEvent event) {
|
192
|
Property property = event.getProperty();
|
193
|
if(property==classificationBox){
|
194
|
TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
|
195
|
if(parentNode!=null){
|
196
|
taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode));
|
197
|
}
|
198
|
else{
|
199
|
taxonTree.setContainerDataSource(null);
|
200
|
}
|
201
|
labelNoClassification.setVisible(parentNode==null);
|
202
|
}
|
203
|
|
204
|
else if(property==distAreaBox){
|
205
|
TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
|
206
|
NamedAreaContainer container = new NamedAreaContainer(vocabulary);
|
207
|
namedAreaList.setContainerDataSource(container);
|
208
|
}
|
209
|
}
|
210
|
|
211
|
@Override
|
212
|
public void buttonClick(ClickEvent event) {
|
213
|
Object source = event.getSource();
|
214
|
if(source==okButton){
|
215
|
TaxonNode taxonNode;
|
216
|
TermVocabulary<NamedArea> term = null;
|
217
|
taxonNode = (TaxonNode) taxonTree.getValue();
|
218
|
if(taxonNode==null){
|
219
|
taxonNode = (TaxonNode) classificationBox.getValue();
|
220
|
}
|
221
|
term = (TermVocabulary<NamedArea>) distAreaBox.getValue();
|
222
|
Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
|
223
|
if(taxonNode==null){
|
224
|
Notification.show("Please choose a classification and/or taxon", Notification.Type.HUMANIZED_MESSAGE);
|
225
|
return;
|
226
|
}
|
227
|
if(term==null){
|
228
|
Notification.show("Please choose a distribution area", Notification.Type.HUMANIZED_MESSAGE);
|
229
|
return;
|
230
|
}
|
231
|
DistributionEditorUtil.openDistributionView(taxonNode, term, selectedAreas);
|
232
|
window.close();
|
233
|
}
|
234
|
else if(source==cancelButton){
|
235
|
window.close();
|
236
|
}
|
237
|
}
|
238
|
|
239
|
}
|