Project

General

Profile

Download (1.46 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
public final class TeamOrPersonBaseCaptionGenerator<T extends TeamOrPersonBase> implements CaptionGenerator<T> {
20

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

    
27
    private CacheType cacheType;
28

    
29
    private static final long serialVersionUID = 116448502301429773L;
30

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

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

    
44
    protected String chooseTitle(T option) {
45
        switch(cacheType){
46
            case NOMENCLATURAL_TITLE:
47
                return option.getNomenclaturalTitleCache();
48
            case COLLECTOR_TITLE:
49
                return option.getCollectorTitleCache();
50
            case BIBLIOGRAPHIC_TITLE:
51
            default:
52
                return null;
53
        }
54
    }
55
}
(16-16/17)