Project

General

Profile

Download (3.62 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.databaseAdmin.preferencePage;
10

    
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.custom.CLabel;
13
import org.eclipse.swt.events.SelectionAdapter;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19

    
20
import eu.etaxonomy.cdm.api.application.ICdmRepository;
21
import eu.etaxonomy.cdm.api.service.IPreferenceService;
22
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
23
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
24
import eu.etaxonomy.taxeditor.l10n.Messages;
25
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
26
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28
import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
29

    
30
/**
31
 * @author k.luther
32
 * @since 05.10.2018
33
 *
34
 */
35
public class VocabularyAdminPreferences extends CdmPreferencePage implements IE4AdminPreferencePage {
36

    
37
    boolean allowOverride;
38
    CdmPreference pref = null;
39

    
40
    @Override
41
    protected Control createContents(Composite parent) {
42
        this.isAdminPreference = true;
43
        Composite composite = createComposite(parent);
44
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
45

    
46

    
47
        final CLabel commonNameAreaLabel = new CLabel(composite, SWT.NULL);
48
        commonNameAreaLabel.setText(Messages.VokabularyAdminPreferences_SELECT_VOCABULARY_TEXT);
49

    
50
        GridData gridData = new GridData();
51
        gridData.horizontalSpan = 2;
52
        commonNameAreaLabel.setLayoutData(gridData);
53

    
54
        final CommandHandlerButton button_opencommonNameAreaWizard = new CommandHandlerButton(composite, SWT.PUSH,
55
                "eu.etaxonomy.taxeditor.store.open.OpenCommonNameAreaWizardAdminHandler"); //$NON-NLS-1$
56

    
57
        button_opencommonNameAreaWizard.setText(Messages.GeneralPreference_open_common_name_area_selection);
58
        final Button allowOverrideCommonNameAreaCheckButton = createAllowOverrideButton(composite);
59

    
60
        if (pref != null){
61
            allowOverride = pref.isAllowOverride();
62
            allowOverrideCommonNameAreaCheckButton.setSelection(allowOverride);
63
        }
64
        else{
65
            allowOverrideCommonNameAreaCheckButton.setSelection(true);
66
        }
67

    
68
        allowOverrideCommonNameAreaCheckButton.addSelectionListener(new SelectionAdapter(){
69
            @Override
70
            public void widgetSelected(SelectionEvent e) {
71
                allowOverride = allowOverrideCommonNameAreaCheckButton.getSelection();
72

    
73
            }
74
        });
75

    
76
        return composite;
77
    }
78

    
79
    @Override
80
    public boolean performOk() {
81
        if (pref == null){
82
            return true;
83
        }
84
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
85

    
86
        if(controller!=null){
87
            IPreferenceService service = controller.getPreferenceService();
88

    
89
            CdmPreference pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
90
            if(pref==null){
91
                pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.CommonNameAreaVocabularies, "");
92
            }
93
            pref.setAllowOverride(allowOverride);
94
            service.set(pref);
95

    
96
            PreferencesUtil.updateDBPreferences();
97
        }
98
        return true;
99

    
100
    }
101

    
102

    
103
}
(13-13/13)