/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
- *
+ *
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.taxeditor.preference;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import java.util.UUID;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
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.strategy.match.IMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.MatchException;
import eu.etaxonomy.cdm.strategy.match.MatchMode;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
/**
* <p>
* PreferencesUtil class.
* </p>
- *
+ *
* @author p.ciardelli
* @author n.hoffmann
* @created 05.12.2008
public class PreferencesUtil implements IPreferenceKeys {
/**
- *
+ *
*/
public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
* <p>
* getPreferenceStore
* </p>
- *
+ *
* @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
*/
public static IPreferenceStore getPreferenceStore() {
* <p>
* setPreferredNomenclaturalCode
* </p>
- *
+ *
* @param preferredCode
* a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
* object.
* <p>
* getPreferredNomenclaturalCode
* </p>
- *
+ *
* @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
*/
public static NomenclaturalCode getPreferredNomenclaturalCode() {
return null;
}
+ public static String getPreferredDefaultLangugae(){
+ String preferredLanguage = getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR);
+ if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
+ return preferredLanguage;
+ }
+ return null;
+ }
+
/**
* 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.
try {
matchStrategy.setMatchMode(fieldName, matchMode);
} catch (MatchException e) {
- StoreUtil.error(PreferencesUtil.class, e);
+ MessagingUtils.error(PreferencesUtil.class, e);
throw new RuntimeException(e);
}
}
/**
* Stores a matchStrategy into the preference store.
- *
+ *
* @param matchStrategy
* a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
* object.
/**
* Helper method to create the preference property for a match field.
- *
+ *
* @param className
* @param fieldName
* @return
/**
* 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.
* <p>
* getDateFormatPattern
* </p>
- *
+ *
* @return a {@link java.lang.String} object.
*/
public static String getDateFormatPattern() {
* <p>
* addTermToPreferredTerms
* </p>
- *
+ *
* @param term
* a T object.
* @param <T>
/**
* Construct a unique key using the CdmBase object's uuid
- *
+ *
* @param cdmBase
* @return
*/
String key = cdmBase.getClass().getName().concat(".")
.concat(cdmBase.getUuid().toString());
if (key.contains("javassist")) {
- StoreUtil.info("proxy");
+ 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 = (ISimpleTerm) 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
*/
String key = definedTerm.getClass().getName().concat(".")
.concat(definedTerm.getUuid().toString());
if (key.contains("javassist")) {
- StoreUtil.warn(PreferencesUtil.class,
+ 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() {
/**
* create new preferences, setting all search options to true
- *
+ *
* @return a
* {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
* object.
// match mode is a simple like, actually all other match modes are kind
// of bogus
configurator
- .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.LIKE);
+ .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
/**
* Store search preferences
- *
+ *
* @param configurator
* a
* {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
* <p>
* firePreferencesChanged
* </p>
- *
+ *
* @param clazz
* a {@link java.lang.Class} object.
*/
getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
true);
getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT,
- "http://edit.br.fgov.be/edit_wp5/v1/areas.php");
- getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP, true);
+ "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(SHOULD_CONNECT_AT_STARTUP, false);
getPreferenceStore().setDefault(OPENURL_ACCESS_POINT,
"http://www.biodiversitylibrary.org/openurl");
getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH, "1000");
*/
public static void checkNomenclaturalCode() {
// First time Editor is opened, no nomenclatural code has been set
+
+
if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
+ PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP);
+ /*
StoreUtil.info("No nomencatural code set.");
Shell shell = StoreUtil.getShell();
- // Query user re: preferred nom. code
+ Query user re: preferred nom. code
Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
dialog.open();
"The following has been set as your preferred nomenclatural code:\n\n\t"
+ NomenclaturalCodeHelper
.getDescription(code)
- + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
+ + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");*/
}
}
+ public static void checkDefaultLanguage(){
+ if(PreferencesUtil.getPreferredDefaultLangugae() == null){
+ Shell shell = StoreUtil.getShell();
+ int open = new DefaultLanguageDialog(shell).open();
+ if(open == 0){//FIXME:window performed ok. Find variable for it
+ 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() {
* <p>
* shouldConnectAtStartUp
* </p>
- *
+ *
* @return a boolean.
*/
public static boolean shouldConnectAtStartUp() {
- return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
+ //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
+ //return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
+ return false;
}
/**
* <p>
* getDefaultFeatureTreeForTextualDescription
* </p>
- *
+ *
* @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
*/
public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
* <p>
* getDefaultFeatureTreeForStructuredDescription
* </p>
- *
+ *
* @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
*/
public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
* <p>
* setSortRanksHierarchichally
* </p>
- *
+ *
* @param selection
* a boolean.
*/
* <p>
* getSortRanksHierarchichally
* </p>
- *
+ *
* @return a boolean.
*/
public static boolean getSortRanksHierarchichally() {
String languageUuidString = getPreferenceStore().getString(
GLOBAL_LANGUAGE_UUID);
- if (CdmUtils.isEmpty(languageUuidString)) {
- return Language.DEFAULT();
+ if (CdmUtils.isBlank(languageUuidString)) {
+ return Language.getDefaultLanguage();
}
UUID languageUuid = UUID.fromString(languageUuidString);
* <p>
* setEditMarkerTypePreference
* </p>
- *
+ *
* @param input
* a {@link org.eclipse.ui.IEditorInput} object.
* @param markerType
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();
+ Properties properties = load(file.getAbsolutePath()+"/config.ini");
+ switch(setLanguage){
+ case 0:
+ properties.setProperty("osgi.nl", "de");
+ PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
+ break;
+ case 1:
+ properties.setProperty("osgi.nl", "en");
+ PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
+ break;
+ default:
+ break;
+ }
+ save(file+"/config.ini", properties);
+ }
+
+ /**
+ * This method loads a property from a given file and returns it.
+ *
+ * @param filename
+ * @return
+ * @throws IOException
+ */
+ private Properties load(String filename) throws IOException {
+ FileInputStream in = new FileInputStream(filename);
+ Properties prop = new Properties();
+ prop.load(in);
+ in.close();
+ return prop;
+ }
+
+ /**
+ * This method saves a property to the specified file.
+ *
+ * @param filename
+ * @param properties
+ * @throws IOException
+ */
+ private void save(String filename, Properties properties) throws IOException{
+ FileOutputStream fos = new FileOutputStream(filename);
+ properties.store(fos, "");
+ fos.close();
+ }
+
}