ref #8648: default handling in name details preference - continue
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / preferencePage / SupplementalDataSourceAdminPreference.java
1 /**
2 * Copyright (C) 2019 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 eu.etaxonomy.cdm.model.metadata.CdmPreference;
12 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
13 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
14 import eu.etaxonomy.taxeditor.preference.SupplementalDataSourcePreferences;
15
16 /**
17 * @author k.luther
18 * @since 28.06.2019
19 *
20 */
21 public class SupplementalDataSourceAdminPreference extends SupplementalDataSourcePreferences implements IE4AdminPreferencePage{
22
23 private CdmPreference prefShowIdNamespace;
24 private CdmPreference prefShowIdInSource;
25
26 @Override
27 public boolean performOk() {
28 if (!isApply()){
29 return true;
30 }
31 boolean setToDefault = false;
32 if (isShowIDSource == null && isAllowOverrideShowIDSource){
33 setToDefault = true;
34 }
35
36 CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowIdInSource, isShowIDSource != null? Boolean.toString(this.isShowIDSource): null);
37 pref.setAllowOverride(isAllowOverrideShowIDSource);
38 PreferencesUtil.setPreferencesToDB(pref, setToDefault);
39 setToDefault = false;
40 if (isShowIDNamespace== null && isAllowOverrideShowIDNamespace){
41 setToDefault = true;
42
43 }
44 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowNamespaceInSource, isShowIDNamespace != null? Boolean.toString(this.isShowIDNamespace): null);
45 pref.setAllowOverride(isAllowOverrideShowIDNamespace);
46 PreferencesUtil.setPreferencesToDB(pref, setToDefault);
47
48 PreferencesUtil.updateDBPreferences();
49 return true;
50 }
51
52 @Override
53 protected void getValues(){
54 isAdminPreference = true;
55
56 prefShowIdNamespace = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowNamespaceInSource);
57 if (prefShowIdNamespace == null){
58 prefShowIdNamespace = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowNamespaceInSource, null);
59 prefShowIdNamespace.setAllowOverride(true);
60 }
61 isShowIDNamespace = prefShowIdNamespace.getValue()!= null? Boolean.parseBoolean(prefShowIdNamespace.getValue()): null;
62 isAllowOverrideShowIDNamespace = prefShowIdNamespace.isAllowOverride();
63
64 prefShowIdInSource = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowIdInSource);
65 if (prefShowIdInSource == null){
66 prefShowIdInSource = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowIdInSource, null);
67 prefShowIdInSource.setAllowOverride(true);
68 }
69 isShowIDSource = prefShowIdInSource.getValue()!= null? Boolean.parseBoolean(prefShowIdInSource.getValue()): null;
70 isAllowOverrideShowIDSource = prefShowIdInSource.isAllowOverride();
71 }
72 }