ref #8045: further implementation for default/explicit value selection preference...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / preferencePage / ChecklistEditorGeneralAdminPreference.java
1 /**
2 * Copyright (C) 2014 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.widgets.Composite;
12 import org.eclipse.swt.widgets.Control;
13
14 import eu.etaxonomy.cdm.api.application.ICdmRepository;
15 import eu.etaxonomy.cdm.api.service.IPreferenceService;
16 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
17 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
18 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
19 import eu.etaxonomy.taxeditor.l10n.Messages;
20 import eu.etaxonomy.taxeditor.preference.ChecklistEditorGeneralPreference;
21 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 /**
25 * @author a.oppermann
26 * @date 21.07.2014
27 *
28 */
29 public class ChecklistEditorGeneralAdminPreference extends ChecklistEditorGeneralPreference implements IE4AdminPreferencePage {
30
31 Composite parent;
32
33
34 @Override
35 protected Control createContents(Composite parent) {
36 this.parent = parent;
37 return super.createContents(parent);
38
39 }
40
41 @Override
42 public boolean performOk() {
43 if (!isApply()){
44 return true;
45 }
46 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
47 if (controller == null){
48 return false;
49 }
50 IPreferenceService service = controller.getPreferenceService();
51 CdmPreference pref;
52 if (isEditorActivated == null){
53 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DistributionEditorActivated));
54 }else{
55 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DistributionEditorActivated, Boolean.toString(isEditorActivated));
56 pref.setAllowOverride(allowOverrideActivatedButton.getSelection());
57 service.set(pref);
58 }
59 if(displayArea.equals(Messages.Preference_Use_Default)){
60 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfAreasInDistributionEditor));
61 }else{
62 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfAreasInDistributionEditor, this.displayArea);
63 pref.setAllowOverride(allowOverrideAreaDisplayButton.getSelection());
64 service.set(pref);
65 }
66
67 if (displayStatus.equals(Messages.Preference_Use_Default)){
68 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfStatus));
69 }else{
70 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfStatus, this.displayStatus);
71 pref.setAllowOverride(allowOverrideStatusDisplayButton.getSelection());
72 service.set(pref);
73 }
74
75 if (isShowRank == null){
76 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowRankInDistributionEditor));
77 }else{
78 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.ShowRankInDistributionEditor, Boolean.toString(isShowRank));
79 pref.setAllowOverride(allowOverrideRankButton.getSelection());
80 service.set(pref);
81 }
82 if (orderAreas.equals(Messages.Preference_Use_Default)){
83 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AreasSortedInDistributionEditor));
84 }else{
85 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.AreasSortedInDistributionEditor, this.orderAreas);
86 pref.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
87 service.set(pref);
88 }
89
90 if (ownDescriptionForDistributionEditor == null){
91 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.OwnDescriptionForDistributionEditor));
92 }else{
93 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.OwnDescriptionForDistributionEditor, Boolean.toString(ownDescriptionForDistributionEditor));
94 pref.setAllowOverride(prefOwnDescription.isAllowOverride());
95 service.set(pref);
96 }
97 // if (statusPref != null){
98 // service.set(statusPref);
99 // }
100 // if (areaVocPref != null){
101 // service.set(areaVocPref);
102 // }
103 PreferencesUtil.updateDBPreferences();
104
105 return true;
106 }
107
108 @Override
109 public void getValues() {
110 super.getValues();
111 //distributionEditorPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
112 if (distributionEditorPref != null){
113 isEditorActivated = Boolean.valueOf(distributionEditorPref.getValue());
114 }
115
116
117 isAdminPreference = true;
118
119 if (prefAreaDisplay != null){
120 this.displayArea = prefAreaDisplay.getValue();
121 }else{
122 this.displayArea = Messages.Preference_Use_Default;
123 }
124
125
126 if (prefStatusDisplay != null){
127 this.displayStatus = prefStatusDisplay.getValue();
128 }else{
129 this.displayStatus = Messages.Preference_Use_Default;
130 }
131
132 if (prefAreaSort != null){
133 if (prefAreaSort.getValue() != null){
134 this.orderAreas = prefAreaSort.getValue().toString();
135 }else{
136 this.orderAreas = Messages.Preference_Use_Default;
137 }
138
139 }else{
140 this.orderAreas = Messages.Preference_Use_Default;
141
142 }
143
144
145 if (prefRank != null){
146 this.isShowRank = Boolean.valueOf(prefRank.getValue().toString());
147
148 }else{
149 this.isShowRank = null;
150 }
151
152
153 if (prefOwnDescription != null){
154 this.ownDescriptionForDistributionEditor = Boolean.valueOf(prefOwnDescription.getValue().toString());
155 }else{
156 this.ownDescriptionForDistributionEditor = Boolean.valueOf(PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString());
157 }
158
159 commandHandlerString = "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardAdminHandler";
160 commandHandlerStringStatus = "eu.etaxonomy.taxeditor.store.open.OpenDistributionPerAreaStatusWizardHandler";
161
162 setValid(false);
163 }
164
165
166
167 }