Project

General

Profile

Download (3.78 KB) Statistics
| Branch: | Tag: | Revision:
1 1a3e979c Alexander Oppermann
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 ce1318e1 Patrick Plitzner
import com.vaadin.ui.Label;
10 1a3e979c Alexander Oppermann
import com.vaadin.ui.Tree;
11
import com.vaadin.ui.Window;
12
13 4bdae8e0 Alexander Oppermann
import eu.etaxonomy.cdm.model.common.CdmBase;
14 1a3e979c Alexander Oppermann
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 bd46f97b Patrick Plitzner
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
20 1a3e979c Alexander Oppermann
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 ce1318e1 Patrick Plitzner
		window.setHeight("600px");
42
		window.setWidth("400px");
43 1a3e979c Alexander Oppermann
		window.setCaption(taxon.getName().getTitleCache());
44
		window.setCloseShortcut(KeyCode.W, ModifierKey.CTRL);
45 ce1318e1 Patrick Plitzner
		if(listDescriptions.isEmpty()){
46
			window.setContent(new Label("No descriptive data found"));
47
		}
48
		else{
49
			window.setContent(constructDescriptionTree(taxon));
50
		}
51 1a3e979c Alexander Oppermann
		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 4bdae8e0 Alexander Oppermann
			if(deb.isInstanceOf(CategoricalData.class)){
72
				CategoricalData cd = CdmBase.deproxy(deb, CategoricalData.class);
73 1a3e979c Alexander Oppermann
				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 4bdae8e0 Alexander Oppermann
			}else if(deb.isInstanceOf(TextData.class)){
84
				TextData td = CdmBase.deproxy(deb,TextData.class);
85 1a3e979c Alexander Oppermann
				tree.addItem(td);
86
				tree.setItemCaption(td, td.getText(Language.GERMAN()));
87
				tree.setParent(td, deb.getFeature());
88
				tree.setChildrenAllowed(td, false);
89 4bdae8e0 Alexander Oppermann
			}else if(deb.isInstanceOf(CommonTaxonName.class)){
90
			    CommonTaxonName td = CdmBase.deproxy(deb, CommonTaxonName.class);
91 1a3e979c Alexander Oppermann
			    tree.addItem(td);
92
			    tree.setItemCaption(td, td.getName());
93
			    tree.setParent(td, deb.getFeature());
94
			    tree.setChildrenAllowed(td, false);
95 4bdae8e0 Alexander Oppermann
			}else if(deb.isInstanceOf(Distribution.class)){
96 bd46f97b Patrick Plitzner
			    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 1a3e979c Alexander Oppermann
			}
107
			tree.expandItemsRecursively(parent);
108
		}
109
110
	}
111
112 7b2a0df1 Andreas Kohlbecker
}