Revision cb4029b0
Added by Patrick Plitzner almost 8 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.vaadin.view.dbstatus; |
11 | 11 |
|
12 |
import java.util.HashSet;
|
|
12 |
import java.util.Set; |
|
13 | 13 |
|
14 | 14 |
import com.vaadin.data.Container; |
15 |
import com.vaadin.data.Property; |
|
15 | 16 |
import com.vaadin.data.Property.ValueChangeEvent; |
16 | 17 |
import com.vaadin.data.Property.ValueChangeListener; |
17 | 18 |
import com.vaadin.server.VaadinSession; |
... | ... | |
24 | 25 |
import com.vaadin.ui.ComboBox; |
25 | 26 |
import com.vaadin.ui.CustomComponent; |
26 | 27 |
import com.vaadin.ui.HorizontalLayout; |
28 |
import com.vaadin.ui.Label; |
|
29 |
import com.vaadin.ui.ListSelect; |
|
30 |
import com.vaadin.ui.Notification; |
|
27 | 31 |
import com.vaadin.ui.Tree; |
28 | 32 |
import com.vaadin.ui.TwinColSelect; |
29 | 33 |
import com.vaadin.ui.VerticalLayout; |
... | ... | |
32 | 36 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
33 | 37 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
34 | 38 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
39 |
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer; |
|
35 | 40 |
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer; |
36 | 41 |
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter; |
37 | 42 |
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil; |
... | ... | |
41 | 46 |
* @date 22.04.2015 |
42 | 47 |
* |
43 | 48 |
*/ |
44 |
public class SettingsConfigWindow extends CustomComponent { |
|
49 |
public class SettingsConfigWindow extends CustomComponent implements ValueChangeListener, ClickListener{
|
|
45 | 50 |
|
46 | 51 |
private static final long serialVersionUID = -8220442386869594032L; |
47 | 52 |
private VerticalLayout mainLayout; |
48 | 53 |
private TwinColSelect distStatusSelect; |
49 | 54 |
private ComboBox classificationBox; |
50 | 55 |
private ComboBox distAreaBox; |
56 |
private ListSelect namedAreaList; |
|
51 | 57 |
private Tree taxonTree; |
58 |
private Label labelNoClassification; |
|
52 | 59 |
private CheckBox boxToggleAbbreviatedLabels; |
53 | 60 |
private Button okButton; |
54 | 61 |
private Button cancelButton; |
... | ... | |
69 | 76 |
} |
70 | 77 |
|
71 | 78 |
private void init() { |
72 |
Container taxonNodeContainer = new TaxonNodeContainer(null); |
|
73 | 79 |
Container distributionContainer = presenter.getDistributionContainer(); |
74 |
TermVocabulary<?> chosenArea = presenter.getChosenArea(); |
|
80 |
TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea(); |
|
81 |
|
|
75 | 82 |
classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL); |
76 |
classificationBox.setContainerDataSource(taxonNodeContainer); |
|
77 |
classificationBox.setValue(presenter.getChosenTaxonNode().getClassification().getRootNode()); |
|
78 |
classificationBox.addValueChangeListener(new ValueChangeListener() { |
|
79 |
private static final long serialVersionUID = -8159622506131474118L; |
|
80 |
|
|
81 |
@Override |
|
82 |
public void valueChange(ValueChangeEvent event) { |
|
83 |
TaxonNode parentNode = (TaxonNode) event.getProperty().getValue(); |
|
84 |
taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode)); |
|
85 |
} |
|
86 |
}); |
|
87 |
taxonTree.setContainerDataSource(new TaxonNodeContainer((TaxonNode) classificationBox.getValue())); |
|
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 |
} |
|
88 | 92 |
taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL); |
89 |
taxonTree.setValue(presenter.getChosenTaxonNode()); |
|
90 | 93 |
distAreaBox.setContainerDataSource(distributionContainer); |
91 | 94 |
distAreaBox.setValue(chosenArea); |
92 |
boxToggleAbbreviatedLabels.addValueChangeListener(new ValueChangeListener() {
|
|
93 |
|
|
94 |
private static final long serialVersionUID = 5734502056399266546L;
|
|
95 |
|
|
96 |
@Override
|
|
97 |
public void valueChange(ValueChangeEvent event) {
|
|
98 |
VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
|
|
99 |
|
|
100 |
} |
|
101 |
});
|
|
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);
|
|
102 | 105 |
distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer()); |
103 | 106 |
|
104 |
okButton.addClickListener(new ClickListener() { |
|
105 |
|
|
106 |
private static final long serialVersionUID = -2554281233796070939L; |
|
107 |
|
|
108 |
@Override |
|
109 |
public void buttonClick(ClickEvent event) { |
|
110 |
TaxonNode taxonNode; |
|
111 |
TermVocabulary<NamedArea> term = null; |
|
112 |
taxonNode = (TaxonNode) taxonTree.getValue(); |
|
113 |
if(taxonNode==null){ |
|
114 |
taxonNode = (TaxonNode) classificationBox.getValue(); |
|
115 |
} |
|
116 |
term = (TermVocabulary<NamedArea>) distAreaBox.getValue(); |
|
117 |
DistributionEditorUtil.openDistributionView(taxonNode, term, new HashSet<NamedArea>()); |
|
118 |
window.close(); |
|
119 |
} |
|
120 |
}); |
|
121 |
cancelButton.addClickListener(new ClickListener() { |
|
122 |
|
|
123 |
private static final long serialVersionUID = -99532405408235383L; |
|
124 |
|
|
125 |
@Override |
|
126 |
public void buttonClick(ClickEvent event) { |
|
127 |
window.close(); |
|
128 |
} |
|
129 |
}); |
|
107 |
okButton.addClickListener(this); |
|
108 |
cancelButton.addClickListener(this); |
|
130 | 109 |
} |
131 | 110 |
|
132 | 111 |
public Window createWindow(){ |
... | ... | |
160 | 139 |
classificationBox.setImmediate(true); |
161 | 140 |
classificationBox.setWidth("100%"); |
162 | 141 |
|
142 |
//distribution area box |
|
163 | 143 |
distAreaBox = new ComboBox("Distribution Area:"); |
164 |
distAreaBox.setImmediate(false);
|
|
144 |
distAreaBox.setImmediate(true);
|
|
165 | 145 |
distAreaBox.setWidth("100%"); |
166 | 146 |
|
147 |
// named areas |
|
148 |
namedAreaList = new ListSelect(); |
|
149 |
namedAreaList.setCaption("Areas"); |
|
150 |
namedAreaList.setWidth("100%"); |
|
151 |
namedAreaList.setMultiSelect(true); |
|
152 |
|
|
167 | 153 |
//distribution status |
168 | 154 |
distStatusSelect = new TwinColSelect("Distribution Status:"); |
169 | 155 |
distStatusSelect.setImmediate(false); |
... | ... | |
176 | 162 |
//taxonomy |
177 | 163 |
taxonTree = new Tree("Taxonomy"); |
178 | 164 |
taxonTree.setImmediate(false); |
165 |
|
|
166 |
//no classification selected label |
|
167 |
labelNoClassification = new Label(" - Please select a classification - "); |
|
179 | 168 |
|
180 | 169 |
verticalLayout.addComponent(classificationBox); |
181 | 170 |
verticalLayout.addComponent(distAreaBox); |
171 |
verticalLayout.addComponent(namedAreaList); |
|
182 | 172 |
verticalLayout.addComponent(boxToggleAbbreviatedLabels); |
183 | 173 |
verticalLayout.addComponent(distStatusSelect); |
184 | 174 |
verticalLayout.setExpandRatio(distStatusSelect, 1); |
... | ... | |
187 | 177 |
topContainer.addComponent(verticalLayout); |
188 | 178 |
topContainer.addComponent(taxonTree); |
189 | 179 |
topContainer.setExpandRatio(taxonTree, 1); |
180 |
topContainer.addComponent(labelNoClassification); |
|
181 |
topContainer.setComponentAlignment(labelNoClassification, Alignment.BOTTOM_RIGHT); |
|
190 | 182 |
topContainer.setExpandRatio(verticalLayout, 1); |
191 | 183 |
|
192 | 184 |
//button toolbar |
... | ... | |
210 | 202 |
return mainLayout; |
211 | 203 |
} |
212 | 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 |
|
|
213 | 257 |
} |
Also available in: Unified diff
ref #5458 Redesign navigation architecture