Project

General

Profile

Revision 33a5d14e

ID33a5d14e88e78548c2312dc0df79d0513acdccf9
Parent f81b22b6
Child 6ec7fb0b

Added by Patrick Plitzner almost 4 years ago

ref #5458 temp commit add tree to distribution selection

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/container/TaxonNodeContainer.java
6 6
import java.util.List;
7 7

  
8 8
import com.vaadin.data.Item;
9
import com.vaadin.data.util.IndexedContainer;
9
import com.vaadin.data.util.HierarchicalContainer;
10
import com.vaadin.ui.Tree;
10 11

  
11 12
import eu.etaxonomy.cdm.api.service.IClassificationService;
12 13
import eu.etaxonomy.cdm.model.name.Rank;
......
14 15
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
15 16
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
16 17

  
17
public class TaxonNodeContainer extends IndexedContainer {
18
public class TaxonNodeContainer extends HierarchicalContainer {
18 19

  
20
	private static final long serialVersionUID = 102401340698963360L;
19 21
	public static final String LABEL = "label";
20 22
	
23
	private Tree tree;
24
	
21 25
	/**
22 26
	 * Creates a new taxon node container
23 27
	 * @param parentNode the parent node which will <b>not</b> be included
24 28
	 * in the result but only its child nodes
25 29
	 */
26
	public TaxonNodeContainer(TaxonNode parentNode) {
27
		List<TaxonNode> taxonNodeList = getTaxonNodeList(parentNode);
30
	public TaxonNodeContainer(TaxonNode parentNode, Tree tree) {
31
		this.tree = tree;
32
		List<TaxonNode> taxonNodeList = getTaxonNodeList(parentNode, tree);
28 33
		addContainerProperty(LABEL, String.class, "[no taxon]");
29 34
		for (TaxonNode taxonNode : taxonNodeList) {
30 35
			Item item = addItem(taxonNode);
......
37 42
		}
38 43
	}
39 44
	
40
	public List<TaxonNode> getTaxonNodeList(TaxonNode parentNode) {
45
	public List<TaxonNode> getTaxonNodeList(TaxonNode parentNode, Tree tree) {
41 46
		List<TaxonNode> nodes = new ArrayList<TaxonNode>();
42 47
		
43 48
		List<String> nodeInitStrategy = Arrays.asList(new String[]{
......
51 56
			IClassificationService classificationService = CdmSpringContextHelper.getClassificationService();
52 57
			List<Classification> classificationList = classificationService.listClassifications(null, null, null, nodeInitStrategy);
53 58
			for (Classification classification : classificationList) {
54
				nodes.add(classification.getRootNode());
59
				TaxonNode rootNode = classification.getRootNode();
60
				setChildrenAllowed(rootNode, false);
61
				nodes.add(rootNode);
55 62
			}
56 63
		}
57 64
		else{
58 65
			//load child nodes
59
			nodes.addAll(addChildNodes(parentNode));
66
			nodes.addAll(addChildNodes(parentNode, tree));
60 67
		}
61 68
		return nodes;
62 69
	}
63 70

  
64
	private Collection<? extends TaxonNode> addChildNodes(TaxonNode parentNode) {
71
	private Collection<? extends TaxonNode> addChildNodes(TaxonNode parentNode, Tree tree) {
72
		tree.addItem(parentNode);
65 73
		List<TaxonNode> nodes = new ArrayList<TaxonNode>();
66
		for (TaxonNode taxonNode : parentNode.getChildNodes()) {
74
		List<TaxonNode> childNodes = parentNode.getChildNodes();
75
		setChildrenAllowed(parentNode, !childNodes.isEmpty());
76
		for (TaxonNode taxonNode : childNodes) {
67 77
			if(taxonNode!=null && taxonNode.getTaxon()!=null && taxonNode.getTaxon().getName()!=null){
68 78
				Rank rank = taxonNode.getTaxon().getName().getRank();
69 79
				if(rank!=null && rank.isHigher(Rank.SPECIES())){
70 80
					nodes.add(taxonNode);
71
					addChildNodes(taxonNode);
81
					tree.setParent(taxonNode, parentNode);
82
					addChildNodes(taxonNode, tree);
83
				}
84
				else{
85
					tree.setChildrenAllowed(parentNode, false);
72 86
				}
73 87
			}
74 88
		}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java
19 19
import com.vaadin.ui.CustomComponent;
20 20
import com.vaadin.ui.Label;
21 21
import com.vaadin.ui.Panel;
22
import com.vaadin.ui.Tree;
22 23
import com.vaadin.ui.VerticalLayout;
23 24

  
24 25
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
......
34 35
    private Button button_proceed;
35 36
    private ComboBox distributionAreaBox;
36 37
    private ComboBox classificationBox;
38
    private Tree taxonTree;
37 39
    private ComboBox taxonBox;
38 40
    private Label label_1;
39 41

  
......
76 78

  
77 79
	public void dataBinding(){
78 80
		classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
79
		classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
81
		classificationBox.setContainerDataSource(new TaxonNodeContainer(null, taxonTree));
80 82
		classificationBox.setImmediate(true);
81 83
		classificationBox.addValueChangeListener(new ValueChangeListener() {
82 84
			@Override
83 85
			public void valueChange(ValueChangeEvent event) {
84 86
				TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
85
				taxonBox.setContainerDataSource(new TaxonNodeContainer(parentNode));
87
				taxonBox.setContainerDataSource(new TaxonNodeContainer(parentNode, taxonTree));
88
				taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode, taxonTree));
86 89
			}
87 90
		});
91

  
92
		taxonTree.setContainerDataSource(new TaxonNodeContainer(null, taxonTree));
93
		taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
88 94
		
89 95
		taxonBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
90 96
		List<TermVocabulary<DefinedTermBase>> namedAreaList = distListener.getNamedAreaList();
......
160 166
        classificationBox.setHeight("-1px");
161 167
        verticalLayout_2.addComponent(classificationBox);
162 168

  
169
        // taxon tree
170
        taxonTree = new Tree("Taxonomy");
171
        verticalLayout_2.addComponent(taxonTree);
172

  
163 173
        // taxonBox
164 174
        taxonBox = new ComboBox();
165 175
        taxonBox.setCaption("Taxon: ");

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)