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.i18n.Messages;
|
14
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
15
|
import eu.etaxonomy.cdm.model.common.Language;
|
16
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
17
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
18
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
19
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
20
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
21
|
import eu.etaxonomy.cdm.model.description.StateData;
|
22
|
import eu.etaxonomy.cdm.model.description.TextData;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
|
25
|
|
26
|
@Scope("prototype")
|
27
|
public class DetailWindow extends CustomComponent{
|
28
|
|
29
|
|
30
|
private final Collection<DescriptionElementBase> listDescriptions;
|
31
|
private final Taxon taxon;
|
32
|
|
33
|
public DetailWindow(Taxon taxon, Collection<DescriptionElementBase> listDescriptions) {
|
34
|
this.taxon = taxon;
|
35
|
this.listDescriptions = listDescriptions;
|
36
|
|
37
|
}
|
38
|
|
39
|
public Window createWindow(){
|
40
|
Window window = new Window();
|
41
|
window.setHeightUndefined();
|
42
|
window.setHeight("600px"); //$NON-NLS-1$
|
43
|
window.setWidth("400px"); //$NON-NLS-1$
|
44
|
window.setCaption(taxon.getName().getTitleCache());
|
45
|
window.setCloseShortcut(KeyCode.W, ModifierKey.CTRL);
|
46
|
if(listDescriptions.isEmpty()){
|
47
|
window.setContent(new Label(Messages.getLocalizedString(Messages.DetailWindow_NO_DESCRIPTIVE_DATA_FOUND)));
|
48
|
}
|
49
|
else{
|
50
|
window.setContent(constructDescriptionTree(taxon));
|
51
|
}
|
52
|
return window;
|
53
|
}
|
54
|
|
55
|
private Tree constructDescriptionTree(Taxon taxon){
|
56
|
Tree tree = new Tree();
|
57
|
tree.setSizeUndefined();
|
58
|
String parent = "Descriptive Data"; //$NON-NLS-1$
|
59
|
tree.setValue(parent);
|
60
|
initDescriptionTree(tree, listDescriptions, parent);
|
61
|
return tree;
|
62
|
}
|
63
|
|
64
|
private void initDescriptionTree(Tree tree, Collection<DescriptionElementBase>listDescriptions, Object parent) {
|
65
|
//TODO: sorting List
|
66
|
for (DescriptionElementBase deb : listDescriptions){
|
67
|
tree.addItem(deb.getFeature());
|
68
|
tree.setItemCaption(deb.getFeature(), deb.getFeature().getTitleCache());
|
69
|
tree.setParent(deb.getFeature(), parent);
|
70
|
tree.setChildrenAllowed(deb.getFeature(), true);
|
71
|
|
72
|
if(deb.isInstanceOf(CategoricalData.class)){
|
73
|
CategoricalData cd = CdmBase.deproxy(deb, CategoricalData.class);
|
74
|
if(cd.getStatesOnly().size() <= 1){
|
75
|
for(StateData st : cd.getStateData()){
|
76
|
tree.addItem(st);
|
77
|
tree.setItemCaption(st, st.getState().getTitleCache());
|
78
|
tree.setParent(st, deb.getFeature());
|
79
|
tree.setChildrenAllowed(st, false);
|
80
|
}
|
81
|
}else{
|
82
|
//TODO: implement recursion
|
83
|
}
|
84
|
}else if(deb.isInstanceOf(TextData.class)){
|
85
|
TextData td = CdmBase.deproxy(deb,TextData.class);
|
86
|
tree.addItem(td);
|
87
|
tree.setItemCaption(td, td.getText(Language.GERMAN()));
|
88
|
tree.setParent(td, deb.getFeature());
|
89
|
tree.setChildrenAllowed(td, false);
|
90
|
}else if(deb.isInstanceOf(CommonTaxonName.class)){
|
91
|
CommonTaxonName td = CdmBase.deproxy(deb, CommonTaxonName.class);
|
92
|
tree.addItem(td);
|
93
|
tree.setItemCaption(td, td.getName());
|
94
|
tree.setParent(td, deb.getFeature());
|
95
|
tree.setChildrenAllowed(td, false);
|
96
|
}else if(deb.isInstanceOf(Distribution.class)){
|
97
|
Distribution db = CdmBase.deproxy(deb, Distribution.class);
|
98
|
PresenceAbsenceTerm status = db.getStatus();
|
99
|
if(status!=null){
|
100
|
tree.addItem(db.toString());
|
101
|
tree.setParent(db.toString(), deb.getFeature());
|
102
|
tree.setChildrenAllowed(db.toString(), true);
|
103
|
tree.addItem(status.toString());
|
104
|
tree.setParent(status.toString(), db.toString());
|
105
|
tree.setChildrenAllowed(status.toString(), false);
|
106
|
}
|
107
|
}
|
108
|
tree.expandItemsRecursively(parent);
|
109
|
}
|
110
|
|
111
|
}
|
112
|
|
113
|
}
|