ref #8648: default handling in name details preference - continue
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / preferencePage / PublishFlagPreference.java
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 eu.etaxonomy.cdm.api.application.ICdmRepository;
12 import eu.etaxonomy.cdm.api.service.IPreferenceService;
13 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
14 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
15 import eu.etaxonomy.cdm.model.metadata.PublishEnum;
16 import eu.etaxonomy.taxeditor.l10n.Messages;
17 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
18 import eu.etaxonomy.taxeditor.preference.PublishFlagLocalPreference;
19 import eu.etaxonomy.taxeditor.store.CdmStore;
20
21 /**
22 * @author k.luther
23 * @since 23.03.2018
24 *
25 */
26 public class PublishFlagPreference extends PublishFlagLocalPreference implements IE4AdminPreferencePage{
27
28
29 @Override
30 public void init() {
31 super.init();
32
33
34 }
35
36
37
38 @Override
39 public boolean performOk() {
40 if (!isApply()){
41 return true;
42 }
43 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
44 if (controller == null){
45 return false;
46 }
47 IPreferenceService service = controller.getPreferenceService();
48 String textCombo = publishFlagBehaviour.getText();
49 String text = null;
50 // default -> delete preference
51 if(textCombo.startsWith(Messages.Preference_Use_Default) && allowOverride){
52 service.remove(pref.getKey());
53 PreferencesUtil.updateDBPreferences();
54 return true;
55 }else if (textCombo.startsWith(Messages.Preference_Use_Default)){
56 text = null;
57 }else{
58 for (PublishEnum display: PublishEnum.values()){
59 if (display.getLabel().equals(textCombo)){
60 text = display.getKey();
61 break;
62 }
63 }
64 }
65 CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DefaultBehaviourForPublishFlag, text);
66 pref.setAllowOverride(allowOverride);
67
68 service.set(pref);
69 PreferencesUtil.updateDBPreferences();
70
71 return true;
72 }
73
74
75
76 @Override
77 public void getValues() {
78 isAdminPreference = true;
79 pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
80 if (pref == null){
81 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DefaultBehaviourForPublishFlag, ((PublishEnum)PreferencePredicate.DefaultBehaviourForPublishFlag.getDefaultValue()).getKey());
82 publishBehaviour = null;
83 allowOverride = pref.isAllowOverride();
84 }
85 else {
86 allowOverride = pref.isAllowOverride();
87 publishBehaviour = pref.getValue() != null? PublishEnum.valueOf(pref.getValue()): null;
88 }
89 }
90
91
92
93
94
95 }