2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.preference
;
13 import java
.io
.FileInputStream
;
14 import java
.io
.FileOutputStream
;
15 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.HashMap
;
21 import java
.util
.List
;
23 import java
.util
.Properties
;
25 import java
.util
.StringTokenizer
;
26 import java
.util
.UUID
;
28 import org
.apache
.commons
.lang
.StringUtils
;
29 import org
.eclipse
.equinox
.internal
.p2
.ui
.model
.MetadataRepositoryElement
;
30 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
31 import org
.eclipse
.jface
.window
.Window
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
33 import org
.eclipse
.swt
.widgets
.Control
;
34 import org
.eclipse
.swt
.widgets
.Shell
;
35 import org
.eclipse
.ui
.PlatformUI
;
37 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
38 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeConfigurator
;
39 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
40 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
41 import eu
.etaxonomy
.cdm
.api
.service
.config
.FindTaxaAndNamesConfiguratorImpl
;
42 import eu
.etaxonomy
.cdm
.api
.service
.config
.IFindTaxaAndNamesConfigurator
;
43 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
44 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
45 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
46 import eu
.etaxonomy
.cdm
.model
.common
.IDefinedTerm
;
47 import eu
.etaxonomy
.cdm
.model
.common
.ISimpleTerm
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
49 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
50 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
51 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
52 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
53 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
54 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
55 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
56 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
57 import eu
.etaxonomy
.cdm
.strategy
.match
.DefaultMatchStrategy
;
58 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchStrategy
;
59 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchException
;
60 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchMode
;
61 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
62 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
63 import eu
.etaxonomy
.taxeditor
.model
.NomenclaturalCodeHelper
;
64 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
65 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
66 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.DefaultLanguageDialog
;
70 * PreferencesUtil class.
78 public class PreferencesUtil
implements IPreferenceKeys
{
83 public static final String PREFERRED_TERMS_CHANGE
= "preferred_terms";
85 public static final String P2_REPOSITORIES_DELIM
= ",";
86 public static final String P2_REPOSITORY_FIELDS_DELIM
= ";";
95 * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
97 public static IPreferenceStore
getPreferenceStore() {
98 return TaxeditorStorePlugin
.getDefault().getPreferenceStore();
103 * setPreferredNomenclaturalCode
106 * @param preferredCode
107 * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
110 public static CdmPreference
setPreferredNomenclaturalCode(
111 NomenclaturalCode preferredCode
, boolean local
) {
113 getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY
,
114 getPreferenceKey(preferredCode
));
117 ICdmRepository controller
;
118 controller
= CdmStore
.getCurrentApplicationConfiguration();
119 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
120 CdmPreference preference
= null;
121 if (controller
== null){
124 if (preferredCode
== null){
125 preference
= controller
.getPreferenceService().find(key
);
126 if (preference
== null){
129 int index
= StringUtils
.lastIndexOf(preference
.getValue(), ".");
130 UUID uuid
= UUID
.fromString(preference
.getValue().substring(index
+1, preference
.getValue().length()));
131 preferredCode
= NomenclaturalCode
.getByUuid(uuid
);
133 getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY
,
134 getPreferenceKey(preferredCode
));
135 getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
,preference
.isAllowOverride());
139 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
, preferredCode
.getKey());
140 controller
.getPreferenceService().set(preference
);
150 public static NomenclaturalCode
getPreferredNomenclaturalCode(){
151 if (getPreferenceStore().getBoolean(OVERRIDE_NOMENCLATURAL_CODE_KEY
)) {
152 return getPreferredNomenclaturalCode(true);
154 return getPreferredNomenclaturalCode(false);
160 * getPreferredNomenclaturalCode
163 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
165 public static NomenclaturalCode
getPreferredNomenclaturalCode(boolean useLocal
) {
167 CdmPreference pref
= null;
169 pref
= getPreferenceFromDB(PreferencePredicate
.NomenclaturalCode
);
172 String preferredCode
;
174 preferredCode
= getPreferenceStore().getString(
175 PREFERRED_NOMENCLATURAL_CODE_KEY
);
178 preferredCode
= pref
.getValue();
181 for (NomenclaturalCode code
: NomenclaturalCodeHelper
.getAllCodes()) {
182 if (getPreferenceKey(code
).equals(preferredCode
)) {
190 private static CdmPreference
getPreferenceFromDB(PreferencePredicate predicate
){
191 ICdmRepository controller
;
192 CdmPreference pref
= null;
195 controller
= CdmStore
.getCurrentApplicationConfiguration();
196 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), predicate
);
197 pref
= controller
.getPreferenceService().find(key
);
207 public static String
getPreferredDefaultLangugae(){
208 String preferredLanguage
= getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR
);
209 if(StringUtils
.isNotEmpty(preferredLanguage
) && StringUtils
.isNotBlank(preferredLanguage
)){
210 return preferredLanguage
;
216 * Get the match strategy for the given class that was stored in preferences
217 * or the default strategy if it was not stored in preferences
220 * a {@link java.lang.Class} object.
221 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
223 public static IMatchStrategy
getMatchStrategy(Class clazz
) {
224 String className
= clazz
.getName();
225 if (getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX
+ className
)) {
226 IMatchStrategy matchStrategy
= getDefaultMatchStrategy(clazz
);
228 for (String fieldName
: matchStrategy
.getMatchFieldPropertyNames()) {
229 String matchModeName
= getPreferenceStore().getString(
230 getMatchStrategyFieldName(className
, fieldName
));
231 MatchMode matchMode
= MatchMode
.valueOf(matchModeName
);
233 matchStrategy
.setMatchMode(fieldName
, matchMode
);
234 } catch (MatchException e
) {
235 MessagingUtils
.error(PreferencesUtil
.class, e
);
236 throw new RuntimeException(e
);
240 return matchStrategy
;
242 return getDefaultMatchStrategy(clazz
);
246 * Stores a matchStrategy into the preference store.
248 * @param matchStrategy
249 * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
252 public static void setMatchStrategy(IMatchStrategy matchStrategy
) {
253 String className
= matchStrategy
.getMatchClass().getName();
254 getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX
+ className
, true);
256 Set
<String
> matchFields
= matchStrategy
.getMatchFieldPropertyNames();
258 for (String fieldName
: matchFields
) {
259 getPreferenceStore().setValue(
260 getMatchStrategyFieldName(className
, fieldName
),
261 matchStrategy
.getMatchMode(fieldName
).name());
266 * Helper method to create the preference property for a match field.
272 private static String
getMatchStrategyFieldName(String className
,
274 return MATCH_STRATEGY_PREFIX
+ className
+ "." + fieldName
;
278 * Returns the default match strategy for a given class.
281 * a {@link java.lang.Class} object.
282 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
284 public static IMatchStrategy
getDefaultMatchStrategy(Class clazz
) {
285 return DefaultMatchStrategy
.NewInstance(clazz
);
290 * getDateFormatPattern
293 * @return a {@link java.lang.String} object.
295 public static String
getDateFormatPattern() {
296 // TODO make this configurable in properties
297 String pattern
= "Y-M-d H:m";
303 * addTermToPreferredTerms
311 public static <T
extends TermBase
> void addTermToPreferredTerms(T term
) {
313 // VocabularyEnum vocabulary =
314 // VocabularyEnum.getVocabularyEnum(term.getClass());
316 // getPreferenceStore().setValue(getPreferenceKey(term),
317 // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
319 // firePreferencesChanged(term.getClass());
323 * Construct a unique key using the CdmBase object's uuid
328 private static String
getPreferenceKey(ICdmBase cdmBase
) {
329 cdmBase
= HibernateProxyHelper
.deproxy(cdmBase
);
331 String key
= cdmBase
.getClass().getName().concat(".")
332 .concat(cdmBase
.getUuid().toString());
333 if (key
.contains("javassist")) {
334 MessagingUtils
.info("proxy");
340 * Construct a unique key using the CdmBase object's uuid
345 public static String
getPreferenceKey(ISimpleTerm simpleTerm
) {
346 simpleTerm
= HibernateProxyHelper
.deproxy(simpleTerm
);
347 String key
= simpleTerm
.getClass().getName().concat(".")
348 .concat(simpleTerm
.getUuid().toString());
349 if (key
.contains("javassist")) {
350 MessagingUtils
.warn(PreferencesUtil
.class,
351 "Trying to persist a preference based on a proxy class.");
359 * Construct a unique key using the CdmBase object's uuid
364 public static String
getPreferenceKey(IDefinedTerm definedTerm
) {
365 definedTerm
= HibernateProxyHelper
.deproxy(definedTerm
);
366 String key
= definedTerm
.getClass().getName().concat(".")
367 .concat(definedTerm
.getUuid().toString());
368 if (key
.contains("javassist")) {
369 MessagingUtils
.warn(PreferencesUtil
.class,
370 "Trying to persist a preference based on a proxy class.");
376 * Retrieves search preferences from the preference store
378 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
380 public static IFindTaxaAndNamesConfigurator
getSearchConfigurator() {
381 IFindTaxaAndNamesConfigurator configurator
= initializeSearchConfigurator();
383 configurator
.setDoTaxa(getPreferenceStore().getBoolean(
384 TAXON_SERVICE_CONFIGURATOR_TAXA
));
385 configurator
.setDoSynonyms(getPreferenceStore().getBoolean(
386 TAXON_SERVICE_CONFIGURATOR_SYNONYMS
));
387 configurator
.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(
388 TAXON_SERVICE_CONFIGURATOR_NAMES
));
389 configurator
.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(
390 TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
));
391 //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getPreferenceStore().getString(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
397 * create new preferences, setting all search options to true
400 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
403 public static IFindTaxaAndNamesConfigurator
initializeSearchConfigurator() {
404 IFindTaxaAndNamesConfigurator configurator
= new FindTaxaAndNamesConfiguratorImpl();
406 configurator
.setDoTaxa(true);
407 configurator
.setDoSynonyms(true);
408 configurator
.setDoNamesWithoutTaxa(true);
409 configurator
.setDoTaxaByCommonNames(true);
411 configurator
.setTaxonPropertyPath(Arrays
.asList("$", "titleCache",
412 "name", "name.$", "relationsFromThisTaxon.$"));
414 configurator
.setSynonymPropertyPath(Arrays
.asList("$", "titleCache",
415 "name", "name.$", "synonymRelations.relatedTo.*"));
418 // match mode is a simple like, actually all other match modes are kind
421 .setMatchMode(eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
.ANYWHERE
);
422 // we set page number and size here as this should always be unlimited
423 configurator
.setPageNumber(0);
424 // TODO currently limit results to 10000
425 configurator
.setPageSize(10000);
431 * Store search preferences
433 * @param configurator
435 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
438 public static void setSearchConfigurator(
439 IFindTaxaAndNamesConfigurator configurator
) {
440 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA
,
441 configurator
.isDoTaxa());
442 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
443 configurator
.isDoSynonyms());
444 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES
,
445 configurator
.isDoNamesWithoutTaxa());
446 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
,
447 configurator
.isDoTaxaByCommonNames());
452 * firePreferencesChanged
456 * a {@link java.lang.Class} object.
458 public static void firePreferencesChanged(Class clazz
) {
459 getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE
,
464 * Set default values for preferences
466 public static void setDefaults() {
467 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA
, true);
468 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
470 getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT
,
471 "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
472 //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
473 getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP
, false);
474 getPreferenceStore().setDefault(OPENURL_ACCESS_POINT
,
475 "http://www.biodiversitylibrary.org/openurl");
476 getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH
, "1000");
477 getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT
, "1000");
478 getPreferenceStore().setDefault(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
, false);
479 getPreferenceStore().setDefault(CHECKLIST_ID_IN_VOCABULARY
, true);
480 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
, true);
481 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE
, true);
482 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP
, true);
483 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_HYBRID
, true);
484 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_LSID
, true);
485 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP
, true);
486 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAMECACHE
, true);
487 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE
, true);
488 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE
, true);
489 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS
, true);
490 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE
, true);
491 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_RANK
, true);
492 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION
, true);
493 getPreferenceStore().setDefault(SORT_NODES_NATURALLY
, false);
494 getPreferenceStore().setDefault(SORT_NODES_ALPHABETICALLY
, false);
500 * checkNomenclaturalCode
503 public static void checkNomenclaturalCode() {
504 // First time Editor is opened, no nomenclatural code has been set
507 if (PreferencesUtil
.getPreferredNomenclaturalCode(true) == null) {
508 PreferencesUtil
.setPreferredNomenclaturalCode(NomenclaturalCode
.ICNAFP
, true);
514 public static void setNomenclaturalCodePreferences(){
515 ICdmRepository controller
;
516 controller
= CdmStore
.getCurrentApplicationConfiguration();
517 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
518 CdmPreference preference
= null;
519 if (controller
== null){
522 preference
= controller
.getPreferenceService().find(key
);
523 if (preference
== null){
526 getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
, preference
.isAllowOverride());
528 int index
= StringUtils
.lastIndexOf(preference
.getValue(), ".");
529 UUID uuid
= UUID
.fromString(preference
.getValue().substring(index
+1, preference
.getValue().length()));
530 NomenclaturalCode preferredCode
= NomenclaturalCode
.getByUuid(uuid
);
532 getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY
,
533 getPreferenceKey(preferredCode
));
535 if (!preference
.isAllowOverride()){
536 getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY
,
537 getPreferenceKey(preferredCode
));
541 public static void checkDefaultLanguage(){
542 if(PreferencesUtil
.getPreferredDefaultLangugae() == null){
543 Shell shell
= AbstractUtility
.getShell();
544 int open
= new DefaultLanguageDialog(shell
).open();
545 if(open
== Window
.OK
){
546 PlatformUI
.getWorkbench().restart();
549 //TODO:In case of a reinstall, the config.ini will be overwritten
550 // here you create config.ini with the stored key from preferences
556 * getMapServiceAccessPoint
559 * @return a {@link java.lang.String} object.
561 public static String
getMapServiceAccessPoint() {
562 return getPreferenceStore().getString(EDIT_MAP_SERVICE_ACCES_POINT
);
567 * shouldConnectAtStartUp
572 public static boolean shouldConnectAtStartUp() {
573 //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
574 //return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
580 * getDefaultFeatureTreeForTextualDescription
583 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
585 public static FeatureTree
getDefaultFeatureTreeForTextualDescription() {
586 String uuidString
= getPreferenceStore().getString(
587 FEATURE_TREE_DEFAULT_TEXT
);
588 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
589 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
594 * getDefaultFeatureTreeForStructuredDescription
597 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
599 public static FeatureTree
getDefaultFeatureTreeForStructuredDescription() {
600 String uuidString
= getPreferenceStore().getString(
601 FEATURE_TREE_DEFAULT_STRUCTURE
);
602 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
603 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
608 * setSortRanksHierarchichally
614 public static void setSortRanksHierarchichally(boolean selection
) {
615 getPreferenceStore().setValue(SORT_RANKS_HIERARCHICHALLY
, selection
);
620 * getSortRanksHierarchichally
625 public static boolean getSortRanksHierarchichally() {
626 return getPreferenceStore().getBoolean(SORT_RANKS_HIERARCHICHALLY
);
629 public static boolean isMultilanguageTextEditingCapability() {
630 return getPreferenceStore().getBoolean(
631 MULTILANGUAGE_TEXT_EDITING_CAPABILITY
);
634 public static Language
getGlobalLanguage() {
637 String languageUuidString
= getPreferenceStore().getString(
638 GLOBAL_LANGUAGE_UUID
);
640 if(!CdmStore
.isActive()) {
641 MessagingUtils
.noDataSourceWarningDialog(languageUuidString
);
645 if (CdmUtils
.isBlank(languageUuidString
)) {
646 return Language
.getDefaultLanguage();
649 UUID languageUuid
= UUID
.fromString(languageUuidString
);
650 return (Language
) CdmStore
.getService(ITermService
.class).load(
654 public static void setGlobalLanguage(Language language
) {
655 if(language
!= null) {
656 getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID
,language
.getUuid().toString());
657 CdmStore
.setDefaultLanguage(language
);
665 public static Map
<MarkerType
, Boolean
> getEditMarkerTypePreferences() {
666 List
<MarkerType
> markerTypes
= CdmStore
.getTermManager()
667 .getPreferredTerms(MarkerType
.class);
669 Map
<MarkerType
, Boolean
> result
= new HashMap
<MarkerType
, Boolean
>();
671 for (MarkerType markerType
: markerTypes
) {
672 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
673 Boolean value
= getPreferenceStore().getBoolean(name
);
675 result
.put(markerType
, value
);
682 * @param markerTypeEditingMap
684 public static void setEditMarkerTypePreferences(
685 Map
<MarkerType
, Boolean
> markerTypeEditingMap
) {
686 for (MarkerType markerType
: markerTypeEditingMap
.keySet()) {
687 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
688 getPreferenceStore().setValue(name
,
689 markerTypeEditingMap
.get(markerType
));
694 private static String
getMarkerTypeEditingPreferenceKey(
695 MarkerType markerType
) {
696 markerType
= HibernateProxyHelper
.deproxy(markerType
);
697 return markerType
.getClass().getName() + EDIT_MARKER_TYPE_PREFIX
;
702 * setEditMarkerTypePreference
706 * a {@link org.eclipse.ui.IEditorInput} object.
708 * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
712 public static void setEditMarkerTypePreference(MarkerType markerType
,
714 getPreferenceStore().setValue(
715 getMarkerTypeEditingPreferenceKey(markerType
), edit
);
721 public static DerivedUnitFacadeConfigurator
getDerivedUnitConfigurator() {
722 DerivedUnitFacadeConfigurator configurator
= DerivedUnitFacadeConfigurator
724 configurator
.setMoveDerivedUnitMediaToGallery(true);
725 configurator
.setMoveFieldObjectMediaToGallery(true);
730 * This method will write language properties to the config.ini located in the configuration folder
731 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
733 * @param setLanguage 0 is for german and 1 for english.
734 * @throws IOException
736 public void writePropertyToConfigFile(int setLanguage
) throws IOException
{
737 File file
= org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
.INSTANCE
.getLocation().toFile();
738 //give warning to user if the directory has no write access
740 throw new IOException();
742 Properties properties
= load(file
.getAbsolutePath()+"/config.ini");
745 properties
.setProperty("osgi.nl", "de");
746 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "de");
749 properties
.setProperty("osgi.nl", "en");
750 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "en");
755 save(file
+"/config.ini", properties
);
759 * This method loads a property from a given file and returns it.
763 * @throws IOException
765 private Properties
load(String filename
) throws IOException
{
766 FileInputStream in
= new FileInputStream(filename
);
767 Properties prop
= new Properties();
774 * This method saves a property to the specified file.
778 * @throws IOException
780 private void save(String filename
, Properties properties
) throws IOException
{
781 FileOutputStream fos
= new FileOutputStream(filename
);
782 properties
.store(fos
, "");
787 * Saves a list of P2 Metadata Repositories as string with specified delimiters
791 public static void setP2Repositories(List
<MetadataRepositoryElement
> p2Repos
) {
792 StringBuilder sb
= new StringBuilder();
793 for(MetadataRepositoryElement p2Repo
: p2Repos
) {
794 sb
.append(P2_REPOSITORIES_DELIM
);
795 if(p2Repo
.getName() == null || p2Repo
.getName().isEmpty()) {
798 sb
.append(p2Repo
.getName());
800 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
801 sb
.append(p2Repo
.getLocation().toString());
802 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
803 sb
.append(String
.valueOf(p2Repo
.isEnabled()));
805 getPreferenceStore().setValue(P2_REPOSITORY_LIST
, sb
.toString());
810 * Retrieves a list of previously saved P2 repositories
814 public static List
<MetadataRepositoryElement
> getP2Repositories() {
815 List
<MetadataRepositoryElement
> p2Repos
= new ArrayList
<MetadataRepositoryElement
>();
816 String p2ReposPref
= getPreferenceStore().getString(P2_REPOSITORY_LIST
);
817 if(p2ReposPref
!= null && !p2ReposPref
.isEmpty()) {
818 StringTokenizer p2ReposPrefST
= new StringTokenizer(p2ReposPref
,P2_REPOSITORIES_DELIM
);
820 while(p2ReposPrefST
.hasMoreTokens()) {
821 String p2RepoStr
= p2ReposPrefST
.nextToken();
822 StringTokenizer p2ReposStrST
= new StringTokenizer(p2RepoStr
,P2_REPOSITORY_FIELDS_DELIM
);
823 if(p2ReposStrST
.countTokens()==3) {
824 String nickname
= p2ReposStrST
.nextToken();
827 uri
= new URI(p2ReposStrST
.nextToken());
828 } catch (URISyntaxException e
) {
831 boolean enabled
= Boolean
.parseBoolean(p2ReposStrST
.nextToken());
832 MetadataRepositoryElement mre
= new MetadataRepositoryElement(null, uri
, true);
833 mre
.setNickname(nickname
);
834 mre
.setEnabled(enabled
);
844 * enables/disables nested composite. <br>
846 * @param ctrl - Composite to be en-/disabeld
847 * @param enabled - boolean
849 public static void recursiveSetEnabled(Control ctrl
, boolean enabled
) {
850 if (ctrl
instanceof Composite
) {
851 Composite comp
= (Composite
) ctrl
;
852 for (Control c
: comp
.getChildren()) {
853 recursiveSetEnabled(c
, enabled
);
856 ctrl
.setEnabled(enabled
);
862 * getSortRanksNaturally
867 public static boolean getSortNodesNaturally() {
868 return getPreferenceStore().getBoolean(SORT_NODES_NATURALLY
);
873 * setSortRanksNaturally
879 public static void setSortNodesNaturally(boolean selection
) {
880 getPreferenceStore().setValue(SORT_NODES_NATURALLY
, selection
);
886 * getSortRanksNaturally
891 public static boolean getSortNodesStrictlyAlphabetically() {
892 return getPreferenceStore().getBoolean(SORT_NODES_ALPHABETICALLY
);
897 * setSortRanksNaturally
903 public static void setSortNodesStrictlyAlphabetically(boolean selection
) {
904 getPreferenceStore().setValue(SORT_NODES_ALPHABETICALLY
, selection
);
909 * setStoreNavigatorState
915 public static boolean isStoreNavigatorState() {
916 return getPreferenceStore().getBoolean(RESTORE_NAVIGATOR_STATE
);
922 * setStoreNavigatorState
928 public static void setStoreNavigatorState(boolean selection
) {
929 getPreferenceStore().setValue(RESTORE_NAVIGATOR_STATE
, selection
);
936 public static boolean isShowUpWidgetIsDisposedMessages() {
937 return getPreferenceStore().getBoolean(IS_SHOW_UP_WIDGET_IS_DISPOSED
);
939 public static void setShowUpWidgetIsDisposedMessages(boolean selection
) {
940 getPreferenceStore().setValue(IS_SHOW_UP_WIDGET_IS_DISPOSED
, selection
);
946 public static boolean isShowIdInVocabularyInChecklistEditor() {
947 return getPreferenceStore().getBoolean(IPreferenceKeys
.CHECKLIST_ID_IN_VOCABULARY
);
949 public static void setShowIdInVocabularyInChecklistEditor(boolean selection
) {
950 getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY
, selection
);
956 public static boolean isShowRankInChecklistEditor() {
957 return getPreferenceStore().getBoolean(IPreferenceKeys
.CHECKLIST_SHOW_RANK
);
959 public static void setShowRankInChecklistEditor(boolean selection
) {
960 getPreferenceStore().setValue(CHECKLIST_SHOW_RANK
, selection
);
968 public static NameDetailsConfigurator
setPreferredNameDetailsConfiguration( boolean local
) {
969 NameDetailsConfigurator config
= new NameDetailsConfigurator(true);
971 CdmPreference preference
= null;
974 preference
= getPreferenceFromDB(PreferencePredicate
.NameDetailsView
);
976 if (preference
== null){
980 getPreferenceStore().setValue(ALLOW_OVERRIDE_NAMEDETAILS
, preference
.isAllowOverride());
982 //the preference value is build like this:
983 //<section1>:true;<section2>:false....
985 String value
= preference
.getValue();
986 String
[] sections
= value
.split(";");
987 Map
<String
, Boolean
> sectionMap
= new HashMap
<String
, Boolean
>();
988 String
[] sectionValues
;
989 for (String sectionValue
: sections
){
990 sectionValues
= sectionValue
.split(":");
991 sectionMap
.put(sectionValues
[0], Boolean
.valueOf(sectionValues
[1]));
996 getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON
,
997 (sectionMap
.get("taxon")));
998 config
.setTaxonSectionActivated(sectionMap
.get("taxon"));
1000 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID
,
1001 (sectionMap
.get("lsid")));
1002 config
.setLSIDActivated(sectionMap
.get("lsid"));
1004 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE
,
1005 (sectionMap
.get("nc")));
1006 config
.setNomenclaturalCodeActived(sectionMap
.get("nc"));
1008 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE
,
1009 (sectionMap
.get("ap")));
1010 config
.setAppendedPhraseActivated(sectionMap
.get("ap"));
1012 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK
,
1013 (sectionMap
.get("rank")));
1014 config
.setRankActivated(sectionMap
.get("rank"));
1017 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
,
1018 (sectionMap
.get("atomisedEpithets")));
1019 config
.setAtomisedEpithetsActivated(sectionMap
.get("atomisedEpithets"));
1021 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP
,
1022 (sectionMap
.get("author")));
1023 config
.setAuthorshipSectionActivated(sectionMap
.get("author"));
1025 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE
,
1026 (sectionMap
.get("nomRef")));
1027 config
.setNomenclaturalReferenceSectionActivated(sectionMap
.get("nomRef"));
1029 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS
,
1030 (sectionMap
.get("nomStat")));
1031 config
.setNomenclaturalStatusSectionActivated(sectionMap
.get("nomStat"));
1034 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE
,
1035 (sectionMap
.get("protologue")));
1036 config
.setProtologueActivated(sectionMap
.get("protologue"));
1038 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION
,
1039 (sectionMap
.get("typeDes")));
1040 config
.setTypeDesignationSectionActivated(sectionMap
.get("typeDes"));
1042 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP
,
1043 (sectionMap
.get("nameRelation")));
1044 config
.setNameRelationsSectionActivated(sectionMap
.get("nameRelation"));
1049 public static boolean getIsDeterminiationOnlyForFieldUnit(boolean local
){
1050 CdmPreference preference
= null;
1053 preference
= getPreferenceFromDB(PreferencePredicate
.DeterminationOnlyForFieldUnits
);
1055 if (preference
== null){
1056 return getPreferenceStore().getBoolean(DETERMINATION_ONLY_FOR_FIELD_UNITS
);
1058 return Boolean
.valueOf(preference
.getValue());
1061 public static boolean getIsShowCollectingAreasInGeneralSection(boolean local
){
1062 CdmPreference preference
= null;
1065 preference
= getPreferenceFromDB(PreferencePredicate
.ShowCollectingAreasInGeneralSection
);
1067 if (preference
== null){
1068 return getPreferenceStore().getBoolean(SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION
);
1070 return Boolean
.valueOf(preference
.getValue());
1073 public static boolean getIsShowTaxonAssociations(boolean local
){
1074 CdmPreference preference
= null;
1077 preference
= getPreferenceFromDB(PreferencePredicate
.ShowTaxonAssociations
);
1079 if (preference
== null){
1080 return getPreferenceStore().getBoolean(SHOW_TAXON_ASSOCIATIONS
);
1082 return Boolean
.valueOf(preference
.getValue());