Project

General

Profile

Download (2.95 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.LazyComboBox;
12
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
13
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
14

    
15
import com.vaadin.data.fieldgroup.FieldGroup;
16
import com.vaadin.server.FontAwesome;
17
import com.vaadin.ui.Button;
18
import com.vaadin.ui.Button.ClickListener;
19
import com.vaadin.ui.Component;
20
import com.vaadin.ui.CssLayout;
21
import com.vaadin.ui.themes.ValoTheme;
22

    
23
/**
24
 * @author a.kohlbecker
25
 * @since May 24, 2017
26
 *
27
 */
28
public class ToOneRelatedEntityCombobox<V extends Object> extends CompositeCustomField<V> implements ToOneRelatedEntityField {
29

    
30
    private static final long serialVersionUID = 6277565876657520311L;
31

    
32
    public static final String PRIMARY_STYLE = "v-related-entity-combobox";
33

    
34
    private Class<V> type;
35

    
36
    private CssLayout container = new CssLayout();
37

    
38
    private LazyComboBox<V> lazySelect;
39

    
40
    private Button addButton = new Button(FontAwesome.PLUS);
41
    private Button editButton  = new Button(FontAwesome.EDIT);
42

    
43
    public ToOneRelatedEntityCombobox(String caption, Class<V> type){
44
        this.type = type;
45
        lazySelect = new LazyComboBox<V>(type);
46
        addStyledComponents(lazySelect, addButton, editButton);
47
        addSizedComponents(lazySelect, container);
48
    }
49

    
50

    
51
    /**
52
     * {@inheritDoc}
53
     */
54
    @Override
55
    protected Component initContent() {
56
        container.addComponents(lazySelect, addButton, editButton);
57
        setPrimaryStyleName(PRIMARY_STYLE);
58
        addDefaultStyles();
59
        return container;
60
    }
61

    
62
    /**
63
     * {@inheritDoc}
64
     */
65
    @Override
66
    public Class<? extends V> getType() {
67
        return type;
68
    }
69

    
70
    /**
71
     * {@inheritDoc}
72
     */
73
    @Override
74
    protected void addDefaultStyles() {
75
        container.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
76
    }
77

    
78
    /**
79
     * {@inheritDoc}
80
     */
81
    @Override
82
    public FieldGroup getFieldGroup() {
83
        return null;
84
    }
85

    
86
    /**
87
     * @return the select
88
     */
89
    public LazyComboBox<V> getSelect() {
90
        return lazySelect;
91
    }
92

    
93
    /**
94
     * {@inheritDoc}
95
     */
96
    public void loadFrom(FilterablePagingProvider<V> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength) {
97
        lazySelect.loadFrom(filterablePagingProvider, filterableCountProvider, pageLength);
98

    
99
    }
100

    
101
    /**
102
     * {@inheritDoc}
103
     */
104
    @Override
105
    public void addClickListenerAddEntity(ClickListener listener) {
106
        addButton.addClickListener(listener);
107
    }
108

    
109
    /**
110
     * {@inheritDoc}
111
     */
112
    @Override
113
    public void addClickListenerEditEntity(ClickListener listener) {
114
        editButton.addClickListener(listener);
115
    }
116

    
117
}
(7-7/9)