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.phycobank;
|
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.ui.Button;
|
17
|
import com.vaadin.ui.Label;
|
18
|
import com.vaadin.ui.Link;
|
19
|
|
20
|
import eu.etaxonomy.cdm.vaadin.design.phycobank.RegistrationItemDesign;
|
21
|
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.RegistrationDTO;
|
22
|
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.RegistrationType;
|
23
|
import eu.etaxonomy.cdm.vaadin.view.phycobank.RegistrationTypeConverter;
|
24
|
import eu.etaxonomy.cdm.vaadin.view.phycobank.RegistrationWorkflowViewBean;
|
25
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
26
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
27
|
|
28
|
/**
|
29
|
* @author a.kohlbecker
|
30
|
* @since Mar 17, 2017
|
31
|
*
|
32
|
*/
|
33
|
public class RegistrationItem extends RegistrationItemDesign {
|
34
|
|
35
|
private static final long serialVersionUID = -211003770452173644L;
|
36
|
|
37
|
private RegistrationDTO regDto;
|
38
|
|
39
|
private RegistrationTypeConverter regTypeConverter = new RegistrationTypeConverter();
|
40
|
|
41
|
private AbstractView<?> parentView;
|
42
|
|
43
|
/**
|
44
|
*
|
45
|
*/
|
46
|
public RegistrationItem(RegistrationDTO item, AbstractView<?> parentView) {
|
47
|
super();
|
48
|
setItem(item, parentView);
|
49
|
}
|
50
|
|
51
|
public void setItem(RegistrationDTO item, AbstractView<?> parentView){
|
52
|
regDto = item;
|
53
|
this.parentView = parentView;
|
54
|
updateUI();
|
55
|
}
|
56
|
|
57
|
|
58
|
/**
|
59
|
*
|
60
|
*/
|
61
|
private void updateUI() {
|
62
|
updateTypeStateLabel();
|
63
|
getCitationLabel().setValue(regDto.getCitationString());
|
64
|
getSummaryLabel().setValue(regDto.getSummary());
|
65
|
updateIdentifierLink();
|
66
|
getOpenButton().addClickListener(e -> parentView.getEventBus().publishEvent(new NavigationEvent(
|
67
|
RegistrationWorkflowViewBean.NAME,
|
68
|
RegistrationWorkflowViewBean.ACTION_EDIT,
|
69
|
regDto.getSpecificIdentifier().toString()
|
70
|
)));
|
71
|
updateDateLabels();
|
72
|
}
|
73
|
|
74
|
|
75
|
/**
|
76
|
*
|
77
|
*/
|
78
|
private void updateTypeStateLabel() {
|
79
|
|
80
|
FontAwesome icon;
|
81
|
if(regDto.getRegistrationType().equals(RegistrationType.NAME)) {
|
82
|
icon = FontAwesome.TAG;
|
83
|
} else if(regDto.getRegistrationType().equals(RegistrationType.TYPIFICATION)) {
|
84
|
icon = FontAwesome.TAGS;
|
85
|
} else {
|
86
|
icon = FontAwesome.WARNING;
|
87
|
}
|
88
|
typeStateLabel.setIcon(icon);
|
89
|
typeStateLabel.setValue(StringUtils.capitalize((regDto.getStatus().name().toLowerCase())));
|
90
|
typeStateLabel.addStyleName("status-" + regDto.getStatus().name());
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
*
|
95
|
*/
|
96
|
private void updateIdentifierLink() {
|
97
|
getIdentifierLink().setResource(new ExternalResource(regDto.getRegistrationId()));
|
98
|
//TODO make responsive and use specificIdetifier in case the space gets too narrow
|
99
|
getIdentifierLink().setCaption(regDto.getRegistrationId());
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
*
|
104
|
*/
|
105
|
private void updateDateLabels() {
|
106
|
getCreatedLabel().setDescription(regDto.getCreated().toString(ISODateTimeFormat.yearMonthDay()));
|
107
|
if(regDto.getRegistrationDate() != null){
|
108
|
getPublishedLabel().setDescription(regDto.getRegistrationDate().toString(ISODateTimeFormat.yearMonthDay()));
|
109
|
} else {
|
110
|
getPublishedLabel().setVisible(false);
|
111
|
}
|
112
|
|
113
|
}
|
114
|
|
115
|
/* ====== RegistrationItemDesign Getters ====== */
|
116
|
/**
|
117
|
* @return the typeStateLabel
|
118
|
*/
|
119
|
public Label getTypeStateLabel() {
|
120
|
return typeStateLabel;
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* @return the identifierLink
|
125
|
*/
|
126
|
public Link getIdentifierLink() {
|
127
|
return identifierLink;
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* @return the citationLabel
|
132
|
*/
|
133
|
public Label getCitationLabel() {
|
134
|
return citationLabel;
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* @return the summaryLabel
|
139
|
*/
|
140
|
public Label getSummaryLabel() {
|
141
|
return summaryLabel;
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* @return the blockedByButton
|
146
|
*/
|
147
|
public Button getBlockedByButton() {
|
148
|
return blockedByButton;
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* @return the messageButton
|
153
|
*/
|
154
|
public Button getMessageButton() {
|
155
|
return messageButton;
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* @return the openButton
|
160
|
*/
|
161
|
public Button getOpenButton() {
|
162
|
return openButton;
|
163
|
}
|
164
|
|
165
|
/**
|
166
|
* @return the createdLabel
|
167
|
*/
|
168
|
public Label getCreatedLabel() {
|
169
|
return createdLabel;
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* @return the publishedLabel
|
174
|
*/
|
175
|
public Label getPublishedLabel() {
|
176
|
return publishedLabel;
|
177
|
}
|
178
|
|
179
|
/* --------------------------------------- */
|
180
|
|
181
|
}
|