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