Project

General

Profile

Download (3.78 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.Label;
10
import com.vaadin.ui.Tree;
11
import com.vaadin.ui.Window;
12

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

    
24

    
25
@Scope("prototype")
26
public class DetailWindow extends CustomComponent{
27

    
28

    
29
	private final Collection<DescriptionElementBase> listDescriptions;
30
	private final Taxon taxon;
31

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

    
36
	}
37

    
38
	public Window createWindow(){
39
		Window window = new Window();
40
		window.setHeightUndefined();
41
		window.setHeight("600px");
42
		window.setWidth("400px");
43
		window.setCaption(taxon.getName().getTitleCache());
44
		window.setCloseShortcut(KeyCode.W, ModifierKey.CTRL);
45
		if(listDescriptions.isEmpty()){
46
			window.setContent(new Label("No descriptive data found"));
47
		}
48
		else{
49
			window.setContent(constructDescriptionTree(taxon));
50
		}
51
		return window;
52
	}
53

    
54
	private Tree constructDescriptionTree(Taxon taxon){
55
		Tree tree = new Tree();
56
		tree.setSizeUndefined();
57
		String parent = "Descriptive Data";
58
		tree.setValue(parent);
59
		initDescriptionTree(tree, listDescriptions, parent);
60
		return tree;
61
	}
62

    
63
	private void initDescriptionTree(Tree tree, Collection<DescriptionElementBase>listDescriptions, Object parent) {
64
		//TODO: sorting List
65
		for (DescriptionElementBase deb : listDescriptions){
66
			tree.addItem(deb.getFeature());
67
			tree.setItemCaption(deb.getFeature(), deb.getFeature().getTitleCache());
68
			tree.setParent(deb.getFeature(), parent);
69
			tree.setChildrenAllowed(deb.getFeature(), true);
70

    
71
			if(deb.isInstanceOf(CategoricalData.class)){
72
				CategoricalData cd = CdmBase.deproxy(deb, CategoricalData.class);
73
				if(cd.getStatesOnly().size() <= 1){
74
					for(StateData st  : cd.getStateData()){
75
						tree.addItem(st);
76
						tree.setItemCaption(st, st.getState().getTitleCache());
77
						tree.setParent(st, deb.getFeature());
78
						tree.setChildrenAllowed(st, false);
79
					}
80
				}else{
81
					//TODO: implement recursion
82
				}
83
			}else if(deb.isInstanceOf(TextData.class)){
84
				TextData td = CdmBase.deproxy(deb,TextData.class);
85
				tree.addItem(td);
86
				tree.setItemCaption(td, td.getText(Language.GERMAN()));
87
				tree.setParent(td, deb.getFeature());
88
				tree.setChildrenAllowed(td, false);
89
			}else if(deb.isInstanceOf(CommonTaxonName.class)){
90
			    CommonTaxonName td = CdmBase.deproxy(deb, CommonTaxonName.class);
91
			    tree.addItem(td);
92
			    tree.setItemCaption(td, td.getName());
93
			    tree.setParent(td, deb.getFeature());
94
			    tree.setChildrenAllowed(td, false);
95
			}else if(deb.isInstanceOf(Distribution.class)){
96
			    Distribution db = CdmBase.deproxy(deb, Distribution.class);
97
			    PresenceAbsenceTerm status = db.getStatus();
98
			    if(status!=null){
99
			        tree.addItem(db.toString());
100
			        tree.setParent(db.toString(), deb.getFeature());
101
			        tree.setChildrenAllowed(db.toString(), true);
102
				    tree.addItem(status.toString());
103
				    tree.setParent(status.toString(), db.toString());
104
				    tree.setChildrenAllowed(status.toString(), false);
105
				}
106
			}
107
			tree.expandItemsRecursively(parent);
108
		}
109

    
110
	}
111

    
112
}
(3-3/6)