Project

General

Profile

Revision 437f2e6f

ID437f2e6ff4477d44c3c0c75043873aebd0055e06
Parent 70c753df
Child 600e562c

Added by Andreas Kohlbecker about 3 years ago

#6562 restricting AbstractEditorPresenter to events coming from the related view

View differences:

src/main/java/eu/etaxonomy/vaadin/mvp/AbstractCdmEditorPresenter.java
34 34
    @Override
35 35
    @EventListener
36 36
    public void onEditorPreSaveEvent(EditorPreSaveEvent preSaveEvent){
37
        super.onEditorPreSaveEvent(preSaveEvent);
37 38
        tx = getRepo().startTransaction(true);
38 39
        // merge the bean and update the fieldGroup with the merged bean, so that updating
39 40
        // of field values in turn of the commit are can not cause LazyInitializationExeptions
......
45 46
    @Override
46 47
    @EventListener
47 48
    public void onEditorSaveEvent(EditorSaveEvent saveEvent){
49
        if(!saveEvent.getView().equals(getView())){
50
            return;
51
        }
48 52
        // the bean is now updated with the changes made by the user
49 53
        // merge the bean into the session, ...
50 54
        DTO bean = mergedBean(saveEvent.getCommitEvent());
......
78 82
            // evict bean before merge to avoid duplicate beans in same session
79 83
            session.evict(bean);
80 84
        }
85

  
81 86
        @SuppressWarnings("unchecked")
82 87
        DTO mergedBean = (DTO) session.merge(bean);
83 88
        itemDataSource.setBean(mergedBean);
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractEditorPresenter.java
29 29

  
30 30
    @EventListener
31 31
    public void onEditorPreSaveEvent(EditorPreSaveEvent preSaveEvent){
32

  
32
        if(!preSaveEvent.getView().equals(getView())){
33
            return;
34
        }
33 35
    }
34 36

  
35 37
    /**
......
38 40
     */
39 41
    @EventListener
40 42
    public void onEditorSaveEvent(EditorSaveEvent saveEvent){
43
        if(!saveEvent.getView().equals(getView())){
44
            return;
45
        }
41 46
        DTO bean = ((BeanFieldGroup<DTO>)saveEvent.getCommitEvent().getFieldBinder()).getItemDataSource().getBean();
42 47
        saveBean(bean);
43 48
    }
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
145 145
        public void preCommit(CommitEvent commitEvent) throws CommitException {
146 146
            logger.debug("preCommit");
147 147
            // notify the presenter to start a transaction
148
            eventBus.publishEvent(new EditorPreSaveEvent(commitEvent));
148
            eventBus.publishEvent(new EditorPreSaveEvent(commitEvent, AbstractPopupEditor.this));
149 149
        }
150 150

  
151 151
        @Override
152 152
        public void postCommit(CommitEvent commitEvent) throws CommitException {
153 153
            try {
154 154
                // notify the presenter to persist the bean and to commit the transaction
155
                eventBus.publishEvent(new EditorSaveEvent(commitEvent));
155
                eventBus.publishEvent(new EditorSaveEvent(commitEvent, AbstractPopupEditor.this));
156 156

  
157 157
                // notify the NavigationManagerBean to close the window and to dispose the view
158 158
                eventBus.publishEvent(new DoneWithPopupEvent(AbstractPopupEditor.this, Reason.SAVE));
src/main/java/eu/etaxonomy/vaadin/mvp/EditorPreSaveEvent.java
22 22

  
23 23
    private CommitEvent commitEvent;
24 24

  
25
    // FIXME this is only a iterim solution for the problem described in https://dev.e-taxonomy.eu/redmine/issues/6562
26
    private AbstractView view;
27

  
25 28
    /**
26 29
     * @param commitEvent
27 30
     */
28
    public EditorPreSaveEvent(CommitEvent commitEvent) {
31
    public EditorPreSaveEvent(CommitEvent commitEvent, AbstractView view) {
29 32
        this.commitEvent = commitEvent;
33
        this.view = view;
30 34
    }
31 35

  
32 36
    public CommitEvent getCommitEvent(){
33 37
        return commitEvent;
34 38
    }
35 39

  
40
    /**
41
     * @return the view
42
     */
43
    public AbstractView getView() {
44
        return view;
45
    }
46

  
36 47
}
src/main/java/eu/etaxonomy/vaadin/mvp/EditorSaveEvent.java
22 22

  
23 23
    private CommitEvent commitEvent;
24 24

  
25
    // FIXME this is only a iterim solution for the problem described in https://dev.e-taxonomy.eu/redmine/issues/6562
26
    private AbstractView view;
27

  
28

  
25 29
    /**
26 30
     * @param commitEvent
27 31
     */
28
    public EditorSaveEvent(CommitEvent commitEvent) {
32
    public EditorSaveEvent(CommitEvent commitEvent, AbstractView view) {
29 33
        this.commitEvent = commitEvent;
34
        this.view = view;
30 35
    }
31 36

  
32 37
    public CommitEvent getCommitEvent(){
33 38
        return commitEvent;
34 39
    }
35 40

  
41
    /**
42
     * @return the view
43
     */
44
    public AbstractView getView() {
45
        return view;
46
    }
47

  
36 48
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)