Project

General

Profile

« Previous | Next » 

Revision fe785c1e

Added by Andreas Kohlbecker almost 7 years ago

fix #6687 per view implementation of the 'session-per-conversation' pattern

View differences:

src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java
23 23
import org.springframework.context.annotation.FilterType;
24 24
import org.springframework.context.annotation.Lazy;
25 25

  
26
import com.vaadin.server.DeploymentConfiguration;
27
import com.vaadin.server.ServiceException;
28
import com.vaadin.server.VaadinServletService;
26 29
import com.vaadin.spring.annotation.EnableVaadin;
27 30
import com.vaadin.spring.annotation.SpringUI;
28 31
import com.vaadin.spring.annotation.UIScope;
......
32 35
import eu.etaxonomy.cdm.common.ConfigFileUtil;
33 36
import eu.etaxonomy.cdm.opt.config.DataSourceConfigurer;
34 37
import eu.etaxonomy.cdm.vaadin.security.annotation.EnableAnnotationBasedAccessControl;
38
import eu.etaxonomy.cdm.vaadin.server.CdmSpringVaadinServletService;
35 39
import eu.etaxonomy.cdm.vaadin.ui.ConceptRelationshipUI;
36 40
import eu.etaxonomy.cdm.vaadin.ui.DistributionStatusUI;
37 41
import eu.etaxonomy.cdm.vaadin.ui.InactiveUIException;
......
87 91

  
88 92
        private static final long serialVersionUID = -2615042297393028775L;
89 93

  
94
        @Override
95
        protected VaadinServletService createServletService(
96
                DeploymentConfiguration deploymentConfiguration)
97
                throws ServiceException {
98

  
99
            //  - The SpringVaadinServletService is needed when using a custom service URL
100
            //  - The CdmSpringVaadinServletService allows to attach listeners to the requestEnd and 
101
            //    requestStart method this is important for proper unbinding of Conversations from 
102
            //    the request threads.
103
            //    see ViewScopeConversationHolder
104
            CdmSpringVaadinServletService service = new CdmSpringVaadinServletService(
105
                    this, deploymentConfiguration, getServiceUrlPath());
106
            service.init();
107
            return service;
108
        }
109

  
90 110
        /**
91 111
         *
92 112
        @SuppressWarnings("serial")
src/main/java/eu/etaxonomy/cdm/service/CdmFilterablePagingProvider.java
19 19
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
20 20
import eu.etaxonomy.cdm.persistence.query.MatchMode;
21 21
import eu.etaxonomy.cdm.persistence.query.OrderHint;
22
import eu.etaxonomy.cdm.vaadin.session.ConversationDirector;
22 23

  
23 24
/**
24 25
 * @author a.kohlbecker
......
29 30

  
30 31
    private int pageSize = 20;
31 32

  
32
    protected IIdentifiableEntityService<T> service;
33
    private IIdentifiableEntityService<T> service;
33 34

  
34 35
    private MatchMode matchMode = MatchMode.ANYWHERE;
35 36

  
36 37
    private List<OrderHint> orderHints = OrderHint.ORDER_BY_TITLE_CACHE.asList();
37 38

  
39
    private ConversationDirector conversationDirector;
40

  
38 41

  
39 42
    /**
40 43
     * @return the matchMode
......
69 72
     *
70 73
     * @param service
71 74
     */
72
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service) {
75
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, ConversationDirector conversationDirector) {
73 76
        super();
74 77
        this.service = service;
78
        this.conversationDirector = conversationDirector;
75 79
    }
76 80

  
77 81
    /**
......
79 83
     * @param matchMode
80 84
     * @param orderHints
81 85
     */
82
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, MatchMode matchMode,
83
            List<OrderHint> orderHints) {
86
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, MatchMode matchMode, List<OrderHint> orderHints, ConversationDirector conversationDirector) {
84 87
        super();
85 88
        this.service = service;
86 89
        this.matchMode = matchMode;
87 90
        this.orderHints = orderHints;
91
        this.conversationDirector = conversationDirector;
88 92
    }
89 93

  
90 94
    /**
......
92 96
     */
93 97
    @Override
