Project

General

Profile

Download (1.52 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.util;
10

    
11
import org.vaadin.viritin.fields.CaptionGenerator;
12

    
13
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
14

    
15
/**
16
 * @author a.kohlbecker
17
 * @since Jun 7, 2017
18
 *
19
 */
20
public final class TeamOrPersonBaseCaptionGenerator<T extends TeamOrPersonBase> implements CaptionGenerator<T> {
21

    
22
    public enum CacheType {
23
        NOMENCLATURAL_TITLE,
24
        COLLECTOR_TITLE,
25
        BIBLIOGRAPHIC_TITLE;
26
    }
27

    
28
    CacheType cacheType;
29

    
30
    private static final long serialVersionUID = 116448502301429773L;
31

    
32
    public TeamOrPersonBaseCaptionGenerator(CacheType cacheType){
33
        this.cacheType = cacheType;
34
    }
35

    
36
    @Override
37
    public String getCaption(T option) {
38
        String caption = chooseTitle(option);
39
        if(caption == null){
40
            caption = option.getTitleCache();
41
        }
42
        return caption;
43
    }
44

    
45
    /**
46
     * @param option
47
     * @return
48
     */
49
    protected String chooseTitle(T option) {
50
        switch(cacheType){
51
            case NOMENCLATURAL_TITLE:
52
                return option.getNomenclaturalTitle();
53
            case COLLECTOR_TITLE:
54
                // return option.getCollectorTitle(); // enable once #4311 is solved
55
            case BIBLIOGRAPHIC_TITLE:
56
            default:
57
                return null;
58
        }
59
    }
60
}
(14-14/15)