Revision 4d00f3a5
Added by Patrick Plitzner almost 8 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/container/TaxonNodeContainer.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.ArrayList; |
4 | 4 |
import java.util.Arrays; |
5 |
import java.util.Collection; |
|
5 | 6 |
import java.util.List; |
6 | 7 |
|
7 | 8 |
import com.vaadin.data.Item; |
8 | 9 |
import com.vaadin.data.util.IndexedContainer; |
9 | 10 |
|
10 | 11 |
import eu.etaxonomy.cdm.api.service.IClassificationService; |
11 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
12 | 12 |
import eu.etaxonomy.cdm.model.name.Rank; |
13 | 13 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
14 | 14 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
... | ... | |
19 | 19 |
public static final String LABEL = "label"; |
20 | 20 |
|
21 | 21 |
public TaxonNodeContainer() { |
22 |
List<TaxonNode> classificationList = getTaxonNodeList();
|
|
22 |
List<TaxonNode> taxonNodeList = getTaxonNodeList();
|
|
23 | 23 |
addContainerProperty(LABEL, String.class, "[no taxon]"); |
24 |
for (TaxonNode taxonNode : classificationList) {
|
|
24 |
for (TaxonNode taxonNode : taxonNodeList) {
|
|
25 | 25 |
Item item = addItem(taxonNode); |
26 | 26 |
if(taxonNode.getTaxon()!=null){ |
27 | 27 |
item.getItemProperty(LABEL).setValue(taxonNode.getTaxon().getName().getTitleCache()); |
... | ... | |
42 | 42 |
}); |
43 | 43 |
|
44 | 44 |
IClassificationService classificationService = CdmSpringContextHelper.getClassificationService(); |
45 |
ITaxonNodeService taxonNodeService = CdmSpringContextHelper.getTaxonNodeService(); |
|
46 | 45 |
List<Classification> classificationList = classificationService.listClassifications(null, null, null, nodeInitStrategy); |
47 | 46 |
for (Classification classification : classificationList) { |
48 | 47 |
nodes.add(classification.getRootNode()); |
49 | 48 |
} |
50 | 49 |
for (Classification classification : classificationList) { |
51 |
List<TaxonNode> allNodesForClassification = taxonNodeService.listAllNodesForClassification(classification, null, null); |
|
52 |
for (TaxonNode taxonNode : allNodesForClassification) { |
|
53 |
if(taxonNode.getTaxon()!=null && taxonNode.getTaxon().getName()!=null && taxonNode.getTaxon().getName().getRank()!=null){ |
|
54 |
Rank rank = taxonNode.getTaxon().getName().getRank(); |
|
55 |
if(rank.isHigher(Rank.SPECIES()) || rank.equals(Rank.SPECIES())){ |
|
56 |
nodes.add(taxonNode); |
|
57 |
} |
|
50 |
nodes.addAll(addChildNodes(classification.getRootNode())); |
|
51 |
} |
|
52 |
return nodes; |
|
53 |
} |
|
54 |
|
|
55 |
private Collection<? extends TaxonNode> addChildNodes(TaxonNode parentNode) { |
|
56 |
List<TaxonNode> nodes = new ArrayList<TaxonNode>(); |
|
57 |
for (TaxonNode taxonNode : parentNode.getChildNodes()) { |
|
58 |
if(taxonNode.getTaxon()!=null && taxonNode.getTaxon().getName()!=null){ |
|
59 |
Rank rank = taxonNode.getTaxon().getName().getRank(); |
|
60 |
if(rank!=null && rank.isHigher(Rank.SPECIES())){ |
|
61 |
nodes.add(taxonNode); |
|
62 |
addChildNodes(taxonNode); |
|
58 | 63 |
} |
59 | 64 |
} |
60 | 65 |
} |
Also available in: Unified diff
Optimize taxon node container #5458