Project

General

Profile

Download (3.89 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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 java.util.ArrayList;
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import org.apache.commons.lang.StringUtils;
16
import org.eclipse.swt.widgets.Shell;
17

    
18
import eu.etaxonomy.cdm.api.service.IVocabularyService;
19
import eu.etaxonomy.cdm.model.common.TermType;
20
import eu.etaxonomy.cdm.model.common.TermVocabulary;
21
import eu.etaxonomy.cdm.model.location.NamedArea;
22
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
/**
27
 * @author k.luther
28
 * @since 09.10.2018
29
 *
30
 */
31
public class CommonNameNamedAreaSelectionDialog extends NamedAreaSelectionDialog {
32

    
33
    /**
34
     * @param shell
35
     * @param title
36
     * @param multi
37
     * @param namedArea
38
     * @param preferenceId
39
     * @param preselectedVocabularyUuids
40
     */
41
    protected CommonNameNamedAreaSelectionDialog(Shell shell, String title, boolean multi, NamedArea namedArea,
42
            Object preferenceId) {
43
        super(shell, title, multi, namedArea, preferenceId, createVocabularyUuidList());
44

    
45

    
46
    }
47

    
48
    private static UUID[] createVocabularyUuidList() {
49
        String preselectedVocString = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.COMMON_NAME_AREA_VOCABULARIES);
50
        if (StringUtils.isBlank(preselectedVocString)){
51
            return null;
52
        }
53
        String[] preselectedVocArray = preselectedVocString.split(";");
54
        UUID[] uuidList = new UUID[preselectedVocArray.length];
55
        int i = 0;
56
        for (String uuidString: preselectedVocArray){
57
            uuidList[i]= UUID.fromString(uuidString);
58
            i++;
59
        }
60
        return uuidList;
61
    }
62
    @Override
63
    protected void init() {
64
        vocabularies = getAvailableVocabularies();
65
    }
66

    
67

    
68
    protected List<TermVocabulary> getAvailableVocabularies(){
69
        List<TermVocabulary> vocabularies = new ArrayList();
70

    
71
        if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE)){
72
            UUID[] preselectedVocabularyUuids = createVocabularyUuidList();
73

    
74
            for(int i=0;i<preselectedVocabularyUuids.length;i++){
75
                TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
76
                vocabularies.add(preselectedVocabulary);
77
            }
78
        }else{
79
            vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null);
80
        }
81
        return vocabularies;
82
    }
83

    
84
    /**
85
     * Creates a filtered selection dialog to select a named area.
86
     *
87
     * @param shell
88
     *              The shell for displaying this widget
89
     * @param namedArea
90
     *              A namedArea that should be selected when the dialog opens
91
     * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
92
     * @param preferenceId a class which is used for generating the preference key so that every
93
     * dialogs can be grouped to have their own preferences depending on this id
94
     * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies
95
     * @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
96
     */
97
    public static NamedArea select(Shell shell, //ConversationHolder conversation,
98
            NamedArea namedArea, String preferenceId) {
99
        CommonNameNamedAreaSelectionDialog dialog = new CommonNameNamedAreaSelectionDialog(shell, //conversation,
100
                "Choose an area", false, namedArea, preferenceId);
101
        return getSelectionFromDialog(dialog);
102
    }
103
}
(9-9/44)