import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.StringTokenizer;
import java.util.UUID;
import eu.etaxonomy.cdm.model.term.ISimpleTerm;
import eu.etaxonomy.cdm.model.term.TermBase;
import eu.etaxonomy.cdm.model.term.TermTree;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
import eu.etaxonomy.cdm.model.term.VocabularyEnum;
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.FieldMatcher;
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.MatchException;
import eu.etaxonomy.cdm.strategy.match.MatchMode;
+import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
public static final String SUBJECT_DELIM = "/";
- private static TermTree preferredNameFeatureTree;
+ private static TermTree<Feature> preferredNameFeatureTree;
+
+ private static TermTree<Feature> preferredTaxonFeatureTree;
private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
if (value != null){
getPreferenceStore().setValue(prefKey(name), value);
}else{
- getPreferenceStore().setToDefault(name);
+ getPreferenceStore().setToDefault(prefKey(name));
}
}
CdmPreference pref = null;
//
pref = cache.get(name);
- if (pref == null ){
- //get default value for Predicate
- IPreferencePredicate pred = PreferencePredicate.getByKey(name);
- if (pred != null){
- if (pred.getDefaultValue() != null){
- pref = CdmPreference.NewTaxEditorInstance(pred, pred.getDefaultValue().toString());
- }else{
- pref = CdmPreference.NewTaxEditorInstance(pred, null);
- }
- pref.setAllowOverride(true);
- }
- }
+// if (pref == null ){
+// //get default value for Predicate
+// IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+// if (pred != null){
+// if (pred.getDefaultValue() != null){
+// pref = CdmPreference.NewTaxEditorInstance(pred, pred.getDefaultValue().toString());
+// }else{
+// pref = CdmPreference.NewTaxEditorInstance(pred, null);
+// }
+// pref.setAllowOverride(true);
+// }
+// }
return pref;
}
String preferredCode;
if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){
preferredCode = getStringValue(
- PreferencePredicate.NomenclaturalCode.getKey(), true);
+ PreferencePredicate.NomenclaturalCode.getKey());
}else{
preferredCode = pref.getValue();
public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
- if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) {
+ if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode) || code.getKey().equals(preferenceKeyNomenclaturalCode)) {
return code;
}
}
}
TermTree tree = CdmStore.getService(
ITermTreeService.class).load(UUID.fromString(uuidString));
- if (tree.getId() == 0) {
+
+ if (tree == null || tree.getId() == 0) {
return null;
}
return tree;
}
public static void setSortNodes(NavigatorOrderEnum nodesOrder) {
- setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key);
+ if (nodesOrder == null){
+ setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), null);
+ }else{
+ setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key);
+ }
}
config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
config.setHybridActivated(getValue(sectionMap,"hybrid"));
config.setNameApprobiationActivated(getValue(sectionMap, "nameApproviation"));
+ }else {
+ return null;
}
return config;
}
}
public static List<UUID> createUUIDListFromStringPref(String prefKey) {
+ if (prefKey == null){
+ return null;
+ }
String prefValue = PreferencesUtil.getStringValue(prefKey);
if (prefValue == null){
return null;
/**
*
*/
- public static TermTree getPreferredFeatureTreeForNameDescription() {
- if(preferredNameFeatureTree != null){
+ public static TermTree getPreferredFeatureTreeForNameDescription(boolean createNew) {
+ if(preferredNameFeatureTree != null && !createNew){
return preferredNameFeatureTree;
}
createPreferredFeatureTreeForNameDescription();
CdmPreferenceCache cache = CdmPreferenceCache.instance();
CdmPreference pref = cache.get(PreferencePredicate.NameFeatures.getKey());
- List<Feature> terms;
+ List<Feature> terms = new ArrayList();
boolean override = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NameFeatures.getKey()));
- if (pref != null ){
- List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(pref.getValue());
+
+ List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.NameFeatures.getKey());
+ if (uuids != null && !uuids.isEmpty()){
terms = CdmStore.getTermManager().getTerms(uuids, Feature.class);
- }else if (override){
- terms = CdmStore.getTermManager().getPreferredTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid()));
- }else{
- terms = new ArrayList();
- terms.addAll(TermStore.getTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid()), null));
+ }
+
+
+
+
+ if (terms.isEmpty()){
+ terms.addAll(TermStore.getTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid()), null));
+
}
terms.remove(Feature.PROTOLOGUE());
- preferredNameFeatureTree = TermTree.NewInstance(terms);
+ if (terms.isEmpty()){
+ preferredNameFeatureTree = TermEditorInput.getDefaultNameFeatureTree();
+ }else{
+ preferredNameFeatureTree = TermTree.NewInstance(terms);
+ }
}
}
+ /**
+ * @return
+ */
+ public static TermTree<?> getPreferredFeatureTreeForTaxonDescription(boolean createNew) {
+ if(preferredTaxonFeatureTree != null && !createNew){
+ return preferredTaxonFeatureTree;
+ }
+ createPreferredFeatureTreeForTaxonDescription();
+ return preferredTaxonFeatureTree;
+
+ }
+
+ public static void createPreferredFeatureTreeForTaxonDescription() {
+
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
+ CdmPreference pref = cache.get(PreferencePredicate.TaxonFeatures.getKey());
+ List<Feature> terms;
+ boolean override = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.TaxonFeatures.getKey()));
+ List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.TaxonFeatures.getKey());
+ terms = CdmStore.getTermManager().getTerms(uuids, Feature.class);
+ if (terms == null || terms.isEmpty()){
+ terms= CdmStore.getTermManager().getPreferredTerms(TermType.Feature);
+ TermVocabulary nameVocabulary = CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid());
+ Set<Feature> nameFeature = nameVocabulary.getTerms();
+ terms.removeAll(nameFeature);
+
+ }
+
+ if (terms.isEmpty()){
+ preferredTaxonFeatureTree = TermEditorInput.getDefaultFeatureTree();
+ }else{
+ preferredTaxonFeatureTree = TermTree.NewInstance(terms);
+ }
+
+
+ }
+
+
}