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 java.util.Collection;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.springframework.security.core.GrantedAuthority;
|
15
|
import org.vaadin.viritin.fields.LazyComboBox;
|
16
|
|
17
|
import com.vaadin.navigator.View;
|
18
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
19
|
import com.vaadin.spring.annotation.SpringView;
|
20
|
import com.vaadin.ui.Alignment;
|
21
|
import com.vaadin.ui.Button;
|
22
|
import com.vaadin.ui.CssLayout;
|
23
|
import com.vaadin.ui.HorizontalLayout;
|
24
|
import com.vaadin.ui.Label;
|
25
|
import com.vaadin.ui.VerticalLayout;
|
26
|
import com.vaadin.ui.themes.ValoTheme;
|
27
|
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
30
|
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
|
31
|
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
|
32
|
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
|
33
|
import eu.etaxonomy.vaadin.event.EditorActionType;
|
34
|
|
35
|
/**
|
36
|
* @author a.kohlbecker
|
37
|
* @since Mar 2, 2017
|
38
|
*
|
39
|
*/
|
40
|
@SpringView(name=StartRegistrationViewBean.NAME)
|
41
|
public class StartRegistrationViewBean extends AbstractPageView<StartRegistrationPresenter>
|
42
|
implements StartRegistrationView, AccessRestrictedView, View {
|
43
|
|
44
|
private static final long serialVersionUID = -9055865292188732909L;
|
45
|
|
46
|
public static final String NAME = "regStart";
|
47
|
|
48
|
public static final String SUBHEADER_DEEFAULT = "Any valid nomenclatural act can only be etablished in a publication. "
|
49
|
+ "To start a new registration process, please choose an existing one or create a new publication.";
|
50
|
|
51
|
private LazyComboBox<Reference> referenceCombobox;
|
52
|
|
53
|
private Button newPublicationButton;
|
54
|
|
55
|
private Button removeNewPublicationButton;
|
56
|
|
57
|
private Label newPublicationLabel;
|
58
|
|
59
|
private Button continueButton;
|
60
|
|
61
|
private static final String ELEMENT_WIDTH = "330px";
|
62
|
|
63
|
|
64
|
public StartRegistrationViewBean() {
|
65
|
super();
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* {@inheritDoc}
|
70
|
*/
|
71
|
@Override
|
72
|
protected void initContent() {
|
73
|
|
74
|
getLayout().setId(NAME);
|
75
|
|
76
|
VerticalLayout vlayout = new VerticalLayout();
|
77
|
vlayout.setSpacing(true);
|
78
|
vlayout.setMargin(true);
|
79
|
|
80
|
HorizontalLayout publicationLayout = new HorizontalLayout();
|
81
|
publicationLayout.setSpacing(true);
|
82
|
|
83
|
referenceCombobox = new LazyComboBox<Reference>(Reference.class);
|
84
|
referenceCombobox.setWidth(ELEMENT_WIDTH);
|
85
|
referenceCombobox.setBuffered(false);
|
86
|
referenceCombobox.addValueChangeListener( e -> {
|
87
|
boolean isValueSelected = e.getProperty().getValue() != null;
|
88
|
continueButton.setEnabled(isValueSelected);
|
89
|
});
|
90
|
|
91
|
newPublicationButton = new Button("New");
|
92
|
newPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
|
93
|
new ReferenceEditorAction(EditorActionType.ADD, newPublicationButton, this)
|
94
|
));
|
95
|
newPublicationButton.setCaption("New");
|
96
|
newPublicationButton.setWidth(ELEMENT_WIDTH);
|
97
|
|
98
|
newPublicationLabel = new Label();
|
99
|
newPublicationLabel.setVisible(false);
|
100
|
|
101
|
removeNewPublicationButton = new Button("Delete");
|
102
|
removeNewPublicationButton.setStyleName(ValoTheme.BUTTON_DANGER);
|
103
|
removeNewPublicationButton.setWidth(ELEMENT_WIDTH);
|
104
|
removeNewPublicationButton.addClickListener( e -> getViewEventBus().publish(this,
|
105
|
new ReferenceEditorAction(EditorActionType.REMOVE, removeNewPublicationButton, this)
|
106
|
));
|
107
|
|
108
|
removeNewPublicationButton.setVisible(false);
|
109
|
|
110
|
Label labelLeft = new Label("Choose from existing publications");
|
111
|
Label labelRight = new Label("Create a new publication");
|
112
|
labelLeft.setWidth(ELEMENT_WIDTH);
|
113
|
labelRight.setWidth(ELEMENT_WIDTH);
|
114
|
|
115
|
CssLayout leftContainer = new CssLayout(labelLeft, referenceCombobox);
|
116
|
CssLayout rightContainer = new CssLayout(labelRight, newPublicationButton, removeNewPublicationButton, newPublicationLabel);
|
117
|
leftContainer.setWidth(ELEMENT_WIDTH);
|
118
|
rightContainer.setWidth(ELEMENT_WIDTH);
|
119
|
|
120
|
publicationLayout.addComponents(
|
121
|
leftContainer,
|
122
|
rightContainer
|
123
|
);
|
124
|
publicationLayout.setComponentAlignment(leftContainer, Alignment.TOP_RIGHT);
|
125
|
publicationLayout.setComponentAlignment(rightContainer, Alignment.TOP_LEFT);
|
126
|
|
127
|
continueButton = new Button("Continue");
|
128
|
continueButton.setStyleName(ValoTheme.BUTTON_PRIMARY + " " + ValoTheme.BUTTON_HUGE);
|
129
|
continueButton.setEnabled(false);
|
130
|
continueButton.addClickListener(e -> {
|
131
|
|
132
|
UUID refUuid = null;
|
133
|
referenceCombobox.commit();
|
134
|
if(referenceCombobox.getValue() != null){
|
135
|
refUuid = referenceCombobox.getValue().getUuid();
|
136
|
}
|
137
|
getViewEventBus().publish(this,
|
138
|
new RegistrationEditorAction(EditorActionType.ADD,
|
139
|
// passing the refId is hack, bit for some reason the presenter is always referring to the wrong view
|
140
|
refUuid,
|
141
|
continueButton,
|
142
|
StartRegistrationViewBean.this)
|
143
|
);
|
144
|
}
|
145
|
);
|
146
|
|
147
|
vlayout.addComponents(publicationLayout, continueButton);
|
148
|
vlayout.setComponentAlignment(publicationLayout, Alignment.TOP_CENTER);
|
149
|
vlayout.setComponentAlignment(continueButton, Alignment.TOP_CENTER);
|
150
|
|
151
|
addContentComponent(vlayout, 1f);
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* {@inheritDoc}
|
156
|
*/
|
157
|
@Override
|
158
|
public boolean allowAnonymousAccess() {
|
159
|
return false;
|
160
|
}
|
161
|
|
162
|
/**
|
163
|
* {@inheritDoc}
|
164
|
*/
|
165
|
@Override
|
166
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
167
|
return null;
|
168
|
}
|
169
|
|
170
|
/**
|
171
|
* {@inheritDoc}
|
172
|
*/
|
173
|
@Override
|
174
|
protected String getHeaderText() {
|
175
|
return "New Registration";
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* {@inheritDoc}
|
180
|
*/
|
181
|
@Override
|
182
|
protected String getSubHeaderText() {
|
183
|
return SUBHEADER_DEEFAULT;
|
184
|
}
|
185
|
|
186
|
/**
|
187
|
* {@inheritDoc}
|
188
|
*/
|
189
|
@Override
|
190
|
public void enter(ViewChangeEvent event) {
|
191
|
// TODO Auto-generated method stub
|
192
|
|
193
|
}
|
194
|
|
195
|
// ------- StartRegistrationView interface methods ----- //
|
196
|
|
197
|
/**
|
198
|
* @return the referenceCombobox
|
199
|
*/
|
200
|
@Override
|
201
|
public LazyComboBox<Reference> getReferenceCombobox() {
|
202
|
return referenceCombobox;
|
203
|
}
|
204
|
|
205
|
/**
|
206
|
* @return the newPublicationButton
|
207
|
*/
|
208
|
@Override
|
209
|
public Button getNewPublicationButton() {
|
210
|
return newPublicationButton;
|
211
|
}
|
212
|
|
213
|
/**
|
214
|
* @return the newPublicationButton
|
215
|
*/
|
216
|
@Override
|
217
|
public Button getRemoveNewPublicationButton() {
|
218
|
return removeNewPublicationButton;
|
219
|
}
|
220
|
|
221
|
/**
|
222
|
* @return the newPublicationButton
|
223
|
*/
|
224
|
@Override
|
225
|
public Button getContinueButton() {
|
226
|
return continueButton;
|
227
|
}
|
228
|
|
229
|
/**
|
230
|
* @return the newPublicationLabel
|
231
|
*/
|
232
|
@Override
|
233
|
public Label getNewPublicationLabel() {
|
234
|
return newPublicationLabel;
|
235
|
}
|
236
|
|
237
|
|
238
|
|
239
|
}
|