10 |
10 |
|
11 |
11 |
import java.util.Arrays;
|
12 |
12 |
import java.util.EnumSet;
|
|
13 |
import java.util.HashSet;
|
13 |
14 |
import java.util.List;
|
14 |
15 |
import java.util.Set;
|
15 |
16 |
|
... | ... | |
17 |
18 |
import org.hibernate.criterion.Restrictions;
|
18 |
19 |
import org.springframework.context.event.EventListener;
|
19 |
20 |
|
|
21 |
import com.vaadin.ui.AbstractField;
|
|
22 |
|
20 |
23 |
import eu.etaxonomy.cdm.api.service.INameService;
|
|
24 |
import eu.etaxonomy.cdm.cache.CdmEntityCache;
|
|
25 |
import eu.etaxonomy.cdm.debug.PersistentContextAnalyzer;
|
21 |
26 |
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
22 |
27 |
import eu.etaxonomy.cdm.model.agent.Person;
|
23 |
28 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
24 |
29 |
import eu.etaxonomy.cdm.model.common.TermType;
|
|
30 |
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
25 |
31 |
import eu.etaxonomy.cdm.model.name.Rank;
|
26 |
32 |
import eu.etaxonomy.cdm.model.name.TaxonName;
|
27 |
33 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
... | ... | |
32 |
38 |
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
33 |
39 |
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
|
34 |
40 |
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
|
41 |
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
35 |
42 |
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
|
36 |
43 |
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
37 |
44 |
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
... | ... | |
48 |
55 |
*/
|
49 |
56 |
public class TaxonNameEditorPresenter extends AbstractCdmEditorPresenter<TaxonName, TaxonNamePopupEditorView> {
|
50 |
57 |
|
|
58 |
/**
|
|
59 |
*
|
|
60 |
*/
|
|
61 |
private static final List<String> BASIONYM_INIT_STRATEGY = Arrays.asList("$", "relationsFromThisName", "homotypicalGroup.typifiedNames");
|
|
62 |
|
51 |
63 |
private static final long serialVersionUID = -3538980627079389221L;
|
52 |
64 |
|
53 |
65 |
private static final Logger logger = Logger.getLogger(TaxonNameEditorPresenter.class);
|
54 |
66 |
|
55 |
|
ReferencePopupEditor newReferencePopup = null;
|
|
67 |
private ReferencePopupEditor referenceEditorPopup = null;
|
|
68 |
|
|
69 |
private TaxonNamePopupEditor basionymNamePopup = null;
|
56 |
70 |
|
57 |
71 |
private CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider;
|
58 |
72 |
|
... | ... | |
60 |
74 |
|
61 |
75 |
private BeanInstantiator<Reference> newReferenceInstantiator;
|
62 |
76 |
|
|
77 |
private BeanInstantiator<TaxonName> newBasionymNameInstantiator;
|
|
78 |
|
|
79 |
private AbstractField<TaxonName> basionymSourceField;
|
|
80 |
|
63 |
81 |
/**
|
64 |
82 |
* {@inheritDoc}
|
65 |
83 |
*/
|
... | ... | |
92 |
110 |
getView().getNomReferenceCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
|
93 |
111 |
getView().getNomReferenceCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Reference>(getView().getNomReferenceCombobox()));
|
94 |
112 |
|
95 |
|
getView().getBasionymCombobox().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
|
96 |
|
CdmFilterablePagingProvider<TaxonName, TaxonName> namePagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(getRepo().getNameService());
|
|
113 |
getView().getBasionymComboboxSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
|
97 |
114 |
|
98 |
|
getView().getBasionymCombobox().setPagingProviders(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize());
|
|
115 |
CdmFilterablePagingProvider<TaxonName, TaxonName> basionymPagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(getRepo().getNameService());
|
|
116 |
basionymPagingProvider.setInitStrategy(BASIONYM_INIT_STRATEGY);
|
|
117 |
getView().getBasionymComboboxSelect().setPagingProviders(basionymPagingProvider, basionymPagingProvider, basionymPagingProvider.getPageSize(), this);
|
99 |
118 |
}
|
100 |
119 |
|
101 |
120 |
/**
|
... | ... | |
200 |
219 |
protected TaxonName handleTransientProperties(TaxonName bean) {
|
201 |
220 |
|
202 |
221 |
logger.trace(this._toString() + ".onEditorSaveEvent - handling transient properties");
|
203 |
|
List<TaxonName> newBasionymNames = getView().getBasionymCombobox().getValueFromNestedFields();
|
|
222 |
|
|
223 |
|
|
224 |
List<TaxonName> newBasionymNames = getView().getBasionymComboboxSelect().getValueFromNestedFields();
|
204 |
225 |
Set<TaxonName> oldBasionyms = bean.getBasionyms();
|
205 |
|
boolean updateBasionyms = false;
|
|
226 |
Set<TaxonName> updateBasionyms = new HashSet<>();
|
|
227 |
Set<TaxonName> removeBasionyms = new HashSet<>();
|
206 |
228 |
|
207 |
229 |
for(TaxonName newB : newBasionymNames){
|
208 |
|
updateBasionyms = updateBasionyms || !oldBasionyms.contains(newB);
|
|
230 |
if(!oldBasionyms.contains(newB)){
|
|
231 |
updateBasionyms.add(newB);
|
|
232 |
}
|
209 |
233 |
}
|
210 |
234 |
|
211 |
235 |
for(TaxonName oldB : oldBasionyms){
|
212 |
|
updateBasionyms = updateBasionyms || !newBasionymNames.contains(oldB);
|
|
236 |
if(!newBasionymNames.contains(oldB)){
|
|
237 |
removeBasionyms.add(oldB);
|
|
238 |
}
|
213 |
239 |
}
|
214 |
|
|
215 |
|
if(updateBasionyms){
|
216 |
|
bean.removeBasionyms();
|
217 |
|
for(TaxonName basionymName :newBasionymNames){
|
218 |
|
if(basionymName != null){
|
219 |
|
if(basionymName .getUuid() != null){
|
220 |
|
// reload
|
221 |
|
basionymName = getRepo().getNameService().load(basionymName.getUuid(), Arrays.asList("$", "relationsFromThisName", "homotypicalGroup.typifiedNames"));
|
222 |
|
}
|
223 |
|
bean.addBasionym(basionymName);
|
|
240 |
for(TaxonName removeBasionym :removeBasionyms){
|
|
241 |
Set<NameRelationship> removeRelations = new HashSet<NameRelationship>();
|
|
242 |
for (NameRelationship nameRelation : bean.getRelationsToThisName()){
|
|
243 |
if (nameRelation.getType().isBasionymRelation() && nameRelation.getFromName().equals(removeBasionym)){
|
|
244 |
removeRelations.add(nameRelation);
|
224 |
245 |
}
|
225 |
246 |
}
|
|
247 |
for (NameRelationship relation : removeRelations){
|
|
248 |
bean.removeNameRelationship(relation);
|
|
249 |
}
|
|
250 |
}
|
|
251 |
// updateBasionyms.clear(); // DEBUGGING #########################
|
|
252 |
getRepo().getSession().clear();
|
|
253 |
for(TaxonName addBasionymName :updateBasionyms){
|
|
254 |
// if(addBasionymName != null){
|
|
255 |
// if(addBasionymName.getUuid() != null){
|
|
256 |
// reload
|
|
257 |
|
|
258 |
System.err.println("====== Cache ======");
|
|
259 |
addBasionymName = getRepo().getNameService().load(addBasionymName.getUuid(), BASIONYM_INIT_STRATEGY);
|
|
260 |
PersistentContextAnalyzer pca = new PersistentContextAnalyzer((CdmEntityCache)getCache(), getRepo().getSession());
|
|
261 |
pca.setShowHashCodes(true);
|
|
262 |
pca.printEntityGraph(System.err);
|
|
263 |
pca.printCopyEntities(System.err);
|
|
264 |
|
|
265 |
System.err.println("====== Basionym ======");
|
|
266 |
PersistentContextAnalyzer basiopca = new PersistentContextAnalyzer(addBasionymName, getRepo().getSession());
|
|
267 |
basiopca.setShowHashCodes(true);
|
|
268 |
basiopca.printEntityGraph(System.err);
|
|
269 |
|
|
270 |
TaxonName cachedName = getCache().find(addBasionymName);
|
|
271 |
if(cachedName != null){
|
|
272 |
System.err.println("====== Cached Basionym ======");
|
|
273 |
PersistentContextAnalyzer cahedbasiopca = new PersistentContextAnalyzer(addBasionymName, getRepo().getSession());
|
|
274 |
cahedbasiopca.setShowHashCodes(true);
|
|
275 |
cahedbasiopca.printEntityGraph(System.err);
|
|
276 |
addBasionymName = cachedName;
|
|
277 |
}
|
|
278 |
// }
|
|
279 |
bean.addBasionym(addBasionymName);
|
|
280 |
//}
|
226 |
281 |
}
|
227 |
282 |
return bean;
|
228 |
283 |
}
|
... | ... | |
235 |
290 |
return getRepo().getNameService();
|
236 |
291 |
}
|
237 |
292 |
|
238 |
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
|
|
293 |
@EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).ADD")
|
239 |
294 |
public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
|
240 |
295 |
|
241 |
296 |
if(getView() == null || event.getSourceView() != getView() ){
|
242 |
297 |
return;
|
243 |
298 |
}
|
244 |
|
newReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
|
299 |
referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
245 |
300 |
|
246 |
|
newReferencePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
247 |
|
newReferencePopup.withDeleteButton(true);
|
248 |
|
newReferencePopup.setBeanInstantiator(newReferenceInstantiator);
|
249 |
|
newReferencePopup.loadInEditor(null);
|
|
301 |
referenceEditorPopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
|
302 |
referenceEditorPopup.withDeleteButton(true);
|
|
303 |
referenceEditorPopup.setBeanInstantiator(newReferenceInstantiator);
|
|
304 |
referenceEditorPopup.loadInEditor(null);
|
250 |
305 |
if(newReferenceInstantiator != null){
|
251 |
306 |
// this is a bit clumsy, we actually need to inject something like a view configurer
|
252 |
307 |
// which can enable, disable fields
|
253 |
|
newReferencePopup.getInReferenceCombobox().setEnabled(false);
|
254 |
|
newReferencePopup.getTypeSelect().setEnabled(false);
|
|
308 |
referenceEditorPopup.getInReferenceCombobox().setEnabled(false);
|
|
309 |
referenceEditorPopup.getTypeSelect().setEnabled(false);
|
255 |
310 |
}
|
256 |
311 |
}
|
257 |
312 |
|
258 |
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT")
|
|
313 |
@EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).EDIT")
|
259 |
314 |
public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
|
260 |
315 |
|
261 |
316 |
if(getView() == null || event.getSourceView() != getView() ){
|
262 |
317 |
return;
|
263 |
318 |
}
|
264 |
|
newReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
|
319 |
referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
265 |
320 |
|
266 |
|
newReferencePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
267 |
|
newReferencePopup.withDeleteButton(true);
|
268 |
|
newReferencePopup.setBeanInstantiator(newReferenceInstantiator);
|
269 |
|
newReferencePopup.loadInEditor(event.getEntityId());
|
|
321 |
referenceEditorPopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
|
322 |
referenceEditorPopup.withDeleteButton(true);
|
|
323 |
referenceEditorPopup.setBeanInstantiator(newReferenceInstantiator);
|
|
324 |
referenceEditorPopup.loadInEditor(event.getEntityId());
|
270 |
325 |
if(newReferenceInstantiator != null){
|
271 |
326 |
// this is a bit clumsy, we actually need to inject something like a view configurer
|
272 |
327 |
// which can enable, disable fields
|
273 |
|
newReferencePopup.getInReferenceCombobox().setEnabled(false);
|
274 |
|
newReferencePopup.getTypeSelect().setEnabled(false);
|
|
328 |
referenceEditorPopup.getInReferenceCombobox().setEnabled(false);
|
|
329 |
referenceEditorPopup.getTypeSelect().setEnabled(false);
|
275 |
330 |
}
|
276 |
331 |
}
|
277 |
332 |
|
278 |
333 |
@EventListener
|
279 |
334 |
public void onDoneWithPopupEvent(DoneWithPopupEvent event){
|
280 |
|
if(event.getPopup() == newReferencePopup){
|
|
335 |
|
|
336 |
if(event.getPopup() == referenceEditorPopup){
|
281 |
337 |
if(event.getReason() == Reason.SAVE){
|
282 |
338 |
|
283 |
|
Reference newReference = newReferencePopup.getBean();
|
|
339 |
Reference modifiedReference = referenceEditorPopup.getBean();
|
|
340 |
|
|
341 |
// TODO the bean contained in the popup editor is not yet updated at this point.
|
|
342 |
// so re reload it using the uuid since new beans will not have an Id at this point.
|
|
343 |
modifiedReference = getRepo().getReferenceService().load(modifiedReference.getUuid(), Arrays.asList("inReference"));
|
|
344 |
getView().getNomReferenceCombobox().setValue(modifiedReference);
|
|
345 |
}
|
|
346 |
|
|
347 |
referenceEditorPopup = null;
|
|
348 |
}
|
|
349 |
if(event.getPopup() == basionymNamePopup){
|
|
350 |
if(event.getReason() == Reason.SAVE){
|
|
351 |
TaxonName modifiedTaxonName = basionymNamePopup.getBean();
|
284 |
352 |
|
285 |
353 |
// TODO the bean contained in the popup editor is not yet updated at this point.
|
286 |
354 |
// so re reload it using the uuid since new beans will not have an Id at this point.
|
287 |
|
newReference = getRepo().getReferenceService().load(newReference.getUuid(), Arrays.asList("inReference"));
|
288 |
|
getView().getNomReferenceCombobox().setValue(newReference);
|
|
355 |
modifiedTaxonName = getRepo().getNameService().load(modifiedTaxonName.getUuid()); //, BASIONYM_INIT_STRATEGY);
|
|
356 |
basionymSourceField.setValue(modifiedTaxonName);
|
|
357 |
|
|
358 |
// TODO create blocking registration
|
289 |
359 |
}
|
|
360 |
if(event.getReason() == Reason.DELETE){
|
|
361 |
basionymSourceField.setValue(null);
|
|
362 |
}
|
|
363 |
|
|
364 |
basionymNamePopup = null;
|
|
365 |
basionymSourceField = null;
|
|
366 |
}
|
|
367 |
}
|
|
368 |
|
|
369 |
@EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).EDIT")
|
|
370 |
public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
|
290 |
371 |
|
291 |
|
newReferencePopup = null;
|
|
372 |
if(getView() == null || event.getSourceView() != getView() ){
|
|
373 |
return;
|
292 |
374 |
}
|
|
375 |
basionymSourceField = (AbstractField<TaxonName>)event.getSourceComponent();
|
|
376 |
|
|
377 |
basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
|
|
378 |
basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
|
379 |
basionymNamePopup.withDeleteButton(true);
|
|
380 |
basionymNamePopup.loadInEditor(event.getEntityId());
|
|
381 |
basionymNamePopup.getBasionymToggle().setVisible(false);
|
|
382 |
|
293 |
383 |
}
|
294 |
384 |
|
|
385 |
@EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).ADD")
|
|
386 |
public void onReferenceEditorActionAdd(TaxonNameEditorAction event) {
|
|
387 |
|
|
388 |
if(getView() == null || event.getSourceView() != getView() ){
|
|
389 |
return;
|
|
390 |
}
|
|
391 |
basionymSourceField = (AbstractField<TaxonName>)event.getSourceComponent();
|
|
392 |
|
|
393 |
basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
|
|
394 |
basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
|
395 |
basionymNamePopup.withDeleteButton(true);
|
|
396 |
basionymNamePopup.loadInEditor(null);
|
|
397 |
basionymNamePopup.getBasionymToggle().setVisible(false);
|
|
398 |
}
|
295 |
399 |
|
296 |
400 |
|
297 |
401 |
}
|
fix #7205 using ToManyRelatedEntitiesListSelect create edit button in TaxonNamePopupEditor