Revision 843f2ff8
Added by Andreas Kohlbecker almost 7 years ago
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 |
|
Also available in: Unified diff
ref #6612 support for editor widgets with nested FieldGroups