Project

General

Profile

Revision 3afedf26

ID3afedf2625558005d812127f9b1d0f6ea28ea06a
Parent 071c2929
Child 5b81fd8a

Added by Andreas Kohlbecker over 3 years ago

ref #6564 TimePeriodFormatter with support for ISO8601 date format
- needs support for dd.mm.yyyy formats
- to be moved into cdmlib

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/TimePeriodField.java
28 28
import eu.etaxonomy.cdm.model.common.TimePeriod;
29 29
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
30 30
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
31
import eu.etaxonomy.cdm.vaadin.util.TimePeriodFormatter;
31 32

  
32 33
/**
33 34
 * @author a.kohlbecker
......
60 61

  
61 62
    Set<Component> styledComponents = new HashSet<>();
62 63

  
64
    private TimePeriodFormatter timePeriodFormatter = new TimePeriodFormatter(TimePeriodFormatter.Format.ISO8601);
65

  
63 66
    /**
64 67
     *
65 68
     */
......
212 215
        fieldGroup.setItemDataSource(new BeanItem<TimePeriod>(newValue));
213 216

  
214 217
        cacheField.setReadOnly(false);
215
        cacheField.setValue(newValue.toString());
218
        cacheField.setValue(timePeriodFormatter.print(newValue));
216 219
        cacheField.setReadOnly(true);
217 220
    }
218 221

  
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItem.java
30 30
import eu.etaxonomy.cdm.vaadin.event.ReferenceEvent;
31 31
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
32 32
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
33
import eu.etaxonomy.cdm.vaadin.util.TimePeriodFormatter;
33 34
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
34 35
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationTypeConverter;
35 36
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowViewBean;
......
60 61

  
61 62
    private AbstractView<?> parentView;
62 63

  
64
    private TimePeriodFormatter timePeriodFormatter = new TimePeriodFormatter(TimePeriodFormatter.Format.ISO8601);
65

  
63 66
    // --------------------------------------------------
64 67
    private TypeStateLabel typeStateLabel = new TypeStateLabel();
65 68
    private Link identifierLink = new Link();
......
168 171
        } else {
169 172
            openButtonEvent = new ReferenceEvent(EntityEventType.ADD);
170 173
        }
171
        updateUI(workingSet.getCitation(), workingSet.getCreated(), null, workingSet.messagesCount(),
174
        TimePeriod datePublished = workingSet.getRegistrationDTOs().get(0).getDatePublished();
175
        updateUI(workingSet.getCitation(), workingSet.getCreated(), datePublished, workingSet.messagesCount(),
172 176
                openButtonEvent, FontAwesome.EDIT, null);
173 177
    }
174 178

  
......
241 245
    /**
242 246
     *
243 247
     */
244
    private void updateDateLabels(DateTime created, TimePeriod published, DateTime released) {
248
    private void updateDateLabels(DateTime created, TimePeriod datePublished, DateTime released) {
245 249
        getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED + "</span>&nbsp;" + created.toString(ISODateTimeFormat.yearMonthDay()));
246
        if(published != null){
250
        if(datePublished != null){
247 251
            getPublishedLabel().setVisible(true);
248
            StringBuffer sb = new StringBuffer();
249
            if(published.getStart() != null){
250
                sb.append(published.getStart().toString(ISODateTimeFormat.yearMonthDay()));
251
            }
252
            if(published.getEnd() != null){
253
                if(sb.length() > 0){
254
                    sb.append('-');
255
                    sb.append(published.getEnd().toString(ISODateTimeFormat.yearMonthDay()));
256
                }
257
            }
258
            getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span>&nbsp;" + sb.toString());
252

  
253

  
254
            getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span>&nbsp;" + timePeriodFormatter.print(datePublished));
259 255
        }
260 256
        if(released != null){
261 257
            getReleasedLabel().setVisible(true);
......
264 260
        // LABEL_CAPTION_RELEASED
265 261
    }
266 262

  
263

  
264

  
267 265
    private void publishEvent(Object event) {
268 266
        parentView.getEventBus().publishEvent(event);
269 267
    }
src/main/java/eu/etaxonomy/cdm/vaadin/util/TimePeriodFormatter.java
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.util;
10

  
11
import org.joda.time.Partial;
12
import org.joda.time.format.DateTimeFormatter;
13
import org.joda.time.format.ISODateTimeFormat;
14

  
15
import eu.etaxonomy.cdm.model.common.TimePeriod;
16

  
17
/**
18
 *
19
 * FIXME move into cdmlib
20
 *
21
 * @author a.kohlbecker
22
 * @since Apr 26, 2017
23
 *
24
 */
25
public class TimePeriodFormatter {
26

  
27
    public enum Format {
28
        /**
29
         * yyyy-mm-dd or yyyy-mm or yyyy
30
         */
31
        ISO8601
32
    }
33

  
34
    private Format format;
35

  
36
    public TimePeriodFormatter(Format format) {
37
        this.format = format;
38
    }
39

  
40
    public String print(TimePeriod timePeriod) {
41

  
42
        switch (format) {
43
        case ISO8601:
44
        default:
45
            return printISO8601(timePeriod);
46
        }
47
    }
48

  
49
    /**
50
     * @param datePublished
51
     */
52
    private String printISO8601(TimePeriod datePublished) {
53
        StringBuffer sb = new StringBuffer();
54
        if (datePublished.getStart() != null) {
55
            sb.append(datePublished.getStart().toString(determineISO860Formatter(datePublished.getStart())));
56
        }
57
        if (datePublished.getEnd() != null) {
58
            if (sb.length() > 0) {
59
                sb.append('-');
60
                sb.append(datePublished.getEnd().toString(determineISO860Formatter(datePublished.getEnd())));
61
            }
62
        }
63
        return sb.toString();
64
    }
65

  
66
    /**
67
     * @param partial
68
     * @return
69
     */
70
    private DateTimeFormatter determineISO860Formatter(Partial partial) {
71
        if (partial.isSupported(TimePeriod.DAY_TYPE)) {
72
            return ISODateTimeFormat.yearMonthDay();
73
        }
74
        if (partial.isSupported(TimePeriod.MONTH_TYPE)) {
75
            return ISODateTimeFormat.yearMonth();
76
        }
77
        return ISODateTimeFormat.year();
78

  
79
    }
80

  
81
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)