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.ui.Button;
|
15
|
import com.vaadin.ui.Button.ClickListener;
|
16
|
import com.vaadin.ui.Component;
|
17
|
import com.vaadin.ui.CssLayout;
|
18
|
import com.vaadin.ui.ListSelect;
|
19
|
import com.vaadin.ui.themes.ValoTheme;
|
20
|
|
21
|
import eu.etaxonomy.cdm.vaadin.component.ButtonFactory;
|
22
|
import eu.etaxonomy.cdm.vaadin.event.NestedButtonStateUpdater;
|
23
|
|
24
|
/**
|
25
|
* @author a.kohlbecker
|
26
|
* @since May 24, 2017
|
27
|
*
|
28
|
*/
|
29
|
public class ToOneRelatedEntityListSelect<V extends Object> extends CompositeCustomField<V> implements ToOneRelatedEntityField<V> {
|
30
|
|
31
|
private static final long serialVersionUID = 6277565876657520311L;
|
32
|
|
33
|
public static final String PRIMARY_STYLE = "v-related-entity-list-select";
|
34
|
|
35
|
private Class<V> type;
|
36
|
|
37
|
private CssLayout container = new CssLayout();
|
38
|
|
39
|
private ListSelect select;
|
40
|
|
41
|
NestedButtonStateUpdater<V> buttonUpdater;
|
42
|
|
43
|
private Button addButton = ButtonFactory.ADD_ITEM.createButton();
|
44
|
private Button editButton = ButtonFactory.EDIT_ITEM.createButton();
|
45
|
|
46
|
public ToOneRelatedEntityListSelect(String caption, Class<V> type, Container dataSource){
|
47
|
this.type = type;
|
48
|
setCaption(caption);
|
49
|
select = new ListSelect(caption, dataSource);
|
50
|
addStyledComponents(select, addButton, editButton);
|
51
|
addSizedComponent(select);
|
52
|
}
|
53
|
|
54
|
|
55
|
/**
|
56
|
* {@inheritDoc}
|
57
|
*/
|
58
|
@Override
|
59
|
protected Component initContent() {
|
60
|
container.addComponents(select, addButton, editButton);
|
61
|
setPrimaryStyleName(PRIMARY_STYLE);
|
62
|
addDefaultStyles();
|
63
|
return container;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* {@inheritDoc}
|
68
|
*/
|
69
|
@Override
|
70
|
public Class<? extends V> getType() {
|
71
|
return type;
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* {@inheritDoc}
|
76
|
*/
|
77
|
@Override
|
78
|
protected void addDefaultStyles() {
|
79
|
container.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* {@inheritDoc}
|
84
|
*/
|
85
|
@Override
|
86
|
public FieldGroup getFieldGroup() {
|
87
|
return null;
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* @return the select
|
92
|
* @deprecated list specific method should not be in
|
93
|
* the interface
|
94
|
*/
|
95
|
@Deprecated
|
96
|
public ListSelect getSelect() {
|
97
|
return select;
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* {@inheritDoc}
|
102
|
*/
|
103
|
@Override
|
104
|
public void setPropertyDataSource(Property newDataSource) {
|
105
|
select.setPropertyDataSource(newDataSource);
|
106
|
if(buttonUpdater != null){
|
107
|
buttonUpdater.updateButtons((V) select.getValue());
|
108
|
}
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public Property getPropertyDataSource() {
|
113
|
return select.getPropertyDataSource();
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* {@inheritDoc}
|
118
|
*/
|
119
|
@Override
|
120
|
public void addClickListenerAddEntity(ClickListener listener) {
|
121
|
addButton.addClickListener(listener);
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* {@inheritDoc}
|
126
|
*/
|
127
|
@Override
|
128
|
public void setAddButtonEnabled(boolean enabled) {
|
129
|
addButton.setEnabled(enabled);
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* {@inheritDoc}
|
134
|
*/
|
135
|
@Override
|
136
|
public void addClickListenerEditEntity(ClickListener listener) {
|
137
|
editButton.addClickListener(listener);
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* {@inheritDoc}
|
142
|
*/
|
143
|
@Override
|
144
|
public void setEditButtonEnabled(boolean enabled) {
|
145
|
editButton.setEnabled(enabled);
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* {@inheritDoc}
|
150
|
*/
|
151
|
@Override
|
152
|
public void selectNewItem(V bean) {
|
153
|
|
154
|
select.addItem(bean);
|
155
|
select.select(bean);
|
156
|
}
|
157
|
|
158
|
|
159
|
/**
|
160
|
* {@inheritDoc}
|
161
|
*/
|
162
|
@Override
|
163
|
public void setNestedButtonStateUpdater(NestedButtonStateUpdater<V> buttonUpdater) {
|
164
|
this.buttonUpdater = buttonUpdater;
|
165
|
select.addValueChangeListener(buttonUpdater);
|
166
|
}
|
167
|
|
168
|
|
169
|
}
|