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 org.apache.commons.lang.StringUtils;
|
12
|
import org.joda.time.format.ISODateTimeFormat;
|
13
|
|
14
|
import com.vaadin.server.ExternalResource;
|
15
|
import com.vaadin.server.FontAwesome;
|
16
|
import com.vaadin.shared.ui.label.ContentMode;
|
17
|
import com.vaadin.ui.Alignment;
|
18
|
import com.vaadin.ui.Button;
|
19
|
import com.vaadin.ui.CssLayout;
|
20
|
import com.vaadin.ui.GridLayout;
|
21
|
import com.vaadin.ui.Label;
|
22
|
import com.vaadin.ui.Link;
|
23
|
import com.vaadin.ui.themes.ValoTheme;
|
24
|
|
25
|
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO;
|
26
|
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationType;
|
27
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationTypeConverter;
|
28
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowViewBean;
|
29
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
30
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
31
|
|
32
|
/**
|
33
|
* @author a.kohlbecker
|
34
|
* @since Mar 17, 2017
|
35
|
*
|
36
|
*/
|
37
|
public class RegistrationItem extends GridLayout {
|
38
|
|
39
|
|
40
|
private static final String LABEL_CAPTION_CREATED = "Created";
|
41
|
|
42
|
private static final String LABEL_CAPTION_PUBLISHED = "Published";
|
43
|
|
44
|
private static final int GRID_ROWS = 3;
|
45
|
|
46
|
private static final int GRID_COLS = 3;
|
47
|
|
48
|
private static final String STYLE_LABEL_NOWRAP = "label-nowrap";
|
49
|
|
50
|
private static final long serialVersionUID = -211003770452173644L;
|
51
|
|
52
|
private RegistrationDTO regDto;
|
53
|
|
54
|
private RegistrationTypeConverter regTypeConverter = new RegistrationTypeConverter();
|
55
|
|
56
|
private AbstractView<?> parentView;
|
57
|
|
58
|
// --------------------------------------------------
|
59
|
private Label typeStateLabel = new Label();
|
60
|
private Link identifierLink = new Link();
|
61
|
private Label citationSummaryLabel = new Label();
|
62
|
private Button blockedByButton = new Button(FontAwesome.WARNING);
|
63
|
private Button messageButton = new Button(FontAwesome.COMMENT);
|
64
|
private Button openButton = new Button(FontAwesome.COGS);
|
65
|
private Label createdLabel = new Label();
|
66
|
private Label publishedLabel = new Label();
|
67
|
// --------------------------------------------------
|
68
|
|
69
|
/**
|
70
|
*
|
71
|
*/
|
72
|
public RegistrationItem(RegistrationDTO item, AbstractView<?> parentView) {
|
73
|
super(GRID_COLS, GRID_ROWS);
|
74
|
init();
|
75
|
setItem(item, parentView);
|
76
|
}
|
77
|
|
78
|
public void init() {
|
79
|
|
80
|
setWidth(100, Unit.PERCENTAGE);
|
81
|
addStyleName("registration-item");
|
82
|
|
83
|
typeStateLabel.setStyleName(STYLE_LABEL_NOWRAP);
|
84
|
addComponent(typeStateLabel, 0, 0);
|
85
|
setComponentAlignment(typeStateLabel, Alignment.TOP_LEFT);
|
86
|
|
87
|
addComponent(identifierLink, 1, 0);
|
88
|
setComponentAlignment(identifierLink, Alignment.TOP_CENTER);
|
89
|
setColumnExpandRatio(1, 1.0f);
|
90
|
|
91
|
CssLayout buttonGroup = new CssLayout(blockedByButton, messageButton, openButton);
|
92
|
blockedByButton.setStyleName(ValoTheme.BUTTON_TINY);
|
93
|
blockedByButton.setEnabled(false);
|
94
|
messageButton.setStyleName(ValoTheme.BUTTON_TINY);
|
95
|
messageButton.setEnabled(false);
|
96
|
openButton.setStyleName(ValoTheme.BUTTON_TINY);
|
97
|
openButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
|
98
|
openButton.addClickListener(e -> parentView.getEventBus().publishEvent(new NavigationEvent(
|
99
|
RegistrationWorkflowViewBean.NAME,
|
100
|
RegistrationWorkflowViewBean.ACTION_EDIT,
|
101
|
regDto.getSpecificIdentifier().toString()
|
102
|
)));
|
103
|
buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
|
104
|
addComponent(buttonGroup, 2, 0);
|
105
|
setComponentAlignment(buttonGroup, Alignment.TOP_RIGHT);
|
106
|
|
107
|
citationSummaryLabel.setContentMode(ContentMode.HTML);
|
108
|
addComponent(citationSummaryLabel, 0, 1, 1, 2);
|
109
|
|
110
|
createdLabel.setStyleName(STYLE_LABEL_NOWRAP);
|
111
|
createdLabel.setContentMode(ContentMode.HTML);
|
112
|
createdLabel.setWidthUndefined();
|
113
|
addComponent(createdLabel, 2, 1);
|
114
|
setComponentAlignment(createdLabel, Alignment.BOTTOM_RIGHT);
|
115
|
|
116
|
publishedLabel.setStyleName(STYLE_LABEL_NOWRAP);
|
117
|
publishedLabel.setContentMode(ContentMode.HTML);
|
118
|
publishedLabel.setWidthUndefined();
|
119
|
addComponent(publishedLabel, 2, 2);
|
120
|
setComponentAlignment(publishedLabel, Alignment.BOTTOM_RIGHT);
|
121
|
|
122
|
}
|
123
|
|
124
|
public void setItem(RegistrationDTO item, AbstractView<?> parentView){
|
125
|
regDto = item;
|
126
|
this.parentView = parentView;
|
127
|
updateUI();
|
128
|
}
|
129
|
|
130
|
|
131
|
/**
|
132
|
*
|
133
|
*/
|
134
|
private void updateUI() {
|
135
|
updateTypeStateLabel();
|
136
|
getCitationSummaryLabel().setValue(regDto.getCitationString() + "</br>" + regDto.getSummary());
|
137
|
updateIdentifierLink();
|
138
|
getOpenButton().addClickListener(e -> parentView.getEventBus().publishEvent(new NavigationEvent(
|
139
|
RegistrationWorkflowViewBean.NAME,
|
140
|
RegistrationWorkflowViewBean.ACTION_EDIT,
|
141
|
regDto.getSpecificIdentifier().toString()
|
142
|
)));
|
143
|
updateDateLabels();
|
144
|
}
|
145
|
|
146
|
|
147
|
/**
|
148
|
*
|
149
|
*/
|
150
|
private void updateTypeStateLabel() {
|
151
|
|
152
|
FontAwesome icon;
|
153
|
if(regDto.getRegistrationType().equals(RegistrationType.NAME)) {
|
154
|
icon = FontAwesome.TAG;
|
155
|
} else if(regDto.getRegistrationType().equals(RegistrationType.TYPIFICATION)) {
|
156
|
icon = FontAwesome.TAGS;
|
157
|
} else {
|
158
|
icon = FontAwesome.WARNING;
|
159
|
}
|
160
|
typeStateLabel.setContentMode(ContentMode.HTML);
|
161
|
typeStateLabel.setValue(icon.getHtml() + " " + StringUtils.capitalize((regDto.getStatus().name().toLowerCase())));
|
162
|
typeStateLabel.addStyleName("status-" + regDto.getStatus().name());
|
163
|
}
|
164
|
|
165
|
/**
|
166
|
*
|
167
|
*/
|
168
|
private void updateIdentifierLink() {
|
169
|
getIdentifierLink().setResource(new ExternalResource(regDto.getRegistrationId()));
|
170
|
//TODO make responsive and use specificIdetifier in case the space gets too narrow
|
171
|
getIdentifierLink().setCaption(regDto.getRegistrationId());
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
*
|
176
|
*/
|
177
|
private void updateDateLabels() {
|
178
|
getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED + "</span> " + regDto.getCreated().toString(ISODateTimeFormat.yearMonthDay()));
|
179
|
if(regDto.getRegistrationDate() != null){
|
180
|
getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span> " + regDto.getRegistrationDate().toString(ISODateTimeFormat.yearMonthDay()));
|
181
|
} else {
|
182
|
getPublishedLabel().setVisible(false);
|
183
|
}
|
184
|
}
|
185
|
|
186
|
/* ====== RegistrationItemDesign Getters ====== */
|
187
|
/**
|
188
|
* @return the typeStateLabel
|
189
|
*/
|
190
|
public Label getTypeStateLabel() {
|
191
|
return typeStateLabel;
|
192
|
}
|
193
|
|
194
|
/**
|
195
|
* @return the identifierLink
|
196
|
*/
|
197
|
public Link getIdentifierLink() {
|
198
|
return identifierLink;
|
199
|
}
|
200
|
|
201
|
/**
|
202
|
* @return the citationSummaryLabel
|
203
|
*/
|
204
|
public Label getCitationSummaryLabel() {
|
205
|
return citationSummaryLabel;
|
206
|
}
|
207
|
|
208
|
/**
|
209
|
* @return the blockedByButton
|
210
|
*/
|
211
|
public Button getBlockedByButton() {
|
212
|
return blockedByButton;
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* @return the messageButton
|
217
|
*/
|
218
|
public Button getMessageButton() {
|
219
|
return messageButton;
|
220
|
}
|
221
|
|
222
|
/**
|
223
|
* @return the openButton
|
224
|
*/
|
225
|
public Button getOpenButton() {
|
226
|
return openButton;
|
227
|
}
|
228
|
|
229
|
/**
|
230
|
* @return the createdLabel
|
231
|
*/
|
232
|
public Label getCreatedLabel() {
|
233
|
return createdLabel;
|
234
|
}
|
235
|
|
236
|
/**
|
237
|
* @return the publishedLabel
|
238
|
*/
|
239
|
public Label getPublishedLabel() {
|
240
|
return publishedLabel;
|
241
|
}
|
242
|
|
243
|
/* --------------------------------------- */
|
244
|
|
245
|
}
|