1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.view.registration;
|
10
|
|
11
|
import org.springframework.context.event.EventListener;
|
12
|
import org.vaadin.viritin.fields.LazyComboBox;
|
13
|
|
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;
|
18
|
|
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;
|
30
|
|
31
|
/**
|
32
|
* @author a.kohlbecker
|
33
|
* @since Jul 11, 2017
|
34
|
*
|
35
|
*/
|
36
|
@SpringComponent
|
37
|
@ViewScope
|
38
|
public class StartRegistrationPresenter extends AbstractEditorPresenter<RegistrationDTO, StartRegistrationView> {
|
39
|
|
40
|
private static final long serialVersionUID = 2283189121081612574L;
|
41
|
|
42
|
private ReferencePopupEditor newReferencePopup;
|
43
|
|
44
|
private Reference newReference;
|
45
|
|
46
|
private boolean registrationInProgress;
|
47
|
|
48
|
public StartRegistrationPresenter (){
|
49
|
super();
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* {@inheritDoc}
|
54
|
*/
|
55
|
@Override
|
56
|
public void onPresenterReady() {
|
57
|
|
58
|
super.onPresenterReady();
|
59
|
|
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());
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* {@inheritDoc}
|
69
|
*/
|
70
|
@Override
|
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);
|
75
|
}
|
76
|
super.handleViewExit();
|
77
|
}
|
78
|
|
79
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
|
80
|
public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
|
81
|
|
82
|
if(getView().getNewPublicationButton() != event.getSourceComponent()){
|
83
|
return;
|
84
|
}
|
85
|
newReferencePopup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
86
|
|
87
|
newReferencePopup.withDeleteButton(true);
|
88
|
newReferencePopup.loadInEditor(null);
|
89
|
}
|
90
|
|
91
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).REMOVE")
|
92
|
public void onReferenceEditorActionRemove(ReferenceEditorAction event) {
|
93
|
|
94
|
if(getView().getRemoveNewPublicationButton() != event.getSourceComponent()){
|
95
|
return;
|
96
|
}
|
97
|
DeleteResult result = getRepo().getReferenceService().delete(newReference);
|
98
|
if(!result.isOk()){
|
99
|
String message = "";
|
100
|
for(Exception e : result.getExceptions()){
|
101
|
message += e.getMessage() + "\n" + e.getStackTrace().toString() + "\n";
|
102
|
}
|
103
|
getView().getRemoveNewPublicationButton().setComponentError(new SystemError(message));
|
104
|
}
|
105
|
|
106
|
getView().getReferenceCombobox().setEnabled(false);
|
107
|
|
108
|
getView().getRemoveNewPublicationButton().setVisible(false);
|
109
|
|
110
|
getView().getNewPublicationButton().setVisible(true);
|
111
|
getView().getNewPublicationLabel().setCaption(null);
|
112
|
getView().getNewPublicationLabel().setVisible(false);
|
113
|
}
|
114
|
|
115
|
@EventListener
|
116
|
public void onDoneWithPopupEvent(DoneWithPopupEvent event){
|
117
|
if(event.getPopup() == newReferencePopup){
|
118
|
if(event.getReason() == Reason.SAVE){
|
119
|
|
120
|
newReference = newReferencePopup.getBean();
|
121
|
|
122
|
getView().getReferenceCombobox().setValue(null); // deselect
|
123
|
getView().getReferenceCombobox().setEnabled(false);
|
124
|
|
125
|
getView().getContinueButton().setEnabled(true);
|
126
|
|
127
|
getView().getNewPublicationButton().setVisible(false);
|
128
|
|
129
|
getView().getRemoveNewPublicationButton().setVisible(true);
|
130
|
getView().getNewPublicationLabel().setCaption(newReference.getTitleCache());
|
131
|
getView().getNewPublicationLabel().setVisible(true);
|
132
|
}
|
133
|
|
134
|
newReferencePopup = null;
|
135
|
}
|
136
|
}
|
137
|
|
138
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
|
139
|
public void onRegistrationEditorActionAdd(RegistrationEditorAction event) {
|
140
|
|
141
|
if(getView().getContinueButton() != event.getSourceComponent()){
|
142
|
return;
|
143
|
}
|
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();
|
152
|
}
|
153
|
if(referenceId == null){
|
154
|
getView().getContinueButton().setComponentError(new UserError("Can't continue. No Reference is chosen."));
|
155
|
getView().getContinueButton().setEnabled(false);
|
156
|
}
|
157
|
registrationInProgress = true;
|
158
|
eventBus.publishEvent(new NavigationEvent(RegistrationWorkflowViewBean.NAME, Integer.toString(referenceId)));
|
159
|
|
160
|
}
|
161
|
|
162
|
/**
|
163
|
* {@inheritDoc}
|
164
|
*/
|
165
|
@Override
|
166
|
protected RegistrationDTO loadBeanById(Object identifier) {
|
167
|
// not needed //
|
168
|
return null;
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* {@inheritDoc}
|
173
|
*/
|
174
|
@Override
|
175
|
protected void saveBean(RegistrationDTO bean) {
|
176
|
// TODO Auto-generated method stub
|
177
|
|
178
|
}
|
179
|
|
180
|
/**
|
181
|
* {@inheritDoc}
|
182
|
*/
|
183
|
@Override
|
184
|
protected void deleteBean(RegistrationDTO bean) {
|
185
|
// TODO Auto-generated method stub
|
186
|
|
187
|
}
|
188
|
|
189
|
}
|