Revision b9801dc0
Added by Katja Luther over 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java | ||
---|---|---|
34 | 34 |
import org.eclipse.swt.widgets.Shell; |
35 | 35 |
import org.eclipse.ui.PlatformUI; |
36 | 36 |
|
37 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
37 | 38 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator; |
38 | 39 |
import eu.etaxonomy.cdm.api.service.IFeatureTreeService; |
40 |
import eu.etaxonomy.cdm.api.service.IPreferenceService; |
|
39 | 41 |
import eu.etaxonomy.cdm.api.service.ITermService; |
40 | 42 |
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl; |
41 | 43 |
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator; |
... | ... | |
48 | 50 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
49 | 51 |
import eu.etaxonomy.cdm.model.common.TermBase; |
50 | 52 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
53 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference; |
|
54 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey; |
|
55 |
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate; |
|
56 |
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject; |
|
51 | 57 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
52 | 58 |
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy; |
53 | 59 |
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy; |
... | ... | |
104 | 110 |
*/ |
105 | 111 |
public static void setPreferredNomenclaturalCode( |
106 | 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 (preferredCode == null){ |
|
118 |
preference = controller.getPreferenceService().find(key); |
|
119 |
int index = StringUtils.lastIndexOf(preference.getValue(), "."); |
|
120 |
UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length())); |
|
121 |
preferredCode = NomenclaturalCode.getByUuid(uuid); |
|
122 |
} else{ |
|
123 |
preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey()); |
|
124 |
controller.getPreferenceService().set(preference); |
|
125 |
} |
|
126 |
|
|
127 |
|
|
107 | 128 |
getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY, |
108 |
getPreferenceKey(preferredCode)); |
|
129 |
getPreferenceKey(preferredCode));
|
|
109 | 130 |
} |
110 | 131 |
|
132 |
public static NomenclaturalCode getPreferredNomenclaturalCode(){ |
|
133 |
return getPreferredNomenclaturalCode(false); |
|
134 |
} |
|
135 |
|
|
111 | 136 |
/** |
112 | 137 |
* <p> |
113 | 138 |
* getPreferredNomenclaturalCode |
... | ... | |
115 | 140 |
* |
116 | 141 |
* @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object. |
117 | 142 |
*/ |
118 |
public static NomenclaturalCode getPreferredNomenclaturalCode() { |
|
119 |
|
|
120 |
for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) { |
|
121 |
String preferredCode = getPreferenceStore().getString( |
|
143 |
public static NomenclaturalCode getPreferredNomenclaturalCode(boolean preConnected) { |
|
144 |
ICdmApplicationConfiguration controller; |
|
145 |
CdmPreference pref = null; |
|
146 |
if (!preConnected){ |
|
147 |
try{ |
|
148 |
controller = CdmStore.getCurrentApplicationConfiguration(); |
|
149 |
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); |
|
150 |
pref = controller.getPreferenceService().find(key); |
|
151 |
}catch(Exception e){ |
|
152 |
e.printStackTrace(); |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
String preferredCode; |
|
157 |
if(pref == null){ |
|
158 |
preferredCode = getPreferenceStore().getString( |
|
122 | 159 |
PREFERRED_NOMENCLATURAL_CODE_KEY); |
160 |
}else{ |
|
161 |
preferredCode = pref.getValue(); |
|
162 |
} |
|
163 |
|
|
164 |
for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) { |
|
165 |
// String preferredCode = getPreferenceStore().getString( |
|
166 |
// PREFERRED_NOMENCLATURAL_CODE_KEY); |
|
123 | 167 |
if (getPreferenceKey(code).equals(preferredCode)) { |
124 | 168 |
return code; |
125 | 169 |
} |
... | ... | |
411 | 455 |
// First time Editor is opened, no nomenclatural code has been set |
412 | 456 |
|
413 | 457 |
|
414 |
if (PreferencesUtil.getPreferredNomenclaturalCode() == null) { |
|
458 |
if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
|
|
415 | 459 |
PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP); |
416 | 460 |
/* |
417 | 461 |
|
Also available in: Unified diff
ref #5969: get the preference NC from db when initialize preference store and save the changes in db