Project

General

Profile

Download (2.8 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.preference.menu;
11

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

    
16
import org.apache.commons.lang3.StringUtils;
17

    
18
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
19
import eu.etaxonomy.cdm.model.term.TermType;
20
import eu.etaxonomy.cdm.persistence.dto.TermDto;
21
import eu.etaxonomy.taxeditor.preference.GeneralTermPreferencePage;
22
import eu.etaxonomy.taxeditor.preference.LocalOrDefaultEnum;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
/**
27
 * <p>NameTypeDesignationStatusMenuPreferences class.</p>
28
 *
29
 * @author n.hoffmann
30
 * @created 25.06.2009
31
 * @version 1.0
32
 */
33
public class NameTypeDesignationStatusMenuPreferences extends
34
		GeneralTermPreferencePage {
35
    /**
36
     * <p>Constructor for NameTypeDesignationStatusMenuPreferences.</p>
37
     */
38
    public NameTypeDesignationStatusMenuPreferences() {
39
        super();
40
        setPredicate(PreferencePredicate.NameTypeDesignationStatus);
41
        type = TermType.NameTypeDesignationStatus;
42
    }
43

    
44
    @Override
45
    public boolean performOk() {
46
        if (!isApply()){
47
            return true;
48
        }
49
        Object[] checkedElements = treeComposite.getViewer().getCheckedElements();
50
        List<UUID> listUIIDChecked = new ArrayList<>();
51
        List<TermDto> preferredTerms = new ArrayList<>();
52
        for (Object o : checkedElements) {
53
            if(o instanceof TermDto){
54
                TermDto termDto = (TermDto) o;
55
                listUIIDChecked.add(termDto.getUuid());
56
                preferredTerms.add(termDto);
57
            }
58
        }
59
        String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
60

    
61
        PreferencesUtil.setStringValue(PreferencePredicate.NameTypeDesignationStatus.getKey(), saveCheckedElements);
62
        String text = this.useLocalOrAdmin.getText();
63
        if (text.equals(LocalOrDefaultEnum.Database.getLabel()) || text.equals(LocalOrDefaultEnum.Default.getLabel())){
64
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NameTypeDesignationStatus.getKey()), false);
65
        }else if (text.equals(LocalOrDefaultEnum.Local.getLabel())){
66
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NameTypeDesignationStatus.getKey()), true);
67
        }
68

    
69
        CdmStore.getTermManager().setPreferredTermsByType(preferredTerms, TermType.NameTypeDesignationStatus);
70
        PreferencesUtil.firePreferencesChanged(this.getClass());
71
        return true;
72
    }
73
}
(14-14/21)