Project

General

Profile

Download (8.08 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.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.event.ShowDetailsEvent;
26
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO;
27
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationType;
28
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationTypeConverter;
29
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowViewBean;
30
import eu.etaxonomy.vaadin.mvp.AbstractView;
31
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
32

    
33
/**
34
 * @author a.kohlbecker
35
 * @since Mar 17, 2017
36
 *
37
 */
38
public class RegistrationItem extends GridLayout {
39

    
40

    
41
    private static final String LABEL_CAPTION_CREATED = "Created";
42

    
43
    private static final String LABEL_CAPTION_PUBLISHED = "Published";
44

    
45
    private static final int GRID_ROWS = 3;
46

    
47
    private static final int GRID_COLS = 3;
48

    
49
    private static final String STYLE_LABEL_NOWRAP = "label-nowrap";
50

    
51
    private static final long serialVersionUID = -211003770452173644L;
52

    
53
    private RegistrationDTO regDto;
54

    
55
    private RegistrationTypeConverter regTypeConverter = new RegistrationTypeConverter();
56

    
57
    private AbstractView<?> parentView;
58

    
59
    // --------------------------------------------------
60
    private Label typeStateLabel = new Label();
61
    private Link identifierLink = new Link();
62
    private Label citationSummaryLabel = new Label();
63
    private Button blockedByButton = new Button(FontAwesome.WARNING);
64
    private Button messageButton = new Button(FontAwesome.COMMENT);
65
    private Button openButton = new Button(FontAwesome.COGS);
66
    private Label createdLabel = new Label();
67
    private Label publishedLabel = new Label();
68
    // --------------------------------------------------
69

    
70
    /**
71
     *
72
     */
73
    public RegistrationItem(RegistrationDTO item, AbstractView<?> parentView) {
74
        super(GRID_COLS, GRID_ROWS);
75
        init();
76
        setItem(item, parentView);
77
    }
78

    
79
    public void init() {
80

    
81
        setWidth(100, Unit.PERCENTAGE);
82
        addStyleName("registration-list-item");
83

    
84
        typeStateLabel.setStyleName(STYLE_LABEL_NOWRAP);
85
        addComponent(typeStateLabel, 0, 0);
86
        setComponentAlignment(typeStateLabel, Alignment.TOP_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

    
100
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
101
        addComponent(buttonGroup, 2, 0);
102
        setComponentAlignment(buttonGroup, Alignment.TOP_RIGHT);
103

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

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

    
113
        publishedLabel.setStyleName(STYLE_LABEL_NOWRAP);
114
        publishedLabel.setContentMode(ContentMode.HTML);
115
        publishedLabel.setWidthUndefined();
116
        addComponent(publishedLabel, 2, 2);
117
        setComponentAlignment(publishedLabel, Alignment.BOTTOM_RIGHT);
118

    
119
    }
120

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

    
127

    
128
    /**
129
     *
130
     */
131
    private void updateUI() {
132
        updateTypeStateLabel();
133
        getCitationSummaryLabel().setValue(regDto.getCitationString() + "</br>" + regDto.getSummary());
134
        updateIdentifierLink();
135

    
136
        // Buttons
137
        getOpenButton().addClickListener(e -> publishEvent(new NavigationEvent(
138
                RegistrationWorkflowViewBean.NAME,
139
                RegistrationWorkflowViewBean.ACTION_EDIT,
140
                Integer.toString(regDto.getId())
141
                )));
142
        if(regDto.getMessages().size() > 0){
143
            getMessageButton().setEnabled(true);
144
            getMessageButton().addStyleName(ValoTheme.BUTTON_FRIENDLY);
145
            getMessageButton().addClickListener(e -> publishEvent(
146
                    new ShowDetailsEvent<RegistrationDTO, Integer>(
147
                            e,
148
                            RegistrationDTO.class,
149
                            regDto.getId(),
150
                            "messages"))
151
                    );
152
        }
153

    
154
        updateDateLabels();
155
    }
156

    
157

    
158
    /**
159
     *
160
     */
161
    private void updateTypeStateLabel() {
162

    
163
        FontAwesome icon;
164
        if(regDto.getRegistrationType().equals(RegistrationType.NAME)) {
165
            icon = FontAwesome.TAG;
166
        } else if(regDto.getRegistrationType().equals(RegistrationType.TYPIFICATION)) {
167
            icon = FontAwesome.TAGS;
168
        } else {
169
            icon = FontAwesome.WARNING;
170
        }
171
        typeStateLabel.setContentMode(ContentMode.HTML);
172
        typeStateLabel.setValue(icon.getHtml() + "&nbsp;" + StringUtils.capitalize((regDto.getStatus().name().toLowerCase())));
173
        typeStateLabel.addStyleName("status-" + regDto.getStatus().name());
174
    }
175

    
176
    /**
177
     *
178
     */
179
    private void updateIdentifierLink() {
180
        getIdentifierLink().setResource(new ExternalResource(regDto.getIdentifier()));
181
        //TODO make responsive and use specificIdetifier in case the space gets too narrow
182
        getIdentifierLink().setCaption(regDto.getIdentifier());
183
    }
184

    
185
    /**
186
     *
187
     */
188
    private void updateDateLabels() {
189
        getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED + "</span>&nbsp;" + regDto.getCreated().toString(ISODateTimeFormat.yearMonthDay()));
190
        if(regDto.getRegistrationDate() != null){
191
            getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span>&nbsp;" + regDto.getRegistrationDate().toString(ISODateTimeFormat.yearMonthDay()));
192
        } else {
193
            getPublishedLabel().setVisible(false);
194
        }
195
    }
196

    
197
    private void publishEvent(Object event) {
198
        parentView.getEventBus().publishEvent(event);
199
    }
200

    
201
    /* ====== RegistrationItemDesign Getters ====== */
202
    /**
203
     * @return the typeStateLabel
204
     */
205
    public Label getTypeStateLabel() {
206
        return typeStateLabel;
207
    }
208

    
209
    /**
210
     * @return the identifierLink
211
     */
212
    public Link getIdentifierLink() {
213
        return identifierLink;
214
    }
215

    
216
    /**
217
     * @return the citationSummaryLabel
218
     */
219
    public Label getCitationSummaryLabel() {
220
        return citationSummaryLabel;
221
    }
222

    
223
    /**
224
     * @return the blockedByButton
225
     */
226
    public Button getBlockedByButton() {
227
        return blockedByButton;
228
    }
229

    
230
    /**
231
     * @return the messageButton
232
     */
233
    public Button getMessageButton() {
234
        return messageButton;
235
    }
236

    
237
    /**
238
     * @return the openButton
239
     */
240
    public Button getOpenButton() {
241
        return openButton;
242
    }
243

    
244
    /**
245
     * @return the createdLabel
246
     */
247
    public Label getCreatedLabel() {
248
        return createdLabel;
249
    }
250

    
251
    /**
252
     * @return the publishedLabel
253
     */
254
    public Label getPublishedLabel() {
255
        return publishedLabel;
256
    }
257

    
258
   /* --------------------------------------- */
259

    
260
}
(2-2/4)