ref #8045: further implementation for default/explicit value selection preference...
[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 String text = publishFlagBehaviour.getText();
44 text = text.replace(Messages.Preference_Use_Default, "");
45 for (PublishEnum display: PublishEnum.values()){
46 if (display.getLabel().equals(text)){
47 text = display.getKey();
48 break;
49 }
50 }
51 CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DefaultBehaviourForPublishFlag, text);
52 pref.setAllowOverride(allowOverride);
53
54 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
55 if (controller == null){
56 return false;
57 }
58 IPreferenceService service = controller.getPreferenceService();
59 service.set(pref);
60 PreferencesUtil.updateDBPreferences();
61
62 return true;
63 }
64
65
66
67 @Override
68 public void getValues() {
69 isAdminPreference = true;
70 pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
71 if (pref == null){
72 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DefaultBehaviourForPublishFlag, ((PublishEnum)PreferencePredicate.DefaultBehaviourForPublishFlag.getDefaultValue()).getKey());
73 }
74 allowOverride = pref.isAllowOverride();
75 publishBehaviour = PublishEnum.valueOf(pref.getValue());
76 }
77
78
79
80
81
82 }