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