ref #6169 RelatedEntityListSelect (ToOneRelatedEntityField) edit and select working...
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / vaadin / component / ToOneRelatedEntityListSelect.java
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 private Button addButton = new Button(FontAwesome.PLUS);
40 private Button editButton = new Button(FontAwesome.EDIT);
41
42 public ToOneRelatedEntityListSelect(String caption, Class<V> type, Container dataSource){
43 this.type = type;
44 select = new ListSelect(caption, dataSource);
45 addStyledComponents(select, addButton, editButton);
46 addSizedComponent(select);
47 }
48
49 /**
50 * {@inheritDoc}
51 */
52 @Override
53 protected Component initContent() {
54 container.addComponents(select, addButton, editButton);
55 setPrimaryStyleName(PRIMARY_STYLE);
56 addDefaultStyles();
57 return container;
58 }
59
60 /**
61 * {@inheritDoc}
62 */
63 @Override
64 public Class<? extends V> getType() {
65 return type;
66 }
67
68 /**
69 * {@inheritDoc}
70 */
71 @Override
72 protected void addDefaultStyles() {
73 container.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
74 }
75
76 /**
77 * {@inheritDoc}
78 */
79 @Override
80 public FieldGroup getFieldGroup() {
81 return null;
82 }
83
84 /**
85 * @return the select
86 */
87 public ListSelect getSelect() {
88 return select;
89 }
90
91
92
93 /**
94 * {@inheritDoc}
95 */
96 @Override
97 public void setPropertyDataSource(Property newDataSource) {
98 select.setPropertyDataSource(newDataSource);
99 }
100
101 @Override
102 public Property getPropertyDataSource() {
103 return select.getPropertyDataSource();
104 }
105
106 /**
107 * {@inheritDoc}
108 */
109 @Override
110 public void addClickListenerAddEntity(ClickListener listener) {
111 addButton.addClickListener(listener);
112 }
113
114 /**
115 * {@inheritDoc}
116 */
117 @Override
118 public void addClickListenerEditEntity(ClickListener listener) {
119 editButton.addClickListener(listener);
120 }
121
122
123 }