Project

General

Profile

Download (3.63 KB) Statistics
| Branch: | Tag: | Revision:
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
        // addEmptyRowOnInitContent is false in this class since adding row is only possible after setting the PagingProviders
44
        addEmptyRowOnInitContent = false;
45
    }
46

    
47
    /**
48
     * {@inheritDoc}
49
     */
50
    @Override
51
    protected LazyComboBox<V> newFieldInstance(V val) throws InstantiationException, IllegalAccessException {
52
        LazyComboBox<V> field = new LazyComboBox<V>(itemType);
53

    
54
        if(filterablePagingProvider == null || filterableCountProvider == null ||  pageLength == null) {
55
            throw new RuntimeException("The filterablePagingProvider, filterableCountProvider and pageLength must be set, use setPagingProviders().");
56
        }
57
        field.loadFrom(filterablePagingProvider, filterableCountProvider, pageLength);
58
        if(captionGenerator != null){
59
            field.setCaptionGenerator(captionGenerator);
60
        }
61
        field.setValue(val);
62
        field.setWidth(100, Unit.PERCENTAGE);
63
        return field;
64
    }
65

    
66
    public void setPagingProviders(FilterablePagingProvider<V> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength){
67
        this.filterablePagingProvider = filterablePagingProvider;
68
        this.filterableCountProvider = filterableCountProvider;
69
        this.pageLength = pageLength;
70
        setInternalValue(null);
71
    }
72

    
73
    /**
74
     * @param cdmTitleCacheCaptionGenerator
75
     */
76
    public void setCaptionGenerator(CaptionGenerator<V> captionGenerator) {
77
        this.captionGenerator = captionGenerator;
78
    }
79

    
80

    
81
    /**
82
     * {@inheritDoc}
83
     */
84
    @Override
85
    protected ClickListener newEditButtonClicklistener(LazyComboBox<V> field) {
86
        // TODO Auto-generated method stub
87
        return super.newEditButtonClicklistener(field);
88
    }
89

    
90
    /**
91
     * {@inheritDoc}
92
     */
93
    @Override
94
    protected ClickListener newAddButtonClicklistener(LazyComboBox<V> field) {
95
        // TODO Auto-generated method stub
96
        return super.newAddButtonClicklistener(field);
97
    }
98

    
99
    /**
100
     * {@inheritDoc}
101
     */
102
    @Override
103
    protected ClickListener newRemoveButtonClicklistener(LazyComboBox<V> field) {
104
        // TODO Auto-generated method stub
105
        return super.newRemoveButtonClicklistener(field);
106
    }
107

    
108

    
109

    
110
}
(6-6/10)