2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.vaadin
.mvp
;
11 import org
.hibernate
.FlushMode
;
12 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
13 import org
.springframework
.context
.ApplicationEventPublisher
;
14 import org
.springframework
.context
.event
.EventListener
;
16 import eu
.etaxonomy
.cdm
.vaadin
.event
.AbstractEditorAction
;
17 import eu
.etaxonomy
.vaadin
.mvp
.event
.EditorDeleteEvent
;
18 import eu
.etaxonomy
.vaadin
.mvp
.event
.EditorPreSaveEvent
;
19 import eu
.etaxonomy
.vaadin
.mvp
.event
.EditorSaveEvent
;
20 import eu
.etaxonomy
.vaadin
.mvp
.event
.EditorViewEvent
;
24 * @author a.kohlbecker
28 public abstract class AbstractEditorPresenter
<DTO
extends Object
, V
extends ApplicationView
<?
>> extends AbstractPresenter
<V
> {
31 private static final long serialVersionUID
= -6677074110764145236L;
33 FlushMode previousPreSaveEvenFlushMode
= null;
36 protected ApplicationEventPublisher eventBus
;
39 * Load the bean to be edited in the editor freshly from the persistent storage.
40 * Ore create an new empty instance in case the supplied <code>identifier</code> is <code>null</code>.
45 protected abstract DTO
loadBeanById(Object identifier
);
49 * Regarding changing the Flush mode see see also {@link ViewScopeConversationHolder}
54 public void onEditorPreSaveEvent(EditorPreSaveEvent
<DTO
> preSaveEvent
){
55 if(!isFromOwnView(preSaveEvent
)){
58 getSession().setFlushMode(FlushMode
.AUTO
);
63 * Regarding changing the Flush mode see see also {@link ViewScopeConversationHolder}
68 public void onEditorSaveEvent(EditorSaveEvent
<DTO
> saveEvent
){
69 if(!isFromOwnView(saveEvent
)){
72 DTO bean
= saveEvent
.getBean();
74 getSession().setFlushMode(previousPreSaveEvenFlushMode
);
75 previousPreSaveEvenFlushMode
= null;
79 * Regarding changing the Flush mode see see also {@link ViewScopeConversationHolder}
84 public void onEditorDeleteEvent(EditorDeleteEvent
<DTO
> deleteEvent
){
85 if(!isFromOwnView(deleteEvent
)){
88 FlushMode previousFlushMode
= getSession().getFlushMode();
89 getSession().setFlushMode(FlushMode
.AUTO
);
90 deleteBean(deleteEvent
.getBean());
91 getSession().setFlushMode(previousFlushMode
);
98 protected boolean isFromOwnView(EditorViewEvent saveEvent
) {
99 return saveEvent
.getView().equals(getView());
102 protected Class
<V
> getViewType() {
103 return (Class
<V
>) super.getView().getClass();
106 protected boolean isFromOwnView(AbstractEditorAction action
){
107 return action
.getSourceView() != null && getView().equals(action
.getSourceView());
111 protected abstract void saveBean(DTO bean
);
116 protected abstract void deleteBean(DTO bean
);