1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.vaadin.component;
|
10
|
|
11
|
import org.vaadin.viritin.fields.CaptionGenerator;
|
12
|
import org.vaadin.viritin.fields.LazyComboBox;
|
13
|
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
|
14
|
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
|
15
|
|
16
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
|
17
|
import eu.etaxonomy.cdm.vaadin.view.name.CachingPresenter;
|
18
|
|
19
|
/**
|
20
|
* A ToManyRelatedEntitiesListSelect which uses a {@link LazyComboBox} as data field.
|
21
|
*
|
22
|
* @author a.kohlbecker
|
23
|
* @since Jun 7, 2017
|
24
|
*
|
25
|
*/
|
26
|
public class ToManyRelatedEntitiesComboboxSelect<V extends Object> extends ToManyRelatedEntitiesListSelect<V, LazyComboBox<V>> {
|
27
|
|
28
|
private static final long serialVersionUID = -4496067980953939548L;
|
29
|
|
30
|
private FilterablePagingProvider<V> filterablePagingProvider = null;
|
31
|
private FilterableCountProvider filterableCountProvider = null;
|
32
|
private Integer pageLength = null;
|
33
|
|
34
|
private CaptionGenerator<V> captionGenerator;
|
35
|
|
36
|
private CachingPresenter cachingPresenter;
|
37
|
|
38
|
/**
|
39
|
* @param itemType
|
40
|
* @param fieldType
|
41
|
* @param caption
|
42
|
*/
|
43
|
public ToManyRelatedEntitiesComboboxSelect(Class<V> itemType, String caption) {
|
44
|
super(itemType, null, caption);
|
45
|
// TODO this.fieldTyp = LazyComboBox.class does not work
|
46
|
LazyComboBox<V> field = new LazyComboBox<V>(itemType);
|
47
|
this.fieldType = (Class<LazyComboBox<V>>) field.getClass();
|
48
|
// addEmptyRowOnInitContent is false in this class since adding row is only possible after setting the PagingProviders
|
49
|
addEmptyRowOnInitContent = false;
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* {@inheritDoc}
|
54
|
*/
|
55
|
@Override
|
56
|
protected LazyComboBox<V> newFieldInstance(V val) throws InstantiationException, IllegalAccessException {
|
57
|
|
58
|
// TODO use the setEntityFieldInstantiator(EntityFieldInstantiator) instead to inject as instantiator?
|
59
|
LazyComboBox<V> field = new LazyComboBox<V>(itemType);
|
60
|
// FIXME using the ToOneRelatedEntityReloader created a dependency to the cdm packages, this should be relaxed!!!
|
61
|
field.addValueChangeListener(new ToOneRelatedEntityReloader(field, cachingPresenter));
|
62
|
|
63
|
if(filterablePagingProvider == null || filterableCountProvider == null || pageLength == null) {
|
64
|
throw new RuntimeException("The filterablePagingProvider, filterableCountProvider and pageLength must be set, use setPagingProviders().");
|
65
|
}
|
66
|
field.loadFrom(filterablePagingProvider, filterableCountProvider, pageLength);
|
67
|
if(captionGenerator != null){
|
68
|
field.setCaptionGenerator(captionGenerator);
|
69
|
}
|
70
|
field.setValue(val);
|
71
|
field.setWidth(100, Unit.PERCENTAGE);
|
72
|
return field;
|
73
|
}
|
74
|
|
75
|
public void setPagingProviders(FilterablePagingProvider<V> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength,
|
76
|
CachingPresenter cachingPresenter){
|
77
|
this.filterablePagingProvider = filterablePagingProvider;
|
78
|
this.filterableCountProvider = filterableCountProvider;
|
79
|
this.pageLength = pageLength;
|
80
|
this.cachingPresenter = cachingPresenter;
|
81
|
setInternalValue(null);
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* @param cdmTitleCacheCaptionGenerator
|
86
|
*/
|
87
|
public void setCaptionGenerator(CaptionGenerator<V> captionGenerator) {
|
88
|
this.captionGenerator = captionGenerator;
|
89
|
}
|
90
|
|
91
|
}
|