Project

General

Profile

Download (7.39 KB) Statistics
| Branch: | Tag: | Revision:
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.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.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;
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
        setId("registration-list");
81
        setWidth(100, Unit.PERCENTAGE);
82
        addStyleName("registration-item");
83

    
84
        typeStateLabel.setStyleName(STYLE_LABEL_NOWRAP);
85
        addComponent(typeStateLabel, 0, 0);
86
        setComponentAlignment(typeStateLabel, Alignment.MIDDLE_LEFT);
87

    
88
        addComponent(identifierLink, 1, 0);
89
        setComponentAlignment(identifierLink, Alignment.TOP_CENTER);
90
        setColumnExpandRatio(1, 1.0f);
91

    
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);
102

    
103
        citationSummaryLabel.setContentMode(ContentMode.HTML);
104
        addComponent(citationSummaryLabel, 0, 1, 1, 2);
105

    
106
        createdLabel.setStyleName(STYLE_LABEL_NOWRAP);
107
        createdLabel.setContentMode(ContentMode.HTML);
108
        addComponent(createdLabel, 2, 1);
109
        setComponentAlignment(createdLabel, Alignment.BOTTOM_RIGHT);
110

    
111
        publishedLabel.setStyleName(STYLE_LABEL_NOWRAP);
112
        publishedLabel.setContentMode(ContentMode.HTML);
113
        addComponent(publishedLabel, 2, 2);
114
        setComponentAlignment(publishedLabel, Alignment.BOTTOM_RIGHT);
115

    
116
    }
117

    
118
    public void setItem(RegistrationDTO item, AbstractView<?> parentView){
119
        regDto = item;
120
        this.parentView = parentView;
121
        updateUI();
122
    }
123

    
124

    
125
    /**
126
     *
127
     */
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()
136
                )));
137
        updateDateLabels();
138
    }
139

    
140

    
141
    /**
142
     *
143
     */
144
    private void updateTypeStateLabel() {
145

    
146
        FontAwesome icon;
147
        if(regDto.getRegistrationType().equals(RegistrationType.NAME)) {
148
            icon = FontAwesome.TAG;
149
        } else if(regDto.getRegistrationType().equals(RegistrationType.TYPIFICATION)) {
150
            icon = FontAwesome.TAGS;
151
        } else {
152
            icon = FontAwesome.WARNING;
153
        }
154
        typeStateLabel.setContentMode(ContentMode.HTML);
155
        typeStateLabel.setValue(icon.getHtml() + "&nbsp;" + StringUtils.capitalize((regDto.getStatus().name().toLowerCase())));
156
        typeStateLabel.addStyleName("status-" + regDto.getStatus().name());
157
    }
158

    
159
    /**
160
     *
161
     */
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());
166
    }
167

    
168
    /**
169
     *
170
     */
171
    private void updateDateLabels() {
172
        getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED + "</span>&nbsp;" + regDto.getCreated().toString(ISODateTimeFormat.yearMonthDay()));
173
        if(regDto.getRegistrationDate() != null){
174
            getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span>&nbsp;" + regDto.getRegistrationDate().toString(ISODateTimeFormat.yearMonthDay()));
175
        } else {
176
            getPublishedLabel().setVisible(false);
177
        }
178
    }
179

    
180
    /* ====== RegistrationItemDesign Getters ====== */
181
    /**
182
     * @return the typeStateLabel
183
     */
184
    public Label getTypeStateLabel() {
185
        return typeStateLabel;
186
    }
187

    
188
    /**
189
     * @return the identifierLink
190
     */
191
    public Link getIdentifierLink() {
192
        return identifierLink;
193
    }
194

    
195
    /**
196
     * @return the citationSummaryLabel
197
     */
198
    public Label getCitationSummaryLabel() {
199
        return citationSummaryLabel;
200
    }
201

    
202
    /**
203
     * @return the blockedByButton
204
     */
205
    public Button getBlockedByButton() {
206
        return blockedByButton;
207
    }
208

    
209
    /**
210
     * @return the messageButton
211
     */
212
    public Button getMessageButton() {
213
        return messageButton;
214
    }
215

    
216
    /**
217
     * @return the openButton
218
     */
219
    public Button getOpenButton() {
220
        return openButton;
221
    }
222

    
223
    /**
224
     * @return the createdLabel
225
     */
226
    public Label getCreatedLabel() {
227
        return createdLabel;
228
    }
229

    
230
    /**
231
     * @return the publishedLabel
232
     */
233
    public Label getPublishedLabel() {
234
        return publishedLabel;
235
    }
236

    
237
   /* --------------------------------------- */
238

    
239
}
(1-1/4)