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.component.registration;
|
10
|
|
11
|
import static eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles.LABEL_NOWRAP;
|
12
|
|
13
|
import java.util.Collection;
|
14
|
|
15
|
import org.joda.time.DateTime;
|
16
|
import org.joda.time.format.ISODateTimeFormat;
|
17
|
|
18
|
import com.vaadin.server.ExternalResource;
|
19
|
import com.vaadin.server.FontAwesome;
|
20
|
import com.vaadin.server.Resource;
|
21
|
import com.vaadin.server.UserError;
|
22
|
import com.vaadin.shared.ui.label.ContentMode;
|
23
|
import com.vaadin.ui.Alignment;
|
24
|
import com.vaadin.ui.Button;
|
25
|
import com.vaadin.ui.Button.ClickListener;
|
26
|
import com.vaadin.ui.CssLayout;
|
27
|
import com.vaadin.ui.GridLayout;
|
28
|
import com.vaadin.ui.Label;
|
29
|
import com.vaadin.ui.Link;
|
30
|
import com.vaadin.ui.themes.ValoTheme;
|
31
|
|
32
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
33
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
34
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
35
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
36
|
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action;
|
37
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
38
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
39
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
40
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
41
|
import eu.etaxonomy.cdm.vaadin.util.formatter.DateTimeFormat;
|
42
|
import eu.etaxonomy.cdm.vaadin.util.formatter.TimePeriodFormatter;
|
43
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
|
44
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationTypeConverter;
|
45
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorksetViewBean;
|
46
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
47
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
48
|
|
49
|
/**
|
50
|
* @author a.kohlbecker
|
51
|
* @since Mar 17, 2017
|
52
|
*
|
53
|
*/
|
54
|
public class RegistrationItem extends GridLayout {
|
55
|
|
56
|
|
57
|
private static final String LABEL_CAPTION_CREATED = "Created";
|
58
|
|
59
|
private static final String LABEL_CAPTION_PUBLISHED = "Published";
|
60
|
|
61
|
private static final String LABEL_CAPTION_RELEASED = "Released";
|
62
|
|
63
|
private static final int GRID_ROWS = 5;
|
64
|
|
65
|
private static final int GRID_COLS = 3;
|
66
|
|
67
|
private static final long serialVersionUID = -211003770452173644L;
|
68
|
|
69
|
private RegistrationTypeConverter regTypeConverter = new RegistrationTypeConverter();
|
70
|
|
71
|
private AbstractView<?> parentView;
|
72
|
|
73
|
private TimePeriodFormatter timePeriodFormatter = new TimePeriodFormatter(DateTimeFormat.ISO8601_DATE);
|
74
|
|
75
|
// --------------------------------------------------
|
76
|
|
77
|
private RegistrationStateLabel stateLabel = new RegistrationStateLabel();
|
78
|
private Link identifierLink = new Link();
|
79
|
private Label citationSummaryLabel = new Label();
|
80
|
private Button blockedByButton = new Button(FontAwesome.WARNING);
|
81
|
private Button messageButton;
|
82
|
private Button openButton = new Button(FontAwesome.COGS);
|
83
|
private Label submitterLabel = new Label();
|
84
|
private Label createdLabel = new Label();
|
85
|
private Label publishedLabel = new Label();
|
86
|
private Label releasedLabel = new Label();
|
87
|
|
88
|
/**
|
89
|
*
|
90
|
*/
|
91
|
public RegistrationItem(RegistrationDTO item, AbstractView<?> parentView) {
|
92
|
super(GRID_COLS, GRID_ROWS);
|
93
|
init();
|
94
|
setItem(item, parentView);
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
*
|
99
|
*/
|
100
|
public RegistrationItem(RegistrationWorkingSet workingSet, AbstractView<?> parentView) {
|
101
|
super(GRID_COLS, GRID_ROWS);
|
102
|
init();
|
103
|
setWorkingSet(workingSet, parentView);
|
104
|
}
|
105
|
|
106
|
public void init() {
|
107
|
|
108
|
setWidth(100, Unit.PERCENTAGE);
|
109
|
addStyleName("registration-list-item");
|
110
|
|
111
|
CssLayout stateUserContainer = new CssLayout();
|
112
|
stateLabel.setStyleName(LABEL_NOWRAP + " registration-state");
|
113
|
stateLabel.setVisible(false);
|
114
|
|
115
|
submitterLabel.setStyleName(LABEL_NOWRAP + " submitter");
|
116
|
submitterLabel.setIcon(FontAwesome.USER);
|
117
|
submitterLabel.setContentMode(ContentMode.HTML);
|
118
|
submitterLabel.setVisible(false);
|
119
|
|
120
|
stateUserContainer.addComponents(stateLabel, submitterLabel);
|
121
|
addComponent(stateUserContainer, 0, 0);
|
122
|
setComponentAlignment(stateUserContainer, Alignment.TOP_LEFT);
|
123
|
|
124
|
identifierLink.setVisible(false);
|
125
|
addComponent(identifierLink, 1, 0);
|
126
|
setComponentAlignment(identifierLink, Alignment.TOP_CENTER);
|
127
|
setColumnExpandRatio(1, 1.0f);
|
128
|
|
129
|
messageButton = new Button(FontAwesome.COMMENT);
|
130
|
CssLayout buttonGroup = new CssLayout(blockedByButton, messageButton, openButton);
|
131
|
blockedByButton.setStyleName(ValoTheme.BUTTON_TINY);
|
132
|
blockedByButton.setEnabled(false);
|
133
|
messageButton.setStyleName(ValoTheme.BUTTON_TINY);
|
134
|
messageButton.setEnabled(false);
|
135
|
|
136
|
openButton.setStyleName(ValoTheme.BUTTON_TINY);
|
137
|
openButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
|
138
|
openButton.setVisible(false);
|
139
|
|
140
|
buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
|
141
|
addComponent(buttonGroup, 2, 0);
|
142
|
setComponentAlignment(buttonGroup, Alignment.TOP_RIGHT);
|
143
|
|
144
|
citationSummaryLabel.setContentMode(ContentMode.HTML);
|
145
|
addComponent(citationSummaryLabel, 0, 1, 1, 3);
|
146
|
|
147
|
createdLabel.setStyleName(LABEL_NOWRAP);
|
148
|
createdLabel.setContentMode(ContentMode.HTML);
|
149
|
createdLabel.setWidthUndefined();
|
150
|
addComponent(createdLabel, 2, 1);
|
151
|
setComponentAlignment(createdLabel, Alignment.BOTTOM_RIGHT);
|
152
|
|
153
|
publishedLabel.setStyleName(LABEL_NOWRAP);
|
154
|
publishedLabel.setContentMode(ContentMode.HTML);
|
155
|
publishedLabel.setWidthUndefined();
|
156
|
publishedLabel.setVisible(false);
|
157
|
addComponent(publishedLabel, 2, 2);
|
158
|
setComponentAlignment(publishedLabel, Alignment.BOTTOM_RIGHT);
|
159
|
|
160
|
releasedLabel.setStyleName(LABEL_NOWRAP);
|
161
|
releasedLabel.setContentMode(ContentMode.HTML);
|
162
|
releasedLabel.setWidthUndefined();
|
163
|
releasedLabel.setVisible(false);
|
164
|
addComponent(releasedLabel, 2, 3);
|
165
|
setComponentAlignment(releasedLabel, Alignment.BOTTOM_RIGHT);
|
166
|
|
167
|
}
|
168
|
|
169
|
public void setItem(RegistrationDTO regDto, AbstractView<?> parentView){
|
170
|
this.parentView = parentView;
|
171
|
|
172
|
NavigationEvent navigationEvent = null;
|
173
|
if(regDto.getCitationID() != null) {
|
174
|
navigationEvent = new NavigationEvent(
|
175
|
RegistrationWorksetViewBean.NAME,
|
176
|
Integer.toString(regDto.getCitationID())
|
177
|
);
|
178
|
} else {
|
179
|
setComponentError(new UserError("Citation is missing"));
|
180
|
}
|
181
|
|
182
|
updateUI(regDto.getBibliographicCitationString(), regDto.getCreated(), regDto.getDatePublished(), regDto.getMessages().size(),
|
183
|
navigationEvent, null, regDto, regDto.getSubmitterUserName());
|
184
|
}
|
185
|
|
186
|
public void setWorkingSet(RegistrationWorkingSet workingSet, AbstractView<?> parentView){
|
187
|
this.parentView = parentView;
|
188
|
|
189
|
ReferenceEditorAction referenceEditorAction = null;
|
190
|
if(workingSet.getCitationId() != null){
|
191
|
if(UserHelper.fromSession().userHasPermission(Reference.class, workingSet.getCitationId(), CRUD.UPDATE)){
|
192
|
referenceEditorAction = new ReferenceEditorAction(Action.EDIT, workingSet.getCitationId());
|
193
|
}
|
194
|
} else {
|
195
|
if(UserHelper.fromSession().userHasPermission(Reference.class, CRUD.CREATE)){
|
196
|
referenceEditorAction = new ReferenceEditorAction(Action.ADD);
|
197
|
}
|
198
|
}
|
199
|
TimePeriod datePublished = null;
|
200
|
String submitterName = null;
|
201
|
if(workingSet.getRegistrationDTOs().size() > 0){
|
202
|
datePublished = workingSet.getRegistrationDTOs().get(0).getDatePublished();
|
203
|
submitterName = workingSet.getRegistrationDTOs().get(0).getSubmitterUserName();
|
204
|
}
|
205
|
updateUI(workingSet.getCitation(), workingSet.getCreated(), datePublished, workingSet.messagesCount(),
|
206
|
referenceEditorAction, FontAwesome.EDIT, null, submitterName);
|
207
|
}
|
208
|
|
209
|
/**
|
210
|
* @param submitterUserName TODO
|
211
|
*
|
212
|
*/
|
213
|
private void updateUI(String citationString, DateTime created, TimePeriod datePublished, int messagesCount,
|
214
|
Object openButtonEvent, Resource openButtonIcon, RegistrationDTO regDto, String submitterUserName) {
|
215
|
|
216
|
StringBuffer labelMarkup = new StringBuffer();
|
217
|
DateTime registrationDate = null;
|
218
|
|
219
|
if(messagesCount > 0){
|
220
|
getMessageButton().setEnabled(true);
|
221
|
// getMessageButton().addStyleName(RegistrationStyles.STYLE_FRIENDLY_FOREGROUND);
|
222
|
getMessageButton().addClickListener(e -> {
|
223
|
ShowDetailsEvent detailsEvent;
|
224
|
if(regDto != null){
|
225
|
detailsEvent = new ShowDetailsEvent<RegistrationDTO, Integer>(
|
226
|
e,
|
227
|
RegistrationDTO.class,
|
228
|
regDto.getId(),
|
229
|
"messages");
|
230
|
} else {
|
231
|
detailsEvent = new ShowDetailsEvent<RegistrationWorkingSet, Integer>(
|
232
|
e,
|
233
|
RegistrationWorkingSet.class,
|
234
|
null,
|
235
|
"messages");
|
236
|
}
|
237
|
publishEvent(detailsEvent);
|
238
|
}
|
239
|
);
|
240
|
getMessageButton().setCaption("<span class=\"" + RegistrationStyles.BUTTON_BADGE +"\"> " + messagesCount + "</span>");
|
241
|
getMessageButton().setCaptionAsHtml(true);
|
242
|
}
|
243
|
|
244
|
labelMarkup.append(citationString);
|
245
|
|
246
|
if(openButtonEvent != null){
|
247
|
// Buttons
|
248
|
getOpenButton().setVisible(true);
|
249
|
Collection<?> removeCandidates = getOpenButton().getListeners(ClickListener.class);
|
250
|
removeCandidates.forEach(l -> getOpenButton().removeClickListener((ClickListener)l));
|
251
|
getOpenButton().addClickListener(e -> publishEvent(openButtonEvent));
|
252
|
}
|
253
|
|
254
|
if(openButtonIcon != null){
|
255
|
getOpenButton().setIcon(openButtonIcon);
|
256
|
}
|
257
|
|
258
|
if(regDto != null){
|
259
|
labelMarkup.append("</br>").append(regDto.getSummary());
|
260
|
|
261
|
stateLabel.setVisible(true);
|
262
|
stateLabel.update(regDto.getStatus());
|
263
|
if(regDto.getIdentifier() != null){
|
264
|
getIdentifierLink().setResource(new ExternalResource(regDto.getIdentifier()));
|
265
|
}
|
266
|
getIdentifierLink().setCaption(regDto.getIdentifier());
|
267
|
//TODO make responsive and use specificIdentifier in case the space gets too narrow
|
268
|
getIdentifierLink().setVisible(true);
|
269
|
getIdentifierLink().setEnabled(regDto.getStatus() == RegistrationStatus.PUBLISHED);
|
270
|
|
271
|
registrationDate = regDto.getRegistrationDate();
|
272
|
}
|
273
|
|
274
|
getCitationSummaryLabel().setValue(labelMarkup.toString());
|
275
|
getSubmitterLabel().setValue(submitterUserName);
|
276
|
updateDateLabels(created, datePublished, registrationDate);
|
277
|
}
|
278
|
|
279
|
|
280
|
private void updateDateLabels(DateTime created, TimePeriod datePublished, DateTime released) {
|
281
|
if(created != null){
|
282
|
getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED + "</span> " + created.toString(ISODateTimeFormat.yearMonthDay()));
|
283
|
}
|
284
|
if(datePublished != null){
|
285
|
getPublishedLabel().setVisible(true);
|
286
|
getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span> " + timePeriodFormatter.print(datePublished));
|
287
|
}
|
288
|
if(released != null){
|
289
|
getReleasedLabel().setVisible(true);
|
290
|
getReleasedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_RELEASED + "</span> " + released.toString(ISODateTimeFormat.yearMonthDay()));
|
291
|
}
|
292
|
}
|
293
|
|
294
|
|
295
|
private void publishEvent(Object event) {
|
296
|
parentView.getEventBus().publishEvent(event);
|
297
|
}
|
298
|
|
299
|
/* ====== RegistrationItemDesign Getters ====== */
|
300
|
/**
|
301
|
* @return the typeStateLabel
|
302
|
*/
|
303
|
public Label getTypeStateLabel() {
|
304
|
return stateLabel;
|
305
|
}
|
306
|
|
307
|
/**
|
308
|
* @return the identifierLink
|
309
|
*/
|
310
|
public Link getIdentifierLink() {
|
311
|
return identifierLink;
|
312
|
}
|
313
|
|
314
|
/**
|
315
|
* @return the citationSummaryLabel
|
316
|
*/
|
317
|
public Label getCitationSummaryLabel() {
|
318
|
return citationSummaryLabel;
|
319
|
}
|
320
|
|
321
|
/**
|
322
|
* @return the blockedByButton
|
323
|
*/
|
324
|
public Button getBlockedByButton() {
|
325
|
return blockedByButton;
|
326
|
}
|
327
|
|
328
|
/**
|
329
|
* @return the messageButton
|
330
|
*/
|
331
|
public Button getMessageButton() {
|
332
|
return messageButton;
|
333
|
}
|
334
|
|
335
|
/**
|
336
|
* @return the openButton
|
337
|
*/
|
338
|
public Button getOpenButton() {
|
339
|
return openButton;
|
340
|
}
|
341
|
|
342
|
/**
|
343
|
* @return the createdLabel
|
344
|
*/
|
345
|
public Label getCreatedLabel() {
|
346
|
return createdLabel;
|
347
|
}
|
348
|
|
349
|
/**
|
350
|
* @return the publishedLabel
|
351
|
*/
|
352
|
public Label getPublishedLabel() {
|
353
|
return publishedLabel;
|
354
|
}
|
355
|
|
356
|
|
357
|
/**
|
358
|
* @return
|
359
|
*/
|
360
|
public Label getReleasedLabel() {
|
361
|
return releasedLabel;
|
362
|
}
|
363
|
|
364
|
/**
|
365
|
* @return the submitterLabel
|
366
|
*/
|
367
|
public Label getSubmitterLabel() {
|
368
|
return submitterLabel;
|
369
|
}
|
370
|
|
371
|
|
372
|
/* --------------------------------------- */
|
373
|
|
374
|
}
|