Project

General

Profile

Download (3.33 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.vaadin.component;
2
import java.util.Collection;
3

    
4
import org.springframework.context.annotation.Scope;
5

    
6
import com.vaadin.event.ShortcutAction.KeyCode;
7
import com.vaadin.event.ShortcutAction.ModifierKey;
8
import com.vaadin.ui.CustomComponent;
9
import com.vaadin.ui.Tree;
10
import com.vaadin.ui.Window;
11

    
12
import eu.etaxonomy.cdm.model.common.Language;
13
import eu.etaxonomy.cdm.model.description.CategoricalData;
14
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
15
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
16
import eu.etaxonomy.cdm.model.description.Distribution;
17
import eu.etaxonomy.cdm.model.description.StateData;
18
import eu.etaxonomy.cdm.model.description.TextData;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20

    
21

    
22
@Scope("prototype")
23
public class DetailWindow extends CustomComponent{
24

    
25

    
26
	private final Collection<DescriptionElementBase> listDescriptions;
27
	private final Taxon taxon;
28

    
29
	public DetailWindow(Taxon taxon, Collection<DescriptionElementBase> listDescriptions) {
30
		this.taxon = taxon;
31
		this.listDescriptions = listDescriptions;
32

    
33
	}
34

    
35
	public Window createWindow(){
36
		Window window = new Window();
37
		window.setHeightUndefined();
38
//		window.setHeight("600px");
39
//		window.setWidth("400px");
40
		window.setCaption(taxon.getName().getTitleCache());
41
		window.setCloseShortcut(KeyCode.W, ModifierKey.CTRL);
42
		window.setContent(constructDescriptionTree(taxon));
43
		return window;
44
	}
45

    
46
	private Tree constructDescriptionTree(Taxon taxon){
47
		Tree tree = new Tree();
48
		tree.setSizeUndefined();
49
		String parent = "Descriptive Data";
50
		tree.setValue(parent);
51
		initDescriptionTree(tree, listDescriptions, parent);
52
		return tree;
53
	}
54

    
55
	private void initDescriptionTree(Tree tree, Collection<DescriptionElementBase>listDescriptions, Object parent) {
56
		//TODO: sorting List
57
		for (DescriptionElementBase deb : listDescriptions){
58
			tree.addItem(deb.getFeature());
59
			tree.setItemCaption(deb.getFeature(), deb.getFeature().getTitleCache());
60
			tree.setParent(deb.getFeature(), parent);
61
			tree.setChildrenAllowed(deb.getFeature(), true);
62

    
63
			if(deb instanceof CategoricalData){
64
				CategoricalData cd = (CategoricalData) deb;
65
				if(cd.getStatesOnly().size() <= 1){
66
					for(StateData st  : cd.getStateData()){
67
						tree.addItem(st);
68
						tree.setItemCaption(st, st.getState().getTitleCache());
69
						tree.setParent(st, deb.getFeature());
70
						tree.setChildrenAllowed(st, false);
71
					}
72
				}else{
73
					//TODO: implement recursion
74
				}
75
			}else if(deb instanceof TextData){
76
				TextData td = (TextData) deb;
77
				tree.addItem(td);
78
				tree.setItemCaption(td, td.getText(Language.GERMAN()));
79
				tree.setParent(td, deb.getFeature());
80
				tree.setChildrenAllowed(td, false);
81
			}else if(deb instanceof CommonTaxonName){
82
			    CommonTaxonName td = (CommonTaxonName) deb;
83
			    tree.addItem(td);
84
			    tree.setItemCaption(td, td.getName());
85
			    tree.setParent(td, deb.getFeature());
86
			    tree.setChildrenAllowed(td, false);
87
			}else if(deb instanceof Distribution){
88
				Distribution db = (Distribution) deb;
89

    
90
				tree.addItem(db.toString());
91
				tree.setParent(db.toString(), deb.getFeature());
92
				tree.setChildrenAllowed(db.toString(), true);
93

    
94
				tree.addItem(db.getStatus().toString());
95
				tree.setParent(db.getStatus().toString(), db.toString());
96
				tree.setChildrenAllowed(db.getStatus().toString(), false);
97
			}
98
			tree.expandItemsRecursively(parent);
99
		}
100

    
101
	}
102

    
103
}
(4-4/8)