Project

General

Profile

Download (4.34 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2014 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.Arrays;
13
import java.util.HashMap;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Set;
18
import java.util.UUID;
19

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

    
23
import eu.etaxonomy.cdm.api.service.IVocabularyService;
24
import eu.etaxonomy.cdm.model.common.TermType;
25
import eu.etaxonomy.cdm.model.common.TermVocabulary;
26
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
27
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
28
import eu.etaxonomy.taxeditor.l10n.Messages;
29
import eu.etaxonomy.taxeditor.preference.EditorPreferencePredicate;
30
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32

    
33
/**
34
 * @author a.oppermann
35
 * @date 21.07.2014
36
 *
37
 */
38
public class AvailableDistributionPage extends AbstractTermSelectionWizardPage {
39

    
40
    protected AvailableDistributionPage(String pageName) {
41
        super(pageName, TermType.NamedArea);
42
        this.localPref = true;
43

    
44

    
45
    }
46

    
47
    @Override
48
    public void createControl(Composite parent) {
49
        setTitle(Messages.AvailableDistributionPage_PAGE_TITLE);
50
        setDescription(Messages.AvailableDistributionPage_PAGE_DESCRIPTION);
51

    
52
        super.createControl(parent);
53
    }
54

    
55
    @Override
56
    protected String getCheckedValuesFromPreferences() {
57
        String checkedValues = PreferencesUtil.getStringValue(EditorPreferencePredicate.AvailableDistributionAreaTerms.getKey());
58

    
59
        return checkedValues;
60
    }
61

    
62
    @Override
63
    public void dispose() {
64
       // CdmStore.getCurrentSessionManager().dispose(this);
65
        super.dispose();
66
    }
67

    
68
//    @Override
69
//    public ICdmEntitySession getCdmEntitySession() {
70
//        return CdmStore.getCurrentSessionManager().getNullSession();
71
//    }
72
//
73
//    @Override
74
//    public <T extends CdmBase> Collection<T> getRootEntities() {
75
//        return null;
76
//    }
77
//
78
//    @Override
79
    public Map<Object, List<String>> getPropertyPathsMap() {
80
        Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
81
        List<String> termsPropertyPaths = Arrays.asList(new String[] {
82
                "includes" //$NON-NLS-1$
83
        });
84
        propertyPathsMap.put("includes", termsPropertyPaths); //$NON-NLS-1$
85
        propertyPathsMap.put("terms", termsPropertyPaths); //$NON-NLS-1$
86
        return propertyPathsMap;
87
    }
88

    
89
    @Override
90
    protected  List<TermVocabularyDto> getVocabulariesFromPreference(){
91
        List<TermVocabularyDto> vocs = new ArrayList<>();
92

    
93
        if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null && PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()) == null){
94
            vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
95
        }else{
96
            String vocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
97
            if (vocString.equals("")){
98
                vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
99
                return vocs;
100
            }
101
            String[] arrayVocs = vocString.split(";"); //$NON-NLS-1$
102

    
103
            Set<UUID> uuidVocs = new HashSet<>();
104
            for (String voc: arrayVocs){
105
                if (!StringUtils.isBlank(voc)){
106
                    uuidVocs.add(UUID.fromString(voc));
107
                }
108
            }
109
            List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
110
            for (TermVocabulary voc: tempVocs){
111
                vocs.add(new TermVocabularyDto(voc.getUuid(), voc.getRepresentations()));
112
            }
113

    
114
        }
115
        return vocs;
116
    }
117
    @Override
118
    protected void initialiseVocabularies() {
119
        if (getVocabularies() != null) {
120
            getVocabularies().clear();
121
        }
122
        List<TermVocabularyDto> vocs = new ArrayList<>();
123
        vocs = getVocabulariesFromPreference();
124

    
125
        setVocabularies(vocs);
126
    }
127

    
128
}
(5-5/14)