1
|
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Set;
|
5
|
|
6
|
import com.vaadin.data.Container;
|
7
|
import com.vaadin.data.Property.ValueChangeEvent;
|
8
|
import com.vaadin.data.Property.ValueChangeListener;
|
9
|
import com.vaadin.data.util.IndexedContainer;
|
10
|
import com.vaadin.event.ShortcutAction.KeyCode;
|
11
|
import com.vaadin.navigator.View;
|
12
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
13
|
import com.vaadin.ui.Alignment;
|
14
|
import com.vaadin.ui.Button;
|
15
|
import com.vaadin.ui.Button.ClickEvent;
|
16
|
import com.vaadin.ui.Button.ClickListener;
|
17
|
import com.vaadin.ui.ComboBox;
|
18
|
import com.vaadin.ui.CustomComponent;
|
19
|
import com.vaadin.ui.Label;
|
20
|
import com.vaadin.ui.ListSelect;
|
21
|
import com.vaadin.ui.Panel;
|
22
|
import com.vaadin.ui.Tree;
|
23
|
import com.vaadin.ui.VerticalLayout;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
26
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
27
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
29
|
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
|
30
|
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
|
31
|
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionSelectionPresenter;
|
32
|
|
33
|
public class DistributionSelectionView extends CustomComponent implements View, ClickListener{
|
34
|
|
35
|
private VerticalLayout mainLayout;
|
36
|
private Panel panel_1;
|
37
|
private VerticalLayout verticalLayout_2;
|
38
|
private Button button_proceed;
|
39
|
private ComboBox classificationBox;
|
40
|
private ComboBox distributionAreaBox;
|
41
|
private ListSelect namedAreaList;
|
42
|
private Tree taxonTree;
|
43
|
private Label labelInstruction;
|
44
|
private Label labelNoClassification;
|
45
|
|
46
|
private static final long serialVersionUID = 1L;
|
47
|
private DistributionSelectionPresenter distListener;
|
48
|
/**
|
49
|
* The constructor should first build the main layout, set the
|
50
|
* composition root and then do any custom initialization.
|
51
|
*
|
52
|
* The constructor will not be automatically regenerated by the
|
53
|
* visual editor.
|
54
|
*/
|
55
|
public DistributionSelectionView(){
|
56
|
buildMainLayout();
|
57
|
setCompositionRoot(mainLayout);
|
58
|
setStyleName("login");
|
59
|
button_proceed.addClickListener(this);
|
60
|
button_proceed.setClickShortcut(KeyCode.ENTER, null);
|
61
|
}
|
62
|
|
63
|
|
64
|
public void addListener(DistributionSelectionPresenter listener) {
|
65
|
distListener = listener;
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public void buttonClick(ClickEvent event) {
|
70
|
TaxonNode taxonNode = (TaxonNode) taxonTree.getValue();
|
71
|
if(taxonNode==null){
|
72
|
taxonNode = (TaxonNode) classificationBox.getValue();
|
73
|
}
|
74
|
TermVocabulary<NamedArea> term = (TermVocabulary<NamedArea>)distributionAreaBox.getValue();
|
75
|
Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
|
76
|
distListener.buttonClick(taxonNode, term, selectedAreas);
|
77
|
}
|
78
|
|
79
|
public void dataBinding(){
|
80
|
classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
|
81
|
classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
|
82
|
classificationBox.setImmediate(true);
|
83
|
classificationBox.addValueChangeListener(new ValueChangeListener() {
|
84
|
@Override
|
85
|
public void valueChange(ValueChangeEvent event) {
|
86
|
TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
|
87
|
if(parentNode!=null){
|
88
|
taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode));
|
89
|
}
|
90
|
else{
|
91
|
taxonTree.setContainerDataSource(null);
|
92
|
}
|
93
|
labelNoClassification.setVisible(parentNode==null);
|
94
|
}
|
95
|
});
|
96
|
taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
|
97
|
|
98
|
distributionAreaBox.addValueChangeListener(new ValueChangeListener() {
|
99
|
|
100
|
@Override
|
101
|
public void valueChange(ValueChangeEvent event) {
|
102
|
TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
|
103
|
NamedAreaContainer container = new NamedAreaContainer(vocabulary);
|
104
|
namedAreaList.setContainerDataSource(container);
|
105
|
}
|
106
|
});
|
107
|
|
108
|
List<TermVocabulary<DefinedTermBase>> namedAreaList = distListener.getNamedAreaList();
|
109
|
Container d = new IndexedContainer(namedAreaList);
|
110
|
distributionAreaBox.setContainerDataSource(d);
|
111
|
}
|
112
|
|
113
|
@Override
|
114
|
public void enter(ViewChangeEvent event) {
|
115
|
}
|
116
|
|
117
|
private VerticalLayout buildMainLayout() {
|
118
|
// common part: create layout
|
119
|
mainLayout = new VerticalLayout();
|
120
|
mainLayout.setImmediate(false);
|
121
|
mainLayout.setWidth("100%");
|
122
|
mainLayout.setHeight("100%");
|
123
|
mainLayout.setMargin(false);
|
124
|
|
125
|
// top-level component properties
|
126
|
setWidth("100.0%");
|
127
|
setHeight("100.0%");
|
128
|
|
129
|
// panel_1
|
130
|
panel_1 = buildPanel_1();
|
131
|
mainLayout.addComponent(panel_1);
|
132
|
mainLayout.setComponentAlignment(panel_1, new Alignment(48));
|
133
|
|
134
|
return mainLayout;
|
135
|
}
|
136
|
|
137
|
|
138
|
private Panel buildPanel_1() {
|
139
|
// common part: create layout
|
140
|
panel_1 = new Panel();
|
141
|
panel_1.setImmediate(false);
|
142
|
panel_1.setWidth("-1px");
|
143
|
panel_1.setHeight("-1px");
|
144
|
|
145
|
// verticalLayout_2
|
146
|
verticalLayout_2 = buildVerticalLayout_2();
|
147
|
panel_1.setContent(verticalLayout_2);
|
148
|
|
149
|
return panel_1;
|
150
|
}
|
151
|
|
152
|
|
153
|
private VerticalLayout buildVerticalLayout_2() {
|
154
|
// common part: create layout
|
155
|
verticalLayout_2 = new VerticalLayout();
|
156
|
verticalLayout_2.setImmediate(false);
|
157
|
verticalLayout_2.setWidth("-1px");
|
158
|
verticalLayout_2.setHeight("-1px");
|
159
|
verticalLayout_2.setMargin(true);
|
160
|
verticalLayout_2.setSpacing(true);
|
161
|
|
162
|
labelInstruction = new Label();
|
163
|
labelInstruction.setImmediate(false);
|
164
|
labelInstruction.setWidth("213px");
|
165
|
labelInstruction.setHeight("-1px");
|
166
|
labelInstruction.setValue("Please choose a Classification and/or taxon and a distribution area to proceed.");
|
167
|
verticalLayout_2.addComponent(labelInstruction);
|
168
|
|
169
|
// classificationBox
|
170
|
classificationBox = new ComboBox();
|
171
|
classificationBox.setCaption("Classification: ");
|
172
|
classificationBox.setImmediate(false);
|
173
|
classificationBox.setWidth("200px");
|
174
|
classificationBox.setHeight("-1px");
|
175
|
verticalLayout_2.addComponent(classificationBox);
|
176
|
|
177
|
// distributionAreaBox
|
178
|
distributionAreaBox = new ComboBox();
|
179
|
distributionAreaBox.setCaption("Distribution Area");
|
180
|
distributionAreaBox.setWidth("200px");
|
181
|
distributionAreaBox.setHeight("-1px");
|
182
|
verticalLayout_2.addComponent(distributionAreaBox);
|
183
|
|
184
|
// named areas
|
185
|
namedAreaList = new ListSelect();
|
186
|
namedAreaList.setCaption("Areas");
|
187
|
namedAreaList.setWidth("200px");
|
188
|
namedAreaList.setHeight("-1px");
|
189
|
namedAreaList.setMultiSelect(true);
|
190
|
verticalLayout_2.addComponent(namedAreaList);
|
191
|
|
192
|
// taxon tree
|
193
|
taxonTree = new Tree("Taxonomy");
|
194
|
taxonTree.setWidth("200px");
|
195
|
verticalLayout_2.addComponent(taxonTree);
|
196
|
labelNoClassification = new Label(" - Please select a classification - ");
|
197
|
verticalLayout_2.addComponent(labelNoClassification);
|
198
|
verticalLayout_2.setComponentAlignment(labelNoClassification, Alignment.BOTTOM_RIGHT);
|
199
|
|
200
|
// button_proceed
|
201
|
button_proceed = new Button();
|
202
|
button_proceed.setCaption("Proceed");
|
203
|
button_proceed.setImmediate(true);
|
204
|
button_proceed.setWidth("-1px");
|
205
|
button_proceed.setHeight("-1px");
|
206
|
verticalLayout_2.addComponent(button_proceed);
|
207
|
verticalLayout_2.setComponentAlignment(button_proceed, new Alignment(10));
|
208
|
|
209
|
return verticalLayout_2;
|
210
|
}
|
211
|
|
212
|
}
|