Project

General

Profile

Download (3.09 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2021 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.taxeditor.ui.dialog.selection;
10

    
11
import org.eclipse.jface.viewers.ILabelProvider;
12
import org.eclipse.jface.viewers.LabelProvider;
13
import org.eclipse.swt.widgets.Shell;
14

    
15
import eu.etaxonomy.cdm.api.service.dto.EntityDTOBase;
16
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
17
import eu.etaxonomy.cdm.model.agent.AgentBase;
18
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
19
import eu.etaxonomy.cdm.persistence.dto.TeamOrPersonUuidAndTitleCache;
20
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21

    
22
/**
23
 * @author k.luther
24
 * @since Jul 1, 2021
25
 */
26
public class CollectorSelectionDialog extends AgentSelectionDialog<AgentBase<?>> {
27

    
28
    /**
29
     * @param shell
30
     * @param title
31
     * @param multi
32
     * @param settings
33
     * @param agent
34
     * @param selectTeamMember
35
     */
36
    protected CollectorSelectionDialog(Shell shell, String title, boolean multi, String settings,
37
            AgentBase<?> agent, boolean selectTeamMember) {
38
        super(shell, title, multi, settings, agent, selectTeamMember);
39

    
40
    }
41
    public static <S extends AgentBase> S select(Shell shell,
42
            S entity, boolean selectTeamMember) {
43
        CollectorSelectionDialog dialog = new CollectorSelectionDialog(shell,
44
                "Choose Collector", false, CollectorSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
45
        return  (S) getSelectionFromDialog(dialog);
46
    }
47

    
48
    @Override
49
    protected ILabelProvider createListLabelProvider() {
50
        return new CollectorLabelProvider();
51
    }
52

    
53
    public class CollectorLabelProvider extends LabelProvider {
54
        @Override
55
        public String getText(Object element) {
56
            if (element == null) {
57
                return null;
58
            }
59
            TeamOrPersonUuidAndTitleCache uuidAndTitleCache = (TeamOrPersonUuidAndTitleCache) element;
60
            String titleCache = uuidAndTitleCache.getTitleCache();
61
            String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
62
            String collectorTitleCache = uuidAndTitleCache.getCollectorTitleCache();
63
            if (!titleCache.equals(abbrevTitleCache)){
64
                titleCache += " - " + abbrevTitleCache;
65
            }
66
            if (!uuidAndTitleCache.getTitleCache().equals(collectorTitleCache) && !abbrevTitleCache.equals(collectorTitleCache)){
67
                titleCache += " - " + collectorTitleCache;
68
            }
69
            if(PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSelectionDialog.getKey())){
70
                titleCache += " ["+uuidAndTitleCache.getId()+"]";
71
            }
72
            if (element instanceof EntityDTOBase){
73
                titleCache += "(" + ((IdentifiedEntityDTO)element).getIdentifier().getTypeLabel() +": " + ((IdentifiedEntityDTO)element).getIdentifier().getIdentifier() + ")";
74
            }
75

    
76
            return titleCache;
77
        }
78

    
79

    
80
    }
81

    
82
}
(9-9/46)