Project

General

Profile

Download (3.51 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
        if (pref != null){
49
            allowOverride = pref.isAllowOverride();
50
        }
51

    
52
        final CLabel commonNameAreaLabel = new CLabel(composite, SWT.NULL);
53
        commonNameAreaLabel.setText("Select the area vocabularies which should be available for common names.");
54

    
55
        final CommandHandlerButton button_opencommonNameAreaWizard = new CommandHandlerButton(composite, SWT.PUSH,
56
                "eu.etaxonomy.taxeditor.store.open.OpenCommonNameAreaWizardAdminHandler");
57

    
58
        button_opencommonNameAreaWizard.setText(Messages.GeneralPreference_open_common_name_area_selection);
59
        final Button allowOverrideCommonNameAreaCheckButton = new Button(composite, SWT.CHECK);
60
        allowOverrideCommonNameAreaCheckButton.setText(Messages.ChecklistEditorGeneralPreference_allowOverride);
61
        allowOverrideCommonNameAreaCheckButton.setSelection(allowOverride);
62
        allowOverrideCommonNameAreaCheckButton.addSelectionListener(new SelectionAdapter(){
63
            @Override
64
            public void widgetSelected(SelectionEvent e) {
65
                allowOverride = allowOverrideCommonNameAreaCheckButton.getSelection();
66

    
67
            }
68
        });
69

    
70
        return composite;
71
    }
72

    
73
    @Override
74
    public boolean performOk() {
75
        if (pref == null){
76
            return true;
77
        }
78
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
79

    
80
        if(controller!=null){
81
            IPreferenceService service = controller.getPreferenceService();
82

    
83
            CdmPreference pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
84
            if(pref==null){
85
                pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.CommonNameAreaVocabularies, "");
86
            }
87
            pref.setAllowOverride(allowOverride);
88
            service.set(pref);
89

    
90
            PreferencesUtil.updateDBPreferences();
91
        }
92
        return true;
93

    
94
    }
95

    
96

    
97
}
(12-12/12)