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 org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
import eu.etaxonomy.cdm.api.application.ICdmRepository;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
-import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.api.service.ITermTreeService;
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.model.common.ICdmBase;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
import eu.etaxonomy.cdm.model.metadata.IPreferencePredicate;
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
+import eu.etaxonomy.cdm.model.metadata.TermOrder;
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
-import eu.etaxonomy.cdm.model.term.FeatureTree;
import eu.etaxonomy.cdm.model.term.IDefinedTerm;
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;
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.TermStore;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
* @created 05.12.2008
*/
public class PreferencesUtil implements IPreferenceKeys {
+ private final static String EDITOR_PREFERENCES_NODE = "eu.etaxonomy.taxeditor";
- public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
+ public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
- public static final String P2_REPOSITORIES_DELIM = ",";
- public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
+ public static final String P2_REPOSITORIES_DELIM = ",";
+ public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
+ public static final String SUBJECT_DELIM = "/";
- private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
+ private static TermTree<Feature> preferredNameFeatureTree;
- public static IPreferenceStore getPreferenceStore() {
- return TaxeditorStorePlugin.getDefault().getPreferenceStore();
- }
+ private static TermTree<Feature> preferredTaxonFeatureTree;
- private static String prefKey(String name) {
- return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
- }
+ private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
- public static String prefOverrideKey(String name) {
+ public static IPreferenceStore getPreferenceStore() {
+ return TaxeditorStorePlugin.getDefault().getPreferenceStore();
+ }
+
+ public static String[] extractSubjectParts(String subject){
+ String[] result = subject.split("/");
+ return result;
+ }
+
+ public static IEclipsePreferences getEditorPreferences(){
+ return ConfigurationScope.INSTANCE.getNode(EDITOR_PREFERENCES_NODE);
+ }
+
+ public static String getPreferenceValue(PrefKey prefKey){
+ try {
+ if(getEditorPreferences().nodeExists(prefKey.getPredicate())){
+ Preferences predicateNode = getEditorPreferences().node(prefKey.getPredicate());
+ String[] splittedSubject = extractSubjectParts(prefKey.getSubject());
+ String value = predicateNode.get(splittedSubject[splittedSubject.length-1], PreferencePredicate.getByKey(prefKey.getPredicate()).getDefaultValue() != null? PreferencePredicate.getByKey(prefKey.getPredicate()).getDefaultValue().toString(): "");
+ int index = splittedSubject.length -2;
+ while (value != null && index >= 0){
+ value = predicateNode.get(splittedSubject[index], prefKey.getPredicate());
+ index--;
+ }
+ return value;
+ }
+
+ } catch (BackingStoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static List<CdmPreference> getPreference(PreferencePredicate prefPredicate){
+ try {
+ List<CdmPreference> prefs = new ArrayList();
+ CdmPreference pref;
+ PreferenceSubject subject;
+ if(getEditorPreferences().nodeExists(prefPredicate.getKey())){
+ Preferences predicateNode = getEditorPreferences().node(prefPredicate.getKey());
+ for (String childName: predicateNode.childrenNames()){
+ Preferences child = predicateNode.node(childName);
+ String subjectString = "";
+ subjectString = createSubjectStringForChildNodes(childName, child);
+ String value = child.get(subjectString, "");
+ subject = PreferenceSubject.NewInstance(subjectString);
+ pref = CdmPreference.NewInstance(subject, prefPredicate, value);
+ prefs.add(pref);
+ }
+
+ }
+
+ } catch (BackingStoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * @param childName
+ * @param child
+ */
+ private static String createSubjectStringForChildNodes(String subject, Preferences parent) {
+ try {
+ for (String childName: parent.childrenNames()){
+ subject = childName+SUBJECT_DELIM+subject;
+ Preferences child = parent.node(childName);
+ createSubjectStringForChildNodes(subject, child);
+ }
+ } catch (BackingStoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return subject;
+
+ }
+
+ private static String prefKey(String name) {
+ return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
+ }
+
+ public static String prefOverrideKey(String name) {
return name + "_OVERRIDE_";
}
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;
}
}
public static boolean getBooleanValue(String name) {
- return getBooleanValue(name, false);
+ Boolean result = getBooleanValue(name, false);
+ if (result == null){
+ return false;
+ }else{
+ return result;
+ }
+
}
- public static boolean getBooleanValue(String name, boolean local) {
+ public static Boolean getBooleanValue(String name, boolean local) {
if (CdmStore.isActive()){
CdmPreference pref = getDBPreferenceValue(name);
if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
String dbSpecific = prefKey(name);
- return getPreferenceStore().getBoolean(dbSpecific);
+ if (getPreferenceStore().contains(dbSpecific)){
+ return getPreferenceStore().getBoolean(dbSpecific);
+ }else{
+ return null;
+ }
}else{
return Boolean.valueOf(pref.getValue());
}
return result;
}
- public static CdmPreference setPreferredNomenclaturalCode(
- String preferenceValue, boolean local) {
- if (local){
- setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
- preferenceValue);
- }
- else{
- ICdmRepository controller;
- controller = CdmStore.getCurrentApplicationConfiguration();
- if (controller == null){
+ public static CdmPreference setPreferredNomenclaturalCode(
+ String preferenceValue, boolean local) {
+ if (local){
+ setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
+ preferenceValue);
+ }
+ else{
+ ICdmRepository controller;
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ if (controller == null){
return null;
}
- PrefKey key = null;
- try{
- key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
- }catch (Exception e){
- System.out.println(e.getStackTrace());
- }
- CdmPreference preference = null;
-
- if (preferenceValue == null){
- preference = controller.getPreferenceService().find(key);
- if (preference == null){
- return null;
- } else{
- setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
- preference.getValue());
-
- return preference;
- }
- } else{
- preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue);
- controller.getPreferenceService().set(preference);
-
- }
- }
+ PrefKey key = null;
+ try{
+ key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+ }catch (Exception e){
+ System.out.println(e.getStackTrace());
+ }
+ CdmPreference preference = null;
+
+ if (preferenceValue == null){
+ preference = controller.getPreferenceService().find(key);
+ if (preference == null){
+ return null;
+ } else{
+ setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
+ preference.getValue());
+
+ return preference;
+ }
+ } else{
+ preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue);
+ controller.getPreferenceService().set(preference);
+
+ }
+ }
return null;
- }
+ }
public static void setPreferredNomenclaturalCode(
CdmPreference preference) {
if (controller == null){
return;
}
- PrefKey key = null;
- try{
- key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
- }catch (Exception e){
- System.out.println(e.getStackTrace());
- }
- controller.getPreferenceService().set(preference);
+ if (preference == null){
+ PrefKey key = null;
+ try{
+ key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+ }catch (Exception e){
+ System.out.println(e.getStackTrace());
+ }
+ controller.getPreferenceService().remove(key);
+ }else{
+ controller.getPreferenceService().set(preference);
+ }
}
- public static NomenclaturalCode getPreferredNomenclaturalCode() {
+ public static NomenclaturalCode getPreferredNomenclaturalCode() {
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
+ CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
- String preferredCode;
- if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){
- preferredCode = getStringValue(
- PreferencePredicate.NomenclaturalCode.getKey(), true);
+ String preferredCode;
+ if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){
+ preferredCode = getStringValue(
+ PreferencePredicate.NomenclaturalCode.getKey());
- }else{
- preferredCode = pref.getValue();
- }
- if (StringUtils.isBlank(preferredCode)){
- preferredCode = getPreferenceKey((NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue());
- }
+ }else{
+ preferredCode = pref.getValue();
+ }
+ if (StringUtils.isBlank(preferredCode)){
+ preferredCode = getPreferenceKey((NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue());
+ }
- return getPreferredNomenclaturalCode(preferredCode);
+ return getPreferredNomenclaturalCode(preferredCode);
- }
+ }
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;
}
}
return null;
}
- public static boolean isShowTaxonAssociations(){
+ public static boolean isShowTaxonAssociations(){
boolean result = getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
return result;
}
- public static boolean isShowLifeForm(){
- boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
- return result;
+ public static boolean isShowLifeForm(){
+ boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
+ return result;
}
- public static boolean isDeterminationOnlyForFieldUnits(){
- boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
+ public static boolean isDeterminationOnlyForFieldUnits(){
+ boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
return result;
}
- public static boolean isCollectingAreaInGeneralSection(){
- boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
+ public static boolean isCollectingAreaInGeneralSection(){
+ boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
return result;
- }
+ }
- public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
+ public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
ICdmRepository controller;
CdmPreference pref = null;
}
- public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate predicate){
+ public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate predicate){
ICdmRepository controller;
List<CdmPreference> prefs = null;
}
- public static void setPreferencesToDB(CdmPreference preference, boolean setDefault){
+ public static void setPreferencesToDB(CdmPreference preference, boolean setDefault){
ICdmRepository controller;
-
-
try{
if(CdmStore.isActive()){
controller = CdmStore.getCurrentApplicationConfiguration();
}
- public static CdmPreference getPreferenceFromDB(PrefKey key){
+ public static CdmPreference getPreferenceFromDB(PrefKey key){
ICdmRepository controller;
CdmPreference pref = null;
try{
if(CdmStore.isActive()){
controller = CdmStore.getCurrentApplicationConfiguration();
- controller.getPreferenceService().set(preference);
+ if (preference.getValue() == null && preference.isAllowOverride()){
+ controller.getPreferenceService().remove(preference.getKey());
+ }else{
+ controller.getPreferenceService().set(preference);
+ }
CdmPreferenceCache.instance().put(preference);
}
}catch(Exception e){
}
- public static String getPreferredDefaultLangugae(){
- String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR);
- if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
- return preferredLanguage;
- }
- return null;
- }
+ public static String getPreferredDefaultLangugae(){
+ String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR);
+ if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
+ return preferredLanguage;
+ }
+ return null;
+ }
- public static boolean isShowMediaPreview(){
+ public static boolean isShowMediaPreview(){
boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW);
return isShowMediaPreview;
}
- /**
- * Get the match strategy for the given class that was stored in preferences
- * or the default strategy if it was not stored in preferences
- *
- * @param clazz
- * a {@link java.lang.Class} object.
- * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- */
- public static IMatchStrategy getMatchStrategy(Class<?> clazz) {
- String className = clazz.getName();
- if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) {
- IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
-
- //TODO CacheMatchers (or multiple field matchers in future) are missing here
- for (FieldMatcher fieldMatcher : matchStrategy.getMatching().getFieldMatchers(false)) {
- String fieldName = fieldMatcher.getPropertyName();
- String matchModeName = getStringValue(
- getMatchStrategyFieldName(className, fieldName));
- MatchMode matchMode = MatchMode.valueOf(matchModeName);
- try {
- matchStrategy.setMatchMode(fieldName, matchMode);
- } catch (MatchException e) {
- MessagingUtils.error(PreferencesUtil.class, e);
- throw new RuntimeException(e);
- }
- }
-
- return matchStrategy;
- }
- return getDefaultMatchStrategy(clazz);
- }
-
- /**
- * Stores a matchStrategy into the preference store.
- *
- * @param matchStrategy
- * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
- * object.
- */
- public static void setMatchStrategy(IMatchStrategy matchStrategy) {
- String className = "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use
- setBooleanValue(MATCH_STRATEGY_PREFIX + className, true);
-
- List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
-
- for (FieldMatcher fieldMatcher : fieldMatchers) {
- String fieldName = fieldMatcher.getPropertyName();
- setStringValue(
- getMatchStrategyFieldName(className, fieldName),
- fieldMatcher.getMatchMode().name());
- }
- }
-
- /**
- * Helper method to create the preference property for a match field.
- *
- * @param className
- * @param fieldName
- * @return
- */
- private static String getMatchStrategyFieldName(String className,
- String fieldName) {
- return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
- }
-
- /**
- * Returns the default match strategy for a given class.
- *
- * @param clazz
- * a {@link java.lang.Class} object.
- * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- */
- public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
- return DefaultMatchStrategy.NewInstance(clazz);
- }
-
- public static String getDateFormatPattern() {
- // TODO make this configurable in properties
- String pattern = "Y-M-d H:m";
- return pattern;
- }
-
- public static <T extends TermBase> void addTermToPreferredTerms(T term) {
-
- // VocabularyEnum vocabulary =
- // VocabularyEnum.getVocabularyEnum(term.getClass());
- //
- // getPreferenceStore().setValue(getPreferenceKey(term),
- // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
- //
- // firePreferencesChanged(term.getClass());
- }
-
- /**
- * Construct a unique key using the CdmBase object's uuid
- *
- * @param cdmBase
- * @return
- */
- private static String getPreferenceKey(ICdmBase cdmBase) {
- cdmBase = HibernateProxyHelper.deproxy(cdmBase);
-
- String key = cdmBase.getClass().getName().concat(".")
- .concat(cdmBase.getUuid().toString());
- if (key.contains("javassist")) {
- MessagingUtils.info("proxy");
- }
- return key;
- }
-
- /**
- * Construct a unique key using the CdmBase object's uuid
- *
- * @param cdmBase
- * @return
- */
- public static String getPreferenceKey(ISimpleTerm simpleTerm) {
- simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
- String key = simpleTerm.getClass().getName().concat(".")
- .concat(simpleTerm.getUuid().toString());
- if (key.contains("javassist")) {
- MessagingUtils.warn(PreferencesUtil.class,
- "Trying to persist a preference based on a proxy class.");
- }
- return key;
- }
-
-
-
- /**
- * Construct a unique key using the CdmBase object's uuid
- *
- * @param cdmBase
- * @return
- */
- public static String getPreferenceKey(IDefinedTerm definedTerm) {
- definedTerm = HibernateProxyHelper.deproxy(definedTerm);
- String key = definedTerm.getClass().getName().concat(".")
- .concat(definedTerm.getUuid().toString());
- if (key.contains("javassist")) {
- MessagingUtils.warn(PreferencesUtil.class,
- "Trying to persist a preference based on a proxy class.");
- }
- return key;
- }
-
- /**
- * Retrieves search preferences from the preference store
- *
- * @return an {@link ITaxonServiceConfigurator} to pass to search methods
- */
- public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
- IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
-
- configurator.setDoTaxa(getBooleanValue(
- TAXON_SERVICE_CONFIGURATOR_TAXA));
- configurator.setDoSynonyms(getBooleanValue(
- TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
- configurator.setDoNamesWithoutTaxa(getBooleanValue(
- TAXON_SERVICE_CONFIGURATOR_NAMES));
- configurator.setDoTaxaByCommonNames(getBooleanValue(
- TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
- //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
-
- return configurator;
- }
-
- /**
- * create new preferences, setting all search options to true
- *
- * @return a
- * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
- * object.
- */
- public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
- IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
-
- configurator.setDoTaxa(true);
- configurator.setDoSynonyms(true);
- configurator.setDoNamesWithoutTaxa(true);
- configurator.setDoTaxaByCommonNames(true);
-
- configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
- "name", "name.$", "relationsFromThisTaxon.$"));
-
- configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
- "name", "name.$", "synonyms.relatedTo.*"));
-
- // DEFAULT VALUES
- // match mode is a simple like, actually all other match modes are kind
- // of bogus
- configurator
- .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
- // we set page number and size here as this should always be unlimited
- configurator.setPageNumber(0);
- // TODO currently limit results to 10000
- configurator.setPageSize(10000);
- //setSearchConfigurator(configurator) ;
- return configurator;
- }
-
- /**
- * Store search preferences
- *
- * @param configurator
- * a
- * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
- * object.
- */
- public static void setSearchConfigurator(
- IFindTaxaAndNamesConfigurator configurator) {
- getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA,
- configurator.isDoTaxa());
- getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
- configurator.isDoSynonyms());
- getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES,
- configurator.isDoNamesWithoutTaxa());
- getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
- configurator.isDoTaxaByCommonNames());
- }
-
- public static void firePreferencesChanged(Class clazz) {
- getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
- null, clazz);
- }
-
- public static String createPreferenceString(String property){
- return prefKey(property);
-
- }
- public static String createOverridePreferenceString(String property){
- return prefOverrideKey(property);
-
- }
-
- /**
- * Set default values for preferences
- */
- public static void setDefaults() {
- getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
- getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
- true);
- getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT),
- "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
- //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
- getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP), false);
- getPreferenceStore().setDefault(createPreferenceString(OPENURL_ACCESS_POINT),
- "http://www.biodiversitylibrary.org/openurl");
- getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_WIDTH), "1000");
- getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_HEIGHT), "1000");
- getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
- getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, true);
- getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_NAMES, true);
- getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, true);
-
- //Distribution Editor:
-// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DistributionEditorActivated.getKey()), Boolean.valueOf(PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString()));
-// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString());
-// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfStatus.getKey()), PreferencePredicate.DisplayOfStatus.getDefaultValue().toString());
-
-
- //Name Details
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
-
- //Navigator preferences
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), NavigatorOrderEnum.RankAndNameOrder.getKey());
-
- //getPreferenceStore().setDefault(createPreferenceString(Prefe), true);
-
- getPreferenceStore().setDefault(createPreferenceString(SHOW_ADVANCED_MEDIA_SECTION), false);
+ /**
+ * Get the match strategy for the given class that was stored in preferences
+ * or the default strategy if it was not stored in preferences
+ *
+ * @param clazz
+ * a {@link java.lang.Class} object.
+ * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
+ */
+ public static IMatchStrategy getMatchStrategy(Class<?> clazz) {
+ String className = clazz.getName();
+ if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) {
+ IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
+
+ //TODO CacheMatchers (or multiple field matchers in future) are missing here
+ for (FieldMatcher fieldMatcher : matchStrategy.getMatching().getFieldMatchers(false)) {
+ String fieldName = fieldMatcher.getPropertyName();
+ String matchModeName = getStringValue(
+ getMatchStrategyFieldName(className, fieldName));
+ MatchMode matchMode = MatchMode.valueOf(matchModeName);
+ try {
+ matchStrategy.setMatchMode(fieldName, matchMode);
+ } catch (MatchException e) {
+ MessagingUtils.error(PreferencesUtil.class, e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ return matchStrategy;
+ }
+ return getDefaultMatchStrategy(clazz);
+ }
+
+ /**
+ * Stores a matchStrategy into the preference store.
+ *
+ * @param matchStrategy
+ * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
+ * object.
+ */
+ public static void setMatchStrategy(IMatchStrategy matchStrategy) {
+ String className = "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use
+ setBooleanValue(MATCH_STRATEGY_PREFIX + className, true);
+
+ List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
+
+ for (FieldMatcher fieldMatcher : fieldMatchers) {
+ String fieldName = fieldMatcher.getPropertyName();
+ setStringValue(
+ getMatchStrategyFieldName(className, fieldName),
+ fieldMatcher.getMatchMode().name());
+ }
+ }
+
+ /**
+ * Helper method to create the preference property for a match field.
+ *
+ * @param className
+ * @param fieldName
+ * @return
+ */
+ private static String getMatchStrategyFieldName(String className,
+ String fieldName) {
+ return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
+ }
+
+ /**
+ * Returns the default match strategy for a given class.
+ *
+ * @param clazz
+ * a {@link java.lang.Class} object.
+ * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
+ */
+ public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
+ return DefaultMatchStrategy.NewInstance(clazz);
+ }
+
+ public static String getDateFormatPattern() {
+ // TODO make this configurable in properties
+ String pattern = "Y-M-d H:m";
+ return pattern;
+ }
+
+ public static <T extends TermBase> void addTermToPreferredTerms(T term) {
+
+ // VocabularyEnum vocabulary =
+ // VocabularyEnum.getVocabularyEnum(term.getClass());
+ //
+ // getPreferenceStore().setValue(getPreferenceKey(term),
+ // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
+ //
+ // firePreferencesChanged(term.getClass());
+ }
+
+ /**
+ * Construct a unique key using the CdmBase object's uuid
+ *
+ * @param cdmBase
+ * @return
+ */
+ private static String getPreferenceKey(ICdmBase cdmBase) {
+ cdmBase = HibernateProxyHelper.deproxy(cdmBase);
+
+ String key = cdmBase.getClass().getName().concat(".")
+ .concat(cdmBase.getUuid().toString());
+ if (key.contains("javassist")) {
+ MessagingUtils.info("proxy");
+ }
+ return key;
+ }
+
+ /**
+ * Construct a unique key using the CdmBase object's uuid
+ *
+ * @param cdmBase
+ * @return
+ */
+ public static String getPreferenceKey(ISimpleTerm simpleTerm) {
+ simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
+ String key = simpleTerm.getClass().getName().concat(".")
+ .concat(simpleTerm.getUuid().toString());
+ if (key.contains("javassist")) {
+ MessagingUtils.warn(PreferencesUtil.class,
+ "Trying to persist a preference based on a proxy class.");
+ }
+ return key;
+ }
+
+
+
+ /**
+ * Construct a unique key using the CdmBase object's uuid
+ *
+ * @param cdmBase
+ * @return
+ */
+ public static String getPreferenceKey(IDefinedTerm definedTerm) {
+ definedTerm = HibernateProxyHelper.deproxy(definedTerm);
+ String key = definedTerm.getClass().getName().concat(".")
+ .concat(definedTerm.getUuid().toString());
+ if (key.contains("javassist")) {
+ MessagingUtils.warn(PreferencesUtil.class,
+ "Trying to persist a preference based on a proxy class.");
+ }
+ return key;
+ }
+
+ /**
+ * Retrieves search preferences from the preference store
+ *
+ * @return an {@link ITaxonServiceConfigurator} to pass to search methods
+ */
+ public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
+ IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
+
+ configurator.setDoTaxa(getBooleanValue(
+ TAXON_SERVICE_CONFIGURATOR_TAXA));
+ configurator.setDoSynonyms(getBooleanValue(
+ TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
+ configurator.setDoNamesWithoutTaxa(getBooleanValue(
+ TAXON_SERVICE_CONFIGURATOR_NAMES));
+ configurator.setDoTaxaByCommonNames(getBooleanValue(
+ TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
+ //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
+
+ return configurator;
+ }
+
+ /**
+ * create new preferences, setting all search options to true
+ *
+ * @return a
+ * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
+ * object.
+ */
+ public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
+ IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
+
+ configurator.setDoTaxa(true);
+ configurator.setDoSynonyms(true);
+ configurator.setDoNamesWithoutTaxa(true);
+ configurator.setDoTaxaByCommonNames(true);
+
+ configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
+ "name", "name.$", "relationsFromThisTaxon.$"));
+
+ configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
+ "name", "name.$", "synonyms.relatedTo.*"));
+
+ // DEFAULT VALUES
+ // match mode is a simple like, actually all other match modes are kind
+ // of bogus
+ configurator
+ .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
+ // we set page number and size here as this should always be unlimited
+ configurator.setPageNumber(0);
+ // TODO currently limit results to 10000
+ configurator.setPageSize(10000);
+ //setSearchConfigurator(configurator) ;
+ return configurator;
+ }
+
+ /**
+ * Store search preferences
+ *
+ * @param configurator
+ * a
+ * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
+ * object.
+ */
+ public static void setSearchConfigurator(
+ IFindTaxaAndNamesConfigurator configurator) {
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA,
+ configurator.isDoTaxa());
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
+ configurator.isDoSynonyms());
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES,
+ configurator.isDoNamesWithoutTaxa());
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
+ configurator.isDoTaxaByCommonNames());
+ }
+
+ public static void firePreferencesChanged(Class clazz) {
+ getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
+ null, clazz);
+ }
+
+
+ public static String createPreferenceString(String property){
+ return prefKey(property);
+
+ }
+ public static String createOverridePreferenceString(String property){
+ return prefOverrideKey(property);
+
+ }
+
+ /**
+ * Set default values for preferences
+ */
+ public static void setDefaults() {
+ getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
+ getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
+ true);
+ getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT),
+ "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
+ //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
+ getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP), false);
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.MobotOpenUrlServiceAccessPoint.getKey()),
+ "http://www.biodiversitylibrary.org/openurl");
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.MobotOpenUrlServiceMaxWidth.getKey()), "1000");
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.MobotOpenUrlServiceMaxHeight.getKey()), "1000");
+ getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
+ getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, true);
+ getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_NAMES, true);
+ getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, true);
+
+ //Distribution Editor:
+// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DistributionEditorActivated.getKey()), Boolean.valueOf(PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString()));
+// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString());
+// getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfStatus.getKey()), PreferencePredicate.DisplayOfStatus.getDefaultValue().toString());
+
+
+ //Name Details
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
+
+ //Navigator preferences
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), NavigatorOrderEnum.RankAndNameOrder.getKey());
+
+ //getPreferenceStore().setDefault(createPreferenceString(Prefe), true);
+
+ getPreferenceStore().setDefault(createPreferenceString(SHOW_ADVANCED_MEDIA_SECTION), false);
getPreferenceStore().setDefault(createPreferenceString(SHOW_MEDIA_PREVIEW), false);
- //override db preferences
- getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())), false);
- getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey())), true);
- getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.NameDetailsView.getKey())), false);
- getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), true);
- getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionStatus.getKey())), true);
- getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaTerms.getKey())), true);
- getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey())), true);
- getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.CommonNameAreaVocabularies.getKey())), false);
- getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false);
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowTaxonNodeWizard.getKey()), Boolean.valueOf(PreferencePredicate.ShowTaxonNodeWizard.getDefaultValue().toString()));
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowNamespaceInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowNamespaceInSource.getDefaultValue().toString()));
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowIdInSource.getDefaultValue().toString()));
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(PreferencePredicate.DisableMultiClassification.getDefaultValue().toString()));
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowImportExportMenu.getKey()), Boolean.valueOf(PreferencePredicate.ShowImportExportMenu.getDefaultValue().toString()));
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowSpecimen.getKey()), Boolean.valueOf(PreferencePredicate.ShowSpecimen.getDefaultValue().toString()));
-
- }
-
- public static void checkNomenclaturalCode() {
- // First time Editor is opened, no nomenclatural code has been set
- if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
- PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
- }
-
-
-
- }
- public static void setNomenclaturalCodePreferences(){
- ICdmRepository controller;
+ //override db preferences
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey())), true);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.NameDetailsView.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), true);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionStatus.getKey())), true);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaTerms.getKey())), true);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey())), true);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.CommonNameAreaVocabularies.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.CommonNameReferencesWithMarker.getKey()), false);
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowTaxonNodeWizard.getKey()), Boolean.valueOf(PreferencePredicate.ShowTaxonNodeWizard.getDefaultValue().toString()));
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowNamespaceInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowNamespaceInSource.getDefaultValue().toString()));
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowIdInSource.getDefaultValue().toString()));
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(PreferencePredicate.DisableMultiClassification.getDefaultValue().toString()));
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowImportExportMenu.getKey()), Boolean.valueOf(PreferencePredicate.ShowImportExportMenu.getDefaultValue().toString()));
+ getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowSpecimen.getKey()), Boolean.valueOf(PreferencePredicate.ShowSpecimen.getDefaultValue().toString()));
+
+ }
+
+ public static void checkNomenclaturalCode() {
+ // First time Editor is opened, no nomenclatural code has been set
+ if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
+ PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
+ }
+
+
+
+ }
+ public static void setNomenclaturalCodePreferences(){
+ ICdmRepository controller;
controller = CdmStore.getCurrentApplicationConfiguration();
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
CdmPreference preference = null;
setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
getPreferenceKey(preferredCode));
- }
-
- public static void checkDefaultLanguage(){
- if(PreferencesUtil.getPreferredDefaultLangugae() == null){
- Shell shell = AbstractUtility.getShell();
- int open = new DefaultLanguageDialog(shell).open();
- if(open == Window.OK){
- PlatformUI.getWorkbench().restart();
- }
- }else{
- //TODO:In case of a reinstall, the config.ini will be overwritten
- // here you create config.ini with the stored key from preferences
- }
- }
-
- public static String getMapServiceAccessPoint() {
- return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
- }
-
- public static boolean shouldConnectAtStartUp() {
- //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
- //return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
- return false;
- }
-
- public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
- String uuidString = getStringValue(
- FEATURE_TREE_DEFAULT_TEXT);
- if (StringUtils.isBlank(uuidString)) {
+ }
+
+ public static void checkDefaultLanguage(){
+ if(PreferencesUtil.getPreferredDefaultLangugae() == null){
+ Shell shell = AbstractUtility.getShell();
+ int open = new DefaultLanguageDialog(shell).open();
+ if(open == Window.OK){
+ PlatformUI.getWorkbench().restart();
+ }
+ }else{
+ //TODO:In case of a reinstall, the config.ini will be overwritten
+ // here you create config.ini with the stored key from preferences
+ }
+ }
+
+ public static String getMapServiceAccessPoint() {
+ return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
+ }
+
+ public static boolean shouldConnectAtStartUp() {
+ //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
+ //return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
+ return false;
+ }
+
+ public static TermTree getDefaultFeatureTreeForTextualDescription() {
+ String uuidString = getStringValue(
+ FEATURE_TREE_DEFAULT_TEXT);
+ if (StringUtils.isBlank(uuidString)) {
return null;
}
- FeatureTree tree = CdmStore.getService(
- IFeatureTreeService.class).load(UUID.fromString(uuidString));
- if (tree.getId() == 0) {
+ TermTree tree = CdmStore.getService(
+ ITermTreeService.class).load(UUID.fromString(uuidString));
+
+ if (tree == null || tree.getId() == 0) {
return null;
}
- return tree;
- }
+ return tree;
+ }
- public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
- String uuidString = getStringValue(
- FEATURE_TREE_DEFAULT_STRUCTURE);
- return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
- IFeatureTreeService.class).load(UUID.fromString(uuidString));
- }
+ public static TermTree getDefaultFeatureTreeForStructuredDescription() {
+ String uuidString = getStringValue(
+ FEATURE_TREE_DEFAULT_STRUCTURE);
+ return StringUtils.isBlank(uuidString) ? null : CdmStore.getService(
+ ITermTreeService.class).load(UUID.fromString(uuidString));
+ }
- public static void setSortRanksHierarchichally(boolean selection) {
- setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
- }
+ public static void setSortRanksHierarchichally(boolean selection) {
+ setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
+ }
- public static boolean getSortRanksHierarchichally() {
- return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
- }
+ public static boolean getSortRanksHierarchichally() {
+ return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
+ }
- public static boolean isMultilanguageTextEditingCapability() {
- return getBooleanValue(
- MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
- }
+ public static boolean isMultilanguageTextEditingCapability() {
+ return getBooleanValue(
+ MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
+ }
- public static Language getGlobalLanguage() {
+ public static Language getGlobalLanguage() {
- String languageUuidString = getStringValue(
- GLOBAL_LANGUAGE_UUID);
+ String languageUuidString = getStringValue(
+ GLOBAL_LANGUAGE_UUID);
- if(!CdmStore.isActive()) {
+ if(!CdmStore.isActive()) {
MessagingUtils.noDataSourceWarningDialog(languageUuidString);
return null;
}
- if (CdmUtils.isBlank(languageUuidString)) {
- return Language.getDefaultLanguage();
- }
-
- UUID languageUuid = UUID.fromString(languageUuidString);
- return (Language) CdmStore.getService(ITermService.class).load(
- languageUuid);
- }
-
- public static void setGlobalLanguage(Language language) {
- if(language != null) {
- setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
- CdmStore.setDefaultLanguage(language);
- }
-
- }
-
- public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
- List<MarkerType> markerTypes = CdmStore.getTermManager()
- .getPreferredTerms(MarkerType.class);
-
- Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
-
- for (MarkerType markerType : markerTypes) {
- String name = getMarkerTypeEditingPreferenceKey(markerType);
- Boolean value = getBooleanValue(name);
-
- result.put(markerType, value);
- }
-
- return result;
- }
-
- public static void setEditMarkerTypePreferences(
- Map<MarkerType, Boolean> markerTypeEditingMap) {
- for (MarkerType markerType : markerTypeEditingMap.keySet()) {
- String name = getMarkerTypeEditingPreferenceKey(markerType);
- setBooleanValue(name,
- markerTypeEditingMap.get(markerType));
- }
-
- }
-
- private static String getMarkerTypeEditingPreferenceKey(
- MarkerType markerType) {
- markerType = HibernateProxyHelper.deproxy(markerType);
- return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
- }
-
- public static void setEditMarkerTypePreference(MarkerType markerType,
- boolean edit) {
- setBooleanValue(
- getMarkerTypeEditingPreferenceKey(markerType), edit);
- }
-
- public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
- DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
- .NewInstance();
- configurator.setMoveDerivedUnitMediaToGallery(true);
- configurator.setMoveFieldObjectMediaToGallery(true);
- return configurator;
- }
-
- /**
- * This method will write language properties to the config.ini located in the configuration folder
- * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
- *
- * @param setLanguage 0 is for german and 1 for english.
- * @throws IOException
- */
+ if (CdmUtils.isBlank(languageUuidString)) {
+ return Language.getDefaultLanguage();
+ }
+
+ UUID languageUuid = UUID.fromString(languageUuidString);
+ return (Language) CdmStore.getService(ITermService.class).load(
+ languageUuid);
+ }
+
+ public static void setGlobalLanguage(Language language) {
+ if(language != null) {
+ setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
+ CdmStore.setDefaultLanguage(language);
+ }
+
+ }
+
+ public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
+ List<MarkerType> markerTypes = CdmStore.getTermManager()
+ .getPreferredTerms(MarkerType.class);
+
+ Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
+
+ for (MarkerType markerType : markerTypes) {
+ String name = getMarkerTypeEditingPreferenceKey(markerType);
+ Boolean value = getBooleanValue(name);
+
+ result.put(markerType, value);
+ }
+
+ return result;
+ }
+
+ public static void setEditMarkerTypePreferences(
+ Map<MarkerType, Boolean> markerTypeEditingMap) {
+ for (MarkerType markerType : markerTypeEditingMap.keySet()) {
+ String name = getMarkerTypeEditingPreferenceKey(markerType);
+ setBooleanValue(name,
+ markerTypeEditingMap.get(markerType));
+ }
+
+ }
+
+ private static String getMarkerTypeEditingPreferenceKey(
+ MarkerType markerType) {
+ markerType = HibernateProxyHelper.deproxy(markerType);
+ return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
+ }
+
+ public static void setEditMarkerTypePreference(MarkerType markerType,
+ boolean edit) {
+ setBooleanValue(
+ getMarkerTypeEditingPreferenceKey(markerType), edit);
+ }
+
+ public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
+ DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
+ .NewInstance();
+ configurator.setMoveDerivedUnitMediaToGallery(true);
+ configurator.setMoveFieldObjectMediaToGallery(true);
+ return configurator;
+ }
+
+ /**
+ * This method will write language properties to the config.ini located in the configuration folder
+ * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
+ *
+ * @param setLanguage 0 is for german and 1 for english.
+ * @throws IOException
+ */
public void writePropertyToConfigFile(int setLanguage) throws IOException {
File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
//give warning to user if the directory has no write access
}
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);
+ }
}
}
public static boolean isStoreNavigatorState() {
- return getBooleanValue(RESTORE_NAVIGATOR_STATE);
+ return getBooleanValue(RESTORE_NAVIGATOR_STATE);
- }
+ }
- public static void setStoreNavigatorState(boolean selection) {
- setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
+ public static void setStoreNavigatorState(boolean selection) {
+ setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
- }
+ }
public static boolean isShowUpWidgetIsDisposedMessages() {
return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED);
return getBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
}
- public static String displayAreaInChecklistEditor() {
- String result = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
- if (StringUtils.isBlank(result)){
- return ((TermDisplayEnum) PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue()).getKey();
+ public static TermDisplayEnum displayAreaInChecklistEditor() {
+ TermDisplayEnum result;
+ try{
+ result = TermDisplayEnum.byKey(getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()));
+ }catch (IllegalArgumentException e){
+ result = ((TermDisplayEnum) PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue());
}
return result;
}
- public static String displayStatusInChecklistEditor() {
- String result = getStringValue(PreferencePredicate.DisplayOfStatus.getKey());
- if (StringUtils.isBlank(result)){
- return((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue()).getKey();
+ public static TermDisplayEnum displayStatusInChecklistEditor() {
+ TermDisplayEnum result;
+ try{
+ result = TermDisplayEnum.byKey(getStringValue(PreferencePredicate.DisplayOfStatus.getKey()));
+ }catch (IllegalArgumentException e){
+ result = ((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue());
}
return result;
}
String value;
if (!local) {
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView);
- preference = cache.findBestMatching(key);
+ preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
if (preference == null){
return null;
}
config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
config.setRankActivated(getValue(sectionMap, "rank"));
+ config.setNameCacheActivated(getValue(sectionMap, "nameCache"));
config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
+ config.setAuthorCacheActivated(getValue(sectionMap, "authorCache"));
config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
config.setProtologueActivated(getValue(sectionMap,"protologue"));
config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
config.setHybridActivated(getValue(sectionMap,"hybrid"));
+ config.setNameApprobiationActivated(getValue(sectionMap, "nameApproviation"));
+ }else {
+ return null;
}
return config;
}
}
private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
- if (sectionMap.containsKey(string)){
- return sectionMap.get(string);
- }else{
- return true;
- }
+ if (sectionMap.containsKey(string)){
+ return sectionMap.get(string);
+ }else{
+ return true;
+ }
- }
+ }
public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
return config;
} else{
String configString = preference.getValue();
+ extractAbcdConfiguratorFromPreferenceString(config, configString);
+ }
+ return config;
+ }
+
+ public static void extractAbcdConfiguratorFromPreferenceString(Abcd206ImportConfigurator config,
+ String configString) {
+ if(configString!=null){
String[] configArray = configString.split(";");
for (String configItem: configArray){
String keyString = keyValue[0];
String valueString = null;
if (keyValue.length>1){
- valueString = keyValue[1];
+ valueString = keyValue[1];
+ if (keyValue.length>2){
+
+ for (int index = 2; index< keyValue.length; index++){
+ valueString += ":"+ keyValue[index];
+ }
+ }
}
if (keyString.equals("ignoreImportOfExistingSpecimen")){
config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
}else if (keyString.equals("overwriteExistingSpecimens")){
config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
}else if (keyString.equals("nomenclaturalCode")){
- config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
+ config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
+ }else if (keyString.equals("removeCountryFromLocalityText")){
+ config.setRemoveCountryFromLocalityText(Boolean.valueOf(valueString));
+ }else if (keyString.equals("getSiblings")){
+ config.setGetSiblings(Boolean.valueOf(valueString));
+ }else if (keyString.equals("dnaSource")){
+ try{
+ config.setDnaSoure(URI.create(valueString));
+ }catch(Exception e){
+ config.setDnaSoure(null);
+ }
}else{
logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
}
+
}
- }
- return config;
+ }
}
public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){
Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
-
- config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
-
- config.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
-
- config.setAllowReuseOtherClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
- config.setDeduplicateClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
- config.setDeduplicateReferences(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
- config.setRemoveCountryFromLocalityText(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT));
- config.setGetSiblings(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
- config.setIgnoreAuthorship(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
- config.setIgnoreImportOfExistingSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
- config.setMapUnitIdToAccessionNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
- config.setMapUnitIdToBarcode(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
- config.setMapUnitIdToCatalogNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
- config.setMoveNewTaxaToDefaultClassification(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
- config.setOverwriteExistingSpecimens(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
- config.setReuseExistingDescriptiveGroups(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
- config.setReuseExistingMetaData(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
- config.setReuseExistingTaxaWhenPossible(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
- config.setNomenclaturalCode(NomenclaturalCode.getByKey(getStringValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
-
- return config;
+ String configString = getStringValue(PreferencePredicate.AbcdImportConfig.getKey(), true);
+ extractAbcdConfiguratorFromPreferenceString(config, configString);
+ return config;
}
public static void resetToDBPreferenceAbcdCOnfigurator(){
Abcd206ImportConfigurator config = getDBAbcdImportConfigurationPreference();
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS, config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN, config.isAddMediaAsMediaSpecimen());
-
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS, config.isAllowReuseOtherClassifications());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS, config.isDeduplicateClassifications());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES, config.isDeduplicateReferences());
+ setStringValue(PreferencePredicate.AbcdImportConfig.getKey(), config.toString());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS, config.isGetSiblings());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP, config.isIgnoreAuthorship());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN, config.isIgnoreImportOfExistingSpecimen());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER, config.isMapUnitIdToAccessionNumber());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE, config.isMapUnitIdToBarcode());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER, config.isMapUnitIdToCatalogNumber());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION, config.isMoveNewTaxaToDefaultClassification());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN, config.isOverwriteExistingSpecimens());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS, config.isReuseExistingDescriptiveGroups());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA, config.isReuseExistingMetaData());
- setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE, config.isReuseExistingTaxaWhenPossible());
- if (config.getNomenclaturalCode() != null){
- setStringValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, config.getNomenclaturalCode().getKey());
- }
}
public static boolean isSortTaxaByRankAndName() {
return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
}
- public static String getSortNamedAreasInDistributionEditor() {
-
- return getStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey());
+ public static TermOrder getSortNamedAreasInDistributionEditor() {
+ TermOrder result;
+ try{
+ result = TermOrder.valueOf(getStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey()));
+ }catch (IllegalArgumentException e){
+ result = (TermOrder)PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue();
+ }
+ return result;
}
public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) {
}
public static List<UUID> createUUIDListFromStringPref(String prefKey) {
+ if (prefKey == null){
+ return null;
+ }
String prefValue = PreferencesUtil.getStringValue(prefKey);
+ if (prefValue == null){
+ return null;
+ }
String[] stringArray = prefValue.split(";");
List<UUID> uuidList = new ArrayList();
for (String uuid: stringArray){
}
public static boolean getFilterCommonNameReferences(){
- return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
+ Boolean result = getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
+ if (result == null){
+ return false;
+ }
+ return result;
}
public static void updateDBPreferences() {
- CdmPreference preference = null;
+
+
CdmPreferenceCache cache = CdmPreferenceCache.instance();
cache.getAllTaxEditorDBPreferences();
//ABCD Configurator
- updateAbcdImportConfigurationPreference();
+ //updateAbcdImportConfigurationPreference();
//Name Details
NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
public static void setPreferencesToDB(List<CdmPreference> preferences) {
ICdmRepository controller;
- try{
+ //try{
if(CdmStore.isActive()){
controller = CdmStore.getCurrentApplicationConfiguration();
for (CdmPreference preference: preferences){
+ if (preference.getValue() == null && preference.isAllowOverride()){
+ controller.getPreferenceService().remove(preference.getKey());
- controller.getPreferenceService().set(preference);
+ }else{
+ controller.getPreferenceService().set(preference);
+
+ }
- CdmPreferenceCache.instance().put(preference);
}
+ CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
+
}
- }catch(Exception e){
+ /*}catch(Exception e){
e.printStackTrace();
- }
+ }*/
}
/**
return getPreferenceStore().contains(prefKey(prefKey));
}
+ /**
+ *
+ */
+ public static TermTree getPreferredFeatureTreeForNameDescription(boolean createNew) {
+ if(preferredNameFeatureTree != null && !createNew){
+ return preferredNameFeatureTree;
+ }
+ createPreferredFeatureTreeForNameDescription();
+ return preferredNameFeatureTree;
+
+ }
+
+ public static void createPreferredFeatureTreeForNameDescription() {
+
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
+ CdmPreference pref = cache.get(PreferencePredicate.NameFeatures.getKey());
+ List<Feature> terms = new ArrayList();
+ boolean override = PreferencesUtil.getBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.NameFeatures.getKey()));
+
+ List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.NameFeatures.getKey());
+ if (uuids != null && !uuids.isEmpty()){
+ terms = CdmStore.getTermManager().getTerms(uuids, Feature.class);
+ }
+
+
+
+
+ if (terms.isEmpty()){
+ terms.addAll(TermStore.getTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid()), null));
+
+ }
+ terms.remove(Feature.PROTOLOGUE());
+ if (terms.isEmpty()){
+ preferredNameFeatureTree = TermEditorInput.getDefaultNameFeatureTree();
+ }else{
+ preferredNameFeatureTree = TermTree.NewInstance(terms);
+ }
+
+
+ }
+
+ /**
+ * @param prefsToDelete
+ */
+ public static void removeFromDB(List<CdmPreference> prefsToDelete) {
+ ICdmRepository controller;
+ //try{
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ for (CdmPreference preference: prefsToDelete){
+ controller.getPreferenceService().remove(preference.getKey());
+ }
+ CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
+ }
+
+ }
+
+ /**
+ * @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);
+ }
+
+
+ }
+
+
}