Project

General

Profile

Download (3.39 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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;
10

    
11
import java.util.ArrayList;
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import org.apache.commons.lang.StringUtils;
16

    
17
import eu.etaxonomy.cdm.api.service.ITermService;
18
import eu.etaxonomy.cdm.api.service.IVocabularyService;
19
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
20
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
21
import eu.etaxonomy.cdm.model.term.TermType;
22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.store.TermStore;
26

    
27
/**
28
 * @author k.luther
29
 * @since 05.06.2019
30
 *
31
 */
32
public class RankPreference extends GeneralTermPreference {
33

    
34
    public RankPreference(){
35
        super();
36
        setLocalPref(true);
37
        setPredicate(PreferencePredicate.AvailableRanks);
38
        type = TermType.Rank;
39
    }
40

    
41

    
42

    
43

    
44
    /**
45
     * {@inheritDoc}
46
     */
47
    @Override
48
    protected List<TermVocabularyDto> getVocabulariesFromPreference() {
49
        // TODO Auto-generated method stub
50
        return null;
51
    }
52

    
53
    @Override
54
    protected void initialiseVocabularies() {
55

    
56
        if (getVocabularies() != null) {
57
            getVocabularies().clear();
58
        }
59
        List<TermVocabularyDto> vocs = new ArrayList<>();
60
        vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
61

    
62
        setVocabularies(vocs);
63
    }
64

    
65
    @Override
66
    public boolean performOk() {
67
        if (!isApply()){
68
            return true;
69
        }
70
        Object[] checkedElements = treeComposite.getViewer().getCheckedElements();
71
        List<UUID> listUIIDChecked = new ArrayList<>();
72
        List<DefinedTermBase> preferredTerms = new ArrayList<>();
73
        for (Object o : checkedElements) {
74
            if(o instanceof TermDto){
75
                TermDto termDto = (TermDto) o;
76
                listUIIDChecked.add(termDto.getUuid());
77
                preferredTerms.add(CdmStore.getService(ITermService.class).load(termDto.getUuid()));
78
            }
79
        }
80
        String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
81

    
82
        PreferencesUtil.setStringValue(PreferencePredicate.AvailableRanks.getKey(), saveCheckedElements);
83
        String text = this.useLocalOrAdmin.getText();
84
        if (text.equals(LocalOrDefaultEnum.Database.getLabel()) || text.equals(LocalOrDefaultEnum.Default.getLabel())){
85
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.AvailableRanks.getKey()), false);
86
        }else if (text.equals(LocalOrDefaultEnum.Local.getLabel())){
87
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.AvailableRanks.getKey()), true);
88
        }
89

    
90
        CdmStore.getTermManager().setPreferredTerms(preferredTerms, TermStore.getTerms(TermType.Rank, null));
91
        PreferencesUtil.firePreferencesChanged(this.getClass());
92
        return true;
93

    
94
    }
95

    
96
    @Override
97
    protected void performDefaults() {
98
        rememberCheckedValues(null);
99
        useLocalOrAdmin.select(1);
100
        allowOverride = true;
101
        setApply(true);
102
    }
103

    
104

    
105

    
106

    
107
}
(35-35/48)