Revision c8a10c34
Added by Andreas Kohlbecker almost 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/SelectFieldFactory.java | ||
---|---|---|
20 | 20 |
import com.vaadin.ui.ListSelect; |
21 | 21 |
|
22 | 22 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
23 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
23 | 24 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
24 | 25 |
import eu.etaxonomy.cdm.model.common.TermType; |
25 | 26 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
... | ... | |
62 | 63 |
return termItemContainer; |
63 | 64 |
} |
64 | 65 |
|
66 |
/** |
|
67 |
* |
|
68 |
* @param caption |
|
69 |
* @param type |
|
70 |
* @return |
|
71 |
*/ |
|
72 |
public <T extends CdmBase> ListSelect createListSelect(String caption, Class<T> type){ |
|
73 |
return createListSelect(caption, type, null); |
|
74 |
} |
|
75 |
|
|
76 |
public <T extends CdmBase> ListSelect createListSelect(String caption, Class<T> type, List<OrderHint> orderHints){ |
|
77 |
|
|
78 |
if(orderHints == null){ |
|
79 |
orderHints = OrderHint.defaultOrderHintsFor(type); |
|
80 |
} |
|
81 |
|
|
82 |
BeanItemContainer<T> termItemContainer = buildBeanItemContainer(type, orderHints); |
|
83 |
ListSelect select = new ListSelect(caption, termItemContainer); |
|
84 |
|
|
85 |
// guess property id to use for display |
|
86 |
String propertyId = null; |
|
87 |
if(orderHints != null && !orderHints.isEmpty()){ |
|
88 |
propertyId = orderHints.get(0).getPropertyName(); |
|
89 |
select.setItemCaptionPropertyId(propertyId); |
|
90 |
} |
|
91 |
return select; |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* @param termType |
|
96 |
*/ |
|
97 |
private <T extends CdmBase> BeanItemContainer<T> buildBeanItemContainer(Class<T> type, List<OrderHint> orderHints) { |
|
98 |
|
|
99 |
List<T> terms = repo.getCommonService().list(type, (Integer)null, (Integer)null, |
|
100 |
orderHints, |
|
101 |
Arrays.asList(new String[]{"$"})); |
|
102 |
BeanItemContainer<T> termItemContainer = new BeanItemContainer<>(type); |
|
103 |
termItemContainer.addAll(terms); |
|
104 |
return termItemContainer; |
|
105 |
} |
|
106 |
|
|
65 | 107 |
} |
Also available in: Unified diff
#6169 generic cdm entity select lists and using them in the Registration editor