94 98
    public List<T> findEntities(int firstRow, String filter) {
99

  
100
        conversationDirector.ensureBoundConversation();
95 101
        Pager<T> page = service.findByTitle(
96 102
                null,
97 103
                filter,
......
110 116
     */
111 117
    @Override
112 118
    public int size(String filter) {
119

  
120
        conversationDirector.ensureBoundConversation();
113 121
        Pager<T> page = service.findByTitle(
114 122
                null,
115 123
                filter,
src/main/java/eu/etaxonomy/cdm/service/CdmStore.java
12 12
import org.hibernate.Session;
13 13
import org.hibernate.engine.spi.SessionImplementor;
14 14
import org.springframework.transaction.TransactionStatus;
15
import org.springframework.transaction.support.DefaultTransactionDefinition;
15 16

  
16 17
import com.vaadin.ui.Notification;
17 18
import com.vaadin.ui.UI;
......
40 41

  
41 42
    private S service;
42 43

  
43
    TransactionStatus tx = null;
44
    TransactionStatus txNonConversational = null;
44 45

  
45 46
    ConversationHolder conversationHolder = null;
46 47

  
48
    /**
49
     * @return the conversationHolder
50
     */
51
    public ConversationHolder getConversationHolder() {
52
        return conversationHolder;
53
    }
54

  
55
    protected DefaultTransactionDefinition txDefinition = null;
56

  
47 57
    /**
48 58
     *
49 59
     * @param repo
......
58 68

  
59 69
    }
60 70

  
61

  
62
    public TransactionStatus startConversationalTransaction() {
63
        checkExistingTransaction();
64
        getConversationHolder().bind();
65
        tx = getConversationHolder().startTransaction();
66
        return tx;
67
    }
68

  
69

  
70 71
    /**
71
     * @return
72
     * constructor which takes a ConversationHolder. The supplying class of the conversationHolder needs
73
     * to care for <code>bind()</code>, <code>unbind()</code> and <code>close()</code> since the store is
74
     * only responsible for starting and committing of transactions.
75
     *
76
     * @param repo
77
     * @param service
78
     * @param conversationHolder
72 79
     */
73
    protected ConversationHolder getConversationHolder() {
74
        if(conversationHolder == null){
75
            conversationHolder = (ConversationHolder) repo.getBean("conversationHolder");
76
        }
77
        return conversationHolder;
80
    public CdmStore(CdmRepository repo, S service, ConversationHolder conversationHolder) {
81

  
82
        this.repo = repo;
83
        this.service = service;
84
        this.conversationHolder = conversationHolder;
85

  
78 86
    }
87

  
79 88
    /**
80 89
     * @return
81 90
     *
82 91
     */
83
    public TransactionStatus startTransaction(boolean readOnly) {
84
        checkExistingTransaction();
85
        return repo.startTransaction(readOnly);
92
    public TransactionStatus startTransaction() {
93
        if(conversationHolder != null && !conversationHolder.isTransactionActive()){
94
            //conversationHolder.setDefinition(getTransactionDefinition());
95
            return conversationHolder.startTransaction();
96
        } else {
97
            checkExistingTransaction();
98
            txNonConversational = repo.startTransaction();
99
            return txNonConversational;
100
        }
86 101
    }
87 102

  
88

  
89 103
    /**
90 104
     *
91 105
     */
92 106
    protected void checkExistingTransaction() {
93
        if (tx != null) {
107
        if (txNonConversational != null) {
94 108
            // @formatter:off
95 109
            // holding the TransactionStatus as state is not good design. we
96 110
            // should change the save operation
......
103 117
            // 2. passing the TransactionState to the view also doesn't seem
104 118
            // like a good idea.
105 119
            // @formatter:on
106
            throw new RuntimeException("Can't process a second save operation while another one is in progress.");
120
            throw new RuntimeException("Opening a second transaction in the same" + this.getClass().getSimpleName() + " is not supported");
107 121
        }
108 122
    }
109 123

  
......
144 158
     */
145 159
    private Session getSession() {
146 160

  
147
        Session session = repo.getSession();
161
        Session session;
162
        if(conversationHolder != null){
163
            session = conversationHolder.getSession();
164
        } else {
165
            session = repo.getSession();
166
        }
148 167
        logger.trace(this._toString() + ".getSession() - session:" + session.hashCode() + ", persistenceContext: "
149 168
                + ((SessionImplementor) session).getPersistenceContext() + " - " + session.toString());
150 169

  
......
170 189
        } else {
171 190
            changeEventType = Type.CREATED;
172 191
        }
192

  
173 193
        Session session = getSession();
174
        boolean conversationTransaction = true;
175
        if(tx == null){
176
            conversationTransaction = false;
177
            tx = startTransaction(false);
178
        }
179 194
        logger.trace(this._toString() + ".onEditorSaveEvent - session: " + session.hashCode());
195

  
196
        if(txNonConversational == null || (conversationHolder != null && !conversationHolder.isTransactionActive())){
197
            // no running transaction, start one ...
198
            startTransaction();
199
        }
200

  
180 201
        logger.trace(this._toString() + ".onEditorSaveEvent - merging bean into session");
181 202
        // merge the changes into the session, ...
182 203
        T mergedBean = mergedBean(bean);
183 204
        repo.getCommonService().saveOrUpdate(mergedBean);
184
        if(conversationTransaction){
185
            flushCommitAndCloseConversationTransaction();
186
        } else {
187
            flushCommitAndClose();
188
        }
205
        session.flush();
206
        commitTransction();
189 207

  
190 208
        return new EntityChangeEvent(mergedBean.getClass(), mergedBean.getId(), changeEventType);
191 209
    }
......
199 217

  
200 218
        logger.trace(this._toString() + ".onEditorPreSaveEvent - starting transaction");
201 219

  
202
        startTransaction(false);
220
        startTransaction();
203 221
        logger.trace(this._toString() + ".deleteBean - deleting" + bean.toString());
204 222
        DeleteResult result = service.delete(bean);
205 223
        if (result.isOk()) {
206 224

  
207
            flushCommitAndClose();
225
            getSession().flush();
226
            commitTransction();
208 227
            logger.trace(this._toString() + ".deleteBean - transaction comitted");
209 228
            return new EntityChangeEvent(bean.getClass(), bean.getId(), Type.REMOVED);
210 229
        } else {
......
237 256
            Notification notification = new Notification(notificationTitle, messageBody.toString(),
238 257
                    com.vaadin.ui.Notification.Type.ERROR_MESSAGE, true);
239 258
            notification.show(UI.getCurrent().getPage());
240
            tx = null;
259
            txNonConversational = null;
241 260
        }
242 261
        return null;
243 262
    }
244 263

  
245
    /**
246
     * @param session
247
     */
248
    protected void flushCommitAndClose() {
249
        Session session = getSession();
250
        session.flush();
251
        logger.trace(this._toString() + "session flushed");
252
        repo.commitTransaction(tx);
253
        tx = null;
254
        if(session.isOpen()){
255
            session.close();
264

  
265
    protected void commitTransction() {
266

  
267
        if(conversationHolder != null){
268
            conversationHolder.commit();
269
        } else {
270
            repo.commitTransaction(txNonConversational);
271
            txNonConversational = null;
256 272
        }
257
        session = null;
273
    }
258 274

  
259
        logger.trace(this._toString() + "transaction comitted and session closed");
275
    /**
276
     * @param entityId
277
     */
278
    public T loadBean(int entityId) {
279
        conversationHolder.startTransaction();
280
        return service.find(entityId);
260 281
    }
261 282

  
262
    protected void flushCommitAndCloseConversationTransaction() {
263
        getConversationHolder().getSession().flush();
264
        logger.trace(this._toString() + "conversational session flushed");
265
        getConversationHolder().commit();
266
        getConversationHolder().close();
267
        tx = null;
268
        logger.trace(this._toString() + "conversational transaction comitted and session closed");
283
    public S getService() {
284
        return service;
269 285
    }
270 286

  
287

  
271 288
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/CdmBeanItemContainerFactory.java
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.component;
10

  
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import com.vaadin.data.util.BeanItemContainer;
17

  
18
import eu.etaxonomy.cdm.api.application.CdmRepository;
19
import eu.etaxonomy.cdm.api.service.pager.Pager;
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
22
import eu.etaxonomy.cdm.model.common.TermType;
23
import eu.etaxonomy.cdm.model.common.TermVocabulary;
24
import eu.etaxonomy.cdm.persistence.query.OrderHint;
25

  
26
/**
27
 * @author a.kohlbecker
28
 * @since Apr 6, 2017
29
 *
30
 */
31
public class CdmBeanItemContainerFactory {
32

  
33
    private CdmRepository repo;
34

  
35
    private final static List<String> INIT_STRATEGY = Arrays.asList(new String[]{"$", "representations"});
36

  
37
    private static List<OrderHint> orderHints = new ArrayList<>();
38

  
39
    static {
40
        orderHints.add(OrderHint.BY_ORDER_INDEX);
41
        orderHints.add(OrderHint.ORDER_BY_TITLE_CACHE);
42
    }
43

  
44
    /**
45
     * Constructor to be used by presenter classes directly
46
     *
47
     * @param repo
48
     */
49
    public CdmBeanItemContainerFactory(CdmRepository repo){
50
        this.repo = repo;
51
    }
52

  
53
    /**
54
     * @param termType
55
     */
56
    public BeanItemContainer<DefinedTermBase> buildBeanItemContainer(TermType termType) {
57
        // TODO use TermCacher?
58
        List<DefinedTermBase> terms = repo.getTermService().listByTermType(termType, null, null, orderHints, INIT_STRATEGY);
59
        BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class);
60
        termItemContainer.addAll(terms);
61
        return termItemContainer;
62
    }
63

  
64
    /**
65
     * @param termType
66
     */
67
    public BeanItemContainer<DefinedTermBase> buildBeanItemContainer(UUID vocabularyUuid) {
68

  
69
        TermVocabulary vocab = repo.getVocabularyService().find(vocabularyUuid);
70
        Pager<DefinedTermBase> terms = repo.getVocabularyService().getTerms(vocab, null, null, orderHints, INIT_STRATEGY);
71
        BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class);
72
        termItemContainer.addAll(terms.getRecords());
73
        return termItemContainer;
74
    }
75

  
76
    /**
77
     * @param termType
78
     */
79
    public BeanItemContainer<DefinedTermBase> buildTermItemContainer(UUID ... termUuid) {
80
        return buildTermItemContainer(Arrays.asList(termUuid));
81
    }
82

  
83
    /**
84
     * @param derivation_EVENT_TYPE_UUIDS
85
     * @return
86
     */
87
    public BeanItemContainer<DefinedTermBase> buildTermItemContainer(List<UUID> termsUuids) {
88
        List<DefinedTermBase> terms = repo.getTermService().load(termsUuids, INIT_STRATEGY);
89
        BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class);
90
        termItemContainer.addAll(terms);
91
        return termItemContainer;
92
    }
93

  
94
    /**
95
     * @param termType
96
     */
97
    public <T extends CdmBase> BeanItemContainer<T> buildBeanItemContainer(Class<T> type, List<OrderHint> orderHints) {
98

  
99
        if(orderHints == null){
100
            orderHints = OrderHint.defaultOrderHintsFor(type);
101
        }
102

  
103
        List<T> terms = repo.getCommonService().list(type, (Integer)null, (Integer)null,
104
                orderHints,
105
                Arrays.asList(new String[]{"$"}));
106
        BeanItemContainer<T> termItemContainer = new BeanItemContainer<>(type);
107
        termItemContainer.addAll(terms);
108
        return termItemContainer;
109
    }
110

  
111
    public <T extends CdmBase> BeanItemContainer<T> buildBeanItemContainer(Class<T> type) {
112
        return buildBeanItemContainer(type, null);
113
    }
114

  
115

  
116
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/SelectFieldFactory.java
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.component;
10

  
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Qualifier;
18

  
19
import com.vaadin.data.util.BeanItemContainer;
20
import com.vaadin.spring.annotation.SpringComponent;
21
import com.vaadin.ui.ListSelect;
22

  
23
import eu.etaxonomy.cdm.api.application.CdmRepository;
24
import eu.etaxonomy.cdm.api.service.pager.Pager;
25
import eu.etaxonomy.cdm.model.common.CdmBase;
26
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
27
import eu.etaxonomy.cdm.model.common.TermType;
28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
29
import eu.etaxonomy.cdm.persistence.query.OrderHint;
30

  
31
/**
32
 * @author a.kohlbecker
33
 * @since Apr 6, 2017
34
 *
35
 */
36
@SpringComponent
37
public class SelectFieldFactory {
38

  
39
    @Autowired
40
    @Qualifier("cdmRepository")
41
    private CdmRepository repo;
42

  
43
    private final static List<String> INIT_STRATEGY = Arrays.asList(new String[]{"$", "representations"});
44

  
45
    private static List<OrderHint> orderHints = new ArrayList<>();
46

  
47
    static {
48
        orderHints.add(OrderHint.BY_ORDER_INDEX);
49
        orderHints.add(OrderHint.ORDER_BY_TITLE_CACHE);
50
    }
51

  
52
    /**
53
     * Constructor for the Spring Bean Factory
54
     */
55
    public SelectFieldFactory(){
56
        this.repo = null;
57
    }
58

  
59
    /**
60
     * Constructor to be used by presenter classes directly
61
     *
62
     * @param repo
63
     */
64
    public SelectFieldFactory(CdmRepository repo){
65
        this.repo = repo;
66
    }
67

  
68
    public ListSelect createListSelect(String caption, TermType termType){
69
        BeanItemContainer<DefinedTermBase> termItemContainer = buildBeanItemContainer(termType);
70
        ListSelect select = new ListSelect(caption, termItemContainer);
71
        return select;
72
    }
73

  
74
    /**
75
     *
76
     * @param caption
77
     * @param type
78
     * @return
79
     */
80
    public <T extends CdmBase> ListSelect createListSelect(String caption, Class<T> type){
81
        return createListSelect(caption, type, null);
82
    }
83

  
84
    public <T extends CdmBase> ListSelect createListSelect(String caption, Class<T> type, List<OrderHint> orderHints){
85
        return createListSelect(caption, type, orderHints, null);
86
    }
87

  
88
    /**
89
     *
90
     * @param caption
91
     * @param type
92
     * @param orderHints
93
     * @param propertyId the property id from which to read the label
94
     * @return
95
     */
96
    public <T extends CdmBase> ListSelect createListSelect(String caption, Class<T> type, List<OrderHint> orderHints, String propertyId){
97

  
98
        if(orderHints == null){
99
            orderHints = OrderHint.defaultOrderHintsFor(type);
100
        }
101

  
102
        BeanItemContainer<T> termItemContainer = buildBeanItemContainer(type, orderHints);
103
        ListSelect select = new ListSelect(caption, termItemContainer);
104

  
105
        // guess property id to use for display
106
        if(propertyId == null) {
107
            if(orderHints != null && !orderHints.isEmpty()){
108
                propertyId = orderHints.get(0).getPropertyName();
109
            }
110
        }
111
        if(propertyId != null){
112
            select.setItemCaptionPropertyId(propertyId);
113
        }
114
        return select;
115
    }
116

  
117

  
118
    /**
119
     * @param termType
120
     */
121
    public BeanItemContainer<DefinedTermBase> buildBeanItemContainer(TermType termType) {
122
        // TODO use TermCacher?
123
        List<DefinedTermBase> terms = repo.getTermService().listByTermType(termType, null, null, orderHints, INIT_STRATEGY);
124
        BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class);
125
        termItemContainer.addAll(terms);
126
        return termItemContainer;
127
    }
128

  
129
    /**
130
     * @param termType
131
     */
132
    public BeanItemContainer<DefinedTermBase> buildBeanItemContainer(UUID vocabularyUuid) {
133

  
134
        TermVocabulary vocab = repo.getVocabularyService().find(vocabularyUuid);
135
        Pager<DefinedTermBase> terms = repo.getVocabularyService().getTerms(vocab, null, null, orderHints, INIT_STRATEGY);
136
        BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class);
137
        termItemContainer.addAll(terms.getRecords());
138
        return termItemContainer;
139
    }
140

  
141
    /**
142
     * @param termType
143
     */
144
    public BeanItemContainer<DefinedTermBase> buildTermItemContainer(UUID ... termUuid) {
145
        return buildTermItemContainer(Arrays.asList(termUuid));
146
    }
147

  
148
    /**
149
     * @param derivation_EVENT_TYPE_UUIDS
150
     * @return
151
     */
152
    public BeanItemContainer<DefinedTermBase> buildTermItemContainer(List<UUID> termsUuids) {
153
        List<DefinedTermBase> terms = repo.getTermService().load(termsUuids, INIT_STRATEGY);
154
        BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class);
155
        termItemContainer.addAll(terms);
156
        return termItemContainer;
157
    }
158

  
159
    /**
160
     * @param termType
161
     */
162
    public <T extends CdmBase> BeanItemContainer<T> buildBeanItemContainer(Class<T> type, List<OrderHint> orderHints) {
163

  
164
        List<T> terms = repo.getCommonService().list(type, (Integer)null, (Integer)null,
165
                orderHints,
166
                Arrays.asList(new String[]{"$"}));
167
        BeanItemContainer<T> termItemContainer = new BeanItemContainer<>(type);
168
        termItemContainer.addAll(terms);
169
        return termItemContainer;
170
    }
171

  
172

  
173
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItemEditButtonGroup.java
20 20
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;
21 21
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
22 22
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSet;
23
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
23 24
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
24 25
import eu.etaxonomy.vaadin.component.CompositeStyledComponent;
25 26

  
......
42 43

  
43 44
    private IdButton<TaxonName> nameIdButton = null;
44 45

  
45
    private List<IdButton<TypeDesignationWorkingSet>> typeDesignationButtons = new ArrayList<>();
46
    private List<TypeDesignationWorkingSetButton> typeDesignationButtons = new ArrayList<>();
46 47

  
47 48
    private List<Label> labels = new ArrayList<>();
48 49

  
......
74 75
//                Set<Integer> idSet = new HashSet<>();
75 76
//                typeDesignationWorkingSet.getTypeDesignations().forEach(td -> idSet.add(td.getId()));
76 77

  
77
                typeDesignationButtons.add(new IdButton<TypeDesignationWorkingSet>(
78
                        TypeDesignationWorkingSet.class,
78
                typeDesignationButtons.add(new TypeDesignationWorkingSetButton(
79
                        typeDesignationWorkingSet.getWorkingsetType(),
79 80
                        typeDesignationWorkingSet.getWorkingSetId(),
80 81
                        tdButton)
81 82
                        );
......
102 103
        return nameIdButton;
103 104
    }
104 105

  
105
    public List<IdButton<TypeDesignationWorkingSet>> getTypeDesignationButtons() {
106
    public List<TypeDesignationWorkingSetButton> getTypeDesignationButtons() {
106 107
        return typeDesignationButtons;
107 108
    }
108 109

  
......
121 122
        addTypeDesignationButton.addStyleName(DEFAULT_BUTTON_STYLES);
122 123
    }
123 124

  
125
    public class TypeDesignationWorkingSetButton {
126
        private Integer id;
127
        private TypeDesignationWorkingSetType type;
128
        private Button button;
129

  
130
        public TypeDesignationWorkingSetButton(TypeDesignationWorkingSetType type, Integer id, Button button){
131
            this.type = type;
132
            this.id = id;
133
            this.button = button;
134
        }
135

  
136
        /**
137
         * @return the id
138
         */
139
        public Integer getId() {
140
            return id;
141
        }
142

  
143
        /**
144
         * @return the button
145
         */
146
        public Button getButton() {
147
            return button;
148
        }
149

  
150
        /**
151
         * @return the type
152
         */
153
        public TypeDesignationWorkingSetType getType() {
154
            return type;
155
        }
156

  
157
    }
158

  
124 159
    public class IdButton<T> {
125 160
        private Integer id;
126
        private Class<T> type;
161
        private Class<T> entityType;
127 162
        private Button button;
128 163

  
129 164
        public IdButton(Class<T> type, Integer id, Button button){
130
            this.type = type;
165
            this.entityType = type;
131 166
            this.id = id;
132 167
            this.button = button;
133 168
        }
......
150 185
         * @return the type
151 186
         */
152 187
        public Class<T> getType() {
153
            return type;
188
            return entityType;
154 189
        }
155 190

  
156 191
    }
src/main/java/eu/etaxonomy/cdm/vaadin/event/TypeDesignationWorkingsetEditorAction.java
10 10

  
11 11
import com.vaadin.ui.Component;
12 12

  
13
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
13
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
14 14
import eu.etaxonomy.vaadin.mvp.AbstractView;
15 15

  
16 16
/**
......
20 20
 */
21 21
public class TypeDesignationWorkingsetEditorAction extends AbstractEditorAction {
22 22

  
23
    private Class<? extends TypeDesignationBase<?>> newEntityType;
23
    private TypeDesignationWorkingSetType workingSetType;
24 24

  
25 25
    private int registrationId;
26 26

  
27 27
    /**
28
     * @param edit
29
     * @param ids
28
     *
29
     * @param action
30
     * @param typeDesignationWorkingsetId
31
     * @param workingSetType
32
     * @param registrationId
33
     * @param source
34
     * @param sourceView
30 35
     */
31
    public TypeDesignationWorkingsetEditorAction(Action action, Integer typeDesignationWorkingsetId, int registrationId, Component source, AbstractView sourceView) {
36
    public TypeDesignationWorkingsetEditorAction(Action action, Integer typeDesignationWorkingsetId, TypeDesignationWorkingSetType workingSetType, int registrationId,
37
            Component source, AbstractView sourceView) {
32 38
        super(action, typeDesignationWorkingsetId, source, sourceView);
33 39
        this.registrationId = registrationId;
40
        this.workingSetType = workingSetType;
34 41
    }
35 42

  
36 43
    /**
37
     * Constructor which is mainly suitable for ADD actions.
38
     * @param
44
     *
45
     * @param action
46
     * @param workingSetType
47
     * @param registrationId
48
     * @param source
49
     * @param sourceView
39 50
     */
40
    public TypeDesignationWorkingsetEditorAction(Action action, Class<? extends TypeDesignationBase<?>> newEntityType, int registrationId,
51
    public TypeDesignationWorkingsetEditorAction(Action action, TypeDesignationWorkingSetType workingSetType, int registrationId,
41 52
            Component source, AbstractView sourceView) {
42 53
        super(action, null, source, sourceView);
43
        this.newEntityType = newEntityType;
54
        this.workingSetType = workingSetType;
44 55
        this.registrationId = registrationId;
45 56
    }
46 57

  
47 58
    /**
48
     * In case of an ADD action the receiver of the event needs to know the specific type of the
49
     * TypeDesignationBase instance to be created.
50 59
     *
51
     * @return the newEntityType
60
     * @return
52 61
     */
53
    public Class<? extends TypeDesignationBase<?>> getNewEntityType() {
54
        return newEntityType;
62
    public TypeDesignationWorkingSetType getWorkingSetType() {
63
        return workingSetType;
55 64
    }
56 65

  
57 66
    /**
src/main/java/eu/etaxonomy/cdm/vaadin/server/CdmSpringVaadinServletService.java
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.server;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import com.vaadin.server.DeploymentConfiguration;
15
import com.vaadin.server.ServiceException;
16
import com.vaadin.server.VaadinRequest;
17
import com.vaadin.server.VaadinResponse;
18
import com.vaadin.server.VaadinServlet;
19
import com.vaadin.server.VaadinSession;
20
import com.vaadin.spring.server.SpringVaadinServletService;
21

  
22
/**
23
 * @author a.kohlbecker
24
 * @since Jul 4, 2017
25
 *
26
 */
27
public class CdmSpringVaadinServletService extends SpringVaadinServletService {
28

  
29
    private static final long serialVersionUID = 5956798985059823698L;
30

  
31
    List<RequestEndListener> requestEndListeners = new ArrayList<>();
32

  
33
    List<RequestStartListener> requestStartListeners = new ArrayList<>();
34

  
35
    /**
36
     * @param servlet
37
     * @param deploymentConfiguration
38
     * @param serviceUrl
39
     * @throws ServiceException
40
     */
41
    public CdmSpringVaadinServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration,
42
            String serviceUrl) throws ServiceException {
43
        super(servlet, deploymentConfiguration, serviceUrl);
44
    }
45

  
46
    @Override
47
    public void requestStart(VaadinRequest request, VaadinResponse response) {
48
        super.requestStart(request, response);
49
        requestStartListeners.forEach(l -> l.onRequestStart(request));
50
    }
51

  
52
    @Override
53
    public void requestEnd(VaadinRequest request, VaadinResponse response,
54
            VaadinSession session) {
55
        super.requestEnd(request, response, session);
56
        requestEndListeners.forEach(l -> l.onRequestEnd(request, session));
57
    }
58

  
59
    public void addRequestStartListener(RequestStartListener requestStartListener){
60
        requestStartListeners.add(requestStartListener);
61
    }
62

  
63
    public void removeRequestStartListener(RequestStartListener requestStartListener){
64
        requestStartListeners.remove(requestStartListener);
65
    }
66

  
67
    public void addRequestEndListener(RequestEndListener requestEndListener){
68
        requestEndListeners.add(requestEndListener);
69
    }
70

  
71
    public void removeRequestEndListener(RequestEndListener requestEndListener){
72
        requestEndListeners.remove(requestEndListener);
73
    }
74

  
75

  
76

  
77

  
78

  
79

  
80
}
src/main/java/eu/etaxonomy/cdm/vaadin/server/RequestEndListener.java
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.server;
10

  
11
import com.vaadin.server.VaadinRequest;
12
import com.vaadin.server.VaadinSession;
13

  
14
/**
15
 * @author a.kohlbecker
16
 * @since Jul 4, 2017
17
 *
18
 */
19
public interface RequestEndListener {
20

  
21
    public void onRequestEnd(VaadinRequest request, VaadinSession session);
22

  
23
}
src/main/java/eu/etaxonomy/cdm/vaadin/server/RequestStartListener.java
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.server;
10

  
11
import com.vaadin.server.VaadinRequest;
12

  
13
/**
14
 * @author a.kohlbecker
15
 * @since Jul 4, 2017
16
 *
17
 */
18
public interface RequestStartListener {
19

  
20
    public void onRequestStart(VaadinRequest request);
21

  
22
}
src/main/java/eu/etaxonomy/cdm/vaadin/session/ConversationDirector.java
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.session;
10

  
11
/**
12
 * @author a.kohlbecker
13
 * @since Jul 6, 2017
14
 *
15
 */
16
public interface ConversationDirector {
17

  
18
    public void ensureBoundConversation();
19

  
20
}
src/main/java/eu/etaxonomy/cdm/vaadin/session/IntraViewConversationDirector.java
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.session;
10

  
11
import eu.etaxonomy.cdm.vaadin.server.RequestEndListener;
12

  
13
/**
14
 * @author a.kohlbecker
15
 * @since Jul 6, 2017
16
 *
17
 */
18
public interface IntraViewConversationDirector extends ConversationDirector, RequestEndListener {
19

  
20
}
src/main/java/eu/etaxonomy/cdm/vaadin/session/ViewScopeConversationHolder.java
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.session;
10

  
11
import java.io.Serializable;
12

  
13
import javax.sql.DataSource;
14

  
15
import org.hibernate.FlushMode;
16
import org.hibernate.SessionFactory;
17
import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter;
18
import org.springframework.transaction.PlatformTransactionManager;
19
import org.springframework.transaction.TransactionDefinition;
20
import org.springframework.transaction.support.DefaultTransactionDefinition;
21

  
22
import com.vaadin.spring.annotation.SpringComponent;
23
import com.vaadin.spring.annotation.ViewScope;
24

  
25
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
26
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
27

  
28
/**
29
 * The ViewScopeConversationHolder allows to span conversations over all request threads
30
 * that are involved in the creation, interaction and ending of a View.
31
 *
32
 * <p><b>NOTE</b>: Hibernate sessions created in the conversation created by this holder
33
 * will not fluish automatically. The flush mode is initially
34
 * set to {@code FlushMode.MANUAL}. It assumes to be used
35
 * in combination with service layer transactions that care for the flushing: The
36
 * active transaction manager will temporarily change the flush mode to
37
 * {@code FlushMode.AUTO} during a read-write transaction, with the flush
38
 * mode reset to {@code FlushMode.NEVER} at the end of each transaction.
39
 * This behavior is implemented consistently in the {@link {@link AbstractEditorPresenter} methods
40
 * {@link AbstractEditorPresenter#onEditorPreSaveEvent(eu.etaxonomy.vaadin.mvp.event.EditorPreSaveEvent) onEditorPreSaveEvent},
41
 * {@link AbstractEditorPresenter#onEditorSaveEvent(eu.etaxonomy.vaadin.mvp.event.EditorSaveEvent) onEditorSaveEvent} and
42
 * {@link AbstractEditorPresenter#onEditorDeleteEvent(eu.etaxonomy.vaadin.mvp.event.EditorDeleteEvent) onEditorDeleteEvent}
43
 * In this whole strategy this class follows the ideas of the {@link OpenSessionInViewFilter}.
44
 *
45
 * @author a.kohlbecker
46
 * @since Jun 30, 2017
47
 *
48
 */
49
@SpringComponent
50
@ViewScope
51
public class ViewScopeConversationHolder extends ConversationHolder implements Serializable {
52

  
53

  
54
    private static final long serialVersionUID = 1001768184000981106L;
55

  
56
    /**
57
     *
58
     */
59
    public ViewScopeConversationHolder() {
60
        super();
61
        applyDefaultSettings();
62

  
63
    }
64

  
65
    /**
66
     * @param dataSource
67
     * @param sessionFactory
68
     * @param transactionManager
69
     */
70
    public ViewScopeConversationHolder(DataSource dataSource, SessionFactory sessionFactory,
71
            PlatformTransactionManager transactionManager) {
72
        super(dataSource, sessionFactory, transactionManager, false);
73
        applyDefaultSettings();
74
    }
75

  
76
    private void applyDefaultSettings(){
77

  
78
        setDefaultFlushMode(FlushMode.MANUAL);
79
        TransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED);
80
        setDefinition(definition );
81
    }
82

  
83

  
84

  
85

  
86
}
src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmTitleCacheCaptionGenerator.java
21 21

  
22 22
    private static final long serialVersionUID = 3151383366731447990L;
23 23

  
24
    public CdmTitleCacheCaptionGenerator(){
25
    }
26

  
24 27
    @Override
25 28
    public String getCaption(T option) {
26 29
        return option.getTitleCache();
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/TypeDesignationSetManager.java
635 635
            return SpecimenOrObservationBase.class.isAssignableFrom(baseEntityReference.getType());
636 636
        }
637 637

  
638
        public TypeDesignationWorkingSetType getWorkingsetType() {
639
            return isSpecimenTypeDesigationWorkingSet() ? TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET : TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET;
640
        }
641

  
642
    }
643

  
644
    public enum TypeDesignationWorkingSetType {
645
        SPECIMEN_TYPE_DESIGNATION_WORKINGSET,
646
        NAME_TYPE_DESIGNATION_WORKINGSET,
638 647
    }
639 648

  
640 649
    @SuppressWarnings({ "deprecation", "serial" })
......
657 666
            // empty
658 667
        }
659 668

  
660

  
661

  
662 669
    }
663 670

  
664 671
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/RegistrationAndWorkingsetId.java
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
public class RegistrationAndWorkingsetId {
12
    Integer registrationId;
13
    Integer workingsetId;
14
    /**
15
     * @param registrationId
16
     * @param specimentId
17
     */
18
    public RegistrationAndWorkingsetId(Integer registrationId, Integer specimentId) {
19
        super();
20
        this.registrationId = registrationId;
21
        this.workingsetId = specimentId;
22
    }
23

  
24
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.name;
10 10

  
11
import java.util.ArrayList;
12
import java.util.Arrays;
11 13
import java.util.HashSet;
12 14
import java.util.Iterator;
15
import java.util.List;
13 16
import java.util.Set;
14 17

  
15 18
import org.hibernate.Session;
......
31 34
import eu.etaxonomy.cdm.model.reference.Reference;
32 35
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
33 36
import eu.etaxonomy.cdm.service.CdmStore;
34
import eu.etaxonomy.cdm.vaadin.component.SelectFieldFactory;
37
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
35 38
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
36 39
import eu.etaxonomy.cdm.vaadin.model.registration.DerivationEventTypes;
37 40
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationTermLists;
38 41
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
39 42
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
43
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSet;
40 44
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
41 45
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
42 46
/**
......
52 56

  
53 57
    private static final long serialVersionUID = 4255636253714476918L;
54 58

  
59
    private List<String> specimenTypeDesignationWorkingsetInitStrategy = Arrays.asList(new String[]{
60
            "typeDesignations.typeStatus.representations",
61
            "typeDesignations.typeSpecimen.sources",
62
            "typeDesignations.typeSpecimen.mediaSpecimen.representations.parts",
63
            "typeDesignations.typeSpecimen.collection",
64
            "typeDesignations.typeSpecimen.derivedFrom.type",
65
            "typeDesignations.typeSpecimen.derivedFrom.derivatives",
66
            // Need to initialize all properties of the DerivedUnit to avoid LIEs while converting DerivedUnit with the DerivedUnitConverter:
67
            "typeDesignations.typeSpecimen.*",
68
    });
69

  
55 70
    CdmStore<Registration, IRegistrationService> store ;
56 71

  
57 72
    protected CdmStore<Registration, IRegistrationService> getStore() {
......
62 77
    }
63 78

  
64 79

  
80
    /**
81
     * {@inheritDoc}
82
     */
83
    @Override
84
    protected SpecimenTypeDesignationWorkingSetDTO loadBeanById(Object identifier) {
85

  
86
        SpecimenTypeDesignationWorkingSetDTO workingSet;
87
        if(identifier != null){
88
            RegistrationAndWorkingsetId registrationAndWorkingsetId = (RegistrationAndWorkingsetId)identifier;
89
            List<Integer> ids = new ArrayList<>();
90
            ids.add(registrationAndWorkingsetId.registrationId);
91
            Registration reg = getRepo().getRegistrationService().loadByIds(ids, specimenTypeDesignationWorkingsetInitStrategy).get(0);
92
            RegistrationDTO regDTO = new RegistrationDTO(reg);
93
            TypeDesignationWorkingSet typeDesignationWorkingSet = regDTO.getTypeDesignationWorkingSet(registrationAndWorkingsetId.workingsetId);
94
            workingSet = regDTO.getSpecimenTypeDesignationWorkingSetDTO(typeDesignationWorkingSet.getBaseEntityReference());
95
        } else {
96
            workingSet = null;
97
        }
98
        return workingSet;
99
    }
100

  
101

  
65 102
    /**
66 103
     * {@inheritDoc}
67 104
     */
......
69 106
    @Override
70 107
    public void handleViewEntered() {
71 108

  
72
        SelectFieldFactory selectFactory = new SelectFieldFactory(getRepo());
109
        CdmBeanItemContainerFactory selectFactory = new CdmBeanItemContainerFactory(getRepo());
73 110
        getView().getCountrySelectField().setContainerDataSource(selectFactory.buildBeanItemContainer(Country.uuidCountryVocabulary));
74 111

  
75 112
        getView().getTypeDesignationsCollectionField().setEditorInstantiator(new AbstractElementCollection.Instantiator<SpecimenTypeDesignationDTORow>() {
76 113

  
77
            CdmFilterablePagingProvider<Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection>(getRepo().getCollectionService());
114
            CdmFilterablePagingProvider<Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection>(getRepo().getCollectionService(), SpecimenTypeDesignationWorkingsetEditorPresenter.this);
78 115

  
79
            CdmFilterablePagingProvider<Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference>(getRepo().getReferenceService());
116
            CdmFilterablePagingProvider<Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference>(getRepo().getReferenceService(), SpecimenTypeDesignationWorkingsetEditorPresenter.this);
80 117

  
81 118
            @Override
82 119
            public SpecimenTypeDesignationDTORow create() {
......
104 141
                        collectionPagingProvider,
105 142
                        collectionPagingProvider.getPageSize()
106 143
                        );
107
                row.collection.getSelect().setCaptionGenerator(
108
                        new CdmTitleCacheCaptionGenerator<Collection>()
109
                        );
144
                row.collection.getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Collection>());
110 145

  
111 146
                row.mediaSpecimenReference.loadFrom(
112 147
                        referencePagingProvider,
113 148
                        referencePagingProvider,
114 149
                        collectionPagingProvider.getPageSize()
115 150
                        );
116
                row.mediaSpecimenReference.getSelect().setCaptionGenerator(
117
                        new CdmTitleCacheCaptionGenerator<Reference>()
118
                        );
151
                row.mediaSpecimenReference.getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
119 152

  
120 153
                getView().applyDefaultComponentStyle(row.components());
121 154

  
......
191 224
    @Override
192 225
    protected void saveBean(SpecimenTypeDesignationWorkingSetDTO dto) {
193 226

  
194
        getStore().startTransaction(false);
195 227
        Registration reg = (Registration) dto.getOwner();
196 228

  
197 229
        // associate all type designations with the fieldUnit
......
238 270
     * @throws Exception
239 271
     */
240 272
    private SpecimenOrObservationBase<?> findEarliestOriginal(DerivedUnit du) throws Exception {
241
    
273

  
242 274
        SpecimenOrObservationBase original = du;
243
    
275

  
244 276
        while(du != null && du.getDerivedFrom() != null && !du.getDerivedFrom().getOriginals().isEmpty()) {
245 277
            Iterator<SpecimenOrObservationBase> it = du.getDerivedFrom().getOriginals().iterator();
246 278
            SpecimenOrObservationBase nextOriginal = it.next();
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.name;
10 10

  
11
import java.util.Arrays;
12 11
import java.util.List;
13 12
import java.util.Set;
14 13

  
15 14
import org.apache.log4j.Logger;
16 15

  
17 16
import eu.etaxonomy.cdm.api.service.INameService;
17
import eu.etaxonomy.cdm.model.common.TermType;
18
import eu.etaxonomy.cdm.model.name.Rank;
18 19
import eu.etaxonomy.cdm.model.name.TaxonName;
20
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
19 21
import eu.etaxonomy.cdm.model.reference.Reference;
20 22
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
23
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
21 24
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
22 25
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
23 26

  
......
37 40
     */
38 41
    @Override
39 42
    public void handleViewEntered() {
43

  
40 44
        super.handleViewEntered();
41 45

  
46
        CdmBeanItemContainerFactory selectFieldFactory = new CdmBeanItemContainerFactory(getRepo());
47
        getView().getRankSelect().setContainerDataSource(selectFieldFactory.buildBeanItemContainer(TermType.Rank));
48
        getView().getRankSelect().setItemCaptionPropertyId("label");
49

  
42 50
        getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
43
        CdmFilterablePagingProvider<Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference>(getRepo().getReferenceService());
51
        CdmFilterablePagingProvider<Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference>(getRepo().getReferenceService(), TaxonNameEditorPresenter.this);
44 52
        getView().getNomReferenceCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
45 53

  
46 54

  
47 55
        getView().getBasionymCombobox().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
48
        CdmFilterablePagingProvider<TaxonName> namePagingProvider = new CdmFilterablePagingProvider<TaxonName>(getRepo().getNameService());
56
        CdmFilterablePagingProvider<TaxonName> namePagingProvider = new CdmFilterablePagingProvider<TaxonName>(getRepo().getNameService(), TaxonNameEditorPresenter.this);
49 57
        getView().getBasionymCombobox().setPagingProviders(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize());
50 58
    }
51 59

  
60

  
61

  
62
    /**
63
     * {@inheritDoc}
64
     */
52 65
    @Override
53
    protected TaxonName prepareAsFieldGroupDataSource(TaxonName bean){
54
        TaxonName initializedBean = getRepo().getNameService().load(bean.getUuid(), Arrays.asList(
55
                "$",
56
                "basionymAuthorship",
57
                "combinationAuthorship",
58
                "exCombinationAuthorship",
59
                "exBasionymAuthorship",
60
                "nomenclaturalReference.authorship.teamMembers"));
61
        return initializedBean;
62
    }
66
    protected TaxonName loadBeanById(Object identifier) {
63 67

  
68
        TaxonName bean;
69
        if(identifier != null){
70
            bean = getRepo().getNameService().find((Integer)identifier);
71
        } else {
72
            bean = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
73
        }
74
        return bean;
75
    }
64 76

  
65 77
    @Override
66 78
    protected TaxonName handleTransientProperties(TaxonName bean) {
......
69 81
        Set<TaxonName> oldBasionyms = bean.getBasionyms();
70 82
        boolean updateBasionyms = false;
71 83
        for(TaxonName newB : newBasionymNames){
84

  
72 85
            updateBasionyms = updateBasionyms || !oldBasionyms.contains(newB);
73 86
        }
74 87
        for(TaxonName oldB : oldBasionyms){
......
77 90
        if(updateBasionyms){
78 91
            bean.removeBasionyms();
79 92
            for(TaxonName basionymName :newBasionymNames){
80
                getSession().merge(basionymName);
81
                bean.addBasionym(basionymName);
93
                if(basionymName != null){
94
                    if(basionymName .getUuid() != null){
95
                        // reload
96
                        basionymName = getRepo().getNameService().load(basionymName.getUuid());
97
                    }
98
                    bean.addBasionym(basionymName);
99
                }
82 100
            }
83 101
        }
84 102
        return bean;
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
21 21
import eu.etaxonomy.cdm.model.name.Rank;
22 22
import eu.etaxonomy.cdm.model.name.TaxonName;
23 23
import eu.etaxonomy.cdm.model.reference.Reference;
24
import eu.etaxonomy.cdm.persistence.query.OrderHint;
25 24
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
26 25
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
27 26
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
......
177 176

  
178 177
        int row = 0;
179 178

  
180
        rankSelect = selectFieldFactory.createListSelect("Rank", Rank.class, OrderHint.BY_ORDER_INDEX.asList(), "label");
179
        rankSelect = new ListSelect("Rank");
181 180
        rankSelect.setNullSelectionAllowed(false);
182 181
        rankSelect.setRows(1);
183 182
        rankSelect.setWidth(100, Unit.PERCENTAGE);
......
352 351
        return basionymCombobox;
353 352
    }
354 353

  
354
    /**
355
     * {@inheritDoc}
356
     */
357
    @Override
358
    public ListSelect getRankSelect() {
359
        return rankSelect;
360
    }
361

  
355 362

  
356 363
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditorView.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.name;
10 10

  
11
import com.vaadin.ui.ListSelect;
12

  
11 13
import eu.etaxonomy.cdm.model.name.TaxonName;
12 14
import eu.etaxonomy.cdm.model.reference.Reference;
13 15
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
......
31 33
     */
32 34
    public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymCombobox();
33 35

  
36
    public ListSelect getRankSelect();
37

  
34 38
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferenceEditorPresenter.java
13 13

  
14 14
import org.apache.log4j.Logger;
15 15
import org.springframework.context.event.EventListener;
16
import org.springframework.transaction.TransactionStatus;
17 16
import org.vaadin.viritin.fields.CaptionGenerator;
18 17
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
19 18
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
......
44 43
    ReferencePopupEditor inReferencePopup = null;
45 44

  
46 45
    public ReferenceEditorPresenter() {
47
        logger.trace("CONTRUCTOR");
46
        
48 47
    }
49 48

  
50 49
    /**
......
96 95
            , 20);
97 96
    }
98 97

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff