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.cdm.vaadin.view.name;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.EnumSet;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Optional;
|
18
|
import java.util.Set;
|
19
|
import java.util.Stack;
|
20
|
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.hibernate.criterion.Restrictions;
|
23
|
import org.springframework.beans.factory.DisposableBean;
|
24
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
import org.springframework.context.annotation.Scope;
|
26
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
27
|
import org.vaadin.viritin.fields.AbstractElementCollection;
|
28
|
|
29
|
import com.vaadin.data.util.BeanItemContainer;
|
30
|
import com.vaadin.spring.annotation.SpringComponent;
|
31
|
|
32
|
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
|
33
|
import eu.etaxonomy.cdm.cache.CdmTransientEntityAndUuidCacher;
|
34
|
import eu.etaxonomy.cdm.format.reference.ReferenceEllypsisFormatter.LabelType;
|
35
|
import eu.etaxonomy.cdm.model.ICdmEntityUuidCacher;
|
36
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
37
|
import eu.etaxonomy.cdm.model.agent.Person;
|
38
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
39
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
40
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
41
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
42
|
import eu.etaxonomy.cdm.model.location.Country;
|
43
|
import eu.etaxonomy.cdm.model.name.Registration;
|
44
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
45
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
|
46
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
47
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
48
|
import eu.etaxonomy.cdm.model.permission.CRUD;
|
49
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
50
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
51
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
52
|
import eu.etaxonomy.cdm.model.term.TermType;
|
53
|
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
|
54
|
import eu.etaxonomy.cdm.persistence.dao.common.Restriction.Operator;
|
55
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
56
|
import eu.etaxonomy.cdm.service.CdmBeanItemContainerFactory;
|
57
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
58
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProviderFactory;
|
59
|
import eu.etaxonomy.cdm.service.ISpecimenTypeDesignationWorkingSetService;
|
60
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
61
|
import eu.etaxonomy.cdm.service.initstrategies.AgentBaseInit;
|
62
|
import eu.etaxonomy.cdm.vaadin.component.CollectionRowItemCollection;
|
63
|
import eu.etaxonomy.cdm.vaadin.event.EditorActionContext;
|
64
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
65
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEventFilter;
|
66
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
|
67
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationTermLists;
|
68
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
|
69
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
|
70
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
71
|
import eu.etaxonomy.cdm.vaadin.util.CollectionCaptionGenerator;
|
72
|
import eu.etaxonomy.cdm.vaadin.util.ReferenceEllypsisCaptionGenerator;
|
73
|
import eu.etaxonomy.cdm.vaadin.view.occurrence.CollectionPopupEditor;
|
74
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
75
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
76
|
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
|
77
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
|
78
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
79
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
80
|
/**
|
81
|
* SpecimenTypeDesignationWorkingsetPopupEditorView implementation must override the showInEditor() method,
|
82
|
* see {@link #prepareAsFieldGroupDataSource()} for details.
|
83
|
*
|
84
|
* @author a.kohlbecker
|
85
|
* @since Jun 13, 2017
|
86
|
*/
|
87
|
@SpringComponent
|
88
|
@Scope("prototype")
|
89
|
public class SpecimenTypeDesignationWorkingsetEditorPresenter
|
90
|
extends AbstractEditorPresenter<SpecimenTypeDesignationWorkingSetDTO , SpecimenTypeDesignationWorkingsetPopupEditorView>
|
91
|
implements CachingPresenter, DisposableBean {
|
92
|
|
93
|
private static final long serialVersionUID = 4255636253714476918L;
|
94
|
|
95
|
public static final Logger logger = Logger.getLogger(SpecimenTypeDesignationWorkingsetEditorPresenter.class);
|
96
|
|
97
|
private static final EnumSet<CRUD> COLLECTION_EDITOR_CRUD = EnumSet.of(CRUD.UPDATE, CRUD.DELETE);
|
98
|
|
99
|
|
100
|
/**
|
101
|
* This object for this field will either be injected by the {@link PopupEditorFactory} or by a Spring
|
102
|
* {@link BeanFactory}
|
103
|
*/
|
104
|
@Autowired
|
105
|
private ISpecimenTypeDesignationWorkingSetService specimenTypeDesignationWorkingSetService;
|
106
|
|
107
|
@Autowired
|
108
|
protected CdmFilterablePagingProviderFactory pagingProviderFactory;
|
109
|
|
110
|
@Autowired
|
111
|
protected CdmBeanItemContainerFactory cdmBeanItemContainerFactory;
|
112
|
|
113
|
/**
|
114
|
* if not null, this CRUD set is to be used to create a CdmAuthoritiy for the base entitiy which will be
|
115
|
* granted to the current use as long this grant is not assigned yet.
|
116
|
*/
|
117
|
private EnumSet<CRUD> crud = null;
|
118
|
|
119
|
private ICdmEntityUuidCacher cache;
|
120
|
|
121
|
SpecimenTypeDesignationWorkingSetDTO<Registration> workingSetDto;
|
122
|
|
123
|
CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider;
|
124
|
|
125
|
/**
|
126
|
* The unit of publication in which the type designation has been published.
|
127
|
* This may be any type listed in {@link RegistrationUIDefaults#NOMECLATURAL_PUBLICATION_UNIT_TYPES}
|
128
|
* but never a {@link ReferenceType#Section}
|
129
|
*/
|
130
|
private DescriptionElementSource publishedUnit;
|
131
|
|
132
|
private Map<CollectionPopupEditor, SpecimenTypeDesignationDTORow> collectionPopupEditorsRowMap = new HashMap<>();
|
133
|
|
134
|
private Map<ReferencePopupEditor, ToOneRelatedEntityCombobox<Reference>> referencePopupEditorsCombobox = new HashMap<>();
|
135
|
|
136
|
private Set<CollectionRowItemCollection> popuEditorTypeDesignationSourceRows = new HashSet<>();
|
137
|
|
138
|
private java.util.Collection<CdmBase> rootEntities = new HashSet<>();
|
139
|
|
140
|
private BeanInstantiator<Reference> newReferenceInstantiator;
|
141
|
|
142
|
/**
|
143
|
* possible values:
|
144
|
*
|
145
|
* <ul>
|
146
|
* <li>NULL: undecided, should be treaded like <code>false</code></li>
|
147
|
* <li>false: the typification is published in an nomenclatural act in which no new name or new combination is being published.
|
148
|
* The available {@link TypeDesignationStatusBase} should be limited to those with
|
149
|
* <code>{@link TypeDesignationStatusBase#hasDesignationSource() hasDesignationSource} == true</code></li>
|
150
|
* <li>true: only status with <code>{@link TypeDesignationStatusBase#hasDesignationSource() hasDesignationSource} == true</li>
|
151
|
* </ul>
|
152
|
*/
|
153
|
private Optional<Boolean> isInTypedesignationOnlyAct = Optional.empty();
|
154
|
|
155
|
|
156
|
/**
|
157
|
* Loads an existing working set from the database. This process actually involves
|
158
|
* loading the Registration specified by the <code>RegistrationAndWorkingsetId.registrationId</code> and in
|
159
|
* a second step to find the workingset by the <code>registrationAndWorkingsetId.workingsetId</code>.
|
160
|
* <p>
|
161
|
* The <code>identifier</code> must be of the type {@link TypeDesignationWorkingsetIds} whereas the
|
162
|
* field <code>registrationId</code> must be present.
|
163
|
* The field <code>workingsetId</code> however can be null.
|
164
|
* I this case a new workingset with a new {@link FieldUnit} as
|
165
|
* base entity is being created.
|
166
|
*
|
167
|
* @param identifier a {@link TypeDesignationWorkingsetIds}
|
168
|
*/
|
169
|
@Override
|
170
|
protected SpecimenTypeDesignationWorkingSetDTO<Registration> loadBeanById(Object identifier) {
|
171
|
|
172
|
cache = new CdmTransientEntityAndUuidCacher(this);
|
173
|
if(identifier != null){
|
174
|
|
175
|
SpecimenTypeDesignationWorkingsetIds idset = (SpecimenTypeDesignationWorkingsetIds)identifier;
|
176
|
|
177
|
if(idset.baseEntityRef != null){
|
178
|
// load existing workingset
|
179
|
workingSetDto = specimenTypeDesignationWorkingSetService.load(idset.registrationUuid, idset.baseEntityRef);
|
180
|
if(workingSetDto.getFieldUnit() == null){
|
181
|
workingSetDto = specimenTypeDesignationWorkingSetService.fixMissingFieldUnit(workingSetDto);
|
182
|
// FIXME open Dialog to warn user about adding an empty fieldUnit to the typeDesignations
|
183
|
// This method must go again into the presenter !!!!
|
184
|
logger.info("Basing all typeDesignations on a new fieldUnit");
|
185
|
}
|
186
|
} else {
|
187
|
// create a new workingset, for a new fieldunit which is the base for the workingset
|
188
|
workingSetDto = specimenTypeDesignationWorkingSetService.create(idset.getRegistrationUUID(), idset.getTypifiedNameUuid());
|
189
|
cache.load(workingSetDto.getTypifiedName());
|
190
|
rootEntities.add(workingSetDto.getTypifiedName());
|
191
|
}
|
192
|
Registration registration = workingSetDto.getOwner();
|
193
|
// need to use load() but put() see #7214
|
194
|
cache.load(registration);
|
195
|
rootEntities.add(registration);
|
196
|
isInTypedesignationOnlyAct = Optional.of(Boolean.valueOf(registration.getName() == null));
|
197
|
try {
|
198
|
setPublishedUnit(RegistrationDTO.findPublishedUnit(registration));
|
199
|
} catch (Exception e) {
|
200
|
// FIXME report error state instead
|
201
|
logger.error("Error on finding published unit in " + registration.toString(), e);
|
202
|
}
|
203
|
} else {
|
204
|
workingSetDto = null;
|
205
|
}
|
206
|
|
207
|
if (getPublishedUnit() != null) {
|
208
|
// reduce available references to those which are sections of
|
209
|
// the publicationUnit and the publishedUnit itself
|
210
|
referencePagingProvider.getCriteria()
|
211
|
.add(Restrictions.or(
|
212
|
Restrictions.and(
|
213
|
Restrictions.eq("inReference", publishedUnit.getCitation()),
|
214
|
Restrictions.eq("type", ReferenceType.Section)),
|
215
|
Restrictions.idEq(publishedUnit.getCitation().getId()))
|
216
|
);
|
217
|
// new Reference only a sub sections of the publishedUnit
|
218
|
newReferenceInstantiator = new BeanInstantiator<Reference>() {
|
219
|
@Override
|
220
|
public Reference createNewBean() {
|
221
|
Reference newRef = ReferenceFactory.newSection();
|
222
|
newRef.setInReference(publishedUnit.getCitation());
|
223
|
return newRef;
|
224
|
}
|
225
|
};
|
226
|
}
|
227
|
|
228
|
return workingSetDto;
|
229
|
}
|
230
|
|
231
|
|
232
|
/**
|
233
|
* {@inheritDoc}
|
234
|
*/
|
235
|
@SuppressWarnings("serial")
|
236
|
@Override
|
237
|
public void handleViewEntered() {
|
238
|
|
239
|
getView().getCountrySelectField().setContainerDataSource(cdmBeanItemContainerFactory.buildVocabularyTermsItemContainer(Country.uuidCountryVocabulary));
|
240
|
|
241
|
CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase> termOrPersonPagingProvider = pagingProviderFactory.teamOrPersonPagingProvider();
|
242
|
CdmFilterablePagingProvider<AgentBase, Person> personPagingProvider = pagingProviderFactory.personPagingProvider();
|
243
|
termOrPersonPagingProvider.setInitStrategy(AgentBaseInit.TEAM_OR_PERSON_INIT_STRATEGY);
|
244
|
// the ToOneRelatedEntityReloader is added internally in the TeamOrPersonField:
|
245
|
getView().getCollectorField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
246
|
getView().getCollectorField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
247
|
|
248
|
getView().getExactLocationField().getReferenceSystemSelect().setContainerDataSource(cdmBeanItemContainerFactory.buildTermItemContainer(TermType.ReferenceSystem));
|
249
|
getView().getExactLocationField().getReferenceSystemSelect().setItemCaptionPropertyId("label");
|
250
|
|
251
|
getView().getTypeDesignationsCollectionField().addElementRemovedListener(e -> deleteTypeDesignation(e.getElement()));
|
252
|
getView().getTypeDesignationsCollectionField().addElementAddedListener(e -> addTypeDesignation(e.getElement()));
|
253
|
|
254
|
getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildVocabularyTermsItemContainer(
|
255
|
AnnotationType.EDITORIAL().getVocabulary().getUuid()));
|
256
|
|
257
|
popuEditorTypeDesignationSourceRows.clear();
|
258
|
CdmFilterablePagingProvider<Collection, Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection, Collection>(getRepo().getCollectionService());
|
259
|
collectionPagingProvider.getRestrictions().add(new Restriction<>("institute.titleCache", Operator.OR, MatchMode.ANYWHERE, CdmFilterablePagingProvider.QUERY_STRING_PLACEHOLDER));
|
260
|
|
261
|
referencePagingProvider = pagingProviderFactory.referencePagingProvider();
|
262
|
|
263
|
getView().getTypeDesignationsCollectionField().setEditorInstantiator(new AbstractElementCollection.Instantiator<SpecimenTypeDesignationDTORow>() {
|
264
|
|
265
|
@Override
|
266
|
public SpecimenTypeDesignationDTORow create() {
|
267
|
|
268
|
SpecimenTypeDesignationDTORow row = new SpecimenTypeDesignationDTORow();
|
269
|
|
270
|
row.kindOfUnit.setContainerDataSource(cdmBeanItemContainerFactory.buildTermItemContainer(
|
271
|
RegistrationTermLists.KIND_OF_UNIT_TERM_UUIDS())
|
272
|
);
|
273
|
row.kindOfUnit.setNullSelectionAllowed(false);
|
274
|
|
275
|
row.typeStatus.setContainerDataSource(provideTypeStatusTermItemContainer());
|
276
|
row.typeStatus.setNullSelectionAllowed(false);
|
277
|
|
278
|
|
279
|
row.collection.loadFrom(
|
280
|
collectionPagingProvider,
|
281
|
collectionPagingProvider,
|
282
|
collectionPagingProvider.getPageSize()
|
283
|
);
|
284
|
row.collection.getSelect().setCaptionGenerator(new CollectionCaptionGenerator());
|
285
|
row.collection.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Collection>(row.collection.getSelect(),
|
286
|
SpecimenTypeDesignationWorkingsetEditorPresenter.this));
|
287
|
row.collection.addClickListenerAddEntity(e -> doCollectionEditorAdd(row));
|
288
|
row.collection.addClickListenerEditEntity(e -> {
|
289
|
if(row.collection.getValue() != null){
|
290
|
doCollectionEditorEdit(row);
|
291
|
}
|
292
|
});
|
293
|
|
294
|
row.designationReference.loadFrom(
|
295
|
referencePagingProvider,
|
296
|
referencePagingProvider,
|
297
|
referencePagingProvider.getPageSize()
|
298
|
);
|
299
|
row.designationReference.getSelect().setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(LabelType.BIBLIOGRAPHIC, row.designationReference.getSelect()));
|
300
|
row.designationReference.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Reference>(row.designationReference.getSelect(),
|
301
|
SpecimenTypeDesignationWorkingsetEditorPresenter.this));
|
302
|
row.designationReference.addClickListenerAddEntity(e -> doReferenceEditorAdd(row.designationReference));
|
303
|
row.designationReference.addClickListenerEditEntity(e -> {
|
304
|
if(row.designationReference.getValue() != null){
|
305
|
doReferenceEditorEdit(row.designationReference);
|
306
|
}
|
307
|
});
|
308
|
|
309
|
row.mediaSpecimenReference.loadFrom(
|
310
|
referencePagingProvider,
|
311
|
referencePagingProvider,
|
312
|
referencePagingProvider.getPageSize()
|
313
|
);
|
314
|
row.mediaSpecimenReference.getSelect().setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(LabelType.BIBLIOGRAPHIC, row.mediaSpecimenReference.getSelect()));
|
315
|
row.mediaSpecimenReference.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Reference>(row.mediaSpecimenReference.getSelect(),
|
316
|
SpecimenTypeDesignationWorkingsetEditorPresenter.this));
|
317
|
row.mediaSpecimenReference.addClickListenerAddEntity(e -> doReferenceEditorAdd(row.mediaSpecimenReference));
|
318
|
row.mediaSpecimenReference.addClickListenerEditEntity(e -> {
|
319
|
if(row.mediaSpecimenReference.getValue() != null){
|
320
|
doReferenceEditorEdit(row.mediaSpecimenReference);
|
321
|
}
|
322
|
});
|
323
|
|
324
|
getView().applyDefaultComponentStyle(row.components());
|
325
|
|
326
|
popuEditorTypeDesignationSourceRows.add(row);
|
327
|
|
328
|
return row;
|
329
|
}
|
330
|
});
|
331
|
|
332
|
}
|
333
|
|
334
|
protected BeanItemContainer<TypeDesignationStatusBase> provideTypeStatusTermItemContainer() {
|
335
|
return cdmBeanItemContainerFactory.buildTypeDesignationStatusBaseItemContainer(
|
336
|
RegistrationTermLists.SPECIMEN_TYPE_DESIGNATION_STATUS_UUIDS(),
|
337
|
isInTypedesignationOnlyAct
|
338
|
);
|
339
|
}
|
340
|
|
341
|
/**
|
342
|
* {@inheritDoc}
|
343
|
*/
|
344
|
@Override
|
345
|
protected void saveBean(SpecimenTypeDesignationWorkingSetDTO dto) {
|
346
|
|
347
|
if(crud != null){
|
348
|
UserHelperAccess.userHelper().createAuthorityForCurrentUser(dto.getFieldUnit(), crud, null);
|
349
|
}
|
350
|
|
351
|
List<SpecimenTypeDesignationDTO> stdDTOs = dto.getSpecimenTypeDesignationDTOs();
|
352
|
for(SpecimenTypeDesignationDTO stddto : stdDTOs) {
|
353
|
// clean up
|
354
|
if(!stddto.getTypeStatus().hasDesignationSource()) {
|
355
|
stddto.setDesignationReference(null);
|
356
|
stddto.setDesignationReferenceDetail(null);
|
357
|
}
|
358
|
}
|
359
|
|
360
|
specimenTypeDesignationWorkingSetService.save(dto);
|
361
|
}
|
362
|
|
363
|
/**
|
364
|
* {@inheritDoc}
|
365
|
*/
|
366
|
@Override
|
367
|
protected void deleteBean(SpecimenTypeDesignationWorkingSetDTO bean) {
|
368
|
specimenTypeDesignationWorkingSetService.delete(bean, true);
|
369
|
}
|
370
|
|
371
|
/**
|
372
|
* @param element
|
373
|
* @return
|
374
|
*/
|
375
|
private void addTypeDesignation(SpecimenTypeDesignationDTO element) {
|
376
|
getView().updateAllowDeleteTypeDesignation();
|
377
|
}
|
378
|
|
379
|
|
380
|
/**
|
381
|
* In this method the SpecimenTypeDesignation is dissociated from the Registration.
|
382
|
* The actual deletion of the SpecimenTypeDesignation and DerivedUnit will take place in {@link #saveBean(SpecimenTypeDesignationWorkingSetDTO)}
|
383
|
*
|
384
|
* TODO once https://dev.e-taxonomy.eu/redmine/issues/7077 is fixed dissociating from the Registration could be removed here
|
385
|
*
|
386
|
* @param e
|
387
|
* @return
|
388
|
*/
|
389
|
private void deleteTypeDesignation(SpecimenTypeDesignationDTO element) {
|
390
|
|
391
|
Registration reg = workingSetDto.getOwner();
|
392
|
SpecimenTypeDesignation std = element.asSpecimenTypeDesignation();
|
393
|
|
394
|
reg.getTypeDesignations().remove(std);
|
395
|
|
396
|
getView().updateAllowDeleteTypeDesignation();
|
397
|
}
|
398
|
|
399
|
/**
|
400
|
* @param crud
|
401
|
*/
|
402
|
public void setGrantsForCurrentUser(EnumSet<CRUD> crud) {
|
403
|
this.crud = crud;
|
404
|
}
|
405
|
|
406
|
/**
|
407
|
* {@inheritDoc}
|
408
|
*/
|
409
|
@Override
|
410
|
public ICdmEntityUuidCacher getCache() {
|
411
|
return cache;
|
412
|
}
|
413
|
|
414
|
@Override
|
415
|
public void disposeCache() {
|
416
|
cache.dispose();
|
417
|
}
|
418
|
|
419
|
public void doCollectionEditorAdd(SpecimenTypeDesignationDTORow row) {
|
420
|
|
421
|
CollectionPopupEditor collectionPopupEditor = openPopupEditor(CollectionPopupEditor.class, null);
|
422
|
|
423
|
collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
424
|
collectionPopupEditor.withDeleteButton(true);
|
425
|
collectionPopupEditor.loadInEditor(null);
|
426
|
|
427
|
collectionPopupEditorsRowMap.put(collectionPopupEditor, row);
|
428
|
}
|
429
|
|
430
|
public void doCollectionEditorEdit(SpecimenTypeDesignationDTORow row) {
|
431
|
|
432
|
CollectionPopupEditor collectionPopupEditor = openPopupEditor(CollectionPopupEditor.class, null);
|
433
|
|
434
|
collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
435
|
collectionPopupEditor.withDeleteButton(true);
|
436
|
collectionPopupEditor.loadInEditor(row.collection.getValue().getUuid());
|
437
|
|
438
|
collectionPopupEditorsRowMap.put(collectionPopupEditor, row);
|
439
|
}
|
440
|
|
441
|
|
442
|
@EventBusListenerMethod(filter = EntityChangeEventFilter.OccurrenceCollectionFilter.class)
|
443
|
public void onCollectionEvent(EntityChangeEvent event){
|
444
|
|
445
|
if(event.getSourceView() instanceof AbstractPopupEditor) {
|
446
|
|
447
|
Stack<EditorActionContext> context = ((AbstractPopupEditor) event.getSourceView()).getEditorActionContext();
|
448
|
if(context.size() > 1){
|
449
|
AbstractView<?> parentView = context.get(context.size() - 2).getParentView();
|
450
|
if(getView().equals(parentView)){
|
451
|
Collection newCollection = getRepo().getCollectionService().load(
|
452
|
event.getEntityUuid(), Arrays.asList(new String[]{"$.institute"})
|
453
|
);
|
454
|
cache.load(newCollection);
|
455
|
|
456
|
if(event.isCreatedType()){
|
457
|
SpecimenTypeDesignationDTORow row = collectionPopupEditorsRowMap.get(event.getSourceView());
|
458
|
ToOneRelatedEntityCombobox<Collection> combobox = row.getComponent(ToOneRelatedEntityCombobox.class, 3);
|
459
|
combobox.setValue((Collection) event.getEntity());
|
460
|
} else {
|
461
|
for( CollectionRowItemCollection row : popuEditorTypeDesignationSourceRows) {
|
462
|
ToOneRelatedEntityCombobox<Collection> combobox = row.getComponent(ToOneRelatedEntityCombobox.class, 3);
|
463
|
combobox.reload();
|
464
|
}
|
465
|
}
|
466
|
}
|
467
|
}
|
468
|
}
|
469
|
}
|
470
|
|
471
|
public void doReferenceEditorAdd(ToOneRelatedEntityCombobox<Reference> referenceComobox) {
|
472
|
|
473
|
ReferencePopupEditor referencePopupEditor = openPopupEditor(ReferencePopupEditor.class, null);
|
474
|
|
475
|
referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
|
476
|
referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
477
|
referencePopupEditor.withDeleteButton(true);
|
478
|
referencePopupEditor.loadInEditor(null);
|
479
|
|
480
|
referencePopupEditorsCombobox.put(referencePopupEditor, referenceComobox);
|
481
|
}
|
482
|
|
483
|
public void doReferenceEditorEdit(ToOneRelatedEntityCombobox<Reference> referenceComobox) {
|
484
|
|
485
|
ReferencePopupEditor referencePopupEditor = openPopupEditor(ReferencePopupEditor.class, null);
|
486
|
referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
|
487
|
referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
488
|
referencePopupEditor.withDeleteButton(true);
|
489
|
referencePopupEditor.loadInEditor(referenceComobox.getValue().getUuid());
|
490
|
|
491
|
referencePopupEditorsCombobox.put(referencePopupEditor, referenceComobox);
|
492
|
}
|
493
|
|
494
|
@EventBusListenerMethod(filter = EntityChangeEventFilter.ReferenceFilter.class)
|
495
|
public void onReferenceEvent(EntityChangeEvent event){
|
496
|
|
497
|
Reference newRef = getRepo().getReferenceService().load(event.getEntityUuid(), Arrays.asList(new String[]{"$"}));
|
498
|
cache.load(newRef);
|
499
|
|
500
|
ToOneRelatedEntityCombobox<Reference> combobox = referencePopupEditorsCombobox.get(event.getSourceView());
|
501
|
if(event.isCreatedType()){
|
502
|
combobox.setValue((Reference) event.getEntity());
|
503
|
} else {
|
504
|
for( CollectionRowItemCollection row : popuEditorTypeDesignationSourceRows) {
|
505
|
combobox.reload();
|
506
|
}
|
507
|
}
|
508
|
}
|
509
|
|
510
|
/**
|
511
|
* {@inheritDoc}
|
512
|
*/
|
513
|
@Override
|
514
|
public void addRootEntity(CdmBase entity) {
|
515
|
rootEntities.add(entity);
|
516
|
}
|
517
|
|
518
|
/**
|
519
|
* {@inheritDoc}
|
520
|
*/
|
521
|
@Override
|
522
|
public java.util.Collection<CdmBase> getRootEntities() {
|
523
|
return rootEntities ;
|
524
|
}
|
525
|
|
526
|
/**
|
527
|
* {@inheritDoc}
|
528
|
*/
|
529
|
@Override
|
530
|
public void destroy() throws Exception {
|
531
|
super.destroy();
|
532
|
cache.dispose();
|
533
|
}
|
534
|
|
535
|
/**
|
536
|
* @return
|
537
|
* the {@link #publishedUnit}
|
538
|
*/
|
539
|
public DescriptionElementSource getPublishedUnit() {
|
540
|
return publishedUnit;
|
541
|
}
|
542
|
|
543
|
/**
|
544
|
* @param publishedUnit
|
545
|
* The unit of publication in which the type designation has been published.
|
546
|
* This may be any type listed in {@link RegistrationUIDefaults#NOMECLATURAL_PUBLICATION_UNIT_TYPES}
|
547
|
*/
|
548
|
protected void setPublishedUnit(DescriptionElementSource publishedUnit) throws Exception {
|
549
|
if(publishedUnit == null) {
|
550
|
throw new NullPointerException();
|
551
|
}
|
552
|
if(publishedUnit.getCitation() == null) {
|
553
|
throw new NullPointerException("The citation of the published unit must not be null.");
|
554
|
}
|
555
|
if(!RegistrationUIDefaults.NOMECLATURAL_PUBLICATION_UNIT_TYPES.contains(publishedUnit.getCitation().getType())) {
|
556
|
throw new Exception("The referrence type '" + publishedUnit.getType() + "'is not allowed for publishedUnit.");
|
557
|
}
|
558
|
this.publishedUnit = publishedUnit;
|
559
|
}
|
560
|
|
561
|
}
|