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
.cdm
.vaadin
.view
.registration
;
11 import java
.util
.EnumSet
;
13 import org
.springframework
.context
.event
.EventListener
;
14 import org
.vaadin
.viritin
.fields
.LazyComboBox
;
16 import com
.vaadin
.server
.SystemError
;
17 import com
.vaadin
.server
.UserError
;
18 import com
.vaadin
.spring
.annotation
.SpringComponent
;
19 import com
.vaadin
.spring
.annotation
.ViewScope
;
21 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
23 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CRUD
;
24 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
25 import eu
.etaxonomy
.cdm
.vaadin
.event
.ReferenceEditorAction
;
26 import eu
.etaxonomy
.cdm
.vaadin
.event
.RegistrationEditorAction
;
27 import eu
.etaxonomy
.cdm
.vaadin
.util
.CdmTitleCacheCaptionGenerator
;
28 import eu
.etaxonomy
.cdm
.vaadin
.view
.reference
.ReferencePopupEditor
;
29 import eu
.etaxonomy
.vaadin
.mvp
.AbstractEditorPresenter
;
30 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationEvent
;
31 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
;
32 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
.Reason
;
35 * @author a.kohlbecker
41 public class StartRegistrationPresenter
extends AbstractEditorPresenter
<RegistrationDTO
, StartRegistrationView
> {
43 private static final long serialVersionUID
= 2283189121081612574L;
45 private ReferencePopupEditor newReferencePopup
;
47 private Reference newReference
;
49 private boolean registrationInProgress
;
51 public StartRegistrationPresenter (){
59 public void onPresenterReady() {
61 super.onPresenterReady();
63 CdmFilterablePagingProvider
<Reference
, Reference
> pagingProvider
= new CdmFilterablePagingProvider
<Reference
, Reference
>(
64 getRepo().getReferenceService());
65 CdmTitleCacheCaptionGenerator
<Reference
> titleCacheGenrator
= new CdmTitleCacheCaptionGenerator
<Reference
>();
66 getView().getReferenceCombobox().setCaptionGenerator(titleCacheGenrator
);
67 getView().getReferenceCombobox().loadFrom(pagingProvider
, pagingProvider
, pagingProvider
.getPageSize());
74 public void handleViewExit() {
75 if(!registrationInProgress
&& newReference
!= null){
76 logger
.info("Deleting newly created Reference due to canceled registration");
77 getRepo().getReferenceService().delete(newReference
);
79 super.handleViewExit();
82 @EventListener(condition
= "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
83 public void onReferenceEditorActionAdd(ReferenceEditorAction event
) {
85 if(getView().getNewPublicationButton() != event
.getSourceComponent()){
88 newReferencePopup
= getNavigationManager().showInPopup(ReferencePopupEditor
.class);
90 newReferencePopup
.grantToCurrentUser(EnumSet
.of(CRUD
.UPDATE
, CRUD
.DELETE
));
91 newReferencePopup
.withDeleteButton(true);
92 newReferencePopup
.loadInEditor(null);
95 @EventListener(condition
= "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).REMOVE")
96 public void onReferenceEditorActionRemove(ReferenceEditorAction event
) {
98 if(getView().getRemoveNewPublicationButton() != event
.getSourceComponent()){
101 DeleteResult result
= getRepo().getReferenceService().delete(newReference
);
104 for(Exception e
: result
.getExceptions()){
105 message
+= e
.getMessage() + "\n" + e
.getStackTrace().toString() + "\n";
107 getView().getRemoveNewPublicationButton().setComponentError(new SystemError(message
));
110 getView().getReferenceCombobox().setEnabled(false);
112 getView().getRemoveNewPublicationButton().setVisible(false);
114 getView().getNewPublicationButton().setVisible(true);
115 getView().getNewPublicationLabel().setCaption(null);
116 getView().getNewPublicationLabel().setVisible(false);
120 public void onDoneWithPopupEvent(DoneWithPopupEvent event
){
121 if(event
.getPopup() == newReferencePopup
){
122 if(event
.getReason() == Reason
.SAVE
){
124 newReference
= newReferencePopup
.getBean();
126 // TODO the bean contained in the popup editor is not yet updated at this point.
127 // so re reload it using the uuid since new beans will not have an Id at this point.
128 newReference
= getRepo().getReferenceService().find(newReference
.getUuid());
130 getView().getReferenceCombobox().setValue(null); // deselect
131 getView().getReferenceCombobox().setEnabled(false);
133 getView().getContinueButton().setEnabled(true);
135 getView().getNewPublicationButton().setVisible(false);
137 getView().getRemoveNewPublicationButton().setVisible(true);
138 getView().getNewPublicationLabel().setCaption(newReference
.getTitleCache());
139 getView().getNewPublicationLabel().setVisible(true);
142 newReferencePopup
= null;
146 @EventListener(condition
= "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
147 public void onRegistrationEditorActionAdd(RegistrationEditorAction event
) {
149 if(getView().getContinueButton() != event
.getSourceComponent()){
152 Integer referenceId
= null;
153 LazyComboBox
<Reference
> referenceCombobox
= getView().getReferenceCombobox();
154 referenceCombobox
.commit();
155 if(newReference
!= null){
156 referenceId
= newReference
.getId();
157 // } else if(referenceCombobox.getValue() != null) {
158 } else if ( event
.getEntityId() != null) { // HACKED, see view implementation
159 referenceId
= event
.getEntityId();
161 if(referenceId
== null){
162 getView().getContinueButton().setComponentError(new UserError("Can't continue. No Reference is chosen."));
163 getView().getContinueButton().setEnabled(false);
165 registrationInProgress
= true;
166 eventBus
.publishEvent(new NavigationEvent(RegistrationWorksetViewBean
.NAME
, Integer
.toString(referenceId
)));
174 protected RegistrationDTO
loadBeanById(Object identifier
) {
183 protected void saveBean(RegistrationDTO bean
) {
184 // TODO Auto-generated method stub
192 protected void deleteBean(RegistrationDTO bean
) {
193 // TODO Auto-generated method stub