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.preference;
|
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.menu.CdmPreferencePage;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
|
28
|
|
29
|
/**
|
30
|
* @author k.luther
|
31
|
* @since 05.10.2018
|
32
|
*
|
33
|
*/
|
34
|
public class CommonNameVocabularySelection extends CdmPreferencePage implements IE4PreferencePage {
|
35
|
|
36
|
boolean allowOverride;
|
37
|
CdmPreference pref = null;
|
38
|
|
39
|
@Override
|
40
|
protected Control createContents(Composite parent) {
|
41
|
|
42
|
Composite composite = createComposite(parent);
|
43
|
getValues();
|
44
|
|
45
|
|
46
|
final CLabel commonNameAreaLabel = new CLabel(composite, SWT.NULL);
|
47
|
commonNameAreaLabel.setText(Messages.VokabularyAdminPreferences_SELECT_VOCABULARY_TEXT);
|
48
|
|
49
|
GridData gridData = new GridData();
|
50
|
gridData.horizontalSpan = 2;
|
51
|
commonNameAreaLabel.setLayoutData(gridData);
|
52
|
|
53
|
final CommandHandlerButton button_opencommonNameAreaWizard = new CommandHandlerButton(composite, SWT.PUSH,
|
54
|
"eu.etaxonomy.taxeditor.store.open.OpenCommonNameAreaWizardHandler"); //$NON-NLS-1$
|
55
|
|
56
|
button_opencommonNameAreaWizard.setText(Messages.GeneralPreference_open_common_name_area_selection);
|
57
|
final Button allowOverrideCommonNameAreaCheckButton = createAllowOverrideButton(composite);
|
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
|
setApply(true);
|
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
|
@Override
|
103
|
public void getValues() {
|
104
|
this.isAdminPreference = false;
|
105
|
setPreferenceStore(PreferencesUtil.getPreferenceStore());
|
106
|
pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
|
107
|
|
108
|
|
109
|
if (pref != null){
|
110
|
allowOverride = pref.isAllowOverride();
|
111
|
}else{
|
112
|
pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.CommonNameAreaVocabularies, "");
|
113
|
allowOverride = true;
|
114
|
}
|
115
|
}
|
116
|
|
117
|
|
118
|
|
119
|
|
120
|
}
|