Project

General

Profile

Download (2.7 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.FilterableCountProvider;
13
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
14

    
15
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
16
import eu.etaxonomy.cdm.vaadin.view.name.CachingPresenter;
17

    
18
/**
19
 * @author a.kohlbecker
20
 * @since May 3, 2018
21
 *
22
 */
23
public class ReloadableLazyComboBoxInstantiator<V extends Object> {
24

    
25
    private FilterablePagingProvider<V> filterablePagingProvider = null;
26
    private FilterableCountProvider filterableCountProvider = null;
27
    private Integer pageLength = null;
28

    
29
    private CaptionGenerator<V> captionGenerator;
30

    
31
    private CachingPresenter cachingPresenter;
32
    private Class<V> itemType;
33

    
34
    public ReloadableLazyComboBoxInstantiator(Class<V> itemType){
35
        this.itemType = itemType;
36
    }
37

    
38
    /**
39
     * {@inheritDoc}
40
     */
41
    protected ReloadableLazyComboBox<V> newInstance(V val) throws InstantiationException, IllegalAccessException {
42

    
43

    
44
        ReloadableLazyComboBox<V> field = new ReloadableLazyComboBox<V>(itemType);
45
        // FIXME using the ToOneRelatedEntityReloader created a dependency to the cdm packages, this should be relaxed!!!
46
        field.addValueChangeListener(new ToOneRelatedEntityReloader(field, cachingPresenter));
47

    
48
        if(filterablePagingProvider == null || filterableCountProvider == null ||  pageLength == null) {
49
            throw new RuntimeException("The filterablePagingProvider, filterableCountProvider and pageLength must be set, use setPagingProviders().");
50
        }
51
        field.loadFrom(filterablePagingProvider, filterableCountProvider, pageLength);
52
        if(captionGenerator != null){
53
            field.setCaptionGenerator(captionGenerator);
54
        }
55
        field.setValue(val);
56
        return field;
57
    }
58

    
59
    public void setPagingProviders(FilterablePagingProvider<V> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength,
60
            CachingPresenter cachingPresenter){
61
        this.filterablePagingProvider = filterablePagingProvider;
62
        this.filterableCountProvider = filterableCountProvider;
63
        this.pageLength = pageLength;
64
        this.cachingPresenter = cachingPresenter;
65
    }
66

    
67
    /**
68
     * @param cdmTitleCacheCaptionGenerator
69
     */
70
    public void setCaptionGenerator(CaptionGenerator<V> captionGenerator) {
71
        this.captionGenerator = captionGenerator;
72
    }
73

    
74

    
75

    
76
}
(9-9/17)