Revision 843f2ff8
Added by Andreas Kohlbecker almost 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/PersonField.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.vaadin.component.common; |
10 | 10 |
|
11 | 11 |
import com.vaadin.data.fieldgroup.BeanFieldGroup; |
12 |
import com.vaadin.data.fieldgroup.FieldGroup; |
|
12 | 13 |
import com.vaadin.ui.Component; |
13 | 14 |
import com.vaadin.ui.CssLayout; |
14 | 15 |
import com.vaadin.ui.TextField; |
... | ... | |
195 | 196 |
cacheField.addStyleName("cache-field"); |
196 | 197 |
detailsContainer.addStyleName("details-fields"); |
197 | 198 |
} |
199 |
|
|
200 |
/** |
|
201 |
* {@inheritDoc} |
|
202 |
*/ |
|
203 |
@Override |
|
204 |
public FieldGroup getFieldGroup() { |
|
205 |
return fieldGroup; |
|
206 |
} |
|
198 | 207 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.vaadin.component.common; |
10 | 10 |
|
11 | 11 |
import com.vaadin.data.fieldgroup.BeanFieldGroup; |
12 |
import com.vaadin.data.fieldgroup.FieldGroup; |
|
12 | 13 |
import com.vaadin.data.util.BeanItem; |
13 | 14 |
import com.vaadin.server.UserError; |
14 | 15 |
import com.vaadin.ui.Component; |
... | ... | |
97 | 98 |
compositeWrapper.addComponent(personField); |
98 | 99 |
|
99 | 100 |
personField.setValue((Person) newValue); |
101 |
personField.registerParentFieldGroup(fieldGroup); |
|
102 |
|
|
100 | 103 |
} |
101 | 104 |
else if(Team.class.isAssignableFrom(newValue.getClass())){ |
102 | 105 |
// otherwise it a Team |
... | ... | |
108 | 111 |
fieldGroup.bind(personsListEditor, "teamMembers"); |
109 | 112 |
|
110 | 113 |
fieldGroup.setItemDataSource(new BeanItem<Team>((Team)newValue)); |
114 |
personsListEditor.registerParentFieldGroup(fieldGroup); |
|
115 |
|
|
116 |
|
|
111 | 117 |
} else { |
112 | 118 |
setComponentError(new UserError("TeamOrPersonField Error: Unsupported value type: " + newValue.getClass().getName())); |
113 | 119 |
} |
... | ... | |
122 | 128 |
|
123 | 129 |
} |
124 | 130 |
|
131 |
/** |
|
132 |
* {@inheritDoc} |
|
133 |
*/ |
|
134 |
@Override |
|
135 |
public FieldGroup getFieldGroup() { |
|
136 |
return fieldGroup; |
|
137 |
} |
|
138 |
|
|
125 | 139 |
|
126 | 140 |
|
127 | 141 |
} |
src/main/java/eu/etaxonomy/vaadin/component/CompositeCustomField.java | ||
---|---|---|
12 | 12 |
import java.util.Arrays; |
13 | 13 |
import java.util.List; |
14 | 14 |
|
15 |
import com.vaadin.data.fieldgroup.FieldGroup; |
|
16 |
import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent; |
|
17 |
import com.vaadin.data.fieldgroup.FieldGroup.CommitException; |
|
18 |
import com.vaadin.data.fieldgroup.FieldGroup.CommitHandler; |
|
15 | 19 |
import com.vaadin.ui.Component; |
16 | 20 |
import com.vaadin.ui.CustomField; |
17 | 21 |
|
... | ... | |
23 | 27 |
* |
24 | 28 |
*/ |
25 | 29 |
@SuppressWarnings("serial") |
26 |
public abstract class CompositeCustomField<T> extends CustomField<T> { |
|
30 |
public abstract class CompositeCustomField<T> extends CustomField<T> implements NestedFieldGroup {
|
|
27 | 31 |
|
28 | 32 |
private List<Component> styledComponents = new ArrayList<>(); |
29 | 33 |
|
... | ... | |
134 | 138 |
*/ |
135 | 139 |
protected abstract void addDefaultStyles(); |
136 | 140 |
|
141 |
/** |
|
142 |
* Implementations return the local fieldGroup |
|
143 |
* |
|
144 |
* @return |
|
145 |
*/ |
|
146 |
@Override |
|
147 |
public abstract FieldGroup getFieldGroup(); |
|
148 |
|
|
149 |
@Override |
|
150 |
public void registerParentFieldGroup(FieldGroup parent) { |
|
151 |
parent.addCommitHandler(new CommitHandler() { |
|
152 |
|
|
153 |
@Override |
|
154 |
public void preCommit(CommitEvent commitEvent) throws CommitException { |
|
155 |
// commit the nested bean(s) first |
|
156 |
if(getFieldGroup() != null){ |
|
157 |
getFieldGroup().commit(); |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
public void postCommit(CommitEvent commitEvent) throws CommitException { |
|
163 |
// noting to do |
|
164 |
}} |
|
165 |
); |
|
166 |
} |
|
167 |
|
|
137 | 168 |
} |
src/main/java/eu/etaxonomy/vaadin/component/FieldListEditor.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.util.List; |
12 | 12 |
|
13 |
import com.vaadin.data.fieldgroup.FieldGroup; |
|
13 | 14 |
import com.vaadin.data.util.BeanItemContainer; |
14 | 15 |
import com.vaadin.server.FontAwesome; |
15 | 16 |
import com.vaadin.ui.AbstractField; |
... | ... | |
32 | 33 |
|
33 | 34 |
private Class<V> itemType; |
34 | 35 |
|
36 |
private FieldGroup parentFieldGroup = null; |
|
37 |
|
|
35 | 38 |
//NOTE: Managing the item |
36 | 39 |
// IDs makes BeanContainer more complex to use, but it is necessary in some cases where the |
37 | 40 |
// equals() or hashCode() methods have been reimplemented in the bean. |
... | ... | |
93 | 96 |
grid.setRows(newValue.size()); |
94 | 97 |
int row = 0; |
95 | 98 |
for(V val : newValue){ |
96 |
try { |
|
97 |
F field = fieldType.newInstance(); |
|
98 |
addStyledComponent(field); |
|
99 |
field.setWidth(100, Unit.PERCENTAGE); |
|
100 |
field.setValue(val); |
|
101 |
grid.addComponent(field, 0, row); |
|
102 |
grid.addComponent(buttonGroup(), 1, row); |
|
103 |
row++; |
|
104 |
} catch (InstantiationException e) { |
|
105 |
// TODO Auto-generated catch block |
|
106 |
e.printStackTrace(); |
|
107 |
} catch (IllegalAccessException e) { |
|
108 |
// TODO Auto-generated catch block |
|
109 |
e.printStackTrace(); |
|
110 |
} |
|
99 |
row = addNewRow(row, val); |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* @param row |
|
105 |
* @param val |
|
106 |
* @return |
|
107 |
*/ |
|
108 |
protected int addNewRow(int row, V val) { |
|
109 |
try { |
|
110 |
F field = fieldType.newInstance(); |
|
111 |
addStyledComponent(field); |
|
112 |
field.setWidth(100, Unit.PERCENTAGE); |
|
113 |
field.setValue(val); |
|
114 |
grid.addComponent(field, 0, row); |
|
115 |
grid.addComponent(buttonGroup(), 1, row); |
|
116 |
nestFieldGroup(field); |
|
117 |
row++; |
|
118 |
} catch (InstantiationException e) { |
|
119 |
// TODO Auto-generated catch block |
|
120 |
e.printStackTrace(); |
|
121 |
} catch (IllegalAccessException e) { |
|
122 |
// TODO Auto-generated catch block |
|
123 |
e.printStackTrace(); |
|
124 |
} |
|
125 |
return row; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* @param field |
|
130 |
*/ |
|
131 |
protected void nestFieldGroup(F field) { |
|
132 |
if(NestedFieldGroup.class.isAssignableFrom(fieldType) && parentFieldGroup != null){ |
|
133 |
((NestedFieldGroup)field).registerParentFieldGroup(parentFieldGroup); |
|
111 | 134 |
} |
112 | 135 |
} |
113 | 136 |
|
... | ... | |
136 | 159 |
// no default styles |
137 | 160 |
} |
138 | 161 |
|
162 |
/** |
|
163 |
* {@inheritDoc} |
|
164 |
* <p> |
|
165 |
* However, this class has no local fieldGroup but must delegate to the nested NestedFieldGroup |
|
166 |
* if there are any. This happens in {@link #nestFieldGroup(AbstractField)}. |
|
167 |
* <p> |
|
168 |
*/ |
|
169 |
@Override |
|
170 |
public FieldGroup getFieldGroup() { |
|
171 |
return null; |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
public void registerParentFieldGroup(FieldGroup parent) { |
|
176 |
parentFieldGroup = parent; |
|
177 |
} |
|
178 |
|
|
139 | 179 |
|
140 | 180 |
|
141 | 181 |
|
src/main/java/eu/etaxonomy/vaadin/component/NestedFieldGroup.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.fieldgroup.FieldGroup; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author a.kohlbecker |
|
15 |
* @since May 12, 2017 |
|
16 |
* |
|
17 |
*/ |
|
18 |
public interface NestedFieldGroup { |
|
19 |
|
|
20 |
/** |
|
21 |
* Implementations return the local fieldGroup |
|
22 |
* |
|
23 |
* @return |
|
24 |
*/ |
|
25 |
public abstract FieldGroup getFieldGroup(); |
|
26 |
|
|
27 |
public abstract void registerParentFieldGroup(FieldGroup parent); |
|
28 |
|
|
29 |
} |
src/main/java/eu/etaxonomy/vaadin/component/SwitchableTextField.java | ||
---|---|---|
104 | 104 |
|
105 | 105 |
} |
106 | 106 |
|
107 |
/** |
|
108 |
* {@inheritDoc} |
|
109 |
*/ |
|
110 |
@Override |
|
111 |
public FieldGroup getFieldGroup() { |
|
112 |
return null; |
|
113 |
} |
|
114 |
|
|
107 | 115 |
} |
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java | ||
---|---|---|
41 | 41 |
import com.vaadin.ui.VerticalLayout; |
42 | 42 |
import com.vaadin.ui.themes.ValoTheme; |
43 | 43 |
|
44 |
import eu.etaxonomy.vaadin.component.NestedFieldGroup; |
|
44 | 45 |
import eu.etaxonomy.vaadin.component.SwitchableTextField; |
45 | 46 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent; |
46 | 47 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason; |
... | ... | |
75 | 76 |
mainLayout.setWidthUndefined(); |
76 | 77 |
|
77 | 78 |
fieldGroup = new BeanFieldGroup<>(dtoType); |
78 |
fieldGroup.setBuffered(false); |
|
79 | 79 |
fieldGroup.addCommitHandler(new SaveHandler()); |
80 | 80 |
|
81 | 81 |
setCompositionRoot(mainLayout); |
... | ... | |
248 | 248 |
|
249 | 249 |
protected <T extends Field> T addField(T field, String propertyId) { |
250 | 250 |
fieldGroup.bind(field, propertyId); |
251 |
if(NestedFieldGroup.class.isAssignableFrom(field.getClass())){ |
|
252 |
((NestedFieldGroup)field).registerParentFieldGroup(fieldGroup); |
|
253 |
} |
|
251 | 254 |
addComponent(field); |
252 | 255 |
return field; |
253 | 256 |
} |
... | ... | |
271 | 274 |
protected <T extends Field> T addField(T field, String propertyId, int column, int row) |
272 | 275 |
throws OverlapsException, OutOfBoundsException { |
273 | 276 |
fieldGroup.bind(field, propertyId); |
277 |
if(NestedFieldGroup.class.isAssignableFrom(field.getClass())){ |
|
278 |
((NestedFieldGroup)field).registerParentFieldGroup(fieldGroup); |
|
279 |
} |
|
274 | 280 |
addComponent(field, column, row); |
275 | 281 |
return field; |
276 | 282 |
} |
... | ... | |
293 | 299 |
throws OverlapsException, OutOfBoundsException { |
294 | 300 |
if(propertyId != null){ |
295 | 301 |
fieldGroup.bind(field, propertyId); |
302 |
if(NestedFieldGroup.class.isAssignableFrom(field.getClass())){ |
|
303 |
((NestedFieldGroup)field).registerParentFieldGroup(fieldGroup); |
|
304 |
} |
|
296 | 305 |
} |
297 | 306 |
addComponent(field, column1, row1, column2, row2); |
298 | 307 |
return field; |
Also available in: Unified diff
ref #6612 support for editor widgets with nested FieldGroups