Revision 834db381
Added by Andreas Kohlbecker over 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.vaadin.component.common; |
10 | 10 |
|
11 |
import java.util.EnumSet; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import com.vaadin.data.Validator.InvalidValueException; |
|
11 | 15 |
import com.vaadin.data.fieldgroup.BeanFieldGroup; |
12 | 16 |
import com.vaadin.data.fieldgroup.FieldGroup; |
13 | 17 |
import com.vaadin.data.util.BeanItem; |
... | ... | |
16 | 20 |
import com.vaadin.ui.Button; |
17 | 21 |
import com.vaadin.ui.Component; |
18 | 22 |
import com.vaadin.ui.CssLayout; |
23 |
import com.vaadin.ui.Field; |
|
19 | 24 |
import com.vaadin.ui.themes.ValoTheme; |
20 | 25 |
|
21 | 26 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
22 | 27 |
import eu.etaxonomy.cdm.model.agent.Person; |
23 | 28 |
import eu.etaxonomy.cdm.model.agent.Team; |
24 | 29 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
30 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; |
|
25 | 31 |
import eu.etaxonomy.cdm.vaadin.security.UserHelper; |
26 | 32 |
import eu.etaxonomy.cdm.vaadin.util.converter.CdmBaseDeproxyConverter; |
27 | 33 |
import eu.etaxonomy.vaadin.component.CompositeCustomField; |
... | ... | |
162 | 168 |
|
163 | 169 |
titleField.bindTo(fieldGroup, "titleCache", "protectedTitleCache"); |
164 | 170 |
nomenclaturalTitleField.bindTo(fieldGroup, "nomenclaturalTitle", "protectedNomenclaturalTitleCache"); |
171 |
fieldGroup.setItemDataSource(new BeanItem<Team>((Team)newValue)); |
|
165 | 172 |
fieldGroup.bind(personsListEditor, "teamMembers"); |
166 | 173 |
|
167 |
fieldGroup.setItemDataSource(new BeanItem<Team>((Team)newValue)); |
|
168 | 174 |
personsListEditor.registerParentFieldGroup(fieldGroup); |
169 | 175 |
|
170 | 176 |
|
... | ... | |
173 | 179 |
} |
174 | 180 |
|
175 | 181 |
updateToolBarButtonStates(); |
176 |
checkUserPermissions(newValue); |
|
177 | 182 |
} |
178 | 183 |
|
179 | 184 |
private void checkUserPermissions(TeamOrPersonBase<?> newValue) { |
... | ... | |
202 | 207 |
return new Component[]{titleField, nomenclaturalTitleField}; |
203 | 208 |
} |
204 | 209 |
|
210 |
/** |
|
211 |
* {@inheritDoc} |
|
212 |
*/ |
|
213 |
@SuppressWarnings("unchecked") |
|
214 |
@Override |
|
215 |
public void commit() throws SourceException, InvalidValueException { |
|
216 |
|
|
217 |
//need to commit the subfields propagation through the fielGroups is not enough |
|
218 |
personField.commit(); |
|
219 |
personsListEditor.commit(); |
|
220 |
super.commit(); |
|
221 |
|
|
222 |
TeamOrPersonBase<?> bean = getValue(); |
|
223 |
if(bean != null && bean instanceof Team){ |
|
205 | 224 |
|
225 |
boolean isUnsaved = bean.getId() == 0; |
|
226 |
if(isUnsaved){ |
|
227 |
UserHelper.fromSession().createAuthorityForCurrentUser(bean, EnumSet.of(CRUD.UPDATE, CRUD.DELETE), null); |
|
228 |
} |
|
229 |
} |
|
230 |
|
|
231 |
if(hasNullContent()){ |
|
232 |
getPropertyDataSource().setValue(null); |
|
233 |
setValue(null); |
|
234 |
|
|
235 |
} |
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
239 |
* {@inheritDoc} |
|
240 |
*/ |
|
241 |
@Override |
|
242 |
protected List<Field> nullValueCheckIgnoreFields() { |
|
243 |
List<Field> ignoreFields = super.nullValueCheckIgnoreFields(); |
|
244 |
ignoreFields.add(personField); |
|
245 |
ignoreFields.add(nomenclaturalTitleField.getUnlockSwitch()); |
|
246 |
if(nomenclaturalTitleField.getUnlockSwitch().getValue().booleanValue() == false){ |
|
247 |
ignoreFields.add(nomenclaturalTitleField.getTextField()); |
|
248 |
} |
|
249 |
ignoreFields.add(titleField.getUnlockSwitch()); |
|
250 |
if(titleField.getUnlockSwitch().getValue().booleanValue() == false){ |
|
251 |
ignoreFields.add(titleField.getTextField()); |
|
252 |
} |
|
253 |
return ignoreFields; |
|
254 |
} |
|
255 |
|
|
256 |
/** |
|
257 |
* {@inheritDoc} |
|
258 |
*/ |
|
259 |
@Override |
|
260 |
public boolean hasNullContent() { |
|
261 |
|
|
262 |
TeamOrPersonBase<?> bean = getValue(); |
|
263 |
if(bean == null) { |
|
264 |
return true; |
|
265 |
} |
|
266 |
if(bean instanceof Team){ |
|
267 |
// --- Team |
|
268 |
return super.hasNullContent(); |
|
269 |
} else { |
|
270 |
// --- Person |
|
271 |
return personField.hasNullContent(); |
|
272 |
} |
|
273 |
} |
|
206 | 274 |
|
207 | 275 |
} |
Also available in: Unified diff
ref #6867 assigning UPDATE,DELETE for new Persons and Teams and fixing bugs related to TeamOrPersonField: