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