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 com.vaadin.ui.Button.ClickListener;
|
17
|
|
18
|
/**
|
19
|
* @author a.kohlbecker
|
20
|
* @since Jun 7, 2017
|
21
|
*
|
22
|
*/
|
23
|
public class ToManyRelatedEntitiesComboboxSelect<V extends Object> extends ToManyRelatedEntitiesListSelect<V, LazyComboBox<V>> {
|
24
|
|
25
|
private static final long serialVersionUID = -4496067980953939548L;
|
26
|
|
27
|
private FilterablePagingProvider<V> filterablePagingProvider = null;
|
28
|
private FilterableCountProvider filterableCountProvider = null;
|
29
|
private Integer pageLength = null;
|
30
|
|
31
|
private CaptionGenerator<V> captionGenerator;
|
32
|
|
33
|
/**
|
34
|
* @param itemType
|
35
|
* @param fieldType
|
36
|
* @param caption
|
37
|
*/
|
38
|
public ToManyRelatedEntitiesComboboxSelect(Class<V> itemType, String caption) {
|
39
|
super(itemType, null, caption);
|
40
|
// TODO this.fieldTyp = LazyComboBox.class does not work
|
41
|
LazyComboBox<V> field = new LazyComboBox<V>(itemType);
|
42
|
this.fieldType = (Class<LazyComboBox<V>>) field.getClass();
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* {@inheritDoc}
|
47
|
*/
|
48
|
@Override
|
49
|
protected LazyComboBox<V> newFieldInstance(V val) throws InstantiationException, IllegalAccessException {
|
50
|
LazyComboBox<V> field = new LazyComboBox<V>(itemType);
|
51
|
|
52
|
if(filterablePagingProvider == null || filterableCountProvider == null || pageLength == null) {
|
53
|
throw new RuntimeException("The filterablePagingProvider, filterableCountProvider and pageLength must be set, use setPagingProviders().");
|
54
|
}
|
55
|
field.loadFrom(filterablePagingProvider, filterableCountProvider, pageLength);
|
56
|
if(captionGenerator != null){
|
57
|
field.setCaptionGenerator(captionGenerator);
|
58
|
}
|
59
|
field.setValue(val);
|
60
|
field.setWidth(100, Unit.PERCENTAGE);
|
61
|
return field;
|
62
|
}
|
63
|
|
64
|
public void setPagingProviders(FilterablePagingProvider<V> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength){
|
65
|
this.filterablePagingProvider = filterablePagingProvider;
|
66
|
this.filterableCountProvider = filterableCountProvider;
|
67
|
this.pageLength = pageLength;
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* @param cdmTitleCacheCaptionGenerator
|
72
|
*/
|
73
|
public void setCaptionGenerator(CaptionGenerator<V> captionGenerator) {
|
74
|
this.captionGenerator = captionGenerator;
|
75
|
}
|
76
|
|
77
|
|
78
|
/**
|
79
|
* {@inheritDoc}
|
80
|
*/
|
81
|
@Override
|
82
|
protected ClickListener newEditButtonClicklistener(LazyComboBox<V> field) {
|
83
|
// TODO Auto-generated method stub
|
84
|
return super.newEditButtonClicklistener(field);
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* {@inheritDoc}
|
89
|
*/
|
90
|
@Override
|
91
|
protected ClickListener newAddButtonClicklistener(LazyComboBox<V> field) {
|
92
|
// TODO Auto-generated method stub
|
93
|
return super.newAddButtonClicklistener(field);
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* {@inheritDoc}
|
98
|
*/
|
99
|
@Override
|
100
|
protected ClickListener newRemoveButtonClicklistener(LazyComboBox<V> field) {
|
101
|
// TODO Auto-generated method stub
|
102
|
return super.newRemoveButtonClicklistener(field);
|
103
|
}
|
104
|
|
105
|
|
106
|
|
107
|
}
|