Project

General

Profile

Download (4 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.preference.wizard;
10

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.UUID;
18

    
19
import org.apache.commons.lang.StringUtils;
20
import org.eclipse.swt.widgets.Composite;
21

    
22
import eu.etaxonomy.cdm.api.service.IVocabularyService;
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24
import eu.etaxonomy.cdm.model.common.TermType;
25
import eu.etaxonomy.cdm.model.common.TermVocabulary;
26
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
27
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
28
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
29
import eu.etaxonomy.taxeditor.editor.definedterm.RootElementsOnlyTreeContentProvider;
30
import eu.etaxonomy.taxeditor.l10n.Messages;
31
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
32
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
33
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
34
import eu.etaxonomy.taxeditor.store.CdmStore;
35

    
36
/**
37
 * @author k.luther
38
 * @since 04.06.2018
39
 *
40
 */
41
public class AvailableAreaVocabulariesPage  extends AbstractAdminTermSelectionWizardPage implements ICdmEntitySessionEnabled{
42

    
43
    String featureTitle;
44

    
45

    
46
    public AvailableAreaVocabulariesPage(String pageName, boolean localPref, CdmPreference pref, String featureTitle) {
47
        super(pageName, TermType.NamedArea, pref);
48
        this.localPref = localPref;
49
        this.featureTitle = featureTitle;
50

    
51
    }
52

    
53
    @Override
54
    public void createControl(Composite parent) {
55

    
56
        setTitle(String.format(Messages.AvailableAreaVocabulariesPage_PAGE_TITLE, featureTitle));
57
        setDescription(String.format(Messages.AvailableAreaVocabulariesPage_PAGE_DESCRIPTION, featureTitle));
58
        if (!localPref){
59

    
60
            createAllowOverrideButton(parent);
61
        }
62
        super.createControl(parent);
63

    
64
        treeComposite.getViewer().setContentProvider(new RootElementsOnlyTreeContentProvider());
65
    }
66

    
67

    
68

    
69
    @Override
70
    protected String getCheckedValuesFromPreferences() {
71
        String vocString = null;
72
        if (localPref){
73
            vocString = PreferencesUtil.getPreferredVocabulariesForDistributionEditor(localPref);
74
        }else if (pref != null){
75
            vocString = pref.getValue();
76
        }
77
        return vocString;
78
    }
79

    
80
    protected CdmPreference getPreferences() {
81
        return pref;
82
    }
83

    
84
    @Override
85
    public ICdmEntitySession getCdmEntitySession() {
86
        return null;
87
    }
88

    
89
    @Override
90
    public <T extends CdmBase> Collection<T> getRootEntities() {
91
        return null;
92
    }
93

    
94
    @Override
95
    public Map<Object, List<String>> getPropertyPathsMap() {
96
        return null;
97
    }
98

    
99
    @Override
100
    protected  List<TermVocabularyDto> getVocabulariesFromPreference(){
101
        List<TermVocabularyDto> vocs = new ArrayList<>();
102

    
103
        if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null ){
104
            vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
105
        }else{
106
            String vocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
107

    
108
            String[] arrayVocs = vocString.split(";"); //$NON-NLS-1$
109

    
110
            Set<UUID> uuidVocs = new HashSet<>();
111
            for (String voc: arrayVocs){
112
                if (!StringUtils.isBlank(voc)){
113
                    uuidVocs.add(UUID.fromString(voc));
114
                }
115
            }
116
            List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
117
            for (TermVocabulary voc: tempVocs){
118
                vocs.add(new TermVocabularyDto(voc.getUuid(), voc.getRepresentations()));
119
            }
120

    
121
        }
122
        return vocs;
123
    }
124

    
125
}
(4-4/14)