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.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.cdm.model.common.ICdmBase;
-import eu.etaxonomy.cdm.model.common.IDefinedTerm;
-import eu.etaxonomy.cdm.model.common.ISimpleTerm;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.MarkerType;
-import eu.etaxonomy.cdm.model.common.TermBase;
-import eu.etaxonomy.cdm.model.common.TermType;
-import eu.etaxonomy.cdm.model.description.FeatureTree;
+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.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;
* @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;
+ private static TermTree<Feature> preferredTaxonFeatureTree;
+ private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
- /**
- * <p>
- * getPreferenceStore
- * </p>
- *
- * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
- */
- public static IPreferenceStore getPreferenceStore() {
- return TaxeditorStorePlugin.getDefault().getPreferenceStore();
- }
+ public static IPreferenceStore getPreferenceStore() {
+ return TaxeditorStorePlugin.getDefault().getPreferenceStore();
+ }
- private static String prefKey(String name) {
- return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
- }
+ public static String[] extractSubjectParts(String subject){
+ String[] result = subject.split("/");
+ return result;
+ }
- /**
- * <p>
- * setStringValue
- * </p>
- *
- *
- **/
- public static void setStringValue(String name, String value) {
- getPreferenceStore().setValue(prefKey(name), value);
+ 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;
}
/**
- * <p>
- * setIntValue
- * </p>
- *
- *
- **/
+ * @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_";
+ }
+
+ public static void setStringValue(String name, String value) {
+ if (value != null){
+ getPreferenceStore().setValue(prefKey(name), value);
+ }else{
+ getPreferenceStore().setToDefault(prefKey(name));
+ }
+ }
+
public static void setIntValue(String name, int value) {
getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setBooleanValue
- * </p>
- *
- *
- **/
public static void setBooleanValue(String name, boolean value) {
getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setBooleanValue
- * </p>
- *
- *
- **/
public static void setDoubleValue(String name, double value) {
getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setFloatValue
- * </p>
- *
- *
- **/
public static void setFloatValue(String name, float value) {
- getPreferenceStore().setValue(name + ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString(), value);
+ getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setFloatValue
- * </p>
- *
- *
- **/
public static void setLongValue(String name, long value) {
getPreferenceStore().setValue(prefKey(name), value);
}
- /**
- * <p>
- * setStringValue
- * </p>
- *
- *
- **/
- public static String getStringValue(String name) {
+ public static String getStringValue(String name, boolean local) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getString(dbSpecific);
- }else{
- return getPreferenceStore().
- getString(name);
- }
+ CdmPreference pref = getDBPreferenceValue(name);
+ String prefValue = null;
+ String overrideKey = createPreferenceString(createOverridePreferenceString(name));
+ boolean override = getPreferenceStore().getBoolean(overrideKey);
+
+ if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
+ String dbSpecific = prefKey(name);
+ if (getPreferenceStore().contains(dbSpecific)){
+ prefValue = getPreferenceStore().getString(dbSpecific);
+ }else{
+ prefValue = getPreferenceStore().
+ getString(name);
+ }
+ }else if (pref != null){
+ prefValue = pref.getValue();
+ }
+ return prefValue;
}
- /**
- * <p>
- * setIntValue
- * </p>
- *
- *
- **/
- public static int getIntValue(String name) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getInt(dbSpecific);
- }else{
- return getPreferenceStore().
- getInt(name);
- }
+ public static String getStringValue(String name){
+ return getStringValue(name, false);
+ }
+ private static CdmPreference getDBPreferenceValue(String name) {
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
+ 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);
+// }
+// }
+ return pref;
}
- /**
- * <p>
- * setBooleanValue
- * </p>
- *
- *
- **/
- public static boolean getBooleanValue(String name) {
- if (CdmStore.isActive()){
+ public static int getIntValue(String name, boolean local) {
+ CdmPreference pref= getDBPreferenceValue(name);
+ String prefValue = null;
+ if (pref != null){
+ prefValue = pref.getValue();
+ }
+ Integer result = null;
+ try{
+ result = Integer.parseInt(prefValue);
+ }catch(NumberFormatException e){
+ logger.debug("Preference value of " + name + " is not a number");
+ }
+
+ String overrideKey = createPreferenceString(createOverridePreferenceString(name));
+ boolean override = true;
+ if (getPreferenceStore().contains(overrideKey)){
+ override = getPreferenceStore().getBoolean(overrideKey);
+ }
+ if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
String dbSpecific = prefKey(name);
if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getBoolean(dbSpecific);
+ result = getPreferenceStore().getInt(dbSpecific);
}else{
- return getPreferenceStore().
- getBoolean(name);
+ result = getPreferenceStore().
+ getInt(name);
}
+ }
+ return result;
+ }
+
+ public static boolean getBooleanValue(String name) {
+ Boolean result = getBooleanValue(name, false);
+ if (result == null){
+ return false;
}else{
+ return result;
+ }
+ }
+
+ public static Boolean getBooleanValue(String name, boolean local) {
+ if (CdmStore.isActive()){
+ CdmPreference pref = getDBPreferenceValue(name);
+
+ String overrideKey = createPreferenceString(createOverridePreferenceString(name));
+ boolean override = getPreferenceStore().getBoolean(overrideKey);
+
+ if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
+ String dbSpecific = prefKey(name);
+ if (getPreferenceStore().contains(dbSpecific)){
+ return getPreferenceStore().getBoolean(dbSpecific);
+ }else{
+ return null;
+ }
+ }else{
+ return Boolean.valueOf(pref.getValue());
+ }
+
+ }else{
return getPreferenceStore().getBoolean(name);
}
}
- /**
- * <p>
- * setBooleanValue
- * </p>
- *
- *
- **/
public static double getDoubleValue(String name) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getDouble(dbSpecific);
- }else{
- return getPreferenceStore().
- getDouble(name);
+ CdmPreference pref = getDBPreferenceValue(name);
+ String prefValue = null;
+ if (pref != null){
+ prefValue = pref.getValue();
}
+ Double result = null;
+ try{
+ result = Double.parseDouble(prefValue);
+ }catch(NumberFormatException e){
+ logger.debug("Preference value of " + name + " is not a number");
+ }
+ if (result == null){
+ String dbSpecific = prefKey(name);
+ if (getPreferenceStore().contains(dbSpecific)){
+ result = getPreferenceStore().getDouble(dbSpecific);
+ }else{
+ result = getPreferenceStore().
+ getDouble(name);
+ }
+ }
+ return result;
}
- /**
- * <p>
- * getFloatValue
- * </p>
- *
- *
- **/
- public static float getFloatValue(String name) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getFloat(dbSpecific);
- }else{
- return getPreferenceStore().
- getFloat(name);
+ public static float getFloatValue(String name, boolean local) {
+ CdmPreference pref = getDBPreferenceValue(name);
+ String prefValue = null;
+ if (pref != null){
+ prefValue = pref.getValue();
+ }
+ Float result = null;
+ try{
+ result = Float.parseFloat(prefValue);
+ }catch(NumberFormatException e){
+ logger.debug("Preference value of " + name + " is not a number");
+ }
+ String overrideKey = createPreferenceString(createOverridePreferenceString(name));
+ boolean override = true;
+ if (getPreferenceStore().contains(overrideKey)){
+ override = getPreferenceStore().getBoolean(overrideKey);
+ }
+ if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
+ String dbSpecific = prefKey(name);
+ if (getPreferenceStore().contains(dbSpecific)){
+ result = getPreferenceStore().getFloat(dbSpecific);
+ }else{
+ result = getPreferenceStore().
+ getFloat(name);
+ }
}
+ return result;
}
- /**
- * <p>
- * getLongValue
- * </p>
- *
- *
- **/
public static long getLongValue(String name) {
- String dbSpecific = prefKey(name);
- if (getPreferenceStore().contains(dbSpecific)){
- return getPreferenceStore().getLong(dbSpecific);
- }else{
- return getPreferenceStore().
- getLong(name);
- }
- }
-
-
- /**
- * <p>
- * setPreferredNomenclaturalCode
- * </p>
- *
- * @param preferredCode
- * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
- * object.
- */
- public static CdmPreference setPreferredNomenclaturalCode(
- String preferenceKey, boolean local) {
- if (local){
- setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
- preferenceKey);
- }
- else{
- ICdmRepository controller;
- controller = CdmStore.getCurrentApplicationConfiguration();
- if (controller == null){
+ CdmPreference pref = getDBPreferenceValue(name);
+ String prefValue = null;
+ if (pref != null){
+ prefValue = pref.getValue();
+ }
+ Long result = null;
+ try{
+ result = Long.parseLong(prefValue);
+ }catch(NumberFormatException e){
+ logger.debug("Preference value of " + name + " is not a number");
+ }
+ if (result == null){
+ String dbSpecific = prefKey(name);
+ if (getPreferenceStore().contains(dbSpecific)){
+ result = getPreferenceStore().getLong(dbSpecific);
+ }else{
+ result = getPreferenceStore().
+ getLong(name);
+ }
+ }
+ 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){
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 (preferenceKey == null){
- preference = controller.getPreferenceService().find(key);
- if (preference == null){
- return null;
- } else{
- setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
- preference.getValue());
- setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,preference.isAllowOverride());
- return preference;
- }
- } else{
- preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceKey);
- 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) {
+
+ ICdmRepository controller;
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ if (controller == null){
+ return;
+ }
- public static NomenclaturalCode getPreferredNomenclaturalCode(){
- if (getBooleanValue(OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
- return getPreferredNomenclaturalCode(true);
- } else{
- return getPreferredNomenclaturalCode(false);
+ 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);
}
- }
- /**
- * <p>
- * getPreferredNomenclaturalCode
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
- */
- public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
+ }
- CdmPreference pref = null;
- if (!useLocal){
- pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
- }
+ public static NomenclaturalCode getPreferredNomenclaturalCode() {
- String preferredCode;
- if(pref == null){
- preferredCode = getStringValue(
- PREFERRED_NOMENCLATURAL_CODE_KEY);
+ CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
- }else{
- preferredCode = pref.getValue();
- }
- return getPreferredNomenclaturalCode(preferredCode);
+ 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());
+ }
+
+ return getPreferredNomenclaturalCode(preferredCode);
+
+ }
- /**
- * <p>
- * getPreferredNomenclaturalCode
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
- */
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(){
- if (getBooleanValue(SHOW_TAXON_ASSOCIATIONS_OVERRIDE) && getBooleanValue(SHOW_TAXON_ASSOCIATIONS_ALLOW_OVERRIDE)) {
- return getBooleanValue(SHOW_TAXON_ASSOCIATIONS);
- } else{
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
+ public static boolean isShowTaxonAssociations(){
+ boolean result = getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
+ return result;
+ }
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
- }
+ public static boolean isShowLifeForm(){
+ boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
+ return result;
}
- public static boolean isShowLifeForm(){
- if (getBooleanValue(SHOW_LIFE_FORM_OVERRIDE) && getBooleanValue(SHOW_LIFE_FORM_ALLOW_OVERRIDE)) {
- return getBooleanValue(SHOW_LIFE_FORM);
- } else{
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
+ public static boolean isDeterminationOnlyForFieldUnits(){
+ boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
+ return result;
+ }
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
- }
+ public static boolean isCollectingAreaInGeneralSection(){
+ boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
+ return result;
}
- public static boolean isDeterminationOnlyForFieldUnits(){
- if (getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS_OVERRIDE) && getBooleanValue(DETERMINATIONS_ONLY_FOR_FIELDUNITS_ALLOW_OVERRIDE)) {
- return getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS);
- } else{
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
+ public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
+ ICdmRepository controller;
+ CdmPreference pref = null;
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
+ try{
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
+ pref = controller.getPreferenceService().find(key);
+ }
+ }catch(Exception e){
+ e.printStackTrace();
}
+
+ return pref;
+
}
- public static boolean isCollectingAreaInGeneralSection(){
- if (getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_OVERRIDE) && getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_ALLOW_OVERRIDE)) {
- return getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION);
- } else{
- CdmPreference pref = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
+ public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate predicate){
+ ICdmRepository controller;
+ List<CdmPreference> prefs = null;
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
+ try{
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
+ prefs = controller.getPreferenceService().list(predicate);
+ }
+ }catch(Exception e){
+ e.printStackTrace();
}
+
+ return prefs;
+
}
- public static boolean isShowSimpleDetailsView(){
- if (getBooleanValue(OVERRIDE_NAME_DETAILS) && getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)) {
- return getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION);
- } else{
- CdmPreference pref = getPreferenceFromDB(EditorPreferencePredicate.NameDetailsView);
+ public static void setPreferencesToDB(CdmPreference preference, boolean setDefault){
+ ICdmRepository controller;
+ try{
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
- return pref!=null?Boolean.valueOf(pref.getValue()):false;
+ if (setDefault){
+ controller.getPreferenceService().remove(preference.getKey());
+ }else{
+ controller.getPreferenceService().set(preference);
+ }
+ }
+ }catch(Exception e){
+ e.printStackTrace();
}
- }
- public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
+ }
+
+ public static CdmPreference getPreferenceFromDB(PrefKey key){
ICdmRepository controller;
CdmPreference pref = null;
try{
if(CdmStore.isActive()){
controller = CdmStore.getCurrentApplicationConfiguration();
- PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
pref = controller.getPreferenceService().find(key);
}
}catch(Exception e){
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){
e.printStackTrace();
}
+ 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);
- }
-
- /**
- * <p>
- * getDateFormatPattern
- * </p>
- *
- * @return a {@link java.lang.String} object.
- */
- public static String getDateFormatPattern() {
- // TODO make this configurable in properties
- String pattern = "Y-M-d H:m";
- return pattern;
- }
-
- /**
- * <p>
- * addTermToPreferredTerms
- * </p>
- *
- * @param term
- * a T object.
- * @param <T>
- * a T object.
- */
- 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());
- }
-
- /**
- * <p>
- * firePreferencesChanged
- * </p>
- *
- * @param clazz
- * a {@link java.lang.Class} object.
- */
- public static void firePreferencesChanged(Class clazz) {
- getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
- null, clazz);
- }
-
- public static String createPreferenceString(String property){
- return prefKey(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");
- //Distribution Editor:
- getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DistributionEditorActivated.getKey()), true);
- getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString());
- getPreferenceStore().setDefault(createPreferenceString(EditorPreferencePredicate.DisplayOfStatus.getKey()), EditorPreferencePredicate.DisplayOfStatus.getDefaultValue().toString());
-
-
- //Name Details
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_HYBRID), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_LSID), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NAMECACHE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_RANK), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION), true);
- //Navigator preferences
- getPreferenceStore().setDefault(createPreferenceString(SORT_NODES), NavigatorOrderEnum.RankAndNameOrder.getKey());
-
- getPreferenceStore().setDefault(createPreferenceString(SORT_TAXA_BY_RANK_AND_NAME), true);
- //override db preferences
- getPreferenceStore().setDefault(createPreferenceString(ABCD_IMPORT_OVERRIDE), false);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_SPECIMEN_OVERRIDE), false);
- getPreferenceStore().setDefault(createPreferenceString(OVERRIDE_NAME_DETAILS), false);
- getPreferenceStore().setDefault(createPreferenceString(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE), false);
-
- getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_SPECIMEN), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_TAXONNODE_WIZARD), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_NAMESPACE_IN_SOURCE), true);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_ID_IN_SOURCE), true);
- getPreferenceStore().setDefault(createPreferenceString(DISABLE_MULTI_CLASSIFICATION), false);
- getPreferenceStore().setDefault(createPreferenceString(DISABLE_SEC), false);
- getPreferenceStore().setDefault(createPreferenceString(SHOW_SEC_DETAILS), true);
- }
-
- /**
- * <p>
- * checkNomenclaturalCode
- * </p>
- */
- public static void checkNomenclaturalCode() {
- // First time Editor is opened, no nomenclatural code has been set
- if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
- PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
- }
-
-
-
- }
- public static void setNomenclaturalCodePreferences(){
- ICdmRepository controller;
+ /**
+ * 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(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;
if (preference == null){
return;
}
- setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
+// setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
int index = StringUtils.lastIndexOf(preference.getValue(), ".");
UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
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
- }
- }
-
- /**
- * <p>
- * getMapServiceAccessPoint
- * </p>
- *
- * @return a {@link java.lang.String} object.
- */
- public static String getMapServiceAccessPoint() {
- return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
- }
-
- /**
- * <p>
- * shouldConnectAtStartUp
- * </p>
- *
- * @return a boolean.
- */
- public static boolean shouldConnectAtStartUp() {
- //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
- //return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
- return false;
- }
-
- /**
- * <p>
- * getDefaultFeatureTreeForTextualDescription
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
- */
- public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
- String uuidString = getStringValue(
- FEATURE_TREE_DEFAULT_TEXT);
- return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
- IFeatureTreeService.class).load(UUID.fromString(uuidString));
- }
-
- /**
- * <p>
- * getDefaultFeatureTreeForStructuredDescription
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
- */
- public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
- String uuidString = getStringValue(
- FEATURE_TREE_DEFAULT_STRUCTURE);
- return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
- IFeatureTreeService.class).load(UUID.fromString(uuidString));
- }
-
- /**
- * <p>
- * setSortRanksHierarchichally
- * </p>
- *
- * @param selection
- * a boolean.
- */
- public static void setSortRanksHierarchichally(boolean selection) {
- setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
- }
-
- /**
- * <p>
- * getSortRanksHierarchichally
- * </p>
- *
- * @return a boolean.
- */
- public static boolean getSortRanksHierarchichally() {
- return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
- }
-
- public static boolean isMultilanguageTextEditingCapability() {
- return getBooleanValue(
- MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
- }
-
- public static Language getGlobalLanguage() {
-
-
- String languageUuidString = getStringValue(
- GLOBAL_LANGUAGE_UUID);
-
- if(!CdmStore.isActive()) {
+ }
+
+ 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;
+ }
+ TermTree tree = CdmStore.getService(
+ ITermTreeService.class).load(UUID.fromString(uuidString));
+
+ if (tree == null || tree.getId() == 0) {
+ return null;
+ }
+ return tree;
+ }
+
+ 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 boolean getSortRanksHierarchichally() {
+ return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
+ }
+
+ public static boolean isMultilanguageTextEditingCapability() {
+ return getBooleanValue(
+ MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
+ }
+
+ public static Language getGlobalLanguage() {
+
+
+ String languageUuidString = getStringValue(
+ GLOBAL_LANGUAGE_UUID);
+
+ 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);
- }
-
- }
-
- /**
- * @return
- */
- 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;
- }
-
- /**
- * @param markerTypeEditingMap
- */
- 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;
- }
-
- /**
- * <p>
- * setEditMarkerTypePreference
- * </p>
- *
- * @param input
- * a {@link org.eclipse.ui.IEditorInput} object.
- * @param markerType
- * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
- * @param edit
- * a boolean.
- */
- public static void setEditMarkerTypePreference(MarkerType markerType,
- boolean edit) {
- setBooleanValue(
- getMarkerTypeEditingPreferenceKey(markerType), edit);
- }
-
- /**
- * @return
- */
- 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
}
}
-
-
-
- /**
- * @param orderActivated
- */
public static void setSortNodes(NavigatorOrderEnum nodesOrder) {
- setStringValue(SORT_NODES, nodesOrder.key);
+ if (nodesOrder == null){
+ setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), null);
+ }else{
+ setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key);
+ }
}
- /**
- * @param orderActivated
- */
public static NavigatorOrderEnum getSortNodes() {
- return NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
+ return NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
}
- /**
- * @param orderActivated
- */
public static boolean isNodesSortedNaturally() {
- NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
+ NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
return value.equals(NavigatorOrderEnum.NaturalOrder);
}
- /**
- * @param orderActivated
- */
public static boolean isNodesSortedByName() {
- NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
+ NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
return value.equals(NavigatorOrderEnum.AlphabeticalOrder);
}
- /**
- * @param orderActivated
- */
public static boolean isNodesSortedByNameAndRank() {
- NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(SORT_NODES));
+ NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
return value.equals(NavigatorOrderEnum.RankAndNameOrder);
}
- /**
- * <p>
- * setStoreNavigatorState
- * </p>
- *
- * @param selection
- * a boolean.
- */
- public static boolean isStoreNavigatorState() {
- return getBooleanValue(RESTORE_NAVIGATOR_STATE);
-
- }
-
- /**
- * <p>
- * setStoreNavigatorState
- * </p>
- *
- * @param selection
- * a boolean.
- */
- public static void setStoreNavigatorState(boolean selection) {
- setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
-
- }
- /**
- * @return
- */
+ public static boolean isStoreNavigatorState() {
+ return getBooleanValue(RESTORE_NAVIGATOR_STATE);
+
+ }
+
+ public static void setStoreNavigatorState(boolean selection) {
+ setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
+
+ }
+
public static boolean isShowUpWidgetIsDisposedMessages() {
return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED);
}
setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
}
- /**
- * @return
- */
public static boolean isShowIdInVocabularyInChecklistEditor() {
- String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
+ String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
if (area_display.equals(TermDisplayEnum.IdInVocabulary.getKey())) {
return true;
}else{
}
}
public static boolean isShowSymbol1InChecklistEditor() {
- String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
+ String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
if (area_display.equals(TermDisplayEnum.Symbol1.getKey())) {
return true;
}else{
}
}
public static boolean isShowSymbol2InChecklistEditor() {
- String area_display = getStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
+ String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
if (area_display.equals(TermDisplayEnum.Symbol2.getKey())) {
return true;
}else{
}
}
public static void setAreaDisplayInChecklistEditor(String selection) {
- setStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
+ setStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
}
public static void setOwnDescriptionForChecklistEditor(boolean selection) {
- setBooleanValue(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), selection);
+ setBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), selection);
}
public static boolean isOwnDescriptionForChecklistEditor() {
- return getBooleanValue(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
+ return getBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
}
- /**
- * @return
- */
- public static String displayStatusInChecklistEditor() {
- return getStringValue(EditorPreferencePredicate.DisplayOfStatus.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 TermDisplayEnum displayStatusInChecklistEditor() {
+ TermDisplayEnum result;
+ try{
+ result = TermDisplayEnum.byKey(getStringValue(PreferencePredicate.DisplayOfStatus.getKey()));
+ }catch (IllegalArgumentException e){
+ result = ((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue());
+ }
+ return result;
}
public static void setDisplayStatusInChecklistEditor(String selection) {
- setStringValue(EditorPreferencePredicate.DisplayOfStatus.getKey(), selection);
+ setStringValue(PreferencePredicate.DisplayOfStatus.getKey(), selection);
+
}
- /**
- * @return
- */
public static boolean isShowRankInChecklistEditor() {
- return getBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey());
+ return getBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey());
}
public static void setShowRankInChecklistEditor(boolean selection) {
- setBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
+ setBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
}
- /**
- * @param object
- * @param b
- * @return
- */
public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
NameDetailsConfigurator config = new NameDetailsConfigurator(true);
-
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
CdmPreference preference = null;
-
+ String value;
if (!local) {
- preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView);
+ preference = getPreferenceFromDB(PreferencePredicate.NameDetailsView);
if (preference == null){
return null;
}
- setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
-
+ // setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
+ value = preference.getValue();
+ config.setAllowOverride(preference.isAllowOverride());
//the preference value is build like this:
//<section1>:true;<section2>:false....
+ }else{
+ value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), local);
+ }
+ if (value!= null){
+ String [] sections = value.split(";");
+ Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
+ String[] sectionValues;
+ for (String sectionValue: sections){
+ sectionValues = sectionValue.split(":");
+ sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
+ }
+ config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
+ config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
+ config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
+ config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
+ config.setLSIDActivated(getValue(sectionMap, "lsid"));
+ 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;
+ }
- String value = preference.getValue();
+ public static NameDetailsConfigurator getPreferredNameDetailsConfiguration() {
+ NameDetailsConfigurator config = new NameDetailsConfigurator(true);
+
+ String value;
+
+ value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), false);
+ if (value != null){
String [] sections = value.split(";");
Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
String[] sectionValues;
sectionValues = sectionValue.split(":");
sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
}
- config.setAllowOverride(preference.isAllowOverride());
+
config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
- // getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON,
- // (getValue(sectionMap, "taxon")));
config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
- config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecEnabled"));
- config.setSecEnabled(getValue(sectionMap, "taxon.SecDetails"));
+ config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
+ config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID,
- // (getValue(sectionMap, "lsid")));
config.setLSIDActivated(getValue(sectionMap, "lsid"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
- // (getValue(sectionMap, "nc")));
config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
- // (getValue(sectionMap, "ap")));
config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK,
- // (getValue(sectionMap, "rank")));
config.setRankActivated(getValue(sectionMap, "rank"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
- // (getValue(sectionMap, "atomisedEpithets")));
config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
- // (getValue(sectionMap,"author")));
config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
- // (getValue(sectionMap, "nomRef")));
config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
- // (getValue(sectionMap, "nomStat")));
config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
-
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
- // (getValue(sectionMap,"protologue")));
config.setProtologueActivated(getValue(sectionMap,"protologue"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
- // (getValue(sectionMap,"typeDes")));
config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
- // (getValue(sectionMap,"nameRelation")));
config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
- // getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_HYBRID,
- // (getValue(sectionMap, "hybrid")));
- config.setHybridActivated(getValue(sectionMap,"hybrid"));
- }else{
- config.setSimpleDetailsViewActivated(getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION));
- config.setTaxonSectionActivated(getBooleanValue(SHOW_SIMPLE_NAME_DETAILS_TAXON));
- config.setSecDetailsActivated(getBooleanValue(SHOW_SEC_DETAILS));
- config.setSecEnabled(getBooleanValue(DISABLE_SEC));
- config.setLSIDActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_LSID));
- config.setNomenclaturalCodeActived(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
- config.setAppendedPhraseActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
- config.setRankActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_RANK));
- config.setAtomisedEpithetsActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
- config.setAuthorshipSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
- config.setNomenclaturalReferenceSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
- config.setNomenclaturalStatusSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
- config.setProtologueActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
- config.setTypeDesignationSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
- config.setNameRelationsSectionActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
- config.setHybridActivated(getBooleanValue(SHOW_NAME_DETAILS_SECTION_HYBRID));
+ config.setHybridActivated(getValue(sectionMap,"hybrid"));
}
return config;
}
- /**
- * @param object
- * @param b
- * @return
- */
public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
CdmPreference preference = null;
if (!local) {
- preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NameDetailsView, config.toString());
+ preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView, config.toString());
setPreferenceToDB(preference);
}
- //also add to local preferences
- setBooleanValue(SHOW_SIMPLE_NAME_DETAILS_SECTION, config.isSimpleDetailsViewActivated());
- setBooleanValue(SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
- setBooleanValue(SHOW_SEC_DETAILS, config.isSecDetailsActivated());
- setBooleanValue(DISABLE_SEC, config.isSecEnabled());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE, config.isNomenclaturalCodeActived());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE, config.isAppendedPhraseActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS, config.isAtomisedEpithetsActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP, config.isAuthorshipSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE, config.isNomenclaturalReferenceSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS, config.isNomenclaturalStatusSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE, config.isProtologueActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION, config.isTypeDesignationSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP, config.isNameRelationsSectionActivated());
- setBooleanValue(SHOW_NAME_DETAILS_SECTION_HYBRID, config.isHybridActivated());
+ else{
+ setStringValue(PreferencePredicate.NameDetailsView.getKey(), config.toString());
+ }
+
}
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;
+ }
+ }
- /**
- * <p>
- * setAbcdConfigurator
- * </p>
- *
- * @param preferredConfiguration
- * a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
- * object.
- */
public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
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 updateAbcdImportConfigurationPreference() {
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
- Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
- ICdmRepository controller;
- controller = CdmStore.getCurrentApplicationConfiguration();
- PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig);
- CdmPreference preference = null;
- if (controller == null){
- return ;
- }
- preference = controller.getPreferenceService().find(key);
- boolean allowOverride = true;
- if (preference != null && !preference.isAllowOverride()){
- allowOverride = false;
- }
- if (!getBooleanValue(IPreferenceKeys.ABCD_IMPORT_OVERRIDE) || !allowOverride){
+ CdmPreference pref = cache.findBestMatching(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig));
+
+ if (!getBooleanValue(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())) || !pref.isAllowOverride()){
resetToDBPreferenceAbcdCOnfigurator();
}
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());
+ setStringValue(PreferencePredicate.AbcdImportConfig.getKey(), config.toString());
- 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());
-
- 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() {
- /**
- *
- */
- public NameDetailsConfigurator createLocalNameDetailsViewConfig(boolean local) {
- NameDetailsConfigurator config = new NameDetailsConfigurator(true);
- if (local){
- config.setSimpleDetailsViewActivated(getBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION));
- config.setAppendedPhraseActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE));
- config.setAtomisedEpithetsActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS));
- config.setAuthorshipSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP));
- config.setLSIDActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID));
- config.setNameApprobiationActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION));
- config.setNameCacheActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE));
- config.setNameRelationsSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP));
- config.setNomenclaturalCodeActived(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE));
- config.setNomenclaturalStatusSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS));
- config.setNomenclaturalReferenceSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE));
- config.setProtologueActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE));
- config.setRankActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK));
- config.setTaxonSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON));
- config.setTypeDesignationSectionActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION));
- config.setHybridActivated(getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID));
- }else{
-
- }
-
- return config;
- }
-
-
- public static void saveConfigToPrefernceStore(NameDetailsConfigurator config) {
- setBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION,
- config.isSimpleDetailsViewActivated());
- setBooleanValue(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_TAXON, config.isTaxonSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID, config.isLSIDActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE,
- config.isNomenclaturalCodeActived());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE,
- config.isNameCacheActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE,
- config.isAppendedPhraseActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK, config.isRankActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS,
- config.isAtomisedEpithetsActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE,
- config.isAuthorCacheActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP,
- config.isAuthorshipSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE,
- config.isNomenclaturalReferenceSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS,
- config.isNomenclaturalStatusSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_PROTOLOGUE,
- config.isProtologueActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION,
- config.isTypeDesignationSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP,
- config.isNameRelationsSectionActivated());
- setBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID,
- config.isHybridActivated());
-
- }
-
-/**
- * @return
- */
-public static boolean isSortTaxaByRankAndName() {
-
- return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
-}
-
-/**
- * @return
- */
-public static boolean isSortNamedAreaByOrderInVocabulary() {
+ return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
+ }
- return getBooleanValue(EditorPreferencePredicate.AreasSortedByIdInVocabulary.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 setSortNamedAreasByOrderInVocabulary(boolean isSortByVocabularyOrder) {
- setBooleanValue(EditorPreferencePredicate.AreasSortedByIdInVocabulary.getKey(), isSortByVocabularyOrder);
+ public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) {
+ setStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey(), isSortByVocabularyOrder);
-}
+ }
-/**
- * <p>
- * setPreferredNamedAreasForDistributionEditor
- * </p>
- *
- * @param saveCheckedElements
- * @param saveGrayedElements
- */
-public static void setLastSelectedReference(
- List<String> lastSelectedReferences) {
+ public static void setLastSelectedReference(
+ List<String> lastSelectedReferences) {
setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
}
-/**
- * <p>
- * setPreferredNamedAreasForDistributionEditor
- * </p>
- *
- * @param saveCheckedElements
- * @param saveGrayedElements
- */
-public static List<String> getLastSelectedReferences() {
+ public static List<String> getLastSelectedReferences() {
//IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES);
return result;
}
+ public static void setPreferredNamedAreasForDistributionEditor(
+ String saveCheckedElements, String saveGrayedElements, boolean local) {
+ if (local){
+ setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
-/**
- * <p>
- * setPreferredNamedAreasForDistributionEditor
- * </p>
- *
- * @param saveCheckedElements
- * @param saveGrayedElements
- */
-public static void setPreferredNamedAreasForDistributionEditor(
- String saveCheckedElements, String saveGrayedElements, boolean local) {
- if (local){
- setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
+ }
+ else{
+ CdmPreference preference = null;
- }
- else{
- CdmPreference preference = null;
+ if (saveCheckedElements == null){
+ preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
- if (saveCheckedElements == null){
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
+ if (preference == null){
+ return ;
+ } else{
+ setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
+ saveCheckedElements);
+ preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
+ setPreferenceToDB(preference);
- if (preference == null){
- return ;
+ }
} else{
- setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
- saveCheckedElements);
preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
setPreferenceToDB(preference);
+ setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
+ saveCheckedElements);
}
- } else{
- preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
- setPreferenceToDB(preference);
- setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
- saveCheckedElements);
-
}
- }
-
-}
-/**
- * @param saveCheckedElements
- * @param saveCheckedElements2
- * @param b
- */
-public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
- boolean local) {
- if (local){
- setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements);
}
- else{
- ICdmRepository controller;
- CdmPreference preference = null;
- if (saveCheckedElements == null){
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
-
- if (preference == null){
- return ;
+ public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
+ boolean local, boolean isOverride) {
+ if (local){
+ setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements);
+ setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride);
+ }
+ else{
+ ICdmRepository controller;
+ CdmPreference preference = null;
+
+ if (saveCheckedElements == null){
+ preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
+
+ if (preference == null){
+ return ;
+ } else{
+ setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
+ saveCheckedElements);
+ preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
+ preference.setAllowOverride(isOverride);
+ setPreferenceToDB(preference);
+ }
} else{
- setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
- saveCheckedElements);
preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
+ preference.setAllowOverride(isOverride);
setPreferenceToDB(preference);
- }
- } else{
- preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
- setPreferenceToDB(preference);
- setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
- saveCheckedElements);
+ setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
+ saveCheckedElements);
+ }
}
}
-}
-
+ public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
+ if (local){
+ String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), local);
+ return pref;
+ }
+ else{
+ CdmPreference preference = null;
+ preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
+ if (preference == null){
+ return null;
+ } else{
+ return preference.getValue();
+ }
-/**
- * @param saveCheckedElements
- * @param saveCheckedElements2
- * @param b
- */
-public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
- if (local){
-
- String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
- return pref;
+ }
}
- else{
- CdmPreference preference = null;
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
- if (preference == null){
+
+ public static List<UUID> createUUIDListFromStringPref(String prefKey) {
+ if (prefKey == null){
return null;
- } else{
- return preference.getValue();
}
-
+ String prefValue = PreferencesUtil.getStringValue(prefKey);
+ if (prefValue == null){
+ return null;
+ }
+ String[] stringArray = prefValue.split(";");
+ List<UUID> uuidList = new ArrayList();
+ for (String uuid: stringArray){
+ if (!StringUtils.isBlank(uuid)){
+ uuidList.add(UUID.fromString(uuid));
+ }
+ }
+ return uuidList;
}
+ public static boolean getFilterCommonNameReferences(){
+ Boolean result = getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
+ if (result == null){
+ return false;
+ }
+ return result;
+ }
+ public static void updateDBPreferences() {
-}
-public static boolean getFilterCommonNameReferences(){
- return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
-}
+ CdmPreferenceCache cache = CdmPreferenceCache.instance();
+ cache.getAllTaxEditorDBPreferences();
-/**
- *
- */
-public static void updateDBPreferences() {
- CdmPreference preference = null;
- IPreferenceStore prefStore = getPreferenceStore();
+ //ABCD Configurator
- //ABCD Configurator
+ //updateAbcdImportConfigurationPreference();
- updateAbcdImportConfigurationPreference();
+ //Name Details
+ NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
+ // if (config != null ){
+ // if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
+ // setPreferredNameDetailsConfiguration(config, false);
+ // }
+ // }
- preference = getPreferenceFromDB(PreferencePredicate.ShowImportExportMenu);
- if (preference != null){
- if(!getBooleanValue(SHOW_IO_MENU) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_IO_MENU, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_IO_MENU, true);
}
- preference = getPreferenceFromDB(PreferencePredicate.ShowMediaView);
- if (preference != null){
- if(!getBooleanValue(SHOW_MEDIA) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_MEDIA, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_MEDIA, true);
- }
+ public static void setPreferencesToDB(List<CdmPreference> preferences) {
- preference = getPreferenceFromDB(PreferencePredicate.ShowChecklistPerspective);
- if (preference != null){
- if(!getBooleanValue(SHOW_CHECKLIST_PERSPECTIVE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_CHECKLIST_PERSPECTIVE, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_CHECKLIST_PERSPECTIVE, false);
- }
+ ICdmRepository controller;
+ //try{
+ if(CdmStore.isActive()){
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ for (CdmPreference preference: preferences){
+ if (preference.getValue() == null && preference.isAllowOverride()){
+ controller.getPreferenceService().remove(preference.getKey());
- //Specimen Details
- preference = getPreferenceFromDB(PreferencePredicate.ShowSpecimen);
- if (preference != null){
- if(!getBooleanValue(SHOW_SPECIMEN) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_SPECIMEN, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_SPECIMEN, true);
- }
+ }else{
+ controller.getPreferenceService().set(preference);
- preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
- if (preference != null){
- if(!getBooleanValue(SHOW_TAXON_ASSOCIATIONS_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_TAXON_ASSOCIATIONS, Boolean.valueOf(preference.getValue()));
- }
- }
- preference = getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
- if (preference != null){
- if(!getBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION, Boolean.valueOf(preference.getValue()));
- }
- }
- preference = getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
- if (preference != null){
- if(!getBooleanValue(SHOW_LIFE_FORM_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_LIFE_FORM, Boolean.valueOf(preference.getValue()));
- }
- }
- preference = getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
- if (preference != null){
- if(!getBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(DETERMINATION_ONLY_FOR_FIELD_UNITS, Boolean.valueOf(preference.getValue()));
- }
- }
+ }
+ }
+ CdmPreferenceCache.instance().getAllTaxEditorDBPreferences();
- //Name Details
- NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
- if (config != null ){
- if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
- setPreferredNameDetailsConfiguration(config, false);
- }
+ }
+ /*}catch(Exception e){
+ e.printStackTrace();
+ }*/
}
- //Distribution Editor
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_VOCABULARIES_OVERRIDE) || !preference.isAllowOverride()){
- setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), preference.getValue());
- setBooleanValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE, preference.isAllowOverride());
- }
- }else{
- setBooleanValue(DISTRIBUTION_VOCABULARIES_ALLOW_OVERRIDE,true);
- setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), "");
+ /**
+ * Returns whether the named preference is known.
+ * @param prefKey the key of the preference
+ * @return <code>true</code> if the preference is known, <code>false</code> otherwise
+ */
+ public static boolean contains(String prefKey){
+ return getPreferenceStore().contains(prefKey(prefKey));
}
- preference = getPreferenceFromDB(EditorPreferencePredicate.DistributionEditorActivated);
- if (preference != null){
- boolean test = getBooleanValue(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE);
- if (!getBooleanValue(DISTRIBUTION_AREA_PREFRENCES_ACTIVE_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey(), Boolean.valueOf(preference.getValue()));
- }else{
- test = getBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey());
- System.err.println(test);
+ /**
+ *
+ */
+ public static TermTree getPreferredFeatureTreeForNameDescription(boolean createNew) {
+ if(preferredNameFeatureTree != null && !createNew){
+ return preferredNameFeatureTree;
}
- }
-
- preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionStatus);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_STATUS_OVERRIDE) || !preference.isAllowOverride()){
- //get terms for the uuids... and add them to the termManager as preferred terms
- ITermService termService = CdmStore.getService(ITermService.class);
- String[] uuidArray = preference.getValue().split(";");
- List<UUID> uuidList = new ArrayList();
- for (String uuidString:uuidArray){
- try {
- uuidList.add(UUID.fromString(uuidString));
- } catch (Exception e) {
- logger.warn("Preference loading failed", e);
- }
- }
+ createPreferredFeatureTreeForNameDescription();
+ return preferredNameFeatureTree;
- List<DefinedTermBase> definedTermBases = termService.load(uuidList, null);
- CdmStore.getTermManager().setPreferredTerms(definedTermBases, TermStore.getTerms(TermType.PresenceAbsenceTerm, null));
- }
}
- preference = getPreferenceFromDB(EditorPreferencePredicate.DistributionEditorActivated);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_DESCRIPTION_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey(), Boolean.valueOf(preference.getValue()));
- }
- }
+ public static void createPreferredFeatureTreeForNameDescription() {
- preference = getPreferenceFromDB(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_DISPLAY_AREA_OVERRIDE) || !preference.isAllowOverride()){
- setStringValue(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), preference.getValue());
- }
- }
+ 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()));
- preference = getPreferenceFromDB(EditorPreferencePredicate.DisplayOfStatus);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_DISPLAY_STATUS_OVERRIDE) || !preference.isAllowOverride()){
- setStringValue(EditorPreferencePredicate.DisplayOfStatus.getKey(), preference.getValue());
+ List<UUID> uuids = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.NameFeatures.getKey());
+ if (uuids != null && !uuids.isEmpty()){
+ terms = CdmStore.getTermManager().getTerms(uuids, Feature.class);
}
- }
- preference = getPreferenceFromDB(EditorPreferencePredicate.ShowRankInDistributionEditor);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_SHOW_RANK_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.ShowRankInDistributionEditor.getKey(), Boolean.valueOf(preference.getValue()));
- }
- }
- preference = getPreferenceFromDB(EditorPreferencePredicate.AreasSortedByIdInVocabulary);
- if (preference != null){
- if (!getBooleanValue(DISTRIBUTION_AREAS_SORTED_BY_IDINVOC_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.AreasSortedByIdInVocabulary.getKey(), Boolean.valueOf(preference.getValue()));
- }
- }
- preference = getPreferenceFromDB(EditorPreferencePredicate.OwnDescriptionForDistributionEditor);
- if (preference != null){
- if (!getBooleanValue(OWN_DESCRIPTION_OVERRIDE) || !preference.isAllowOverride()){
- setBooleanValue(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), Boolean.valueOf(preference.getValue()));
- }
- }
- //common names
- preference = getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
- if (preference != null){
- if (!getBooleanValue(COMMON_NAME_AREA_VOCABULARIES) || !preference.isAllowOverride()){
- setStringValue(COMMON_NAME_AREA_VOCABULARIES, preference.getValue());
- setBooleanValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, preference.isAllowOverride());
- }
- }else{
- setStringValue(COMMON_NAME_AREA_VOCABULARIES, "");
- setBooleanValue(COMMON_NAME_AREA_VOCABULARIES_ALLOW_OVERRIDE, true);
- }
+ if (terms.isEmpty()){
+ terms.addAll(TermStore.getTerms(CdmStore.getService(IVocabularyService.class).load(VocabularyEnum.NameFeature.getUuid()), null));
- preference = getPreferenceFromDB(PreferencePredicate.CommonNameReferencesWithMarker);
- if (preference != null){
- if (!getBooleanValue(FILTER_COMMON_NAME_REFERENCES) || !preference.isAllowOverride()){
- setBooleanValue(FILTER_COMMON_NAME_REFERENCES, Boolean.valueOf(preference.getValue()));
}
- }else{
- setBooleanValue(FILTER_COMMON_NAME_REFERENCES, false);
- }
+ 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();
+ }
- //sources
- preference = getPreferenceFromDB(PreferencePredicate.ShowIdInSource);
- if (preference != null){
- if (!getBooleanValue(SHOW_ID_IN_SOURCE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_ID_IN_SOURCE, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_ID_IN_SOURCE, true);
}
- preference = getPreferenceFromDB(PreferencePredicate.ShowNamespaceInSource);
- if (preference != null){
- if (!getBooleanValue(SHOW_NAMESPACE_IN_SOURCE) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_NAMESPACE_IN_SOURCE, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_NAMESPACE_IN_SOURCE, true);
- }
- //multiple classifications / taxon navigator
- preference = getPreferenceFromDB(PreferencePredicate.DisableMultiClassification);
- if (preference != null){
- if (!getBooleanValue(DISABLE_MULTI_CLASSIFICATION) || !preference.isAllowOverride()){
- setBooleanValue(DISABLE_MULTI_CLASSIFICATION, Boolean.valueOf(preference.getValue()));
+ /**
+ * @return
+ */
+ public static TermTree<?> getPreferredFeatureTreeForTaxonDescription(boolean createNew) {
+ if(preferredTaxonFeatureTree != null && !createNew){
+ return preferredTaxonFeatureTree;
}
- }else{
- setBooleanValue(DISABLE_MULTI_CLASSIFICATION, false);
- }
+ createPreferredFeatureTreeForTaxonDescription();
+ return preferredTaxonFeatureTree;
- preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonNodeWizard);
- if (preference != null){
- if (!getBooleanValue(SHOW_TAXONNODE_WIZARD) || !preference.isAllowOverride()){
- setBooleanValue(SHOW_TAXONNODE_WIZARD, Boolean.valueOf(preference.getValue()));
- }
- }else{
- setBooleanValue(SHOW_TAXONNODE_WIZARD, true);
}
-}
+ 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);
+ }
+ }