Project

General

Profile

Download (3.5 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.CdmBase;
13
import eu.etaxonomy.cdm.model.common.Language;
14
import eu.etaxonomy.cdm.model.description.CategoricalData;
15
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
16
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
17
import eu.etaxonomy.cdm.model.description.Distribution;
18
import eu.etaxonomy.cdm.model.description.StateData;
19
import eu.etaxonomy.cdm.model.description.TextData;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21

    
22

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

    
26

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

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

    
34
	}
35

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

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

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

    
64
			if(deb.isInstanceOf(CategoricalData.class)){
65
				CategoricalData cd = CdmBase.deproxy(deb, CategoricalData.class);
66
				if(cd.getStatesOnly().size() <= 1){
67
					for(StateData st  : cd.getStateData()){
68
						tree.addItem(st);
69
						tree.setItemCaption(st, st.getState().getTitleCache());
70
						tree.setParent(st, deb.getFeature());
71
						tree.setChildrenAllowed(st, false);
72
					}
73
				}else{
74
					//TODO: implement recursion
75
				}
76
			}else if(deb.isInstanceOf(TextData.class)){
77
				TextData td = CdmBase.deproxy(deb,TextData.class);
78
				tree.addItem(td);
79
				tree.setItemCaption(td, td.getText(Language.GERMAN()));
80
				tree.setParent(td, deb.getFeature());
81
				tree.setChildrenAllowed(td, false);
82
			}else if(deb.isInstanceOf(CommonTaxonName.class)){
83
			    CommonTaxonName td = CdmBase.deproxy(deb, CommonTaxonName.class);
84
			    tree.addItem(td);
85
			    tree.setItemCaption(td, td.getName());
86
			    tree.setParent(td, deb.getFeature());
87
			    tree.setChildrenAllowed(td, false);
88
			}else if(deb.isInstanceOf(Distribution.class)){
89
				Distribution db = CdmBase.deproxy(deb, Distribution.class);
90
				tree.addItem(db.toString());
91
				tree.setParent(db.toString(), deb.getFeature());
92
				tree.setChildrenAllowed(db.toString(), true);
93
				tree.addItem(db.getStatus().toString());
94
				tree.setParent(db.getStatus().toString(), db.toString());
95
				tree.setChildrenAllowed(db.getStatus().toString(), false);
96
			}
97
			tree.expandItemsRecursively(parent);
98
		}
99

    
100
	}
101

    
102
}
(4-4/8)