2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.component
.phycobank
;
11 import org
.apache
.commons
.lang
.StringUtils
;
12 import org
.joda
.time
.format
.ISODateTimeFormat
;
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
;
25 import eu
.etaxonomy
.cdm
.vaadin
.presenter
.phycobank
.RegistrationDTO
;
26 import eu
.etaxonomy
.cdm
.vaadin
.presenter
.phycobank
.RegistrationType
;
27 import eu
.etaxonomy
.cdm
.vaadin
.view
.phycobank
.RegistrationTypeConverter
;
28 import eu
.etaxonomy
.cdm
.vaadin
.view
.phycobank
.RegistrationWorkflowViewBean
;
29 import eu
.etaxonomy
.vaadin
.mvp
.AbstractView
;
30 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationEvent
;
33 * @author a.kohlbecker
37 public class RegistrationItem
extends GridLayout
{
40 private static final String LABEL_CAPTION_CREATED
= "Created";
42 private static final String LABEL_CAPTION_PUBLISHED
= "Published";
44 private static final int GRID_ROWS
= 3;
46 private static final int GRID_COLS
= 3;
48 private static final String STYLE_LABEL_NOWRAP
= "label-nowrap";
50 private static final long serialVersionUID
= -211003770452173644L;
52 private RegistrationDTO regDto
;
54 private RegistrationTypeConverter regTypeConverter
= new RegistrationTypeConverter();
56 private AbstractView
<?
> parentView
;
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 // --------------------------------------------------
72 public RegistrationItem(RegistrationDTO item
, AbstractView
<?
> parentView
) {
73 super(GRID_COLS
, GRID_ROWS
);
75 setItem(item
, parentView
);
80 setId("registration-list");
81 setWidth(100, Unit
.PERCENTAGE
);
82 addStyleName("registration-item");
84 typeStateLabel
.setStyleName(STYLE_LABEL_NOWRAP
);
85 addComponent(typeStateLabel
, 0, 0);
86 setComponentAlignment(typeStateLabel
, Alignment
.MIDDLE_LEFT
);
88 addComponent(identifierLink
, 1, 0);
89 setComponentAlignment(identifierLink
, Alignment
.TOP_CENTER
);
90 setColumnExpandRatio(1, 1.0f
);
92 CssLayout buttonGroup
= new CssLayout(blockedByButton
, messageButton
, openButton
);
93 blockedByButton
.setStyleName(ValoTheme
.BUTTON_TINY
);
94 blockedByButton
.setEnabled(false);
95 messageButton
.setStyleName(ValoTheme
.BUTTON_TINY
);
96 messageButton
.setEnabled(false);
97 openButton
.setStyleName(ValoTheme
.BUTTON_TINY
);
98 openButton
.addStyleName(ValoTheme
.BUTTON_PRIMARY
);
99 buttonGroup
.setStyleName(ValoTheme
.LAYOUT_COMPONENT_GROUP
);
100 addComponent(buttonGroup
, 2, 0);
101 setComponentAlignment(buttonGroup
, Alignment
.TOP_RIGHT
);
103 citationSummaryLabel
.setContentMode(ContentMode
.HTML
);
104 addComponent(citationSummaryLabel
, 0, 1, 1, 2);
106 createdLabel
.setStyleName(STYLE_LABEL_NOWRAP
);
107 createdLabel
.setContentMode(ContentMode
.HTML
);
108 addComponent(createdLabel
, 2, 1);
109 setComponentAlignment(createdLabel
, Alignment
.BOTTOM_RIGHT
);
111 publishedLabel
.setStyleName(STYLE_LABEL_NOWRAP
);
112 publishedLabel
.setContentMode(ContentMode
.HTML
);
113 addComponent(publishedLabel
, 2, 2);
114 setComponentAlignment(publishedLabel
, Alignment
.BOTTOM_RIGHT
);
118 public void setItem(RegistrationDTO item
, AbstractView
<?
> parentView
){
120 this.parentView
= parentView
;
128 private void updateUI() {
129 updateTypeStateLabel();
130 getCitationSummaryLabel().setValue(regDto
.getCitationString() + "</br>" + regDto
.getSummary());
131 updateIdentifierLink();
132 getOpenButton().addClickListener(e
-> parentView
.getEventBus().publishEvent(new NavigationEvent(
133 RegistrationWorkflowViewBean
.NAME
,
134 RegistrationWorkflowViewBean
.ACTION_EDIT
,
135 regDto
.getSpecificIdentifier().toString()
144 private void updateTypeStateLabel() {
147 if(regDto
.getRegistrationType().equals(RegistrationType
.NAME
)) {
148 icon
= FontAwesome
.TAG
;
149 } else if(regDto
.getRegistrationType().equals(RegistrationType
.TYPIFICATION
)) {
150 icon
= FontAwesome
.TAGS
;
152 icon
= FontAwesome
.WARNING
;
154 typeStateLabel
.setContentMode(ContentMode
.HTML
);
155 typeStateLabel
.setValue(icon
.getHtml() + " " + StringUtils
.capitalize((regDto
.getStatus().name().toLowerCase())));
156 typeStateLabel
.addStyleName("status-" + regDto
.getStatus().name());
162 private void updateIdentifierLink() {
163 getIdentifierLink().setResource(new ExternalResource(regDto
.getRegistrationId()));
164 //TODO make responsive and use specificIdetifier in case the space gets too narrow
165 getIdentifierLink().setCaption(regDto
.getRegistrationId());
171 private void updateDateLabels() {
172 getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED
+ "</span> " + regDto
.getCreated().toString(ISODateTimeFormat
.yearMonthDay()));
173 if(regDto
.getRegistrationDate() != null){
174 getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED
+ "</span> " + regDto
.getRegistrationDate().toString(ISODateTimeFormat
.yearMonthDay()));
176 getPublishedLabel().setVisible(false);
180 /* ====== RegistrationItemDesign Getters ====== */
182 * @return the typeStateLabel
184 public Label
getTypeStateLabel() {
185 return typeStateLabel
;
189 * @return the identifierLink
191 public Link
getIdentifierLink() {
192 return identifierLink
;
196 * @return the citationSummaryLabel
198 public Label
getCitationSummaryLabel() {
199 return citationSummaryLabel
;
203 * @return the blockedByButton
205 public Button
getBlockedByButton() {
206 return blockedByButton
;
210 * @return the messageButton
212 public Button
getMessageButton() {
213 return messageButton
;
217 * @return the openButton
219 public Button
getOpenButton() {
224 * @return the createdLabel
226 public Label
getCreatedLabel() {
231 * @return the publishedLabel
233 public Label
getPublishedLabel() {
234 return publishedLabel
;
237 /* --------------------------------------- */