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 com.vaadin.data.Container;
|
12
|
import com.vaadin.data.Property;
|
13
|
import com.vaadin.data.fieldgroup.FieldGroup;
|
14
|
import com.vaadin.server.FontAwesome;
|
15
|
import com.vaadin.ui.Button;
|
16
|
import com.vaadin.ui.Button.ClickListener;
|
17
|
import com.vaadin.ui.Component;
|
18
|
import com.vaadin.ui.CssLayout;
|
19
|
import com.vaadin.ui.ListSelect;
|
20
|
import com.vaadin.ui.themes.ValoTheme;
|
21
|
|
22
|
/**
|
23
|
* @author a.kohlbecker
|
24
|
* @since May 24, 2017
|
25
|
*
|
26
|
*/
|
27
|
public class ToOneRelatedEntityListSelect<V extends Object> extends CompositeCustomField<V> implements ToOneRelatedEntityField {
|
28
|
|
29
|
private static final long serialVersionUID = 6277565876657520311L;
|
30
|
|
31
|
public static final String PRIMARY_STYLE = "v-related-entity-list-select";
|
32
|
|
33
|
private Class<V> type;
|
34
|
|
35
|
private CssLayout container = new CssLayout();
|
36
|
|
37
|
private ListSelect select;
|
38
|
|
39
|
|
40
|
private Button addButton = new Button(FontAwesome.PLUS);
|
41
|
private Button editButton = new Button(FontAwesome.EDIT);
|
42
|
|
43
|
public ToOneRelatedEntityListSelect(String caption, Class<V> type, Container dataSource){
|
44
|
this.type = type;
|
45
|
select = new ListSelect(caption, dataSource);
|
46
|
addStyledComponents(select, addButton, editButton);
|
47
|
addSizedComponent(select);
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* {@inheritDoc}
|
52
|
*/
|
53
|
@Override
|
54
|
protected Component initContent() {
|
55
|
container.addComponents(select, addButton, editButton);
|
56
|
setPrimaryStyleName(PRIMARY_STYLE);
|
57
|
addDefaultStyles();
|
58
|
return container;
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* {@inheritDoc}
|
63
|
*/
|
64
|
@Override
|
65
|
public Class<? extends V> getType() {
|
66
|
return type;
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* {@inheritDoc}
|
71
|
*/
|
72
|
@Override
|
73
|
protected void addDefaultStyles() {
|
74
|
container.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* {@inheritDoc}
|
79
|
*/
|
80
|
@Override
|
81
|
public FieldGroup getFieldGroup() {
|
82
|
return null;
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* @return the select
|
87
|
* @deprecated list specific method should not be in the interface
|
88
|
*/
|
89
|
@Deprecated
|
90
|
public ListSelect getSelect() {
|
91
|
return select;
|
92
|
}
|
93
|
|
94
|
|
95
|
|
96
|
/**
|
97
|
* {@inheritDoc}
|
98
|
*/
|
99
|
@Override
|
100
|
public void setPropertyDataSource(Property newDataSource) {
|
101
|
select.setPropertyDataSource(newDataSource);
|
102
|
}
|
103
|
|
104
|
@Override
|
105
|
public Property getPropertyDataSource() {
|
106
|
return select.getPropertyDataSource();
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* {@inheritDoc}
|
111
|
*/
|
112
|
@Override
|
113
|
public void addClickListenerAddEntity(ClickListener listener) {
|
114
|
addButton.addClickListener(listener);
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* {@inheritDoc}
|
119
|
*/
|
120
|
@Override
|
121
|
public void addClickListenerEditEntity(ClickListener listener) {
|
122
|
editButton.addClickListener(listener);
|
123
|
}
|
124
|
|
125
|
|
126
|
}
|