Revision 7cef91f1
Added by Alexander Oppermann over 9 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.vaadin.presenter.dbstatus; |
2 | 2 |
|
3 |
import java.util.Arrays; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.HashSet; |
|
6 |
import java.util.List; |
|
7 |
import java.util.Set; |
|
8 |
import java.util.UUID; |
|
9 |
|
|
10 |
import com.vaadin.data.util.BeanItemContainer; |
|
11 |
import com.vaadin.server.VaadinSession; |
|
12 |
import com.vaadin.ui.ComboBox; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
|
15 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
16 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
17 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
18 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
19 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
20 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
21 |
import eu.etaxonomy.cdm.model.description.Distribution; |
|
22 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
23 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
|
24 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
25 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
|
3 | 26 |
import eu.etaxonomy.cdm.vaadin.view.dbstatus.IDistributionTableComponent; |
4 | 27 |
|
5 | 28 |
|
6 | 29 |
public class DistributionTablePresenter implements IDistributionTableComponent.DistributionTableComponentListener{ |
7 | 30 |
|
31 |
private IVocabularyService vocabularyService; |
|
32 |
private IDescriptionService descriptionService; |
|
33 |
private ITermService termService; |
|
34 |
|
|
35 |
public DistributionTablePresenter(){ |
|
36 |
vocabularyService = (IVocabularyService)CdmSpringContextHelper.newInstance().getBean("vocabularyServiceImpl"); |
|
37 |
descriptionService = (IDescriptionService)CdmSpringContextHelper.newInstance().getBean("descriptionServiceImpl"); |
|
38 |
termService = (ITermService)CdmSpringContextHelper.newInstance().getBean("termServiceImpl"); |
|
39 |
} |
|
40 |
|
|
41 |
|
|
42 |
@Override |
|
43 |
public ComboBox updateDistributionField(DescriptionElementBase deb, |
|
44 |
Distribution db, |
|
45 |
BeanItemContainer<PresenceAbsenceTerm> termContainer, ComboBox box, |
|
46 |
Taxon taxon) { |
|
47 |
// TODO Auto-generated method stub |
|
48 |
return null; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public Set<DefinedTermBase> getChosenTerms() { |
|
53 |
VaadinSession session = VaadinSession.getCurrent(); |
|
54 |
UUID termUUID = (UUID) session.getAttribute("selectedTerm"); |
|
55 |
TermVocabulary<DefinedTermBase> term = vocabularyService.load(termUUID); |
|
56 |
term = CdmBase.deproxy(term, TermVocabulary.class); |
|
57 |
return term.getTerms(); |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon) { |
|
62 |
Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION())); |
|
63 |
List<DescriptionElementBase> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY); |
|
64 |
for(DescriptionElementBase deb : listTaxonDescription){ |
|
65 |
if(deb instanceof Distribution){ |
|
66 |
Distribution db = (Distribution)deb; |
|
67 |
String titleCache = dt.getTitleCache(); |
|
68 |
if(db.getArea().getTitleCache().equalsIgnoreCase(titleCache)){ |
|
69 |
HashMap<DescriptionElementBase, Distribution> map = new HashMap<DescriptionElementBase, Distribution>(); |
|
70 |
map.put(deb, db); |
|
71 |
return map; |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
return null; |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public List<PresenceAbsenceTerm> getPresenceAbsenceTerms() { |
|
80 |
//TODO Better to use TermType instead of class to get the list |
|
81 |
return termService.list(PresenceAbsenceTerm.class, null, null, null, DESCRIPTION_INIT_STRATEGY); |
|
82 |
} |
|
83 |
|
|
84 |
protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{ |
|
85 |
"$", |
|
86 |
"elements.*", |
|
87 |
"elements.sources.citation.authorship.$", |
|
88 |
"elements.sources.nameUsedInSource.originalNameString", |
|
89 |
"elements.area.level", |
|
90 |
"elements.modifyingText", |
|
91 |
"elements.states.*", |
|
92 |
"elements.media", |
|
93 |
"elements.multilanguageText", |
|
94 |
"multilanguageText", |
|
95 |
"stateData.$" |
|
96 |
}); |
|
97 |
|
|
98 |
|
|
99 |
|
|
8 | 100 |
} |
Also available in: Unified diff
table component