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
.ICdmApplicationConfiguration
;
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 ICdmApplicationConfiguration 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
) {
166 ICdmApplicationConfiguration controller
;
167 CdmPreference pref
= null;
170 controller
= CdmStore
.getCurrentApplicationConfiguration();
171 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
172 pref
= controller
.getPreferenceService().find(key
);
178 String preferredCode
;
180 preferredCode
= getPreferenceStore().getString(
181 PREFERRED_NOMENCLATURAL_CODE_KEY
);
184 preferredCode
= pref
.getValue();
187 for (NomenclaturalCode code
: NomenclaturalCodeHelper
.getAllCodes()) {
188 if (getPreferenceKey(code
).equals(preferredCode
)) {
195 public static String
getPreferredDefaultLangugae(){
196 String preferredLanguage
= getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR
);
197 if(StringUtils
.isNotEmpty(preferredLanguage
) && StringUtils
.isNotBlank(preferredLanguage
)){
198 return preferredLanguage
;
204 * Get the match strategy for the given class that was stored in preferences
205 * or the default strategy if it was not stored in preferences
208 * a {@link java.lang.Class} object.
209 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
211 public static IMatchStrategy
getMatchStrategy(Class clazz
) {
212 String className
= clazz
.getName();
213 if (getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX
+ className
)) {
214 IMatchStrategy matchStrategy
= getDefaultMatchStrategy(clazz
);
216 for (String fieldName
: matchStrategy
.getMatchFieldPropertyNames()) {
217 String matchModeName
= getPreferenceStore().getString(
218 getMatchStrategyFieldName(className
, fieldName
));
219 MatchMode matchMode
= MatchMode
.valueOf(matchModeName
);
221 matchStrategy
.setMatchMode(fieldName
, matchMode
);
222 } catch (MatchException e
) {
223 MessagingUtils
.error(PreferencesUtil
.class, e
);
224 throw new RuntimeException(e
);
228 return matchStrategy
;
230 return getDefaultMatchStrategy(clazz
);
234 * Stores a matchStrategy into the preference store.
236 * @param matchStrategy
237 * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
240 public static void setMatchStrategy(IMatchStrategy matchStrategy
) {
241 String className
= matchStrategy
.getMatchClass().getName();
242 getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX
+ className
, true);
244 Set
<String
> matchFields
= matchStrategy
.getMatchFieldPropertyNames();
246 for (String fieldName
: matchFields
) {
247 getPreferenceStore().setValue(
248 getMatchStrategyFieldName(className
, fieldName
),
249 matchStrategy
.getMatchMode(fieldName
).name());
254 * Helper method to create the preference property for a match field.
260 private static String
getMatchStrategyFieldName(String className
,
262 return MATCH_STRATEGY_PREFIX
+ className
+ "." + fieldName
;
266 * Returns the default match strategy for a given class.
269 * a {@link java.lang.Class} object.
270 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
272 public static IMatchStrategy
getDefaultMatchStrategy(Class clazz
) {
273 return DefaultMatchStrategy
.NewInstance(clazz
);
278 * getDateFormatPattern
281 * @return a {@link java.lang.String} object.
283 public static String
getDateFormatPattern() {
284 // TODO make this configurable in properties
285 String pattern
= "Y-M-d H:m";
291 * addTermToPreferredTerms
299 public static <T
extends TermBase
> void addTermToPreferredTerms(T term
) {
301 // VocabularyEnum vocabulary =
302 // VocabularyEnum.getVocabularyEnum(term.getClass());
304 // getPreferenceStore().setValue(getPreferenceKey(term),
305 // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
307 // firePreferencesChanged(term.getClass());
311 * Construct a unique key using the CdmBase object's uuid
316 private static String
getPreferenceKey(ICdmBase cdmBase
) {
317 cdmBase
= HibernateProxyHelper
.deproxy(cdmBase
);
319 String key
= cdmBase
.getClass().getName().concat(".")
320 .concat(cdmBase
.getUuid().toString());
321 if (key
.contains("javassist")) {
322 MessagingUtils
.info("proxy");
328 * Construct a unique key using the CdmBase object's uuid
333 public static String
getPreferenceKey(ISimpleTerm simpleTerm
) {
334 simpleTerm
= HibernateProxyHelper
.deproxy(simpleTerm
);
335 String key
= simpleTerm
.getClass().getName().concat(".")
336 .concat(simpleTerm
.getUuid().toString());
337 if (key
.contains("javassist")) {
338 MessagingUtils
.warn(PreferencesUtil
.class,
339 "Trying to persist a preference based on a proxy class.");
347 * Construct a unique key using the CdmBase object's uuid
352 public static String
getPreferenceKey(IDefinedTerm definedTerm
) {
353 definedTerm
= HibernateProxyHelper
.deproxy(definedTerm
);
354 String key
= definedTerm
.getClass().getName().concat(".")
355 .concat(definedTerm
.getUuid().toString());
356 if (key
.contains("javassist")) {
357 MessagingUtils
.warn(PreferencesUtil
.class,
358 "Trying to persist a preference based on a proxy class.");
364 * Retrieves search preferences from the preference store
366 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
368 public static IFindTaxaAndNamesConfigurator
getSearchConfigurator() {
369 IFindTaxaAndNamesConfigurator configurator
= initializeSearchConfigurator();
371 configurator
.setDoTaxa(getPreferenceStore().getBoolean(
372 TAXON_SERVICE_CONFIGURATOR_TAXA
));
373 configurator
.setDoSynonyms(getPreferenceStore().getBoolean(
374 TAXON_SERVICE_CONFIGURATOR_SYNONYMS
));
375 configurator
.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(
376 TAXON_SERVICE_CONFIGURATOR_NAMES
));
377 configurator
.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(
378 TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
));
379 //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getPreferenceStore().getString(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
385 * create new preferences, setting all search options to true
388 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
391 public static IFindTaxaAndNamesConfigurator
initializeSearchConfigurator() {
392 IFindTaxaAndNamesConfigurator configurator
= new FindTaxaAndNamesConfiguratorImpl();
394 configurator
.setDoTaxa(true);
395 configurator
.setDoSynonyms(true);
396 configurator
.setDoNamesWithoutTaxa(true);
397 configurator
.setDoTaxaByCommonNames(true);
399 configurator
.setTaxonPropertyPath(Arrays
.asList("$", "titleCache",
400 "name", "name.$", "relationsFromThisTaxon.$"));
402 configurator
.setSynonymPropertyPath(Arrays
.asList("$", "titleCache",
403 "name", "name.$", "synonymRelations.relatedTo.*"));
406 // match mode is a simple like, actually all other match modes are kind
409 .setMatchMode(eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
.ANYWHERE
);
410 // we set page number and size here as this should always be unlimited
411 configurator
.setPageNumber(0);
412 // TODO currently limit results to 10000
413 configurator
.setPageSize(10000);
419 * Store search preferences
421 * @param configurator
423 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
426 public static void setSearchConfigurator(
427 IFindTaxaAndNamesConfigurator configurator
) {
428 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA
,
429 configurator
.isDoTaxa());
430 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
431 configurator
.isDoSynonyms());
432 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES
,
433 configurator
.isDoNamesWithoutTaxa());
434 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
,
435 configurator
.isDoTaxaByCommonNames());
440 * firePreferencesChanged
444 * a {@link java.lang.Class} object.
446 public static void firePreferencesChanged(Class clazz
) {
447 getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE
,
452 * Set default values for preferences
454 public static void setDefaults() {
455 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA
, true);
456 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
458 getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT
,
459 "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
460 //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
461 getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP
, false);
462 getPreferenceStore().setDefault(OPENURL_ACCESS_POINT
,
463 "http://www.biodiversitylibrary.org/openurl");
464 getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH
, "1000");
465 getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT
, "1000");
466 getPreferenceStore().setDefault(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
, false);
467 getPreferenceStore().setDefault(CHECKLIST_ID_IN_VOCABULARY
, true);
468 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
, true);
469 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP
, true);
470 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_HYBRID
, true);
471 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_LSID
, true);
472 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP
, true);
473 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAMECACHE
, true);
474 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE
, true);
475 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE
, true);
476 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS
, true);
477 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE
, true);
478 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_RANK
, true);
479 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION
, true);
484 * checkNomenclaturalCode
487 public static void checkNomenclaturalCode() {
488 // First time Editor is opened, no nomenclatural code has been set
491 if (PreferencesUtil
.getPreferredNomenclaturalCode(true) == null) {
492 PreferencesUtil
.setPreferredNomenclaturalCode(NomenclaturalCode
.ICNAFP
, true);
498 public static void setNomenclaturalCodePreferences(){
499 ICdmApplicationConfiguration controller
;
500 controller
= CdmStore
.getCurrentApplicationConfiguration();
501 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
502 CdmPreference preference
= null;
503 if (controller
== null){
506 preference
= controller
.getPreferenceService().find(key
);
507 if (preference
== null){
510 getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY
, preference
.isAllowOverride());
512 int index
= StringUtils
.lastIndexOf(preference
.getValue(), ".");
513 UUID uuid
= UUID
.fromString(preference
.getValue().substring(index
+1, preference
.getValue().length()));
514 NomenclaturalCode preferredCode
= NomenclaturalCode
.getByUuid(uuid
);
516 getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY
,
517 getPreferenceKey(preferredCode
));
519 if (!preference
.isAllowOverride()){
520 getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY
,
521 getPreferenceKey(preferredCode
));
525 public static void checkDefaultLanguage(){
526 if(PreferencesUtil
.getPreferredDefaultLangugae() == null){
527 Shell shell
= AbstractUtility
.getShell();
528 int open
= new DefaultLanguageDialog(shell
).open();
529 if(open
== Window
.OK
){
530 PlatformUI
.getWorkbench().restart();
533 //TODO:In case of a reinstall, the config.ini will be overwritten
534 // here you create config.ini with the stored key from preferences
540 * getMapServiceAccessPoint
543 * @return a {@link java.lang.String} object.
545 public static String
getMapServiceAccessPoint() {
546 return getPreferenceStore().getString(EDIT_MAP_SERVICE_ACCES_POINT
);
551 * shouldConnectAtStartUp
556 public static boolean shouldConnectAtStartUp() {
557 //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
558 //return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
564 * getDefaultFeatureTreeForTextualDescription
567 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
569 public static FeatureTree
getDefaultFeatureTreeForTextualDescription() {
570 String uuidString
= getPreferenceStore().getString(
571 FEATURE_TREE_DEFAULT_TEXT
);
572 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
573 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
578 * getDefaultFeatureTreeForStructuredDescription
581 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
583 public static FeatureTree
getDefaultFeatureTreeForStructuredDescription() {
584 String uuidString
= getPreferenceStore().getString(
585 FEATURE_TREE_DEFAULT_STRUCTURE
);
586 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
587 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
592 * setSortRanksHierarchichally
598 public static void setSortRanksHierarchichally(boolean selection
) {
599 getPreferenceStore().setValue(SORT_RANKS_HIERARCHICHALLY
, selection
);
604 * getSortRanksHierarchichally
609 public static boolean getSortRanksHierarchichally() {
610 return getPreferenceStore().getBoolean(SORT_RANKS_HIERARCHICHALLY
);
613 public static boolean isMultilanguageTextEditingCapability() {
614 return getPreferenceStore().getBoolean(
615 MULTILANGUAGE_TEXT_EDITING_CAPABILITY
);
618 public static Language
getGlobalLanguage() {
621 String languageUuidString
= getPreferenceStore().getString(
622 GLOBAL_LANGUAGE_UUID
);
624 if(!CdmStore
.isActive()) {
625 MessagingUtils
.noDataSourceWarningDialog(languageUuidString
);
629 if (CdmUtils
.isBlank(languageUuidString
)) {
630 return Language
.getDefaultLanguage();
633 UUID languageUuid
= UUID
.fromString(languageUuidString
);
634 return (Language
) CdmStore
.getService(ITermService
.class).load(
638 public static void setGlobalLanguage(Language language
) {
639 if(language
!= null) {
640 getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID
,language
.getUuid().toString());
641 CdmStore
.setDefaultLanguage(language
);
649 public static Map
<MarkerType
, Boolean
> getEditMarkerTypePreferences() {
650 List
<MarkerType
> markerTypes
= CdmStore
.getTermManager()
651 .getPreferredTerms(MarkerType
.class);
653 Map
<MarkerType
, Boolean
> result
= new HashMap
<MarkerType
, Boolean
>();
655 for (MarkerType markerType
: markerTypes
) {
656 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
657 Boolean value
= getPreferenceStore().getBoolean(name
);
659 result
.put(markerType
, value
);
666 * @param markerTypeEditingMap
668 public static void setEditMarkerTypePreferences(
669 Map
<MarkerType
, Boolean
> markerTypeEditingMap
) {
670 for (MarkerType markerType
: markerTypeEditingMap
.keySet()) {
671 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
672 getPreferenceStore().setValue(name
,
673 markerTypeEditingMap
.get(markerType
));
678 private static String
getMarkerTypeEditingPreferenceKey(
679 MarkerType markerType
) {
680 markerType
= HibernateProxyHelper
.deproxy(markerType
);
681 return markerType
.getClass().getName() + EDIT_MARKER_TYPE_PREFIX
;
686 * setEditMarkerTypePreference
690 * a {@link org.eclipse.ui.IEditorInput} object.
692 * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
696 public static void setEditMarkerTypePreference(MarkerType markerType
,
698 getPreferenceStore().setValue(
699 getMarkerTypeEditingPreferenceKey(markerType
), edit
);
705 public static DerivedUnitFacadeConfigurator
getDerivedUnitConfigurator() {
706 DerivedUnitFacadeConfigurator configurator
= DerivedUnitFacadeConfigurator
708 configurator
.setMoveDerivedUnitMediaToGallery(true);
709 configurator
.setMoveFieldObjectMediaToGallery(true);
714 * This method will write language properties to the config.ini located in the configuration folder
715 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
717 * @param setLanguage 0 is for german and 1 for english.
718 * @throws IOException
720 public void writePropertyToConfigFile(int setLanguage
) throws IOException
{
721 File file
= org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
.INSTANCE
.getLocation().toFile();
722 //give warning to user if the directory has no write access
724 throw new IOException();
726 Properties properties
= load(file
.getAbsolutePath()+"/config.ini");
729 properties
.setProperty("osgi.nl", "de");
730 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "de");
733 properties
.setProperty("osgi.nl", "en");
734 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "en");
739 save(file
+"/config.ini", properties
);
743 * This method loads a property from a given file and returns it.
747 * @throws IOException
749 private Properties
load(String filename
) throws IOException
{
750 FileInputStream in
= new FileInputStream(filename
);
751 Properties prop
= new Properties();
758 * This method saves a property to the specified file.
762 * @throws IOException
764 private void save(String filename
, Properties properties
) throws IOException
{
765 FileOutputStream fos
= new FileOutputStream(filename
);
766 properties
.store(fos
, "");
771 * Saves a list of P2 Metadata Repositories as string with specified delimiters
775 public static void setP2Repositories(List
<MetadataRepositoryElement
> p2Repos
) {
776 StringBuilder sb
= new StringBuilder();
777 for(MetadataRepositoryElement p2Repo
: p2Repos
) {
778 sb
.append(P2_REPOSITORIES_DELIM
);
779 if(p2Repo
.getName() == null || p2Repo
.getName().isEmpty()) {
782 sb
.append(p2Repo
.getName());
784 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
785 sb
.append(p2Repo
.getLocation().toString());
786 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
787 sb
.append(String
.valueOf(p2Repo
.isEnabled()));
789 getPreferenceStore().setValue(P2_REPOSITORY_LIST
, sb
.toString());
794 * Retrieves a list of previously saved P2 repositories
798 public static List
<MetadataRepositoryElement
> getP2Repositories() {
799 List
<MetadataRepositoryElement
> p2Repos
= new ArrayList
<MetadataRepositoryElement
>();
800 String p2ReposPref
= getPreferenceStore().getString(P2_REPOSITORY_LIST
);
801 if(p2ReposPref
!= null && !p2ReposPref
.isEmpty()) {
802 StringTokenizer p2ReposPrefST
= new StringTokenizer(p2ReposPref
,P2_REPOSITORIES_DELIM
);
804 while(p2ReposPrefST
.hasMoreTokens()) {
805 String p2RepoStr
= p2ReposPrefST
.nextToken();
806 StringTokenizer p2ReposStrST
= new StringTokenizer(p2RepoStr
,P2_REPOSITORY_FIELDS_DELIM
);
807 if(p2ReposStrST
.countTokens()==3) {
808 String nickname
= p2ReposStrST
.nextToken();
811 uri
= new URI(p2ReposStrST
.nextToken());
812 } catch (URISyntaxException e
) {
815 boolean enabled
= Boolean
.parseBoolean(p2ReposStrST
.nextToken());
816 MetadataRepositoryElement mre
= new MetadataRepositoryElement(null, uri
, true);
817 mre
.setNickname(nickname
);
818 mre
.setEnabled(enabled
);
828 * enables/disables nested composite. <br>
830 * @param ctrl - Composite to be en-/disabeld
831 * @param enabled - boolean
833 public static void recursiveSetEnabled(Control ctrl
, boolean enabled
) {
834 if (ctrl
instanceof Composite
) {
835 Composite comp
= (Composite
) ctrl
;
836 for (Control c
: comp
.getChildren()) {
837 recursiveSetEnabled(c
, enabled
);
840 ctrl
.setEnabled(enabled
);
846 * getSortRanksNaturally
851 public static boolean getSortNodesNaturally() {
852 return getPreferenceStore().getBoolean(SORT_NODES_NATURALLY
);
857 * setSortRanksNaturally
863 public static void setSortNodesNaturally(boolean selection
) {
864 getPreferenceStore().setValue(SORT_NODES_NATURALLY
, selection
);
870 * getSortRanksNaturally
875 public static boolean getSortNodesStrictlyAlphabetically() {
876 return getPreferenceStore().getBoolean(SORT_NODES_ALPHABETICALLY
);
881 * setSortRanksNaturally
887 public static void setSortNodesStrictlyAlphabetically(boolean selection
) {
888 getPreferenceStore().setValue(SORT_NODES_ALPHABETICALLY
, selection
);
893 * setStoreNavigatorState
899 public static boolean isStoreNavigatorState() {
900 return getPreferenceStore().getBoolean(RESTORE_NAVIGATOR_STATE
);
906 * setStoreNavigatorState
912 public static void setStoreNavigatorState(boolean selection
) {
913 getPreferenceStore().setValue(RESTORE_NAVIGATOR_STATE
, selection
);
920 public static boolean isShowUpWidgetIsDisposedMessages() {
921 return getPreferenceStore().getBoolean(IS_SHOW_UP_WIDGET_IS_DISPOSED
);
923 public static void setShowUpWidgetIsDisposedMessages(boolean selection
) {
924 getPreferenceStore().setValue(IS_SHOW_UP_WIDGET_IS_DISPOSED
, selection
);
930 public static boolean isShowIdInVocabularyInChecklistEditor() {
931 return getPreferenceStore().getBoolean(IPreferenceKeys
.CHECKLIST_ID_IN_VOCABULARY
);
933 public static void setShowIdInVocabularyInChecklistEditor(boolean selection
) {
934 getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY
, selection
);
940 public static boolean isShowRankInChecklistEditor() {
941 return getPreferenceStore().getBoolean(IPreferenceKeys
.CHECKLIST_SHOW_RANK
);
943 public static void setShowRankInChecklistEditor(boolean selection
) {
944 getPreferenceStore().setValue(CHECKLIST_SHOW_RANK
, selection
);
952 public static NameDetailsConfigurator
setPreferredNameDetailsConfiguration( boolean local
) {
953 NameDetailsConfigurator config
= new NameDetailsConfigurator(true);
954 ICdmApplicationConfiguration controller
;
955 controller
= CdmStore
.getCurrentApplicationConfiguration();
956 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NameDetailsView
);
957 CdmPreference preference
= null;
958 if (controller
== null){
961 preference
= controller
.getPreferenceService().find(key
);
962 if (preference
== null){
965 getPreferenceStore().setValue(ALLOW_OVERRIDE_NAMEDETAILS
, preference
.isAllowOverride());
967 //the preference value is build like this:
968 //<section1>:true;<section2>:false....
970 String value
= preference
.getValue();
971 String
[] sections
= value
.split(";");
972 Map
<String
, Boolean
> sectionMap
= new HashMap
<String
, Boolean
>();
973 String
[] sectionValues
;
974 for (String sectionValue
: sections
){
975 sectionValues
= sectionValue
.split(":");
976 sectionMap
.put(sectionValues
[0], Boolean
.valueOf(sectionValues
[1]));
981 getPreferenceStore().setValue(SHOW_SIMPLE_NAME_DETAILS_TAXON
,
982 (sectionMap
.get("taxon")));
983 config
.setTaxonSectionActivated(sectionMap
.get("taxon"));
985 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_LSID
,
986 (sectionMap
.get("lsid")));
987 config
.setLSIDActivated(sectionMap
.get("lsid"));
989 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE
,
990 (sectionMap
.get("nc")));
991 config
.setNomenclaturalCodeActived(sectionMap
.get("nc"));
993 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE
,
994 (sectionMap
.get("ap")));
995 config
.setAppendedPhraseActivated(sectionMap
.get("ap"));
997 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_RANK
,
998 (sectionMap
.get("rank")));
999 config
.setRankActivated(sectionMap
.get("rank"));
1002 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
,
1003 (sectionMap
.get("atomisedEpithets")));
1004 config
.setAtomisedEpithetsActivated(sectionMap
.get("atomisedEpithets"));
1006 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP
,
1007 (sectionMap
.get("author")));
1008 config
.setAuthorshipSectionActivated(sectionMap
.get("author"));
1010 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE
,
1011 (sectionMap
.get("nomRef")));
1012 config
.setNomenclaturalReferenceSectionActivated(sectionMap
.get("nomRef"));
1014 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS
,
1015 (sectionMap
.get("nomStat")));
1016 config
.setNomenclaturalStatusSectionActivated(sectionMap
.get("nomStat"));
1019 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE
,
1020 (sectionMap
.get("protologue")));
1021 config
.setProtologueActivated(sectionMap
.get("protologue"));
1023 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION
,
1024 (sectionMap
.get("typeDes")));
1025 config
.setTypeDesignationSectionActivated(sectionMap
.get("typeDes"));
1027 getPreferenceStore().setValue(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP
,
1028 (sectionMap
.get("nameRelation")));
1029 config
.setNameRelationsSectionActivated(sectionMap
.get("nameRelation"));