Project

General

Profile

Revision e8674a36

IDe8674a36164f46003d61dcfa99d1e43c73176de7
Parent d8e0a88c
Child f2e16939

Added by Andreas Kohlbecker over 3 years ago

ref #7195 introducing the concept of EditorActionContext stacks to facilitate creating blocking relations

View differences:

src/main/java/eu/etaxonomy/cdm/service/CdmStore.java
24 24
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
25 25
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
26 26
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent.Type;
27
import eu.etaxonomy.vaadin.mvp.AbstractView;
27 28

  
28 29
/**
29 30
 * @author a.kohlbecker
......
176 177
    /**
177 178
     *
178 179
     * @param bean
179
     * 
180
     *
180 181
     * @return the merged bean, this bean is <b>not reloaded</b> from the
181 182
     *         persistent storage.
182 183
     */
183
    public EntityChangeEvent saveBean(T bean) {
184
    public EntityChangeEvent saveBean(T bean, AbstractView view) {
184 185

  
185 186
        Type changeEventType;
186 187
        if(bean.getId() > 1){
......
209 210
        session.flush();
210 211
        commitTransction();
211 212

  
212
        return new EntityChangeEvent(mergedBean.getClass(), mergedBean.getId(), changeEventType);
213
        return new EntityChangeEvent(mergedBean.getClass(), mergedBean.getId(), changeEventType, view);
213 214
    }
214 215

  
215 216
    /**
......
217 218
     * @param bean
218 219
     * @return a EntityChangeEvent in case the deletion was successful otherwise <code>null</code>.
219 220
     */
220
    public final EntityChangeEvent deleteBean(T bean) {
221
    public final EntityChangeEvent deleteBean(T bean, AbstractView view) {
221 222

  
222 223
        logger.trace(this._toString() + ".onEditorPreSaveEvent - starting transaction");
223 224

  
......
229 230
            getSession().flush();
230 231
            commitTransction();
231 232
            logger.trace(this._toString() + ".deleteBean - transaction comitted");
232
            return new EntityChangeEvent(bean.getClass(), bean.getId(), Type.REMOVED);
233
            return new EntityChangeEvent(bean.getClass(), bean.getId(), Type.REMOVED, view);
233 234
        } else {
234 235
            String notificationTitle;
235 236
            StringBuffer messageBody = new StringBuffer();
src/main/java/eu/etaxonomy/cdm/vaadin/event/AbstractEditorAction.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.event;
10 10

  
11
import java.util.Stack;
12

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

  
13 15
import eu.etaxonomy.vaadin.event.EditorActionType;
14 16
import eu.etaxonomy.vaadin.mvp.AbstractView;
15 17

  
16 18
/**
17
 * Base implementation for an event which
18
 * which represents the request to start an editor to enable the
19
 * user to perform the <code>action</code> transported with this event.
19
 * Base implementation for an event which which represents the request to start
20
 * an editor to enable the user to perform the <code>action</code> transported
21
 * with this event.
20 22
 *
21 23
 * @author a.kohlbecker
22 24
 * @since Mar 22, 2017
......
26 28

  
27 29
    private Component sourceComponent = null;
28 30

  
29
    private AbstractView sourceView = null;
31
    protected Stack<EditorActionContext> context;
30 32

  
31 33
    public AbstractEditorAction(EditorActionType action) {
32
        super(action, null);
33
    }
34

  
35
    public AbstractEditorAction(EditorActionType action, Component source) {
36
        this(action, null, source);
34
        this(action, null, null);
37 35
    }
38 36

  
39
    /**
40
     * @param type
41
     * @param citationId
42
     */
43
    public AbstractEditorAction(EditorActionType action, Integer entityId) {
44
        super(action, entityId);
37
    public AbstractEditorAction(EditorActionType action, Component source, AbstractView sourceView) {
38
        this(action, null, source, sourceView);
39
        if (!action.equals(EditorActionType.ADD)) {
40
            throw new RuntimeException("This constructor must only be used for EditorActionType.ADD");
41
        }
45 42
    }
46 43

  
47
    public AbstractEditorAction(EditorActionType action, Integer entityId, Component source) {
48
        super(action, entityId);
49
        this.sourceComponent = source;
44
    public AbstractEditorAction(EditorActionType action, Integer entityId, Component source, AbstractView sourceView) {
45
        this(action, entityId, source, sourceView, null);
50 46
    }
51 47

  
52
    public AbstractEditorAction(EditorActionType action, Integer entityId, Component source, AbstractView sourceView) {
53
        super(action, entityId);
48
    /**
49
     *
50
     * @param action
51
     *            the action being requested
52
     * @param entityId
53
     *            the id of the entity to which the action
54
     * @param source
55
     *            The vaadin ui component from which the action was triggered
56
     * @param sourceView
57
     *            The view from which the action is send
58
     * @param context
59
     *            Editor actions can hold a stack of entities to represent the chain of
60
     *            Editor actions from previous views and editors that lead to the point
61
     *            from where this action is spawned.
62
     */
63
    public AbstractEditorAction(EditorActionType action, Integer entityId, Component source, AbstractView sourceView,
64
            Stack<EditorActionContext> context) {
65
        super(action, entityId, sourceView);
54 66
        this.sourceComponent = source;
55
        this.sourceView = sourceView;
67
        this.context = context;
56 68
    }
57 69

  
58 70
    public boolean isAddAction() {
......
67 79
        return type.equals(EditorActionType.REMOVE);
68 80
    }
69 81

  
70
    public Component getSourceComponent(){
82
    public Component getSourceComponent() {
71 83
        return sourceComponent;
72 84
    }
73 85

  
......
76 88
    }
77 89

  
78 90
    /**
79
     * @return the sourceView
91
     * @return the context
80 92
     */
81
    public AbstractView getSourceView() {
82
        return sourceView;
93
    public Stack<EditorActionContext> getContext() {
94
        return context;
83 95
    }
84 96

  
97
    public static class EditorActionContext {
98

  
99
        Object parentEntity;
100

  
101
        AbstractView parentView;
102

  
103
        /**
104
         * @param parentEntity
105
         * @param parentView
106
         */
107
        public EditorActionContext(Object parentEntity, AbstractView parentView) {
108
            super();
109
            this.parentEntity = parentEntity;
110
            this.parentView = parentView;
111
        }
112

  
113
        /**
114
         * @return the parentEntity
115
         */
116
        public Object getParentEntity() {
117
            return parentEntity;
118
        }
119

  
120
        /**
121
         * @return the parentView
122
         */
123
        public AbstractView getParentView() {
124
            return parentView;
125
        }
126

  
127

  
128

  
129
    }
85 130

  
86 131
}
src/main/java/eu/etaxonomy/cdm/vaadin/event/AbstractEntityEvent.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.event;
10 10

  
11
import eu.etaxonomy.vaadin.mvp.AbstractView;
12

  
11 13
/**
12 14
 * @author a.kohlbecker
13 15
 * @since May 10, 2017
......
19 21

  
20 22
    protected T type;
21 23

  
22
    public AbstractEntityEvent(T type, Integer entityId) {
24
    private AbstractView sourceView = null;
25

  
26
    public AbstractEntityEvent(T type, Integer entityId, AbstractView sourceView) {
23 27
        this.entityId = entityId;
24 28
        this.type = type;
29
        this.sourceView = sourceView;
25 30
        if(type == null){
26 31
            throw new NullPointerException();
27 32
        }
......
38 43
        return type;
39 44
    }
40 45

  
46
    /**
47
     * @return the sourceView
48
     */
49
    public AbstractView getSourceView() {
50
        return sourceView;
51
    }
52

  
41 53
}
src/main/java/eu/etaxonomy/cdm/vaadin/event/CollectionEditorAction.java
27 27
    }
28 28

  
29 29
    /**
30
     * @param edit
31
     * @param citationId
32
     */
33
    public CollectionEditorAction(EditorActionType type, Integer citationId) {
34
        super(type, citationId);
35
    }
36

  
37
    /**
38
     * @param type
39
     * @param entityId
40
     * @param source
41
     */
42
    public CollectionEditorAction(EditorActionType type, Integer entityId, Component source) {
43
        super(type, entityId, source);
44
    }
45

  
46
    /**
47 30
     * @param action
48 31
     * @param source
49 32
     */
50
    public CollectionEditorAction(EditorActionType action, Component source) {
51
        super(action, source);
33
    public CollectionEditorAction(EditorActionType action, Component source, AbstractView sourceView) {
34
        super(action, source, sourceView);
52 35
    }
53 36

  
54 37
    /**
src/main/java/eu/etaxonomy/cdm/vaadin/event/EntityChangeEvent.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.event;
10 10

  
11
import eu.etaxonomy.vaadin.mvp.AbstractView;
12

  
11 13
/**
12 14
 * @author a.kohlbecker
13 15
 * @since May 10, 2017
......
27 29
     * @param type
28 30
     * @param entityId
29 31
     */
30
    public EntityChangeEvent(Class<?> entityType, Integer entityId, Type type) {
31
        super(type, entityId);
32
    public EntityChangeEvent(Class<?> entityType, Integer entityId, Type type, AbstractView sourceView) {
33
        super(type, entityId, sourceView);
32 34
        this.entityType = entityType;
33 35
    }
34 36

  
src/main/java/eu/etaxonomy/cdm/vaadin/event/ReferenceEditorAction.java
27 27
    }
28 28

  
29 29
    /**
30
     * @param edit
31
     * @param citationId
32
     */
33
    public ReferenceEditorAction(EditorActionType type, Integer citationId) {
34
        super(type, citationId);
35
    }
36

  
37
    /**
38
     * @param type
39
     * @param entityId
40
     * @param source
41
     */
42
    public ReferenceEditorAction(EditorActionType type, Integer entityId, Component source) {
43
        super(type, entityId, source);
44
    }
45

  
46
    /**
47 30
     * @param action
48 31
     * @param source
49 32
     */
50
    public ReferenceEditorAction(EditorActionType action, Component source) {
51
        super(action, source);
33
    public ReferenceEditorAction(EditorActionType action, Component source, AbstractView sourceView) {
34
        super(action, source, sourceView);
52 35
    }
53 36

  
54 37
    /**
src/main/java/eu/etaxonomy/cdm/vaadin/event/RegistrationEditorAction.java
26 26
        super(type);
27 27
    }
28 28

  
29
    /**
30
     * @param edit
31
     * @param citationId
32
     */
33
    public RegistrationEditorAction(EditorActionType type, Integer enitityId) {
34
        super(type, enitityId);
35
    }
36 29

  
37 30
    /**
38 31
     * @param action
39 32
     * @param source
40 33
     */
41
    public RegistrationEditorAction(EditorActionType action, Component source) {
42
        super(action, source);
34
    public RegistrationEditorAction(EditorActionType action, Component source, AbstractView sourceView) {
35
        super(action, source, sourceView);
43 36
    }
44 37

  
45 38
    /**
......
52 45
        super(action, entityId, source, sourceView);
53 46
    }
54 47

  
55
    /**
56
     * @param action
57
     * @param entityId
58
     * @param source
59
     */
60
    public RegistrationEditorAction(EditorActionType action, Integer entityId, Component source) {
61
        super(action, entityId, source);
62
    }
63 48

  
64 49

  
65 50

  
src/main/java/eu/etaxonomy/cdm/vaadin/event/TaxonNameEditorAction.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.event;
10 10

  
11
import java.util.Stack;
12

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

  
13 15
import eu.etaxonomy.vaadin.event.EditorActionType;
......
26 28
    }
27 29

  
28 30
    /**
29
     * @param type
30
     * @param entityId
31
     */
32
    public TaxonNameEditorAction(EditorActionType type, Integer entityId) {
33
        super(type, entityId);
34
    }
35

  
36
    /**
37
     * @param type
38
     * @param entityId
31
     * @param action
39 32
     * @param source
40 33
     */
41
    public TaxonNameEditorAction(EditorActionType type, Integer entityId, Component source) {
42
        super(type, entityId, source);
34
    public TaxonNameEditorAction(EditorActionType action, Component source, AbstractView sourceView) {
35
        super(action, source, sourceView);
43 36
    }
44 37

  
45 38
    /**
46 39
     * @param action
40
     * @param entityId
47 41
     * @param source
42
     * @param sourceView
48 43
     */
49
    public TaxonNameEditorAction(EditorActionType action, Component source) {
50
        super(action, source);
51
        // TODO Auto-generated constructor stub
44
    public TaxonNameEditorAction(EditorActionType action, Integer entityId, Component source, AbstractView sourceView) {
45
        super(action, entityId, source, sourceView);
52 46
    }
53 47

  
54 48
    /**
......
56 50
     * @param entityId
57 51
     * @param source
58 52
     * @param sourceView
53
     * @param context
59 54
     */
60
    public TaxonNameEditorAction(EditorActionType action, Integer entityId, Component source, AbstractView sourceView) {
61
        super(action, entityId, source, sourceView);
62
        // TODO Auto-generated constructor stub
55
    public TaxonNameEditorAction(EditorActionType action, Integer entityId, Component source, AbstractView sourceView,
56
            Stack<EditorActionContext> context) {
57
        super(action, entityId, source, sourceView, context);
63 58
    }
64 59

  
65 60

  
src/main/java/eu/etaxonomy/cdm/vaadin/event/TypeDesignationEditorAction.java
21 21
        super(eventType);
22 22
    }
23 23

  
24
    /**
25
     * @param type
26
     * @param entityId
27
     */
28
    public TypeDesignationEditorAction(EditorActionType type, Integer entityId) {
29
        super(type, entityId);
30
    }
31 24

  
32 25
}
src/main/java/eu/etaxonomy/cdm/vaadin/event/TypeDesignationWorkingsetEditorAction.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.event;
10 10

  
11
import java.util.Stack;
12

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

  
13 15
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
16
import eu.etaxonomy.cdm.model.name.Registration;
14 17
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
15 18
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
16 19
import eu.etaxonomy.vaadin.event.EditorActionType;
......
38 41
     * @param source
39 42
     * @param sourceView
40 43
     */
41
    public TypeDesignationWorkingsetEditorAction(EditorActionType action, TypedEntityReference<IdentifiableEntity<?>> baseEntityRef, TypeDesignationWorkingSetType workingSetType, int registrationId,
42
            Component source, AbstractView sourceView) {
44
    public TypeDesignationWorkingsetEditorAction(EditorActionType action, TypedEntityReference<IdentifiableEntity<?>> baseEntityRef,
45
            TypeDesignationWorkingSetType workingSetType, int registrationId, Component source, AbstractView sourceView, Stack<EditorActionContext> context) {
43 46
        super(action, null, source, sourceView);
44 47
        this.baseEntityRef = baseEntityRef;
45 48
        this.registrationId = registrationId;
46 49
        this.workingSetType = workingSetType;
50
        this.context.addAll(context);
47 51
    }
48 52

  
49 53
    /**
......
59 63
        super(action, null, source, sourceView);
60 64
        this.workingSetType = workingSetType;
61 65
        this.registrationId = registrationId;
66
        this.context.push(new EditorActionContext(new TypedEntityReference<Registration>(Registration.class, registrationId), sourceView));
62 67
    }
63 68

  
69

  
70

  
64 71
    /**
65 72
     *
66 73
     * @return
src/main/java/eu/etaxonomy/cdm/vaadin/model/TypedEntityReference.java
26 26
        this.type = type;
27 27
    }
28 28

  
29
    public TypedEntityReference(Class<T> type, int id) {
30
        super(id, null);
31
        this.type = type;
32
    }
33

  
29 34
    /**
30 35
     * @return the type
31 36
     */
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
305 305

  
306 306
    public void doCollectionEditorAdd() {
307 307

  
308
        collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
308
        collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
309 309

  
310 310
        collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
311 311
        collectionPopupEditor.withDeleteButton(true);
......
314 314

  
315 315
    public void doCollectionEditorEdit(int collectionId) {
316 316

  
317
        collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
317
        collectionPopupEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
318 318

  
319 319
        collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
320 320
        collectionPopupEditor.withDeleteButton(true);
......
338 338

  
339 339
    public void doReferenceEditorAdd() {
340 340

  
341
        referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class);
341
        referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
342 342

  
343 343
        referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
344 344
        referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
......
348 348

  
349 349
    public void doReferenceEditorEdit(int referenceId) {
350 350

  
351
        referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class);
351
        referencePopupEditor = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
352 352
        referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
353 353
        referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
354 354
        referencePopupEditor.withDeleteButton(true);
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
283 283
            return;
284 284
        }
285 285

  
286
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
286
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
287 287

  
288 288
        referenceEditorPopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
289 289
        referenceEditorPopup.withDeleteButton(true);
......
304 304
        if(getView() == null || event.getSourceView() != getView() ){
305 305
            return;
306 306
        }
307
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
307
        referenceEditorPopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
308 308

  
309 309
        referenceEditorPopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
310 310
        referenceEditorPopup.withDeleteButton(true);
......
363 363

  
364 364
        basionymSourceField = (AbstractField<TaxonName>)event.getSourceComponent();
365 365

  
366
        basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
366
        basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
367 367
        basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
368 368
        basionymNamePopup.withDeleteButton(true);
369 369
        getView().getModesActive().forEach(m -> basionymNamePopup.enableMode(m));
......
381 381

  
382 382
        basionymSourceField = (AbstractField<TaxonName>)event.getSourceComponent();
383 383

  
384
        basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
384
        basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
385 385
        basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
386 386
        basionymNamePopup.withDeleteButton(true);
387 387
        basionymNamePopup.loadInEditor(null);
src/main/java/eu/etaxonomy/cdm/vaadin/view/occurrence/CollectionEditorPresenter.java
113 113
            return;
114 114
        }
115 115

  
116
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
116
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
117 117

  
118 118
        collectionPopuEditor.grantToCurrentUser(this.crud);
119 119
        collectionPopuEditor.withDeleteButton(true);
......
127 127
            return;
128 128
        }
129 129

  
130
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
130
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
131 131

  
132 132
        collectionPopuEditor.grantToCurrentUser(this.crud);
133 133
        collectionPopuEditor.withDeleteButton(true);
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferenceEditorPresenter.java
149 149

  
150 150
       if(ToOneRelatedEntityField.class.isAssignableFrom(editorAction.getSourceComponent().getClass())){
151 151
           if(editorAction.isAddAction()){
152
               inReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
152
               inReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
153 153
               inReferencePopup.loadInEditor(null);
154 154
           }
155 155
           if(editorAction.isEditAction()){
156
               ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
156
               ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
157 157
               popup.withDeleteButton(true);
158 158
               popup.loadInEditor(editorAction.getEntityId());
159 159
           }
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
12 12
import java.util.Arrays;
13 13
import java.util.EnumSet;
14 14
import java.util.List;
15
import java.util.Stack;
15 16
import java.util.UUID;
16 17

  
17 18
import org.hibernate.Session;
......
46 47
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
47 48
import eu.etaxonomy.cdm.service.CdmStore;
48 49
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
50
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.EditorActionContext;
49 51
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
50 52
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
51 53
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
......
56 58
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
57 59
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkingsetAction;
58 60
import eu.etaxonomy.cdm.vaadin.model.EntityReference;
61
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
59 62
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
60 63
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
61 64
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
......
67 70
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditorMode;
68 71
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet;
69 72
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
73
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
70 74
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
75
import eu.etaxonomy.vaadin.mvp.AbstractView;
71 76
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
72 77
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
73 78
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
......
151 156
                null);
152 157
        Authentication authentication = currentSecurityContext().getAuthentication();
153 158
        reg.setSubmitter((User)authentication.getPrincipal());
154
        EntityChangeEvent event = getRegistrationStore().saveBean(reg);
159
        EntityChangeEvent event = getRegistrationStore().saveBean(reg, (AbstractView) getView());
155 160
        UserHelper.fromSession().createAuthorityForCurrentUser(Registration.class, event.getEntityId(), Operation.UPDATE, RegistrationStatus.PREPARATION.name());
156 161
        getRepo().commitTransaction(txStatus);
157 162
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
223 228
            return;
224 229
        }
225 230

  
226
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
231
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
227 232
        popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
228 233
        popup.loadInEditor(null);
229 234
    }
......
234 239
        if(!checkFromOwnView(event)){
235 240
            return;
236 241
        }
237
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
242
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
238 243
        popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
239 244
        popup.withDeleteButton(true);
240 245
        popup.loadInEditor(event.getEntityId());
241 246
    }
242 247

  
243
    @EventBusListenerMethod    
248
    @EventBusListenerMethod
244 249
    public void onDoneWithReferencePopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
245 250
        if(event.getPopup() instanceof ReferencePopupEditor){
246 251
            if(event.getReason().equals(Reason.SAVE)){
......
265 270
            return;
266 271
        }
267 272

  
268
        RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class);
273
        RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class, getView());
269 274
        popup.loadInEditor(event.getEntityId());
270 275
    }
271 276

  
......
276 281
            return;
277 282
        }
278 283

  
279
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
284
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
285
        popup.setParentEditorActionContext(event.getContext());
280 286
        popup.withDeleteButton(true);
281 287
        configureTaxonNameEditor(popup);
282 288
        popup.loadInEditor(event.getEntityId());
......
296 302

  
297 303
        newTaxonNameForRegistration = TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES());
298 304
        newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationId()));
299
        EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration);
305
        EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration, (AbstractView) getView());
300 306
        newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityId());
301
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
307
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
308
        popup.setParentEditorActionContext(event.getContext());
302 309
        popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE,CRUD.DELETE));
303 310
        popup.withDeleteButton(true);
304 311
        configureTaxonNameEditor(popup);
......
345 352
            } else if(event.getReason().equals(Reason.CANCEL)){
346 353
                if(newTaxonNameForRegistration != null){
347 354
                    // clean up
348
                    getTaxonNameStore().deleteBean(newTaxonNameForRegistration);
355
                    getTaxonNameStore().deleteBean(newTaxonNameForRegistration, (AbstractView) getView());
349 356
                }
350 357
            }
351 358
            getRepo().commitTransaction(txStatus);
......
393 400
        }
394 401

  
395 402
        if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){
396
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
403
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView());
404
            popup.setParentEditorActionContext(event.getContext());
397 405
            popup.withDeleteButton(true);
398 406
            popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getBaseEntityRef()));
399 407
            if(event.getSourceComponent() != null){
......
401 409
                popup.setReadOnly(event.getSourceComponent().isReadOnly());
402 410
            }
403 411
        } else {
404
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class);
412
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView());
413
            popup.setParentEditorActionContext(event.getContext());
405 414
            popup.withDeleteButton(true);
406 415
            popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getBaseEntityRef()));
407 416

  
......
424 433
        }
425 434

  
426 435
        if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){
427
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
436
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView());
437
            popup.setParentEditorActionContext(event.getContext());
428 438
            TypeDesignationWorkingsetEditorIdSet identifierSet;
429 439
            Integer typifiedNameId;
430 440
            if(newRegistrationDTOWithExistingName != null){
......
453 463
                popup.setReadOnly(event.getSourceComponent().isReadOnly());
454 464
            }
455 465
        } else {
456
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class);
466
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView());
467
            popup.setParentEditorActionContext(event.getContext());
457 468
            popup.withDeleteButton(true);
458 469
            popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
459 470
            newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
......
498 509
            } else if(event.getReason().equals(Reason.CANCEL)){
499 510
                // clean up
500 511
                if(newRegistrationDTOWithExistingName != null){
501
                    getRegistrationStore().deleteBean(newRegistrationDTOWithExistingName.registration());
512
                    getRegistrationStore().deleteBean(newRegistrationDTOWithExistingName.registration(), (AbstractView) getView());
502 513
                }
503 514
            }
504 515
            // set newRegistrationDTOWithExistingName NULL in any case
......
566 577
            }
567 578
        } else
568 579
        if(TaxonName.class.isAssignableFrom(event.getEntityType())){
580
            if(event.getType().equals(EntityChangeEvent.Type.CREATED)){
581
                // new name! create a blocking registration
582
                Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getSourceView()).getEditorActionContext();
583
                EditorActionContext rootContext = context.get(0);
584
                if(rootContext.getParentView().equals(getView())){
585
                    TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootContext.getParentEntity();
586
                    TaxonName newName = getRepo().getNameService().load(event.getEntityId(), Arrays.asList("$", "registrations"));
587
                    Registration blockingRegistration = Registration.NewInstance();
588
                    blockingRegistration = getRepo().getRegistrationService().save(blockingRegistration);
589
                    blockingRegistration.setName(newName);
590
                    Registration registration = getRepo().getRegistrationService().load(regReference.getId(), Arrays.asList("$", "blockedBy"));
591
                    registration.getBlockedBy().add(blockingRegistration);
592
                    getRepo().getRegistrationService().saveOrUpdate(registration);
593
                    logger.debug("Blocking registration created");
594
                } else {
595
                    throw new RuntimeException("huuu?");
596
                }
597
            }
569 598
            if(workingset.getRegistrationDTOs().stream().anyMatch(reg ->
570 599
                reg.getTypifiedNameRef() != null
571 600
                && reg.getTypifiedNameRef().getId() == event.getEntityId())){
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorksetViewBean.java
12 12
import java.util.Collection;
13 13
import java.util.EnumSet;
14 14
import java.util.List;
15
import java.util.Stack;
15 16
import java.util.UUID;
16 17

  
17 18
import org.springframework.security.core.GrantedAuthority;
......
45 46
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup.TypeDesignationWorkingSetButton;
46 47
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStateLabel;
47 48
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
49
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.EditorActionContext;
48 50
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
49 51
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
50 52
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
......
265 267
        Component regItem;
266 268

  
267 269
        RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
270
        Integer registrationEntityID = dto.getId();
271
        Stack<EditorActionContext> context = new Stack<EditorActionContext>();
272
        context.push(new EditorActionContext(
273
                    new TypedEntityReference<>(Registration.class, registrationEntityID),
274
                    this)
275
                    );
268 276

  
269 277
        if(editButtonGroup.getNameButton() != null){
270 278
            editButtonGroup.getNameButton().getButton().addClickListener(e -> {
......
273 281
                    EditorActionType.EDIT,
274 282
                    nameId,
275 283
                    e.getButton(),
276
                    this
284
                    this,
285
                    context
277 286
                    )
278 287
                );
279 288
            });
......
283 292
            workingsetButton.getButton().addClickListener(e -> {
284 293
                TypedEntityReference baseEntityRef = workingsetButton.getBaseEntity();
285 294
                TypeDesignationWorkingSetType workingsetType = workingsetButton.getType();
286
                Integer registrationEntityID = dto.getId();
287 295
                getViewEventBus().publish(this, new TypeDesignationWorkingsetEditorAction(
288 296
                        EditorActionType.EDIT,
289 297
                        baseEntityRef,
290 298
                        workingsetType,
291 299
                        registrationEntityID,
292 300
                        e.getButton(),
293
                        this
301
                        this,
302
                        context
294 303
                        )
295 304
                    );
296 305
            });
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/StartRegistrationPresenter.java
92 92
            return;
93 93
        }
94 94

  
95
        newReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
95
        newReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
96 96
        EnumSet<ReferenceType> refTypes = RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES.clone();
97 97
        refTypes.remove(ReferenceType.Section);
98 98
        newReferencePopup.withReferenceTypes(refTypes);
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/StartRegistrationViewBean.java
89 89

  
90 90
        newPublicationButton = new Button("New");
91 91
        newPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
92
                new ReferenceEditorAction(EditorActionType.ADD, newPublicationButton)
92
                new ReferenceEditorAction(EditorActionType.ADD, newPublicationButton, this)
93 93
                ));
94 94
        newPublicationButton.setCaption("New");
95 95
        newPublicationButton.setWidth(ELEMENT_WIDTH);
......
101 101
        removeNewPublicationButton.setStyleName(ValoTheme.BUTTON_DANGER);
102 102
        removeNewPublicationButton.setWidth(ELEMENT_WIDTH);
103 103
        removeNewPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
104
                new ReferenceEditorAction(EditorActionType.REMOVE, removeNewPublicationButton)
104
                new ReferenceEditorAction(EditorActionType.REMOVE, removeNewPublicationButton, this)
105 105
                ));
106 106

  
107 107
        removeNewPublicationButton.setVisible(false);
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractCdmEditorPresenter.java
14 14

  
15 15
import org.apache.log4j.Logger;
16 16
import org.hibernate.HibernateException;
17
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
18 17

  
19 18
import eu.etaxonomy.cdm.api.service.IService;
20 19
import eu.etaxonomy.cdm.cache.CdmTransientEntityCacher;
......
120 119
     * @return
121 120
     */
122 121
    protected abstract IService<DTO> getService();
123
    
122

  
124 123
    @SuppressWarnings("unchecked")
125 124
    @Override
126
    @EventBusListenerMethod
125
    // @EventBusListenerMethod // already annotated at super class
127 126
    public void onEditorPreSaveEvent(EditorPreSaveEvent preSaveEvent){
128 127

  
129 128
        if(!isFromOwnView(preSaveEvent)){
......
134 133

  
135 134
    @SuppressWarnings("unchecked")
136 135
    @Override
137
    @EventBusListenerMethod
136
    // @EventBusListenerMethod // already annotated at super class
138 137
    public void onEditorSaveEvent(EditorSaveEvent<DTO> saveEvent){
139 138

  
140 139
        if(!isFromOwnView(saveEvent)){
141 140
            return;
142 141
        }
143
        
142

  
144 143
        // the bean is now updated with the changes made by the user
145 144
        DTO bean = saveEvent.getBean();
146 145

  
......
157 156
            pca.printCopyEntities(System.err);
158 157
        }
159 158
        try {
160
            EntityChangeEvent changeEvent = getStore().saveBean(bean);
159
            EntityChangeEvent changeEvent = getStore().saveBean(bean, (AbstractView) getView());
161 160

  
162 161
            if(changeEvent != null){
163 162
                viewEventBus.publish(this, changeEvent);
......
217 216

  
218 217
    @Override
219 218
    protected final void deleteBean(DTO bean){
220
        EntityChangeEvent changeEvent = getStore().deleteBean(bean);
219
        EntityChangeEvent changeEvent = getStore().deleteBean(bean, (AbstractView) getView());
221 220
        if(changeEvent != null){
222 221
            viewEventBus.publish(this, changeEvent);
223 222
        }
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
9 9
package eu.etaxonomy.vaadin.mvp;
10 10

  
11 11
import java.util.Map;
12
import java.util.Stack;
12 13

  
13 14
import org.apache.log4j.Logger;
14 15
import org.vaadin.spring.events.EventScope;
......
47 48

  
48 49
import eu.etaxonomy.cdm.database.PermissionDeniedException;
49 50
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix;
51
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
52
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.EditorActionContext;
50 53
import eu.etaxonomy.vaadin.component.NestedFieldGroup;
51 54
import eu.etaxonomy.vaadin.component.SwitchableTextField;
52 55
import eu.etaxonomy.vaadin.mvp.event.EditorDeleteEvent;
......
90 93

  
91 94
    private boolean isBeanLoaded;
92 95

  
96
    private Stack<EditorActionContext> context = new Stack<EditorActionContext>();
97

  
98
    private boolean isContextUpdated;
99

  
93 100
    public AbstractPopupEditor(Layout layout, Class<DTO> dtoType) {
94 101

  
95 102
        mainLayout = new VerticalLayout();
......
621 628
        return getPresenter();
622 629
    }
623 630

  
631
    /**
632
     * Returns the context of editor actions for this editor.
633
     * The context submitted with {@link #setParentContext(Stack)} will be updated
634
     * to represent the current context.
635
     *
636
     * @return the context
637
     */
638
    public Stack<EditorActionContext> getEditorActionContext() {
639
        if(!isContextUpdated){
640
            if(getBean() == null){
641
                throw new RuntimeException("getContext() is only possible after the bean is loaded");
642
            }
643
            context.push(new AbstractEditorAction.EditorActionContext(getBean(), this));
644
            isContextUpdated = true;
645
        }
646
        return context;
647
    }
648

  
649
    /**
650
     * Set the context of editor actions parent to this editor
651
     *
652
     * @param context the context to set
653
     */
654
    public void setParentEditorActionContext(Stack<EditorActionContext> context) {
655
        this.context.addAll(context);
656
    }
657

  
624 658
}
src/main/java/eu/etaxonomy/vaadin/ui/navigation/NavigationManager.java
5 5
import com.vaadin.navigator.View;
6 6

  
7 7
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
8
import eu.etaxonomy.vaadin.mvp.ApplicationView;
8 9
import eu.etaxonomy.vaadin.ui.view.PopupView;
9 10

  
10 11
public interface NavigationManager {
11 12

  
12 13
	View getCurrentView();
13 14

  
14
	<T extends PopupView> T showInPopup(Class<T> popupType);
15
	/**
16
	 *
17
	 * @param popupType
18
	 *         Type of the popup to open
19
	 * @param parentView
20
	 *         The view from where the request to open the popup is being triggered
21
	 * @return
22
	 */
23
	<T extends PopupView> T showInPopup(Class<T> popupType, ApplicationView parentView);
15 24

  
16 25
	public List<AbstractEditorPresenter<?,?>> getPopupEditorPresenters();
17 26

  
src/main/java/eu/etaxonomy/vaadin/ui/navigation/NavigationManagerBean.java
6 6
import java.util.HashSet;
7 7
import java.util.List;
8 8
import java.util.Map;
9
import java.util.Stack;
9 10

  
10 11
import org.apache.commons.lang3.StringUtils;
11 12
import org.apache.log4j.Logger;
12 13
import org.springframework.beans.factory.annotation.Autowired;
13 14
import org.springframework.context.ApplicationContext;
14 15
import org.springframework.context.annotation.Lazy;
15
import org.springframework.context.event.PojoEventListenerManager;
16 16
import org.vaadin.spring.events.EventBus;
17 17
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
18 18

  
......
26 26
import com.vaadin.ui.UI;
27 27
import com.vaadin.ui.Window;
28 28

  
29
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.EditorActionContext;
29 30
import eu.etaxonomy.cdm.vaadin.security.PermissionDebugUtils;
30 31
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
31 32
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
32 33
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
34
import eu.etaxonomy.vaadin.mvp.ApplicationView;
33 35
import eu.etaxonomy.vaadin.ui.UIInitializedEvent;
34 36
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
35 37
import eu.etaxonomy.vaadin.ui.view.PopEditorOpenedEvent;
......
58 60
	@Autowired
59 61
	protected ApplicationContext applicationContext;
60 62

  
61
	@Autowired
62
	private PojoEventListenerManager eventListenerManager;
63

  
64 63
	protected EventBus.UIEventBus uiEventBus;
65 64

  
66 65
    @Autowired
......
166 165
	}
167 166

  
168 167
	@Override
169
	public <T extends PopupView> T showInPopup(Class<T> popupType) {
168
	public <T extends PopupView> T showInPopup(Class<T> popupType, ApplicationView parentView) {
170 169

  
171 170
	    PopupView popupView =  findPopupView(popupType);
172 171

  
173 172
	    if(AbstractPopupEditor.class.isAssignableFrom(popupView.getClass())){
174
	        AbstractEditorPresenter presenter = ((AbstractPopupEditor)popupView).presenter();
175
	        eventListenerManager.addEventListeners(presenter);
173
	        if(parentView instanceof AbstractPopupEditor){
174
	            // retain the chain of EditorActionContexts when starting a new pupupEditor
175
	            Stack<EditorActionContext> parentEditorActionContext = ((AbstractPopupEditor)parentView).getEditorActionContext();
176
	            ((AbstractPopupEditor)popupView).setParentEditorActionContext(parentEditorActionContext);
177
	        }
176 178
	    }
177 179

  
180

  
178 181
		Window window = new Window();
179 182
		window.setCaption(popupView.getWindowCaption());
180 183
		window.center();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)