Project

General

Profile

Download (3.8 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.PreferencesUtil;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

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

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

    
43
    }
44

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

    
50
        super.createControl(parent);
51
    }
52

    
53
    @Override
54
    protected String getCheckedValuesFromPreferences() {
55
        String checkedValues = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey());
56

    
57
        return checkedValues;
58
    }
59

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

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

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

    
91
        if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null && PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()) == null){
92
            vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
93
        }else{
94
            String vocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
95

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

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

    
109
        }
110
        return vocs;
111
    }
112

    
113
}
(5-5/14)