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.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.springframework.security.core.GrantedAuthority;
|
17
|
import org.vaadin.viritin.fields.LazyComboBox;
|
18
|
|
19
|
import com.vaadin.navigator.View;
|
20
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
21
|
import com.vaadin.server.FontAwesome;
|
22
|
import com.vaadin.server.Page;
|
23
|
import com.vaadin.spring.annotation.SpringView;
|
24
|
import com.vaadin.ui.AbstractLayout;
|
25
|
import com.vaadin.ui.Alignment;
|
26
|
import com.vaadin.ui.Button;
|
27
|
import com.vaadin.ui.Component;
|
28
|
import com.vaadin.ui.CssLayout;
|
29
|
import com.vaadin.ui.GridLayout;
|
30
|
import com.vaadin.ui.HorizontalLayout;
|
31
|
import com.vaadin.ui.Label;
|
32
|
import com.vaadin.ui.Notification;
|
33
|
import com.vaadin.ui.Panel;
|
34
|
import com.vaadin.ui.UI;
|
35
|
import com.vaadin.ui.VerticalLayout;
|
36
|
import com.vaadin.ui.Window;
|
37
|
import com.vaadin.ui.themes.ValoTheme;
|
38
|
|
39
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
40
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
|
41
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup;
|
42
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup.TypeDesignationWorkingSetButton;
|
43
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStateLabel;
|
44
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
|
45
|
import eu.etaxonomy.cdm.vaadin.component.registration.WorkflowSteps;
|
46
|
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
|
47
|
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action;
|
48
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
49
|
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
|
50
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
51
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
52
|
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
|
53
|
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
|
54
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
55
|
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
|
56
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
57
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
|
58
|
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
|
59
|
|
60
|
/**
|
61
|
* @author a.kohlbecker
|
62
|
* @since Mar 2, 2017
|
63
|
*
|
64
|
*/
|
65
|
@SpringView(name=RegistrationWorksetViewBean.NAME)
|
66
|
public class RegistrationWorksetViewBean extends AbstractPageView<RegistrationWorkingsetPresenter>
|
67
|
implements RegistrationWorkingsetView, View, AccessRestrictedView {
|
68
|
|
69
|
public static final String DOM_ID_WORKINGSET = "workingset";
|
70
|
|
71
|
private static final long serialVersionUID = -213040114015958970L;
|
72
|
|
73
|
public static final String NAME = "workingset";
|
74
|
|
75
|
public RegistrationType regType = null;
|
76
|
|
77
|
private List<CssLayout> registrations = new ArrayList<>();
|
78
|
|
79
|
private String headerText = "Registration Workingset Editor";
|
80
|
private String subheaderText = "";
|
81
|
|
82
|
private Integer citationID;
|
83
|
|
84
|
private Button addNewNameRegistrationButton;
|
85
|
|
86
|
private LazyComboBox<TaxonName> existingNameCombobox;
|
87
|
|
88
|
private GridLayout registrationsGrid;
|
89
|
|
90
|
private Button addExistingNameButton;
|
91
|
|
92
|
private RegistrationItem workingsetHeader;
|
93
|
|
94
|
private Panel registrationListPanel;
|
95
|
|
96
|
public RegistrationWorksetViewBean() {
|
97
|
super();
|
98
|
}
|
99
|
|
100
|
|
101
|
/**
|
102
|
* {@inheritDoc}
|
103
|
*/
|
104
|
@Override
|
105
|
protected void initContent() {
|
106
|
getLayout().setId(NAME);
|
107
|
updateHeader();
|
108
|
// all content is added in createRegistrationsList()
|
109
|
}
|
110
|
|
111
|
|
112
|
/**
|
113
|
* {@inheritDoc}
|
114
|
*/
|
115
|
@Override
|
116
|
public void enter(ViewChangeEvent event) {
|
117
|
if(event.getParameters() != null){
|
118
|
this.citationID = Integer.valueOf(event.getParameters());
|
119
|
|
120
|
getPresenter().handleViewEntered();
|
121
|
}
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* {@inheritDoc}
|
126
|
*/
|
127
|
@Override
|
128
|
public void setWorkingset(RegistrationWorkingSet workingset) {
|
129
|
if(workingsetHeader != null){
|
130
|
getLayout().removeComponent(workingsetHeader);
|
131
|
getLayout().removeComponent(registrationListPanel);
|
132
|
}
|
133
|
|
134
|
registrationListPanel = createRegistrationsList(workingset);
|
135
|
registrationListPanel.setStyleName("registration-list");
|
136
|
registrationListPanel.setCaption("Registrations");
|
137
|
|
138
|
workingsetHeader = new RegistrationItem(workingset, this);
|
139
|
if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
|
140
|
workingsetHeader.getSubmitterLabel().setVisible(true);
|
141
|
}
|
142
|
addContentComponent(workingsetHeader, null);
|
143
|
addContentComponent(registrationListPanel, 1.0f);
|
144
|
|
145
|
}
|
146
|
|
147
|
/**
|
148
|
* {@inheritDoc}
|
149
|
*/
|
150
|
@Override
|
151
|
public void addBlockingRegistration(RegistrationDTO blocking) {
|
152
|
if(registrations == null) {
|
153
|
throw new RuntimeException("A Workingset must be present prior adding blocking registrations.");
|
154
|
}
|
155
|
// add the blocking registration
|
156
|
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* @param workingset
|
161
|
* @return
|
162
|
*/
|
163
|
public Panel createRegistrationsList(RegistrationWorkingSet workingset) {
|
164
|
|
165
|
registrationsGrid = new GridLayout(3, 1);
|
166
|
registrationsGrid.setWidth("100%");
|
167
|
// allow vertical scrolling:
|
168
|
registrationsGrid.setHeightUndefined();
|
169
|
|
170
|
//registrationsGrid.setColumnExpandRatio(0, 0.1f);
|
171
|
registrationsGrid.setColumnExpandRatio(1, 1f);
|
172
|
|
173
|
int row = 0;
|
174
|
for(RegistrationDTO dto : workingset.getRegistrationDTOs()) {
|
175
|
putRegistrationListComponent(registrationsGrid, row++, dto);
|
176
|
}
|
177
|
|
178
|
Label addRegistrationLabel_1 = new Label("Add a new registration for a");
|
179
|
Label addRegistrationLabel_2 = new Label("or an");
|
180
|
|
181
|
addNewNameRegistrationButton = new Button("new name");
|
182
|
addNewNameRegistrationButton.setDescription("A name which is newly published in this publication.");
|
183
|
addNewNameRegistrationButton.addClickListener(
|
184
|
e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.ADD, addNewNameRegistrationButton))
|
185
|
);
|
186
|
|
187
|
addExistingNameButton = new Button("existing name:");
|
188
|
addExistingNameButton.setDescription("A name which was previously published in a earlier publication.");
|
189
|
addExistingNameButton.setEnabled(false);
|
190
|
addExistingNameButton.addClickListener(
|
191
|
e -> eventBus.publishEvent(new RegistrationWorkflowEvent(citationID, RegistrationWorkflowEvent.Action.start))
|
192
|
);
|
193
|
|
194
|
existingNameCombobox = new LazyComboBox<TaxonName>(TaxonName.class);
|
195
|
existingNameCombobox.addValueChangeListener(
|
196
|
e -> addExistingNameButton.setEnabled(e.getProperty().getValue() != null)
|
197
|
);
|
198
|
|
199
|
HorizontalLayout buttonContainer = new HorizontalLayout(addRegistrationLabel_1, addNewNameRegistrationButton, addRegistrationLabel_2, addExistingNameButton, existingNameCombobox);
|
200
|
buttonContainer.setSpacing(true);
|
201
|
// buttonContainer.setWidth(100, Unit.PERCENTAGE);
|
202
|
buttonContainer.setComponentAlignment(addRegistrationLabel_1, Alignment.MIDDLE_LEFT);
|
203
|
buttonContainer.setComponentAlignment(addRegistrationLabel_2, Alignment.MIDDLE_LEFT);
|
204
|
registrationsGrid.addComponent(buttonContainer, 0, row, 2, row);
|
205
|
registrationsGrid.setComponentAlignment(buttonContainer, Alignment.MIDDLE_RIGHT);
|
206
|
|
207
|
Panel namesTypesPanel = new Panel(registrationsGrid);
|
208
|
namesTypesPanel.setSizeFull();
|
209
|
return namesTypesPanel;
|
210
|
}
|
211
|
|
212
|
|
213
|
/**
|
214
|
* @param grid
|
215
|
* @param row If null, the new row will be inserted as last registration item, that is before the button row.
|
216
|
* @param dto
|
217
|
*/
|
218
|
protected void putRegistrationListComponent(GridLayout grid, int row, RegistrationDTO dto) {
|
219
|
|
220
|
grid.setRows(grid.getRows() + 1);
|
221
|
|
222
|
CssLayout buttonGroup = new CssLayout();
|
223
|
buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
|
224
|
|
225
|
Button messageButton = new Button(FontAwesome.COMMENT);
|
226
|
messageButton.setStyleName(ValoTheme.BUTTON_TINY); // + " " + RegistrationStyles.STYLE_FRIENDLY_FOREGROUND);
|
227
|
if(dto.getMessages().isEmpty()){
|
228
|
messageButton.setEnabled(false);
|
229
|
} else {
|
230
|
messageButton.addClickListener(e -> eventBus.publishEvent(
|
231
|
new ShowDetailsEvent<RegistrationDTO, Integer>(
|
232
|
e,
|
233
|
RegistrationDTO.class,
|
234
|
dto.getId(),
|
235
|
"messages"
|
236
|
)
|
237
|
)
|
238
|
);
|
239
|
}
|
240
|
messageButton.setCaption("<span class=\"" + RegistrationStyles.BUTTON_BADGE +"\"> " + dto.getMessages().size() + "</span>");
|
241
|
messageButton.setCaptionAsHtml(true);
|
242
|
buttonGroup.addComponent(messageButton);
|
243
|
|
244
|
RegistrationStateLabel stateLabel = new RegistrationStateLabel().update(dto.getStatus());
|
245
|
|
246
|
|
247
|
if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()) {
|
248
|
Button editRegistrationButton = new Button(FontAwesome.COG);
|
249
|
editRegistrationButton.setStyleName(ValoTheme.BUTTON_TINY);
|
250
|
editRegistrationButton.setDescription("Edit registration");
|
251
|
editRegistrationButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
|
252
|
AbstractEditorAction.Action.EDIT,
|
253
|
dto.getId(),
|
254
|
null,
|
255
|
this
|
256
|
)));
|
257
|
buttonGroup.addComponent(editRegistrationButton);
|
258
|
}
|
259
|
|
260
|
Component regItem;
|
261
|
|
262
|
RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
|
263
|
|
264
|
if(editButtonGroup.getNameButton() != null){
|
265
|
editButtonGroup.getNameButton().getButton().addClickListener(e -> {
|
266
|
Integer nameId = editButtonGroup.getNameButton().getId();
|
267
|
getEventBus().publishEvent(new TaxonNameEditorAction(
|
268
|
AbstractEditorAction.Action.EDIT,
|
269
|
nameId,
|
270
|
null, //e.getButton(), the listener method expects this to be null
|
271
|
this
|
272
|
)
|
273
|
);
|
274
|
});
|
275
|
editButtonGroup.getNameButton().getButton().addFocusListener(e -> System.out.println("###"));
|
276
|
}
|
277
|
|
278
|
for(TypeDesignationWorkingSetButton workingsetButton : editButtonGroup.getTypeDesignationButtons()){
|
279
|
workingsetButton.getButton().addClickListener(e -> {
|
280
|
Integer typeDesignationWorkingsetId = workingsetButton.getId();
|
281
|
TypeDesignationWorkingSetType workingsetType = workingsetButton.getType();
|
282
|
Integer registrationEntityID = dto.getId();
|
283
|
getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
|
284
|
AbstractEditorAction.Action.EDIT,
|
285
|
typeDesignationWorkingsetId,
|
286
|
workingsetType,
|
287
|
registrationEntityID,
|
288
|
null, //e.getButton(), the listener method expects this to be null
|
289
|
this
|
290
|
)
|
291
|
);
|
292
|
});
|
293
|
}
|
294
|
|
295
|
editButtonGroup.getAddTypeDesignationButton().addClickListener(
|
296
|
e -> chooseNewTypeRegistrationWorkingset(dto.getId())
|
297
|
);
|
298
|
regItem = editButtonGroup;
|
299
|
|
300
|
|
301
|
grid.addComponent(stateLabel, 0, row);
|
302
|
grid.setComponentAlignment(stateLabel, Alignment.TOP_LEFT);
|
303
|
grid.addComponent(regItem, 1, row);
|
304
|
grid.addComponent(buttonGroup, 2, row);
|
305
|
grid.setComponentAlignment(buttonGroup, Alignment.TOP_LEFT);
|
306
|
}
|
307
|
|
308
|
/**
|
309
|
* @param button
|
310
|
* @param registrationEntityId
|
311
|
*
|
312
|
*/
|
313
|
@Override
|
314
|
public void chooseNewTypeRegistrationWorkingset(Integer registrationEntityId) {
|
315
|
|
316
|
Window typeDesignationTypeCooser = new Window();
|
317
|
typeDesignationTypeCooser.setModal(true);
|
318
|
typeDesignationTypeCooser.setResizable(false);
|
319
|
typeDesignationTypeCooser.setCaption("Add new type designation");
|
320
|
Label label = new Label("Please select kind of type designation to be created.");
|
321
|
Button newSpecimenTypeDesignationButton = new Button("Specimen type designation",
|
322
|
e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
|
323
|
Button newNameTypeDesignationButton = new Button("Name type designation",
|
324
|
e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
|
325
|
newNameTypeDesignationButton.setEnabled(false);
|
326
|
|
327
|
VerticalLayout layout = new VerticalLayout(label, newSpecimenTypeDesignationButton, newNameTypeDesignationButton);
|
328
|
layout.setMargin(true);
|
329
|
layout.setSpacing(true);
|
330
|
layout.setComponentAlignment(newSpecimenTypeDesignationButton, Alignment.MIDDLE_CENTER);
|
331
|
layout.setComponentAlignment(newNameTypeDesignationButton, Alignment.MIDDLE_CENTER);
|
332
|
typeDesignationTypeCooser.setContent(layout);
|
333
|
UI.getCurrent().addWindow(typeDesignationTypeCooser);
|
334
|
}
|
335
|
|
336
|
/**
|
337
|
* @param button
|
338
|
*
|
339
|
*/
|
340
|
protected void addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType newWorkingsetType, Integer registrationEntityId, Window typeDesignationTypeCooser) {
|
341
|
UI.getCurrent().removeWindow(typeDesignationTypeCooser);
|
342
|
getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
|
343
|
AbstractEditorAction.Action.ADD,
|
344
|
newWorkingsetType,
|
345
|
registrationEntityId,
|
346
|
null,
|
347
|
this
|
348
|
));
|
349
|
}
|
350
|
|
351
|
|
352
|
/**
|
353
|
*
|
354
|
*/
|
355
|
private void addBulletWorkflowName() {
|
356
|
WorkflowSteps steps = new WorkflowSteps();
|
357
|
steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
|
358
|
e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
|
359
|
steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
|
360
|
e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
|
361
|
steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
|
362
|
steps.appendNewWorkflowItem(4, "Awaiting publication", null);
|
363
|
getWorkflow().addComponent(steps);
|
364
|
}
|
365
|
|
366
|
/**
|
367
|
*
|
368
|
*/
|
369
|
private void addBulletWorkflowTypification() {
|
370
|
WorkflowSteps steps = new WorkflowSteps();
|
371
|
steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
|
372
|
e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
|
373
|
steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
|
374
|
e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
|
375
|
steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
|
376
|
steps.appendNewWorkflowItem(4, "Awaiting publication", null);
|
377
|
getWorkflow().addComponent(steps);
|
378
|
}
|
379
|
|
380
|
/**
|
381
|
* {@inheritDoc}
|
382
|
*/
|
383
|
@Override
|
384
|
public void openReferenceEditor(UUID referenceUuid) {
|
385
|
// TODO Auto-generated method stub
|
386
|
|
387
|
}
|
388
|
|
389
|
/**
|
390
|
* {@inheritDoc}
|
391
|
*/
|
392
|
@Override
|
393
|
public void openNameEditor(UUID nameUuid) {
|
394
|
// TODO Auto-generated method stub
|
395
|
|
396
|
}
|
397
|
|
398
|
/**
|
399
|
* {@inheritDoc}
|
400
|
*/
|
401
|
@Override
|
402
|
protected String getHeaderText() {
|
403
|
return headerText;
|
404
|
}
|
405
|
|
406
|
/**
|
407
|
* {@inheritDoc}
|
408
|
*/
|
409
|
@Override
|
410
|
public void setHeaderText(String text) {
|
411
|
this.headerText = text;
|
412
|
updateHeader();
|
413
|
|
414
|
}
|
415
|
|
416
|
/**
|
417
|
* @return the subheaderText
|
418
|
*/
|
419
|
public String getSubheaderText() {
|
420
|
return subheaderText;
|
421
|
}
|
422
|
|
423
|
/**
|
424
|
* {@inheritDoc}
|
425
|
*/
|
426
|
@Override
|
427
|
public void setSubheaderText(String text) {
|
428
|
subheaderText = text;
|
429
|
updateHeader();
|
430
|
}
|
431
|
|
432
|
/**
|
433
|
* {@inheritDoc}
|
434
|
*/
|
435
|
@Override
|
436
|
protected String getSubHeaderText() {
|
437
|
return subheaderText;
|
438
|
}
|
439
|
|
440
|
/**
|
441
|
* {@inheritDoc}
|
442
|
*/
|
443
|
@Override
|
444
|
public AbstractLayout getWorkflow() {
|
445
|
return getLayout();
|
446
|
}
|
447
|
|
448
|
/**
|
449
|
* {@inheritDoc}
|
450
|
*/
|
451
|
@Override
|
452
|
public void openDetailsPopup(String caption, List<String> messages) {
|
453
|
StringBuffer sb = new StringBuffer();
|
454
|
sb.append("<div class=\"details-popup-content\">");
|
455
|
messages.forEach(s -> sb.append(s).append("</br>"));
|
456
|
sb.append("</div>");
|
457
|
new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
|
458
|
}
|
459
|
|
460
|
/**
|
461
|
* {@inheritDoc}
|
462
|
*/
|
463
|
@Override
|
464
|
public boolean allowAnonymousAccess() {
|
465
|
return false;
|
466
|
}
|
467
|
|
468
|
/**
|
469
|
* {@inheritDoc}
|
470
|
*/
|
471
|
@Override
|
472
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
473
|
return null;
|
474
|
}
|
475
|
|
476
|
/**
|
477
|
* @return the addNewNameRegistrationButton
|
478
|
*/
|
479
|
@Override
|
480
|
public Button getAddNewNameRegistrationButton() {
|
481
|
return addNewNameRegistrationButton;
|
482
|
}
|
483
|
|
484
|
@Override
|
485
|
public Button getAddExistingNameRegistrationButton() {
|
486
|
return addExistingNameButton;
|
487
|
}
|
488
|
|
489
|
@Override
|
490
|
public LazyComboBox<TaxonName> getAddExistingNameCombobox() {
|
491
|
return existingNameCombobox;
|
492
|
}
|
493
|
|
494
|
/**
|
495
|
* @return the citationID
|
496
|
*/
|
497
|
@Override
|
498
|
public Integer getCitationID() {
|
499
|
return citationID;
|
500
|
}
|
501
|
|
502
|
|
503
|
}
|