ref #8648: default handling in name details preference - continue
[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.cdm.model.metadata.TermComboEnum;
20 import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
21 import eu.etaxonomy.cdm.model.metadata.TermOrder;
22 import eu.etaxonomy.taxeditor.preference.ChecklistEditorGeneralPreference;
23 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25
26 /**
27 * @author a.oppermann
28 * @date 21.07.2014
29 *
30 */
31 public class ChecklistEditorGeneralAdminPreference extends ChecklistEditorGeneralPreference implements IE4AdminPreferencePage {
32
33 Composite parent;
34
35
36 @Override
37 protected Control createContents(Composite parent) {
38 this.parent = parent;
39 return super.createContents(parent);
40
41 }
42
43 @Override
44 public boolean performOk() {
45 if (!isApply()){
46 return true;
47 }
48 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
49 if (controller == null){
50 return false;
51 }
52 IPreferenceService service = controller.getPreferenceService();
53 CdmPreference pref;
54 if (isEditorActivated == null && allowOverrideActivatedButton.getSelection()){
55 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DistributionEditorActivated));
56 }else{
57 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DistributionEditorActivated, isEditorActivated != null? Boolean.toString(isEditorActivated): null);
58 pref.setAllowOverride(allowOverrideActivatedButton.getSelection());
59 service.set(pref);
60 }
61 if(displayArea == null && allowOverrideAreaDisplayButton.getSelection()){
62 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfAreasInDistributionEditor));
63 }else{
64 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfAreasInDistributionEditor, displayArea != null ?this.displayArea.getKey(): null);
65 pref.setAllowOverride(allowOverrideAreaDisplayButton.getSelection());
66 service.set(pref);
67 }
68
69 if (displayStatus == null && allowOverrideStatusDisplayButton.getSelection()){
70 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfStatus));
71 }else{
72 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfStatus, displayStatus != null? this.displayStatus.getKey(): null);
73 pref.setAllowOverride(allowOverrideStatusDisplayButton.getSelection());
74 service.set(pref);
75 }
76
77 if (isShowRank == null && allowOverrideRankButton.getSelection()){
78 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowRankInDistributionEditor));
79 }else{
80 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.ShowRankInDistributionEditor, isShowRank != null? Boolean.toString(isShowRank): null);
81 pref.setAllowOverride(allowOverrideRankButton.getSelection());
82 service.set(pref);
83 }
84 if (orderAreas == null && allowOverrideOrderAreasButton.getSelection()){
85 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AreasSortedInDistributionEditor));
86 }else{
87 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.AreasSortedInDistributionEditor, orderAreas != null? this.orderAreas.getKey(): null);
88 pref.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
89 service.set(pref);
90 }
91
92 if (displayStatusCombo == null && allowOverrideStatusDisplayInComboButton.getSelection()){
93 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfStatusInCombo));
94 }else{
95 pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfStatusInCombo, displayStatusCombo != null? displayStatusCombo.getKey(): null);
96 if (prefStatusDisplayInCombo == null){
97 prefStatusDisplayInCombo = pref;
98 }
99 pref.setAllowOverride(prefStatusDisplayInCombo.isAllowOverride());
100 service.set(pref);
101 }
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 = distributionEditorPref.getValue() != null? Boolean.valueOf(distributionEditorPref.getValue()): null;
114 }else{
115 isEditorActivated = null;
116 }
117
118
119 isAdminPreference = true;
120
121 if (prefAreaDisplay != null){
122 this.displayArea = prefAreaDisplay.getValue()!= null?TermDisplayEnum.byKey(prefAreaDisplay.getValue()): null;
123 }else{
124 this.displayArea = null;
125 }
126
127
128 if (prefStatusDisplay != null){
129 this.displayStatus = prefStatusDisplay.getValue() != null? TermDisplayEnum.byKey(prefStatusDisplay.getValue()): null;
130 }else{
131 this.displayStatus = null;
132 }
133
134 if (prefStatusDisplayInCombo != null){
135 this.displayStatusCombo = prefStatusDisplayInCombo.getValue() != null? TermComboEnum.byKey(prefStatusDisplayInCombo.getValue()): null;
136 }else{
137 this.displayStatusCombo = null;
138 }
139
140
141 if (prefAreaSort != null){
142 if (prefAreaSort.getValue() != null){
143 this.orderAreas = prefAreaSort.getValue() != null? TermOrder.valueOf(prefAreaSort.getValue().toString()): null;
144 }else{
145 this.orderAreas = null;
146 }
147
148 }else{
149 this.orderAreas = null;
150
151 }
152
153
154 if (prefRank != null){
155 this.isShowRank = prefRank.getValue() != null?Boolean.valueOf(prefRank.getValue().toString()): null;
156
157 }else{
158 this.isShowRank = null;
159 }
160
161
162 if (prefOwnDescription != null){
163 this.ownDescriptionForDistributionEditor = prefOwnDescription.getValue() != null? Boolean.valueOf(prefOwnDescription.getValue().toString()): null;
164 }else{
165 this.ownDescriptionForDistributionEditor = null;
166 }
167
168
169
170 setValid(false);
171 }
172
173
174
175 }