Revision be140ab3
Added by Katja Luther over 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java | ||
---|---|---|
37 | 37 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
38 | 38 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator; |
39 | 39 |
import eu.etaxonomy.cdm.api.service.IFeatureTreeService; |
40 |
import eu.etaxonomy.cdm.api.service.IPreferenceService; |
|
41 | 40 |
import eu.etaxonomy.cdm.api.service.ITermService; |
42 | 41 |
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl; |
43 | 42 |
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator; |
... | ... | |
108 | 107 |
* a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} |
109 | 108 |
* object. |
110 | 109 |
*/ |
111 |
public static void setPreferredNomenclaturalCode( |
|
112 |
NomenclaturalCode preferredCode) { |
|
113 |
ICdmApplicationConfiguration controller; |
|
114 |
controller = CdmStore.getCurrentApplicationConfiguration(); |
|
115 |
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); |
|
116 |
CdmPreference preference = null; |
|
117 |
if (controller == null){ |
|
118 |
return; |
|
119 |
} |
|
120 |
if (preferredCode == null){ |
|
121 |
preference = controller.getPreferenceService().find(key); |
|
122 |
if (preference == null){ |
|
123 |
return; |
|
124 |
} else{ |
|
125 |
int index = StringUtils.lastIndexOf(preference.getValue(), "."); |
|
126 |
UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length())); |
|
127 |
preferredCode = NomenclaturalCode.getByUuid(uuid); |
|
128 |
} |
|
129 |
} else{ |
|
130 |
preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey()); |
|
131 |
controller.getPreferenceService().set(preference); |
|
132 |
} |
|
133 |
|
|
134 |
|
|
135 |
getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY, |
|
136 |
getPreferenceKey(preferredCode)); |
|
110 |
public static NomenclaturalCode setPreferredNomenclaturalCode( |
|
111 |
NomenclaturalCode preferredCode, boolean local) { |
|
112 |
if (local){ |
|
113 |
getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY, |
|
114 |
getPreferenceKey(preferredCode)); |
|
115 |
} |
|
116 |
else{ |
|
117 |
ICdmApplicationConfiguration controller; |
|
118 |
controller = CdmStore.getCurrentApplicationConfiguration(); |
|
119 |
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); |
|
120 |
CdmPreference preference = null; |
|
121 |
if (controller == null){ |
|
122 |
return null; |
|
123 |
} |
|
124 |
if (preferredCode == null){ |
|
125 |
preference = controller.getPreferenceService().find(key); |
|
126 |
if (preference == null){ |
|
127 |
return null; |
|
128 |
} else{ |
|
129 |
int index = StringUtils.lastIndexOf(preference.getValue(), "."); |
|
130 |
UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length())); |
|
131 |
preferredCode = NomenclaturalCode.getByUuid(uuid); |
|
132 |
return preferredCode; |
|
133 |
} |
|
134 |
} else{ |
|
135 |
preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey()); |
|
136 |
controller.getPreferenceService().set(preference); |
|
137 |
|
|
138 |
} |
|
139 |
} |
|
140 |
return preferredCode; |
|
141 |
|
|
142 |
|
|
143 |
|
|
137 | 144 |
} |
138 | 145 |
|
139 | 146 |
public static NomenclaturalCode getPreferredNomenclaturalCode(){ |
140 |
return getPreferredNomenclaturalCode(false); |
|
147 |
if (getPreferenceStore().getBoolean(OVERRIDE_NOMENCLATURAL_CODE_KEY)) { |
|
148 |
return getPreferredNomenclaturalCode(true); |
|
149 |
} else{ |
|
150 |
return getPreferredNomenclaturalCode(false); |
|
151 |
} |
|
141 | 152 |
} |
142 |
|
|
153 |
|
|
143 | 154 |
/** |
144 | 155 |
* <p> |
145 | 156 |
* getPreferredNomenclaturalCode |
... | ... | |
147 | 158 |
* |
148 | 159 |
* @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object. |
149 | 160 |
*/ |
150 |
public static NomenclaturalCode getPreferredNomenclaturalCode(boolean preConnected) {
|
|
161 |
public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
|
|
151 | 162 |
ICdmApplicationConfiguration controller; |
152 | 163 |
CdmPreference pref = null; |
153 |
if (!preConnected){
|
|
164 |
if (!useLocal){
|
|
154 | 165 |
try{ |
155 | 166 |
controller = CdmStore.getCurrentApplicationConfiguration(); |
156 | 167 |
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); |
... | ... | |
159 | 170 |
e.printStackTrace(); |
160 | 171 |
} |
161 | 172 |
} |
162 |
|
|
173 |
|
|
163 | 174 |
String preferredCode; |
164 | 175 |
if(pref == null){ |
165 | 176 |
preferredCode = getPreferenceStore().getString( |
... | ... | |
167 | 178 |
}else{ |
168 | 179 |
preferredCode = pref.getValue(); |
169 | 180 |
} |
170 |
|
|
181 |
|
|
171 | 182 |
for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) { |
172 |
// String preferredCode = getPreferenceStore().getString( |
|
173 |
// PREFERRED_NOMENCLATURAL_CODE_KEY); |
|
174 | 183 |
if (getPreferenceKey(code).equals(preferredCode)) { |
175 | 184 |
return code; |
176 | 185 |
} |
... | ... | |
475 | 484 |
|
476 | 485 |
|
477 | 486 |
if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) { |
478 |
PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP); |
|
487 |
PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP, true);
|
|
479 | 488 |
/* |
480 | 489 |
|
481 | 490 |
StoreUtil.info("No nomencatural code set."); |
Also available in: Unified diff
ref #5971: add an admin page to the prefs and add cdm pref nomenclatural code