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