1
|
/**
|
2
|
* Copyright (C) 2018 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.HashSet;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.service.IService;
|
18
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
19
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
21
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
22
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
23
|
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
|
24
|
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
|
25
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
|
26
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
|
27
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
28
|
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
29
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSet;
|
30
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
|
31
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
|
32
|
|
33
|
/**
|
34
|
* @author a.kohlbecker
|
35
|
* @since Jan 26, 2018
|
36
|
*
|
37
|
*/
|
38
|
public class NameTypeDesignationPresenter
|
39
|
extends AbstractCdmEditorPresenter<NameTypeDesignation, NameTypeDesignationEditorView> {
|
40
|
|
41
|
@Autowired
|
42
|
private IRegistrationWorkingSetService registrationWorkingSetService;
|
43
|
|
44
|
HashSet<TaxonName> typifiedNamesAsLoaded;
|
45
|
|
46
|
|
47
|
/**
|
48
|
* {@inheritDoc}
|
49
|
*/
|
50
|
@Override
|
51
|
protected NameTypeDesignation loadBeanById(Object identifier) {
|
52
|
if(identifier instanceof Integer || identifier == null){
|
53
|
return super.loadBeanById(identifier);
|
54
|
} else {
|
55
|
TypeDesignationWorkingsetEditorIdSet idset = (TypeDesignationWorkingsetEditorIdSet)identifier;
|
56
|
RegistrationDTO regDTO = registrationWorkingSetService.loadDtoById(idset.registrationId);
|
57
|
// find the working set
|
58
|
TypeDesignationWorkingSet typeDesignationWorkingSet = regDTO.getTypeDesignationWorkingSet(idset.baseEntityRef);
|
59
|
|
60
|
// NameTypeDesignation bameTypeDesignation = regDTO.getNameTypeDesignation(typeDesignationWorkingSet.getBaseEntityReference());
|
61
|
if(!typeDesignationWorkingSet.getBaseEntityReference().getType().equals(TaxonName.class)){
|
62
|
throw new RuntimeException("TypeDesignationWorkingsetEditorIdSet references not a NameTypeDesignation");
|
63
|
}
|
64
|
// TypeDesignationWorkingSet for NameTyped only contain one item!!!
|
65
|
int nameTypeDesignationId = typeDesignationWorkingSet.getTypeDesignations().get(0).getId();
|
66
|
return super.loadBeanById(nameTypeDesignationId);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
|
71
|
/**
|
72
|
* {@inheritDoc}
|
73
|
*/
|
74
|
@Override
|
75
|
protected NameTypeDesignation loadCdmEntityById(Integer identifier) {
|
76
|
List<String> initStrategy = Arrays.asList(new String []{
|
77
|
"$",
|
78
|
"typifiedNames.typeDesignations", // important !!
|
79
|
"typeName.$",
|
80
|
"citation.authorship.$",
|
81
|
}
|
82
|
);
|
83
|
|
84
|
NameTypeDesignation typeDesignation;
|
85
|
if(identifier != null){
|
86
|
typeDesignation = (NameTypeDesignation) getRepo().getNameService().loadTypeDesignation(identifier, initStrategy);
|
87
|
} else {
|
88
|
if(beanInstantiator != null){
|
89
|
typeDesignation = beanInstantiator.createNewBean();
|
90
|
} else {
|
91
|
typeDesignation = NameTypeDesignation.NewInstance();
|
92
|
}
|
93
|
}
|
94
|
|
95
|
typifiedNamesAsLoaded = new HashSet<>(typeDesignation.getTypifiedNames());
|
96
|
|
97
|
return typeDesignation;
|
98
|
}
|
99
|
|
100
|
|
101
|
|
102
|
|
103
|
/**
|
104
|
* {@inheritDoc}
|
105
|
*/
|
106
|
@Override
|
107
|
public void handleViewEntered() {
|
108
|
|
109
|
CdmBeanItemContainerFactory selectFactory = new CdmBeanItemContainerFactory(getRepo());
|
110
|
getView().getTypeStatusSelect().setContainerDataSource(selectFactory.buildBeanItemContainer(NameTypeDesignationStatus.class));
|
111
|
getView().getTypeStatusSelect().setItemCaptionPropertyId("description");
|
112
|
|
113
|
getView().getCitationCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
|
114
|
CdmFilterablePagingProvider<Reference,Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference, Reference>(getRepo().getReferenceService());
|
115
|
getView().getCitationCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
|
116
|
getView().getCitationCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Reference>(getView().getCitationCombobox()));
|
117
|
getView().getCitationCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getCitationCombobox(), this));
|
118
|
|
119
|
CdmFilterablePagingProvider<TaxonName,TaxonName> namePagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(getRepo().getNameService());
|
120
|
getView().getTypeNameField().loadFrom(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize());
|
121
|
getView().getTypeNameField().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<TaxonName>(getView().getTypeNameField()));
|
122
|
getView().getTypeNameField().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getTypeNameField(), this));
|
123
|
|
124
|
getView().getTypifiedNamesComboboxSelect().setPagingProviders(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize(), this);
|
125
|
|
126
|
}
|
127
|
|
128
|
|
129
|
/**
|
130
|
* {@inheritDoc}
|
131
|
*/
|
132
|
@Override
|
133
|
protected void guaranteePerEntityCRUDPermissions(Integer identifier) {
|
134
|
if(crud != null){
|
135
|
newAuthorityCreated = UserHelper.fromSession().createAuthorityForCurrentUser(NameTypeDesignation.class, identifier, crud, null);
|
136
|
}
|
137
|
}
|
138
|
|
139
|
/**
|
140
|
* {@inheritDoc}
|
141
|
*/
|
142
|
@Override
|
143
|
protected void guaranteePerEntityCRUDPermissions(NameTypeDesignation bean) {
|
144
|
// TODO Auto-generated method stub
|
145
|
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* {@inheritDoc}
|
150
|
*/
|
151
|
@Override
|
152
|
protected IService<NameTypeDesignation> getService() {
|
153
|
// TODO Auto-generated method stub
|
154
|
return null;
|
155
|
}
|
156
|
|
157
|
|
158
|
/**
|
159
|
* {@inheritDoc}
|
160
|
*/
|
161
|
@Override
|
162
|
protected NameTypeDesignation handleTransientProperties(NameTypeDesignation bean) {
|
163
|
|
164
|
// the typifiedNames can only be set on the name side, so we need to
|
165
|
// handle changes explicitly here
|
166
|
HashSet<TaxonName> typifiedNames = new HashSet<>(bean.getTypifiedNames());
|
167
|
|
168
|
// handle adds
|
169
|
for(TaxonName name : typifiedNames){
|
170
|
if(!name.getTypeDesignations().contains(bean)){
|
171
|
name.addTypeDesignation(bean, false);
|
172
|
}
|
173
|
}
|
174
|
// handle removed
|
175
|
for(TaxonName name : typifiedNamesAsLoaded){
|
176
|
if(!typifiedNames.contains(name)){
|
177
|
name.removeTypeDesignation(bean);
|
178
|
}
|
179
|
// FIXME do we need to save the names here or is the delete cascaded from the typedesignation to the name?
|
180
|
}
|
181
|
|
182
|
return bean;
|
183
|
}
|
184
|
|
185
|
|
186
|
|
187
|
}
|