Project

General

Profile

Download (3.61 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.GridLayout;
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 VokabularyAdminPreferences extends CdmPreferencePage implements IE4AdminPreferencePage {
36

    
37
    boolean allowOverride;
38
    CdmPreference pref = null;
39

    
40
    @Override
41
    protected Control createContents(Composite parent) {
42

    
43
        Composite composite = new Composite(parent, SWT.NULL);
44
        composite.setLayout(new GridLayout());
45

    
46
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
47

    
48

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

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

    
55
        button_opencommonNameAreaWizard.setText(Messages.GeneralPreference_open_common_name_area_selection);
56
        final Button allowOverrideCommonNameAreaCheckButton = new Button(composite, SWT.CHECK);
57
        allowOverrideCommonNameAreaCheckButton.setText(Messages.ChecklistEditorGeneralPreference_allowOverride);
58

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

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

    
72
            }
73
        });
74

    
75
        return composite;
76
    }
77

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

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

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

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

    
99
    }
100

    
101

    
102
}
(12-12/12)