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 org
.springframework
.context
.event
.EventListener
;
12 import org
.vaadin
.viritin
.fields
.LazyComboBox
;
14 import com
.vaadin
.server
.SystemError
;
15 import com
.vaadin
.server
.UserError
;
16 import com
.vaadin
.spring
.annotation
.SpringComponent
;
17 import com
.vaadin
.spring
.annotation
.ViewScope
;
19 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
20 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
21 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
22 import eu
.etaxonomy
.cdm
.vaadin
.event
.ReferenceEditorAction
;
23 import eu
.etaxonomy
.cdm
.vaadin
.event
.RegistrationEditorAction
;
24 import eu
.etaxonomy
.cdm
.vaadin
.util
.CdmTitleCacheCaptionGenerator
;
25 import eu
.etaxonomy
.cdm
.vaadin
.view
.reference
.ReferencePopupEditor
;
26 import eu
.etaxonomy
.vaadin
.mvp
.AbstractEditorPresenter
;
27 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationEvent
;
28 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
;
29 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
.Reason
;
32 * @author a.kohlbecker
38 public class StartRegistrationPresenter
extends AbstractEditorPresenter
<RegistrationDTO
, StartRegistrationView
> {
40 private static final long serialVersionUID
= 2283189121081612574L;
42 private ReferencePopupEditor newReferencePopup
;
44 private Reference newReference
;
46 private boolean registrationInProgress
;
48 public StartRegistrationPresenter (){
56 public void onPresenterReady() {
58 super.onPresenterReady();
60 CdmFilterablePagingProvider
<Reference
> pagingProvider
= new CdmFilterablePagingProvider
<Reference
>(
61 getRepo().getReferenceService(), this);
62 CdmTitleCacheCaptionGenerator
<Reference
> titleCacheGenrator
= new CdmTitleCacheCaptionGenerator
<Reference
>();
63 getView().getReferenceCombobox().setCaptionGenerator(titleCacheGenrator
);
64 getView().getReferenceCombobox().loadFrom(pagingProvider
, pagingProvider
, pagingProvider
.getPageSize());
71 public void handleViewExit() {
72 if(!registrationInProgress
&& newReference
!= null){
73 logger
.info("Deleting newly created Reference due to canceled registration");
74 getRepo().getReferenceService().delete(newReference
);
76 super.handleViewExit();
79 @EventListener(condition
= "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
80 public void onReferenceEditorActionAdd(ReferenceEditorAction event
) {
82 if(getView().getNewPublicationButton() != event
.getSourceComponent()){
85 newReferencePopup
= getNavigationManager().showInPopup(ReferencePopupEditor
.class);
87 newReferencePopup
.withDeleteButton(true);
88 newReferencePopup
.loadInEditor(null);
91 @EventListener(condition
= "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).REMOVE")
92 public void onReferenceEditorActionRemove(ReferenceEditorAction event
) {
94 if(getView().getRemoveNewPublicationButton() != event
.getSourceComponent()){
97 DeleteResult result
= getRepo().getReferenceService().delete(newReference
);
100 for(Exception e
: result
.getExceptions()){
101 message
+= e
.getMessage() + "\n" + e
.getStackTrace().toString() + "\n";
103 getView().getRemoveNewPublicationButton().setComponentError(new SystemError(message
));
106 getView().getReferenceCombobox().setEnabled(false);
108 getView().getRemoveNewPublicationButton().setVisible(false);
110 getView().getNewPublicationButton().setVisible(true);
111 getView().getNewPublicationLabel().setCaption(null);
112 getView().getNewPublicationLabel().setVisible(false);
116 public void onDoneWithPopupEvent(DoneWithPopupEvent event
){
117 if(event
.getPopup() == newReferencePopup
){
118 if(event
.getReason() == Reason
.SAVE
){
120 newReference
= newReferencePopup
.getBean();
122 getView().getReferenceCombobox().setValue(null); // deselect
123 getView().getReferenceCombobox().setEnabled(false);
125 getView().getContinueButton().setEnabled(true);
127 getView().getNewPublicationButton().setVisible(false);
129 getView().getRemoveNewPublicationButton().setVisible(true);
130 getView().getNewPublicationLabel().setCaption(newReference
.getTitleCache());
131 getView().getNewPublicationLabel().setVisible(true);
134 newReferencePopup
= null;
138 @EventListener(condition
= "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
139 public void onRegistrationEditorActionAdd(RegistrationEditorAction event
) {
141 if(getView().getContinueButton() != event
.getSourceComponent()){
144 Integer referenceId
= null;
145 LazyComboBox
<Reference
> referenceCombobox
= getView().getReferenceCombobox();
146 referenceCombobox
.commit();
147 if(newReference
!= null){
148 referenceId
= newReference
.getId();
149 // } else if(referenceCombobox.getValue() != null) {
150 } else if ( event
.getEntityId() != null) { // HACKED, see view implementation
151 referenceId
= event
.getEntityId();
153 if(referenceId
== null){
154 getView().getContinueButton().setComponentError(new UserError("Can't continue. No Reference is chosen."));
155 getView().getContinueButton().setEnabled(false);
157 registrationInProgress
= true;
158 eventBus
.publishEvent(new NavigationEvent(RegistrationWorksetViewBean
.NAME
, Integer
.toString(referenceId
)));
166 protected RegistrationDTO
loadBeanById(Object identifier
) {
175 protected void saveBean(RegistrationDTO bean
) {
176 // TODO Auto-generated method stub
184 protected void deleteBean(RegistrationDTO bean
) {
185 // TODO Auto-generated method stub