Revision f8b0de79
Added by Patrick Plitzner over 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.vaadin.view.dbstatus; |
11 | 11 |
|
12 |
import java.sql.SQLException; |
|
12 | 13 |
import java.util.Collection; |
13 | 14 |
import java.util.Set; |
14 | 15 |
import java.util.UUID; |
... | ... | |
32 | 33 |
import com.vaadin.ui.TreeTable; |
33 | 34 |
import com.vaadin.ui.VerticalLayout; |
34 | 35 |
|
35 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
36 | 36 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
37 | 37 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
38 | 38 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
39 | 39 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
40 |
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer; |
|
40 | 41 |
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer; |
41 | 42 |
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer; |
43 |
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory; |
|
42 | 44 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
43 | 45 |
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil; |
44 | 46 |
|
... | ... | |
71 | 73 |
//init classification and taxon selection |
72 | 74 |
TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode(); |
73 | 75 |
|
74 |
classificationBox.setContainerDataSource(new TaxonNodeContainer(null)); |
|
76 |
try { |
|
77 |
classificationBox.setContainerDataSource(new CdmSQLContainer(CdmQueryFactory.generateTableQuery("Classification"))); |
|
78 |
} catch (SQLException e) { |
|
79 |
DistributionEditorUtil.showSqlError(e); |
|
80 |
} |
|
75 | 81 |
Object classificationSelection = null; |
76 | 82 |
if(classificationBox.getItemIds().size()==1){ |
77 | 83 |
//only one classification exists |
... | ... | |
85 | 91 |
classificationBox.setValue(classificationSelection); |
86 | 92 |
taxonTree.addExpandListener(this); |
87 | 93 |
|
88 |
UUID uuid = ((CdmBase) classificationSelection).getUuid(); |
|
89 |
int id = ((CdmBase) classificationSelection).getId(); |
|
90 |
String titleCache = ((TaxonNode) classificationSelection).getClassification().getTitleCache(); |
|
94 |
String uuidString = (String) classificationBox.getContainerProperty(classificationSelection, "uuid").getValue(); |
|
95 |
int id = (int) classificationBox.getContainerProperty(classificationSelection, "id").getValue(); |
|
96 |
String titleCache = (String) classificationBox.getContainerProperty(classificationSelection, "titleCache").getValue(); |
|
97 |
UUID uuid = UUID.fromString(uuidString); |
|
91 | 98 |
UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache); |
92 | 99 |
taxonTree.setContainerDataSource(new TaxonNodeContainer(parent)); |
100 |
addChildItems(parent); |
|
93 | 101 |
if(chosenTaxonNode!=null){ |
94 | 102 |
taxonTree.select(new RowId(chosenTaxonNode.getId())); |
95 | 103 |
} |
... | ... | |
205 | 213 |
String titleCache = parentNode.getClassification().getTitleCache(); |
206 | 214 |
UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache); |
207 | 215 |
taxonTree.setContainerDataSource(new TaxonNodeContainer(parent)); |
208 |
} |
|
209 |
else{ |
|
210 |
taxonTree.setContainerDataSource(null); |
|
216 |
addChildItems(parent); |
|
211 | 217 |
} |
212 | 218 |
} |
213 |
|
|
214 | 219 |
else if(property==distAreaBox){ |
215 | 220 |
TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue(); |
216 | 221 |
NamedAreaContainer container = new NamedAreaContainer(vocabulary); |
... | ... | |
232 | 237 |
TermVocabulary<NamedArea> term = null; |
233 | 238 |
//TODO use field converter |
234 | 239 |
if(taxonTree.getValue()!=null){ |
235 |
taxonNode = CdmSpringContextHelper.getTaxonNodeService().find((Integer)((RowId) taxonTree.getValue()).getId()[0]);
|
|
240 |
taxonNode = CdmSpringContextHelper.getTaxonNodeService().load(((UuidAndTitleCache<TaxonNode>)taxonTree.getValue()).getUuid());
|
|
236 | 241 |
} |
237 | 242 |
if(taxonNode==null){ |
238 | 243 |
taxonNode = (TaxonNode) classificationBox.getValue(); |
... | ... | |
250 | 255 |
@Override |
251 | 256 |
public void nodeExpand(ExpandEvent event) { |
252 | 257 |
UuidAndTitleCache<TaxonNode> parent = (UuidAndTitleCache<TaxonNode>) event.getItemId(); |
258 |
addChildItems(parent); |
|
259 |
} |
|
260 |
|
|
261 |
/** |
|
262 |
* @param parent |
|
263 |
*/ |
|
264 |
private void addChildItems(UuidAndTitleCache<TaxonNode> parent) { |
|
253 | 265 |
Collection<UuidAndTitleCache<TaxonNode>> children = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(parent); |
254 | 266 |
taxonTree.setChildrenAllowed(parent, !children.isEmpty()); |
255 | 267 |
for (UuidAndTitleCache<TaxonNode> child : children) { |
256 | 268 |
Item childItem = taxonTree.addItem(child); |
257 | 269 |
if(childItem!=null){ |
258 | 270 |
taxonTree.setParent(child, parent); |
259 |
childItem.getItemProperty(TaxonNodeContainer.LABEL).setValue(child.getTitleCache()); |
|
260 | 271 |
} |
261 | 272 |
Collection<UuidAndTitleCache<TaxonNode>> grandChildren = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(child); |
262 | 273 |
taxonTree.setChildrenAllowed(child, !grandChildren.isEmpty()); |
Also available in: Unified diff
ref #5458 Fix item initialization problems