Project

General

Profile

Download (4.09 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

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

    
51
        super.createControl(parent);
52
    }
53

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

    
58
        return checkedValues;
59
    }
60

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

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

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

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

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

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

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

    
121
        setVocabularies(vocs);
122
    }
123

    
124
}
(5-5/14)