Project

General

Profile

Download (4.25 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 AbstractTermSelectionWizardPage implements ICdmEntitySessionEnabled{
42

    
43
    CdmPreference pref;
44
    String featureTitle;
45
    /**
46
     * @param pageName
47
     */
48
    public AvailableAreaVocabulariesPage(String pageName, boolean localPref, CdmPreference pref, String featureTitle) {
49
        super(pageName, TermType.NamedArea);
50
        this.localPref = localPref;
51
        this.pref = pref;
52
        this.featureTitle = featureTitle;
53

    
54
    }
55

    
56
     /**
57
     * {@inheritDoc}
58
     */
59
    @Override
60
    public void createControl(Composite parent) {
61

    
62
        setTitle(String.format(Messages.AvailableAreaVocabulariesPage_PAGE_TITLE, featureTitle));
63
        setDescription(String.format(Messages.AvailableAreaVocabulariesPage_PAGE_DESCRIPTION, featureTitle));
64

    
65
        super.createControl(parent);
66
        treeComposite.getViewer().setContentProvider(new RootElementsOnlyTreeContentProvider());
67
    }
68

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

    
83
    /**
84
     * {@inheritDoc}
85
     */
86
    @Override
87
    protected String getGrayedValuesFromPreferences() {
88
        // TODO Auto-generated method stub
89
        return null;
90
    }
91

    
92
    /**
93
     * {@inheritDoc}
94
     */
95
    @Override
96
    public ICdmEntitySession getCdmEntitySession() {
97
        return null;
98
    }
99

    
100
    /**
101
     * {@inheritDoc}
102
     */
103
    @Override
104
    public <T extends CdmBase> Collection<T> getRootEntities() {
105
        return null;
106
    }
107

    
108
    /**
109
     * {@inheritDoc}
110
     */
111
    @Override
112
    public Map<Object, List<String>> getPropertyPathsMap() {
113
        return null;
114
    }
115

    
116
    @Override
117
    protected  List<TermVocabularyDto> getVocabulariesFromPreference(){
118
        List<TermVocabularyDto> vocs = new ArrayList<>();
119

    
120
        if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null ){
121
            vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
122
        }else{
123
            String vocString = PreferencesUtil.getStringValue(PreferencesUtil.DISTRIBUTION_VOCABULARIES);
124

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

    
127
            Set<UUID> uuidVocs = new HashSet();
128
            for (String voc: arrayVocs){
129
                if (!StringUtils.isBlank(voc)){
130
                    uuidVocs.add(UUID.fromString(voc));
131
                }
132
            }
133
            List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
134
            for (TermVocabulary voc: tempVocs){
135
                vocs.add(new TermVocabularyDto(voc.getUuid(), voc.getRepresentations()));
136
            }
137

    
138
        }
139
        return vocs;
140
    }
141

    
142
}
(4-4/14)