Revision f9517a12
Added by Patrick Plitzner over 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.vaadin.view.dbstatus; |
11 | 11 |
|
12 | 12 |
import java.sql.SQLException; |
13 |
import java.util.Collections; |
|
13 |
import java.util.Collection; |
|
14 |
import java.util.List; |
|
14 | 15 |
import java.util.Set; |
15 | 16 |
import java.util.UUID; |
16 | 17 |
|
17 | 18 |
import com.vaadin.data.Property; |
18 | 19 |
import com.vaadin.data.Property.ValueChangeEvent; |
19 | 20 |
import com.vaadin.data.Property.ValueChangeListener; |
21 |
import com.vaadin.data.util.BeanItemContainer; |
|
20 | 22 |
import com.vaadin.data.util.sqlcontainer.RowId; |
21 | 23 |
import com.vaadin.server.VaadinSession; |
22 | 24 |
import com.vaadin.ui.AbstractLayout; |
... | ... | |
27 | 29 |
import com.vaadin.ui.HorizontalLayout; |
28 | 30 |
import com.vaadin.ui.ListSelect; |
29 | 31 |
import com.vaadin.ui.Table.ColumnHeaderMode; |
32 |
import com.vaadin.ui.TextField; |
|
30 | 33 |
import com.vaadin.ui.Tree.ExpandEvent; |
31 | 34 |
import com.vaadin.ui.Tree.ExpandListener; |
32 | 35 |
import com.vaadin.ui.TreeTable; |
33 | 36 |
import com.vaadin.ui.VerticalLayout; |
34 | 37 |
|
38 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
35 | 39 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
36 | 40 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
37 | 41 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
... | ... | |
52 | 56 |
|
53 | 57 |
private static final long serialVersionUID = 1439411115014088780L; |
54 | 58 |
private ComboBox classificationBox; |
59 |
private TextField taxonFilter; |
|
55 | 60 |
private ComboBox distAreaBox; |
56 | 61 |
private ListSelect namedAreaList; |
57 | 62 |
private TreeTable taxonTree; |
... | ... | |
90 | 95 |
classificationBox.setValue(classificationSelection); |
91 | 96 |
taxonTree.addExpandListener(this); |
92 | 97 |
|
93 |
String uuidString = (String) classificationBox.getContainerProperty(classificationSelection, "uuid").getValue(); |
|
94 |
int id = (int) classificationBox.getContainerProperty(classificationSelection, "id").getValue(); |
|
95 |
String titleCache = (String) classificationBox.getContainerProperty(classificationSelection, "titleCache").getValue(); |
|
96 |
UUID uuid = UUID.fromString(uuidString); |
|
97 |
UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache); |
|
98 |
taxonTree.setContainerDataSource(new TaxonNodeContainer(Collections.singleton(parent))); |
|
98 |
UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationSelection); |
|
99 |
showClassificationTaxa(parent); |
|
99 | 100 |
if(chosenTaxonNode!=null){ |
100 | 101 |
taxonTree.select(new RowId(chosenTaxonNode.getId())); |
101 | 102 |
} |
102 | 103 |
} |
103 | 104 |
classificationBox.addValueChangeListener(this); |
105 |
taxonFilter.addValueChangeListener(this); |
|
104 | 106 |
|
105 | 107 |
TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea(); |
106 | 108 |
distAreaBox.setContainerDataSource(presenter.getDistributionContainer()); |
... | ... | |
141 | 143 |
rightContainer.setSpacing(true); |
142 | 144 |
rightContainer.setSizeFull(); |
143 | 145 |
|
144 |
//classification and term
|
|
146 |
//classification |
|
145 | 147 |
classificationBox = new ComboBox("Classification"); |
146 | 148 |
classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL); |
147 | 149 |
classificationBox.setInputPrompt("Please select a classification..."); |
... | ... | |
151 | 153 |
classificationBox.setSizeFull(); |
152 | 154 |
classificationBox.setWidth("100%"); |
153 | 155 |
|
156 |
//taxonFilter |
|
157 |
taxonFilter = new TextField("Filter"); |
|
158 |
taxonFilter.setInputPrompt("Filter taxa by name..."); |
|
159 |
taxonFilter.setSizeFull(); |
|
160 |
taxonFilter.setImmediate(true); |
|
161 |
|
|
154 | 162 |
//distribution area box |
155 | 163 |
distAreaBox = new ComboBox("Distribution Area:"); |
156 | 164 |
distAreaBox.setInputPrompt("Please select a distribution area..."); |
... | ... | |
181 | 189 |
leftContainer.setSizeFull(); |
182 | 190 |
|
183 | 191 |
rightContainer.addComponent(classificationBox); |
192 |
rightContainer.addComponent(taxonFilter); |
|
184 | 193 |
rightContainer.addComponent(taxonTree); |
185 | 194 |
rightContainer.setExpandRatio(classificationBox, 0.1f); |
186 |
rightContainer.setExpandRatio(taxonTree, 0.9f); |
|
195 |
rightContainer.setExpandRatio(taxonFilter, 0.1f); |
|
196 |
rightContainer.setExpandRatio(taxonTree, 0.8f); |
|
187 | 197 |
|
188 | 198 |
leftAndRightContainer.addComponent(leftContainer); |
189 | 199 |
leftAndRightContainer.addComponent(rightContainer); |
... | ... | |
205 | 215 |
Property property = event.getProperty(); |
206 | 216 |
if(property==classificationBox){ |
207 | 217 |
TaxonNode parentNode = (TaxonNode) event.getProperty().getValue(); |
208 |
if(parentNode!=null){ |
|
209 |
UUID uuid = parentNode.getUuid(); |
|
210 |
int id = parentNode.getId(); |
|
211 |
String titleCache = parentNode.getClassification().getTitleCache(); |
|
212 |
UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache); |
|
213 |
taxonTree.setContainerDataSource(new TaxonNodeContainer(Collections.singleton(parent))); |
|
218 |
UUID uuid = parentNode.getUuid(); |
|
219 |
int id = parentNode.getId(); |
|
220 |
String titleCache = parentNode.getClassification().getTitleCache(); |
|
221 |
UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache); |
|
222 |
showClassificationTaxa(parent); |
|
223 |
} |
|
224 |
else if(property==taxonFilter){ |
|
225 |
String filterText = taxonFilter.getValue(); |
|
226 |
if(CdmUtils.isNotBlank(filterText)){ |
|
227 |
List<UuidAndTitleCache<TaxonNode>> taxa = CdmSpringContextHelper.getTaxonNodeService().getUuidAndTitleCache(null, filterText); |
|
228 |
if(!taxa.isEmpty()){ |
|
229 |
BeanItemContainer<UuidAndTitleCache<TaxonNode>> container = new BeanItemContainer<>(UuidAndTitleCache.class); |
|
230 |
taxonTree.setContainerDataSource(container); |
|
231 |
for (UuidAndTitleCache<TaxonNode> taxon : taxa) { |
|
232 |
container.addItem(taxon); |
|
233 |
taxonTree.setChildrenAllowed(taxon, false); |
|
234 |
} |
|
235 |
taxonTree.setVisibleColumns("titleCache"); |
|
236 |
} |
|
237 |
} |
|
238 |
else{ |
|
239 |
UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationBox.getValue()); |
|
240 |
showClassificationTaxa(parent); |
|
214 | 241 |
} |
215 | 242 |
} |
216 | 243 |
else if(property==distAreaBox){ |
... | ... | |
257 | 284 |
((TaxonNodeContainer) taxonTree.getContainerDataSource()).addChildItems(parent); |
258 | 285 |
} |
259 | 286 |
|
287 |
private void showClassificationTaxa(UuidAndTitleCache<TaxonNode> parent) { |
|
288 |
Collection<UuidAndTitleCache<TaxonNode>> children = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(parent); |
|
289 |
taxonTree.setContainerDataSource(new TaxonNodeContainer(children)); |
|
290 |
} |
|
291 |
|
|
292 |
private UuidAndTitleCache<TaxonNode> getUuidAndTitleCacheFromRowId(Object classificationSelection) { |
|
293 |
String uuidString = (String) classificationBox.getContainerProperty(classificationSelection, "uuid").getValue(); |
|
294 |
int id = (int) classificationBox.getContainerProperty(classificationSelection, "id").getValue(); |
|
295 |
String titleCache = (String) classificationBox.getContainerProperty(classificationSelection, "titleCache").getValue(); |
|
296 |
UUID uuid = UUID.fromString(uuidString); |
|
297 |
UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache); |
|
298 |
return parent; |
|
299 |
} |
|
260 | 300 |
} |
Also available in: Unified diff
ref #5458 Add taxon filter to distribution settings