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
;
12 import java
.util
.UUID
;
14 import org
.vaadin
.spring
.events
.EventScope
;
15 import org
.vaadin
.spring
.events
.annotation
.EventBusListenerMethod
;
16 import org
.vaadin
.viritin
.fields
.LazyComboBox
;
18 import com
.vaadin
.server
.SystemError
;
19 import com
.vaadin
.server
.UserError
;
20 import com
.vaadin
.spring
.annotation
.SpringComponent
;
21 import com
.vaadin
.spring
.annotation
.ViewScope
;
23 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
24 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RegistrationDTO
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
27 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CRUD
;
28 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
29 import eu
.etaxonomy
.cdm
.vaadin
.event
.EditorActionTypeFilter
;
30 import eu
.etaxonomy
.cdm
.vaadin
.event
.ReferenceEditorAction
;
31 import eu
.etaxonomy
.cdm
.vaadin
.event
.RegistrationEditorAction
;
32 import eu
.etaxonomy
.cdm
.vaadin
.ui
.RegistrationUIDefaults
;
33 import eu
.etaxonomy
.cdm
.vaadin
.util
.CdmTitleCacheCaptionGenerator
;
34 import eu
.etaxonomy
.cdm
.vaadin
.view
.reference
.ReferencePopupEditor
;
35 import eu
.etaxonomy
.vaadin
.mvp
.AbstractEditorPresenter
;
36 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationEvent
;
37 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
;
38 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
.Reason
;
41 * @author a.kohlbecker
47 public class StartRegistrationPresenter
extends AbstractEditorPresenter
<RegistrationDTO
, StartRegistrationView
> {
49 private static final long serialVersionUID
= 2283189121081612574L;
51 private ReferencePopupEditor newReferencePopup
;
53 private Reference newReference
;
55 private boolean registrationInProgress
;
57 public StartRegistrationPresenter (){
66 public void onPresenterReady() {
68 super.onPresenterReady();
70 CdmFilterablePagingProvider
<Reference
, Reference
> pagingProvider
= new CdmFilterablePagingProvider
<Reference
, Reference
>(
71 getRepo().getReferenceService());
72 CdmTitleCacheCaptionGenerator
<Reference
> titleCacheGenrator
= new CdmTitleCacheCaptionGenerator
<Reference
>();
73 getView().getReferenceCombobox().setCaptionGenerator(titleCacheGenrator
);
74 getView().getReferenceCombobox().loadFrom(pagingProvider
, pagingProvider
, pagingProvider
.getPageSize());
81 public void handleViewExit() {
82 if(!registrationInProgress
&& newReference
!= null){
83 logger
.info("Deleting newly created Reference due to canceled registration");
84 getRepo().getReferenceService().delete(newReference
);
86 super.handleViewExit();
90 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
91 public void onReferenceEditorActionAdd(ReferenceEditorAction event
) {
93 if(getView() == null || getView().getNewPublicationButton() != event
.getSource()){
97 newReferencePopup
= openPopupEditor(ReferencePopupEditor
.class, event
);
98 EnumSet
<ReferenceType
> refTypes
= RegistrationUIDefaults
.PRINTPUB_REFERENCE_TYPES
.clone();
99 refTypes
.remove(ReferenceType
.Section
);
100 newReferencePopup
.withReferenceTypes(refTypes
);
101 newReferencePopup
.grantToCurrentUser(EnumSet
.of(CRUD
.UPDATE
, CRUD
.DELETE
));
102 newReferencePopup
.withDeleteButton(true);
103 newReferencePopup
.loadInEditor(null);
106 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Remove
.class)
107 public void onReferenceEditorActionRemove(ReferenceEditorAction event
) {
109 if(getView().getRemoveNewPublicationButton() != event
.getSource()){
112 DeleteResult result
= getRepo().getReferenceService().delete(newReference
);
115 for(Exception e
: result
.getExceptions()){
116 message
+= e
.getMessage() + "\n" + e
.getStackTrace().toString() + "\n";
118 getView().getRemoveNewPublicationButton().setComponentError(new SystemError(message
));
121 getView().getReferenceCombobox().setEnabled(false);
123 getView().getRemoveNewPublicationButton().setVisible(false);
125 getView().getNewPublicationButton().setVisible(true);
126 getView().getNewPublicationLabel().setCaption(null);
127 getView().getNewPublicationLabel().setVisible(false);
130 @EventBusListenerMethod
131 public void onDoneWithPopupEvent(DoneWithPopupEvent event
){
133 if(event
.getPopup() == newReferencePopup
){
134 if(event
.getReason() == Reason
.SAVE
){
136 newReference
= newReferencePopup
.getBean();
138 // TODO the bean contained in the popup editor is not yet updated at this point.
139 // so re reload it using the uuid since new beans will not have an Id at this point.
140 newReference
= getRepo().getReferenceService().find(newReference
.getUuid());
142 getView().getReferenceCombobox().setValue(null); // deselect
143 getView().getReferenceCombobox().setEnabled(false);
145 getView().getContinueButton().setEnabled(true);
147 getView().getNewPublicationButton().setVisible(false);
149 getView().getRemoveNewPublicationButton().setVisible(true);
150 getView().getNewPublicationLabel().setCaption(newReference
.getTitleCache());
151 getView().getNewPublicationLabel().setVisible(true);
154 newReferencePopup
= null;
158 @SuppressWarnings("null")
159 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
160 public void onRegistrationEditorActionAdd(RegistrationEditorAction event
) {
162 if(getView().getContinueButton() != event
.getSource()){
166 UUID referenceUuid
= null;
167 LazyComboBox
<Reference
> referenceCombobox
= getView().getReferenceCombobox();
168 referenceCombobox
.commit();
169 if(newReference
!= null){
170 referenceUuid
= newReference
.getUuid();
171 // } else if(referenceCombobox.getValue() != null) {
172 } else if ( event
.getEntityUuid() != null) { // HACKED, see view implementation
173 referenceUuid
= event
.getEntityUuid();
175 if(referenceUuid
== null){
176 getView().getContinueButton().setComponentError(new UserError("Can't continue. No Reference is chosen."));
177 getView().getContinueButton().setEnabled(false);
179 registrationInProgress
= true;
180 viewEventBus
.publish(EventScope
.UI
, this, new NavigationEvent(RegistrationWorksetViewBean
.NAME
, referenceUuid
.toString()));
188 protected RegistrationDTO
loadBeanById(Object identifier
) {
197 protected void saveBean(RegistrationDTO bean
) {
198 // TODO Auto-generated method stub
206 protected void deleteBean(RegistrationDTO bean
) {
207 // TODO Auto-generated method stub