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
|
|
18
|
import com.vaadin.navigator.View;
|
19
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
20
|
import com.vaadin.server.FontAwesome;
|
21
|
import com.vaadin.server.GenericFontIcon;
|
22
|
import com.vaadin.server.Page;
|
23
|
import com.vaadin.spring.annotation.SpringView;
|
24
|
import com.vaadin.ui.Alignment;
|
25
|
import com.vaadin.ui.Button;
|
26
|
import com.vaadin.ui.Component;
|
27
|
import com.vaadin.ui.CssLayout;
|
28
|
import com.vaadin.ui.GridLayout;
|
29
|
import com.vaadin.ui.Label;
|
30
|
import com.vaadin.ui.Notification;
|
31
|
import com.vaadin.ui.Panel;
|
32
|
import com.vaadin.ui.TabSheet;
|
33
|
import com.vaadin.ui.TabSheet.Tab;
|
34
|
import com.vaadin.ui.themes.ValoTheme;
|
35
|
|
36
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
|
37
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup;
|
38
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
|
39
|
import eu.etaxonomy.cdm.vaadin.component.registration.TypeStateLabel;
|
40
|
import eu.etaxonomy.cdm.vaadin.component.registration.WorkflowSteps;
|
41
|
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
|
42
|
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action;
|
43
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
44
|
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
|
45
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
46
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
47
|
import eu.etaxonomy.cdm.vaadin.event.TypedesignationsEditorAction;
|
48
|
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
|
49
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
50
|
import eu.etaxonomy.cdm.vaadin.model.registration.WorkflowStep;
|
51
|
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
|
52
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
53
|
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
|
54
|
|
55
|
/**
|
56
|
* @author a.kohlbecker
|
57
|
* @since Mar 2, 2017
|
58
|
*
|
59
|
*/
|
60
|
@SpringView(name=RegistrationWorkflowViewBean.NAME)
|
61
|
public class RegistrationWorkflowViewBean extends AbstractPageView<RegistrationWorkflowPresenter>
|
62
|
implements RegistrationWorkflowView, View, AccessRestrictedView {
|
63
|
|
64
|
|
65
|
public static final String DOM_ID_WORKFLOW = "workflow-container";
|
66
|
|
67
|
public static final String DOM_ID_WORKINGSET = "workingset";
|
68
|
|
69
|
public static final String SUBHEADER_DEEFAULT = "Advance step by step through the registration workflow.";
|
70
|
|
71
|
private static final long serialVersionUID = -213040114015958970L;
|
72
|
|
73
|
public static final String NAME = "workflow";
|
74
|
|
75
|
public static final String ACTION_NEW = "new";
|
76
|
|
77
|
public static final String ACTION_EDIT = "edit";
|
78
|
|
79
|
private static final boolean REG_ITEM_AS_BUTTON_GROUP = true;
|
80
|
|
81
|
public RegistrationType regType = null;
|
82
|
|
83
|
private CssLayout workflow;
|
84
|
|
85
|
private List<CssLayout> registrations = new ArrayList<>();
|
86
|
|
87
|
private String headerText = "-- empty --";
|
88
|
private String subheaderText = SUBHEADER_DEEFAULT;
|
89
|
|
90
|
private boolean addNameAndTypeEditButtons = false;
|
91
|
|
92
|
|
93
|
public RegistrationWorkflowViewBean() {
|
94
|
super();
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
protected void initContent() {
|
99
|
workflow = new CssLayout();
|
100
|
workflow.setSizeFull();
|
101
|
workflow.setId(DOM_ID_WORKFLOW);
|
102
|
getLayout().addComponent(workflow);
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* {@inheritDoc}
|
107
|
*/
|
108
|
@Override
|
109
|
public void enter(ViewChangeEvent event) {
|
110
|
if(event.getParameters() != null){
|
111
|
String[] params = event.getParameters().split("/");
|
112
|
|
113
|
if(params[0].equals(ACTION_NEW)) {
|
114
|
regType = RegistrationType.valueOf(params[1]);
|
115
|
headerText = regType.name() + " ...";
|
116
|
eventBus.publishEvent(new RegistrationWorkflowEvent(regType));
|
117
|
|
118
|
} else if( params[0].equals(ACTION_EDIT)) {
|
119
|
headerText = params[1];
|
120
|
eventBus.publishEvent(new RegistrationWorkflowEvent(Integer.parseInt(params[1])));
|
121
|
}
|
122
|
updateHeader();
|
123
|
}
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* {@inheritDoc}
|
128
|
*/
|
129
|
@Override
|
130
|
public void setWorkingset(RegistrationWorkingSet workingset) {
|
131
|
|
132
|
CssLayout registration = new CssLayout();
|
133
|
registration.setId(DOM_ID_WORKINGSET);
|
134
|
registration.setWidth(100, Unit.PERCENTAGE);
|
135
|
|
136
|
Panel registrationListPanel = createRegistrationsList(workingset);
|
137
|
registrationListPanel.setStyleName("registration-list");
|
138
|
registrationListPanel.setCaption("Registrations");
|
139
|
|
140
|
|
141
|
// registration.addComponent(createWorkflowTabSheet(workingset, null));
|
142
|
RegistrationItem registrationItem = new RegistrationItem(workingset, this);
|
143
|
if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
|
144
|
registrationItem.getSubmitterLabel().setVisible(true);
|
145
|
};
|
146
|
registration.addComponent(registrationItem);
|
147
|
registration.addComponent(registrationListPanel);
|
148
|
|
149
|
registrations.add(registration);
|
150
|
workflow.removeAllComponents();
|
151
|
workflow.addComponent(registration);
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* {@inheritDoc}
|
156
|
*/
|
157
|
@Override
|
158
|
public void addBlockingRegistration(RegistrationDTO blocking) {
|
159
|
if(registrations == null) {
|
160
|
throw new RuntimeException("A Workingset must be present prior adding blocking registrations.");
|
161
|
}
|
162
|
// add the blocking registration
|
163
|
|
164
|
}
|
165
|
|
166
|
private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
|
167
|
|
168
|
if(namesTypesPanel == null){
|
169
|
namesTypesPanel = new CssLayout();
|
170
|
}
|
171
|
Component citationComponent = new CssLayout(); // new Label(workingset.getCitation());
|
172
|
Component curationComponent = new CssLayout(); // new Label("Curation in progress ...")
|
173
|
Component releaseComponent = new CssLayout(); // new Label("Not yet published")
|
174
|
|
175
|
GenericFontIcon tabIcon = new GenericFontIcon("IcoMoon", 0xe900);
|
176
|
TabSheet tabsheet = new TabSheet();
|
177
|
// tabsheet.addStyleName(ValoTheme.TABSHEET_FRAMED);
|
178
|
//tabsheet.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
|
179
|
tabsheet.addStyleName("workflow-tabsheet");
|
180
|
|
181
|
Tab pubDetailsTab = tabsheet.addTab(citationComponent, WorkflowStep.PUBLICATION_DETAILS.getRepresentation(), tabIcon);
|
182
|
Tab namesTypesTab = tabsheet.addTab(namesTypesPanel, WorkflowStep.NAMES_N_TYPES.getRepresentation(), tabIcon);
|
183
|
Tab curationTab = tabsheet.addTab(curationComponent, WorkflowStep.CURATION.getRepresentation(), tabIcon);
|
184
|
Tab awaitingPubTab = tabsheet.addTab(releaseComponent, WorkflowStep.AWAITING_PUBLICATION.getRepresentation(), tabIcon);
|
185
|
|
186
|
pubDetailsTab.setStyleName("bg-status-" + WorkflowStep.PUBLICATION_DETAILS.name());
|
187
|
namesTypesTab.setStyleName("bg-status-" + WorkflowStep.NAMES_N_TYPES.name());
|
188
|
curationTab.setStyleName("bg-status-" + WorkflowStep.CURATION.name());
|
189
|
awaitingPubTab.setStyleName("bg-status-" + WorkflowStep.AWAITING_PUBLICATION.name());
|
190
|
|
191
|
return tabsheet;
|
192
|
}
|
193
|
|
194
|
/**
|
195
|
* @param workingset
|
196
|
* @return
|
197
|
*/
|
198
|
public Panel createRegistrationsList(RegistrationWorkingSet workingset) {
|
199
|
// prepare name and type list
|
200
|
GridLayout namesTypesList = new GridLayout(3, workingset.getRegistrationDTOs().size());
|
201
|
int row = 0;
|
202
|
for(RegistrationDTO dto : workingset.getRegistrationDTOs()) {
|
203
|
registrationListComponent(namesTypesList, row++, dto);
|
204
|
}
|
205
|
|
206
|
namesTypesList.setSizeUndefined();
|
207
|
namesTypesList.setWidth(100, Unit.PERCENTAGE);
|
208
|
namesTypesList.setColumnExpandRatio(0, 0.1f);
|
209
|
namesTypesList.setColumnExpandRatio(1, 0.9f);
|
210
|
Panel namesTypesPanel = new Panel(namesTypesList);
|
211
|
namesTypesPanel.setHeight("300px");
|
212
|
return namesTypesPanel;
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* @param namesTypesList
|
217
|
* @param row
|
218
|
* @param dto
|
219
|
*/
|
220
|
protected void registrationListComponent(GridLayout namesTypesList, int row, RegistrationDTO dto) {
|
221
|
CssLayout buttonGroup = new CssLayout();
|
222
|
buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
|
223
|
|
224
|
Button messageButton = new Button(FontAwesome.COMMENT);
|
225
|
messageButton.setStyleName(ValoTheme.BUTTON_TINY); // + " " + RegistrationStyles.STYLE_FRIENDLY_FOREGROUND);
|
226
|
if(dto.getMessages().isEmpty()){
|
227
|
messageButton.setEnabled(false);
|
228
|
} else {
|
229
|
messageButton.addClickListener(e -> eventBus.publishEvent(
|
230
|
new ShowDetailsEvent<RegistrationDTO, Integer>(
|
231
|
e,
|
232
|
RegistrationDTO.class,
|
233
|
dto.getId(),
|
234
|
"messages"
|
235
|
)
|
236
|
)
|
237
|
);
|
238
|
}
|
239
|
messageButton.setCaption("<span class=\"" + RegistrationStyles.BUTTON_BADGE +"\"> " + dto.getMessages().size() + "</span>");
|
240
|
messageButton.setCaptionAsHtml(true);
|
241
|
buttonGroup.addComponent(messageButton);
|
242
|
|
243
|
TypeStateLabel typeStateLabel = new TypeStateLabel().update(dto.getRegistrationType(), dto.getStatus());
|
244
|
|
245
|
|
246
|
if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()) {
|
247
|
Button editRegistrationButton = new Button(FontAwesome.COG);
|
248
|
editRegistrationButton.setStyleName(ValoTheme.BUTTON_TINY);
|
249
|
editRegistrationButton.setDescription("Edit registration");
|
250
|
editRegistrationButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
|
251
|
AbstractEditorAction.Action.EDIT,
|
252
|
dto.getId(),
|
253
|
null,
|
254
|
this
|
255
|
)));
|
256
|
buttonGroup.addComponent(editRegistrationButton);
|
257
|
}
|
258
|
|
259
|
if(addNameAndTypeEditButtons ){
|
260
|
Button editNameButton = new Button(FontAwesome.TAG);
|
261
|
editNameButton.setStyleName(ValoTheme.BUTTON_TINY);
|
262
|
editNameButton.setDescription("Edit name");
|
263
|
if(dto.getName() != null){
|
264
|
editNameButton.addClickListener(e -> {
|
265
|
Integer nameId = dto.getName().getId();
|
266
|
getEventBus().publishEvent(new TaxonNameEditorAction(
|
267
|
AbstractEditorAction.Action.EDIT,
|
268
|
nameId
|
269
|
)
|
270
|
);
|
271
|
});
|
272
|
} else {
|
273
|
editNameButton.setEnabled(false);
|
274
|
}
|
275
|
|
276
|
Button editTypesButton = new Button(FontAwesome.LEAF);
|
277
|
editTypesButton.setStyleName(ValoTheme.BUTTON_TINY);
|
278
|
editTypesButton.setDescription("Edit type designations");
|
279
|
if(dto.getOrderdTypeDesignationWorkingSets() != null && !dto.getOrderdTypeDesignationWorkingSets().isEmpty()){
|
280
|
editTypesButton.addClickListener(e -> {
|
281
|
int regId = dto.getId();
|
282
|
getEventBus().publishEvent(new TypedesignationsEditorAction(
|
283
|
AbstractEditorAction.Action.EDIT,
|
284
|
regId
|
285
|
)
|
286
|
);
|
287
|
});
|
288
|
} else {
|
289
|
editTypesButton.setEnabled(false);
|
290
|
}
|
291
|
buttonGroup.addComponents(editNameButton, editTypesButton);
|
292
|
}
|
293
|
|
294
|
Component regItem;
|
295
|
if(REG_ITEM_AS_BUTTON_GROUP){
|
296
|
RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
|
297
|
if(editButtonGroup.getNameButton() != null){
|
298
|
|
299
|
editButtonGroup.getNameButton().getButton().addClickListener(e -> {
|
300
|
Integer nameId = editButtonGroup.getNameButton().getId();
|
301
|
getEventBus().publishEvent(new TaxonNameEditorAction(
|
302
|
AbstractEditorAction.Action.EDIT,
|
303
|
nameId
|
304
|
)
|
305
|
);
|
306
|
});
|
307
|
}
|
308
|
regItem = editButtonGroup;
|
309
|
} else {
|
310
|
regItem = new Label(dto.getSummary());
|
311
|
}
|
312
|
|
313
|
namesTypesList.addComponent(typeStateLabel, 0, row);
|
314
|
namesTypesList.setComponentAlignment(typeStateLabel, Alignment.TOP_LEFT);
|
315
|
namesTypesList.addComponent(regItem, 1, row);
|
316
|
namesTypesList.addComponent(buttonGroup, 2, row);
|
317
|
namesTypesList.setComponentAlignment(buttonGroup, Alignment.TOP_LEFT);
|
318
|
}
|
319
|
|
320
|
|
321
|
/**
|
322
|
*
|
323
|
*/
|
324
|
private void addBulletWorkflowName() {
|
325
|
WorkflowSteps steps = new WorkflowSteps();
|
326
|
steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
|
327
|
e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
|
328
|
steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
|
329
|
e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
|
330
|
steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
|
331
|
steps.appendNewWorkflowItem(4, "Awaiting publication", null);
|
332
|
getWorkflow().addComponent(steps);
|
333
|
}
|
334
|
|
335
|
/**
|
336
|
*
|
337
|
*/
|
338
|
private void addBulletWorkflowTypification() {
|
339
|
WorkflowSteps steps = new WorkflowSteps();
|
340
|
steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
|
341
|
e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
|
342
|
steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
|
343
|
e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
|
344
|
steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
|
345
|
steps.appendNewWorkflowItem(4, "Awaiting publication", null);
|
346
|
getWorkflow().addComponent(steps);
|
347
|
}
|
348
|
|
349
|
/**
|
350
|
* {@inheritDoc}
|
351
|
*/
|
352
|
@Override
|
353
|
public void openReferenceEditor(UUID referenceUuid) {
|
354
|
// TODO Auto-generated method stub
|
355
|
|
356
|
}
|
357
|
|
358
|
/**
|
359
|
* {@inheritDoc}
|
360
|
*/
|
361
|
@Override
|
362
|
public void openNameEditor(UUID nameUuid) {
|
363
|
// TODO Auto-generated method stub
|
364
|
|
365
|
}
|
366
|
|
367
|
/**
|
368
|
* {@inheritDoc}
|
369
|
*/
|
370
|
@Override
|
371
|
protected String getHeaderText() {
|
372
|
return headerText;
|
373
|
}
|
374
|
|
375
|
/**
|
376
|
* {@inheritDoc}
|
377
|
*/
|
378
|
@Override
|
379
|
public void setHeaderText(String text) {
|
380
|
this.headerText = text;
|
381
|
|
382
|
}
|
383
|
|
384
|
/**
|
385
|
* @return the subheaderText
|
386
|
*/
|
387
|
public String getSubheaderText() {
|
388
|
return subheaderText;
|
389
|
}
|
390
|
|
391
|
/**
|
392
|
* {@inheritDoc}
|
393
|
*/
|
394
|
@Override
|
395
|
public void setSubheaderText(String text) {
|
396
|
subheaderText = text;
|
397
|
}
|
398
|
|
399
|
/**
|
400
|
* {@inheritDoc}
|
401
|
*/
|
402
|
@Override
|
403
|
protected String getSubHeaderText() {
|
404
|
return subheaderText;
|
405
|
}
|
406
|
|
407
|
/**
|
408
|
* {@inheritDoc}
|
409
|
*/
|
410
|
@Override
|
411
|
public CssLayout getWorkflow() {
|
412
|
return workflow;
|
413
|
}
|
414
|
|
415
|
/**
|
416
|
* {@inheritDoc}
|
417
|
*/
|
418
|
@Override
|
419
|
public void openDetailsPopup(String caption, List<String> messages) {
|
420
|
StringBuffer sb = new StringBuffer();
|
421
|
sb.append("<div class=\"details-popup-content\">");
|
422
|
messages.forEach(s -> sb.append(s).append("</br>"));
|
423
|
sb.append("</div>");
|
424
|
new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
|
425
|
}
|
426
|
|
427
|
/**
|
428
|
* {@inheritDoc}
|
429
|
*/
|
430
|
@Override
|
431
|
public boolean allowAnonymousAccess() {
|
432
|
return false;
|
433
|
}
|
434
|
|
435
|
/**
|
436
|
* {@inheritDoc}
|
437
|
*/
|
438
|
@Override
|
439
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
440
|
return null;
|
441
|
}
|
442
|
|
443
|
}
|