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
.springframework
.beans
.factory
.annotation
.Autowired
;
12 import org
.springframework
.context
.ApplicationEventPublisher
;
13 import org
.springframework
.context
.event
.EventListener
;
15 import eu
.etaxonomy
.cdm
.vaadin
.event
.AbstractEditorAction
;
16 import eu
.etaxonomy
.vaadin
.mvp
.event
.EditorDeleteEvent
;
17 import eu
.etaxonomy
.vaadin
.mvp
.event
.EditorPreSaveEvent
;
18 import eu
.etaxonomy
.vaadin
.mvp
.event
.EditorSaveEvent
;
19 import eu
.etaxonomy
.vaadin
.mvp
.event
.EditorViewEvent
;
22 * @author a.kohlbecker
26 public abstract class AbstractEditorPresenter
<DTO
extends Object
, V
extends ApplicationView
<?
>> extends AbstractPresenter
<V
> {
29 private static final long serialVersionUID
= -6677074110764145236L;
32 protected ApplicationEventPublisher eventBus
;
35 * This method is called directly before setting the bean as item data source to
36 * the field group of the editor.
38 * Override this method to pre-process the bean if needed. This can be the case if
39 * you are using a persistence layer with short running session like Hibernate.
44 protected DTO
prepareAsFieldGroupDataSource(DTO bean
){
49 public void onEditorPreSaveEvent(EditorPreSaveEvent
<DTO
> preSaveEvent
){
50 if(!isFromOwnView(preSaveEvent
)){
60 public void onEditorSaveEvent(EditorSaveEvent
<DTO
> saveEvent
){
61 if(!isFromOwnView(saveEvent
)){
64 DTO bean
= saveEvent
.getBean();
73 public void onEditorDeleteEvent(EditorDeleteEvent
<DTO
> deleteEvent
){
74 if(!isFromOwnView(deleteEvent
)){
77 deleteBean(deleteEvent
.getBean());
84 protected boolean isFromOwnView(EditorViewEvent saveEvent
) {
85 return saveEvent
.getView().equals(getView());
88 protected Class
<V
> getViewType() {
89 return (Class
<V
>) super.getView().getClass();
92 protected boolean isFromOwnView(AbstractEditorAction action
){
93 return action
.getSourceView() != null && getView().equals(action
.getSourceView());
96 protected abstract void saveBean(DTO bean
);
101 protected abstract void deleteBean(DTO bean
);