2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.vaadin
.component
;
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
;
23 * @author a.kohlbecker
27 public class ToOneRelatedEntityListSelect
<V
extends Object
> extends CompositeCustomField
<V
> implements ToOneRelatedEntityField
<V
> {
29 private static final long serialVersionUID
= 6277565876657520311L;
31 public static final String PRIMARY_STYLE
= "v-related-entity-list-select";
33 private Class
<V
> type
;
35 private CssLayout container
= new CssLayout();
37 private ListSelect select
;
40 private Button addButton
= new Button(FontAwesome
.PLUS
);
41 private Button editButton
= new Button(FontAwesome
.EDIT
);
43 public ToOneRelatedEntityListSelect(String caption
, Class
<V
> type
, Container dataSource
){
46 select
= new ListSelect(caption
, dataSource
);
47 addStyledComponents(select
, addButton
, editButton
);
48 addSizedComponent(select
);
55 protected Component
initContent() {
56 container
.addComponents(select
, addButton
, editButton
);
57 setPrimaryStyleName(PRIMARY_STYLE
);
66 public Class
<?
extends V
> getType() {
74 protected void addDefaultStyles() {
75 container
.addStyleName(ValoTheme
.LAYOUT_COMPONENT_GROUP
);
82 public FieldGroup
getFieldGroup() {
88 * @deprecated list specific method should not be in the interface
91 public ListSelect
getSelect() {
99 public void setPropertyDataSource(Property newDataSource
) {
100 select
.setPropertyDataSource(newDataSource
);
104 public Property
getPropertyDataSource() {
105 return select
.getPropertyDataSource();
112 public void addClickListenerAddEntity(ClickListener listener
) {
113 addButton
.addClickListener(listener
);
120 public void setAddButtonEnabled(boolean enabled
) {
121 addButton
.setEnabled(enabled
);
128 public void addClickListenerEditEntity(ClickListener listener
) {
129 editButton
.addClickListener(listener
);
136 public void setEditButtonEnabled(boolean enabled
) {
137 editButton
.setEnabled(enabled
);
144 public void selectNewItem(V bean
) {
146 select
.addItem(bean
);