Project

General

Profile

Download (3.79 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.IAgentService;
16
import eu.etaxonomy.cdm.api.service.dto.EntityDTOBase;
17
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
18
import eu.etaxonomy.cdm.model.agent.AgentBase;
19
import eu.etaxonomy.cdm.model.agent.Person;
20
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
21
import eu.etaxonomy.cdm.persistence.dto.TeamOrPersonUuidAndTitleCache;
22
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
/**
27
 * @author k.luther
28
 * @since Jul 1, 2021
29
 */
30
public class CollectorSelectionDialog extends AgentSelectionDialog<AgentBase<?>> {
31

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

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

    
52
    @Override
53
    protected ILabelProvider createListLabelProvider() {
54
        return new CollectorLabelProvider();
55
    }
56

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

    
84
            return title;
85
        }
86

    
87

    
88
    }
89
    @Override
90
    protected void callService(String pattern) {
91
        Class clazz = AgentBase.class;
92
        if (selectTeamMember){
93
            clazz = Person.class;
94
        }
95

    
96
        model = CdmStore.getService(IAgentService.class).getUuidAndTitleCacheWithCollectorTitleCache(clazz, limitOfInitialElements, pattern);
97
    }
98

    
99

    
100
}
(9-9/46)