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