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 NomenclaturalCode
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
);
132 return preferredCode
;
135 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
, preferredCode
.getKey());
136 controller
.getPreferenceService().set(preference
);
140 return preferredCode
;
146 public static NomenclaturalCode
getPreferredNomenclaturalCode(){
147 if (getPreferenceStore().getBoolean(OVERRIDE_NOMENCLATURAL_CODE_KEY
)) {
148 return getPreferredNomenclaturalCode(true);
150 return getPreferredNomenclaturalCode(false);
156 * getPreferredNomenclaturalCode
159 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
161 public static NomenclaturalCode
getPreferredNomenclaturalCode(boolean useLocal
) {
162 ICdmApplicationConfiguration controller
;
163 CdmPreference pref
= null;
166 controller
= CdmStore
.getCurrentApplicationConfiguration();
167 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
168 pref
= controller
.getPreferenceService().find(key
);
174 String preferredCode
;
176 preferredCode
= getPreferenceStore().getString(
177 PREFERRED_NOMENCLATURAL_CODE_KEY
);
179 preferredCode
= pref
.getValue();
182 for (NomenclaturalCode code
: NomenclaturalCodeHelper
.getAllCodes()) {
183 if (getPreferenceKey(code
).equals(preferredCode
)) {
190 public static String
getPreferredDefaultLangugae(){
191 String preferredLanguage
= getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR
);
192 if(StringUtils
.isNotEmpty(preferredLanguage
) && StringUtils
.isNotBlank(preferredLanguage
)){
193 return preferredLanguage
;
199 * Get the match strategy for the given class that was stored in preferences
200 * or the default strategy if it was not stored in preferences
203 * a {@link java.lang.Class} object.
204 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
206 public static IMatchStrategy
getMatchStrategy(Class clazz
) {
207 String className
= clazz
.getName();
208 if (getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX
+ className
)) {
209 IMatchStrategy matchStrategy
= getDefaultMatchStrategy(clazz
);
211 for (String fieldName
: matchStrategy
.getMatchFieldPropertyNames()) {
212 String matchModeName
= getPreferenceStore().getString(
213 getMatchStrategyFieldName(className
, fieldName
));
214 MatchMode matchMode
= MatchMode
.valueOf(matchModeName
);
216 matchStrategy
.setMatchMode(fieldName
, matchMode
);
217 } catch (MatchException e
) {
218 MessagingUtils
.error(PreferencesUtil
.class, e
);
219 throw new RuntimeException(e
);
223 return matchStrategy
;
225 return getDefaultMatchStrategy(clazz
);
229 * Stores a matchStrategy into the preference store.
231 * @param matchStrategy
232 * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
235 public static void setMatchStrategy(IMatchStrategy matchStrategy
) {
236 String className
= matchStrategy
.getMatchClass().getName();
237 getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX
+ className
, true);
239 Set
<String
> matchFields
= matchStrategy
.getMatchFieldPropertyNames();
241 for (String fieldName
: matchFields
) {
242 getPreferenceStore().setValue(
243 getMatchStrategyFieldName(className
, fieldName
),
244 matchStrategy
.getMatchMode(fieldName
).name());
249 * Helper method to create the preference property for a match field.
255 private static String
getMatchStrategyFieldName(String className
,
257 return MATCH_STRATEGY_PREFIX
+ className
+ "." + fieldName
;
261 * Returns the default match strategy for a given class.
264 * a {@link java.lang.Class} object.
265 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
267 public static IMatchStrategy
getDefaultMatchStrategy(Class clazz
) {
268 return DefaultMatchStrategy
.NewInstance(clazz
);
273 * getDateFormatPattern
276 * @return a {@link java.lang.String} object.
278 public static String
getDateFormatPattern() {
279 // TODO make this configurable in properties
280 String pattern
= "Y-M-d H:m";
286 * addTermToPreferredTerms
294 public static <T
extends TermBase
> void addTermToPreferredTerms(T term
) {
296 // VocabularyEnum vocabulary =
297 // VocabularyEnum.getVocabularyEnum(term.getClass());
299 // getPreferenceStore().setValue(getPreferenceKey(term),
300 // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
302 // firePreferencesChanged(term.getClass());
306 * Construct a unique key using the CdmBase object's uuid
311 private static String
getPreferenceKey(ICdmBase cdmBase
) {
312 cdmBase
= HibernateProxyHelper
.deproxy(cdmBase
);
314 String key
= cdmBase
.getClass().getName().concat(".")
315 .concat(cdmBase
.getUuid().toString());
316 if (key
.contains("javassist")) {
317 MessagingUtils
.info("proxy");
323 * Construct a unique key using the CdmBase object's uuid
328 public static String
getPreferenceKey(ISimpleTerm simpleTerm
) {
329 simpleTerm
= HibernateProxyHelper
.deproxy(simpleTerm
);
330 String key
= simpleTerm
.getClass().getName().concat(".")
331 .concat(simpleTerm
.getUuid().toString());
332 if (key
.contains("javassist")) {
333 MessagingUtils
.warn(PreferencesUtil
.class,
334 "Trying to persist a preference based on a proxy class.");
342 * Construct a unique key using the CdmBase object's uuid
347 public static String
getPreferenceKey(IDefinedTerm definedTerm
) {
348 definedTerm
= HibernateProxyHelper
.deproxy(definedTerm
);
349 String key
= definedTerm
.getClass().getName().concat(".")
350 .concat(definedTerm
.getUuid().toString());
351 if (key
.contains("javassist")) {
352 MessagingUtils
.warn(PreferencesUtil
.class,
353 "Trying to persist a preference based on a proxy class.");
359 * Retrieves search preferences from the preference store
361 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
363 public static IFindTaxaAndNamesConfigurator
getSearchConfigurator() {
364 IFindTaxaAndNamesConfigurator configurator
= initializeSearchConfigurator();
366 configurator
.setDoTaxa(getPreferenceStore().getBoolean(
367 TAXON_SERVICE_CONFIGURATOR_TAXA
));
368 configurator
.setDoSynonyms(getPreferenceStore().getBoolean(
369 TAXON_SERVICE_CONFIGURATOR_SYNONYMS
));
370 configurator
.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(
371 TAXON_SERVICE_CONFIGURATOR_NAMES
));
372 configurator
.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(
373 TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
));
374 //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getPreferenceStore().getString(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
380 * create new preferences, setting all search options to true
383 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
386 public static IFindTaxaAndNamesConfigurator
initializeSearchConfigurator() {
387 IFindTaxaAndNamesConfigurator configurator
= new FindTaxaAndNamesConfiguratorImpl();
389 configurator
.setDoTaxa(true);
390 configurator
.setDoSynonyms(true);
391 configurator
.setDoNamesWithoutTaxa(true);
392 configurator
.setDoTaxaByCommonNames(true);
394 configurator
.setTaxonPropertyPath(Arrays
.asList("$", "titleCache",
395 "name", "name.$", "relationsFromThisTaxon.$"));
397 configurator
.setSynonymPropertyPath(Arrays
.asList("$", "titleCache",
398 "name", "name.$", "synonymRelations.relatedTo.*"));
401 // match mode is a simple like, actually all other match modes are kind
404 .setMatchMode(eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
.ANYWHERE
);
405 // we set page number and size here as this should always be unlimited
406 configurator
.setPageNumber(0);
407 // TODO currently limit results to 10000
408 configurator
.setPageSize(10000);
414 * Store search preferences
416 * @param configurator
418 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
421 public static void setSearchConfigurator(
422 IFindTaxaAndNamesConfigurator configurator
) {
423 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA
,
424 configurator
.isDoTaxa());
425 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
426 configurator
.isDoSynonyms());
427 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES
,
428 configurator
.isDoNamesWithoutTaxa());
429 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
,
430 configurator
.isDoTaxaByCommonNames());
435 * firePreferencesChanged
439 * a {@link java.lang.Class} object.
441 public static void firePreferencesChanged(Class clazz
) {
442 getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE
,
447 * Set default values for preferences
449 public static void setDefaults() {
450 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA
, true);
451 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
453 getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT
,
454 "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
455 //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
456 getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP
, false);
457 getPreferenceStore().setDefault(OPENURL_ACCESS_POINT
,
458 "http://www.biodiversitylibrary.org/openurl");
459 getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH
, "1000");
460 getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT
, "1000");
461 getPreferenceStore().setDefault(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
, false);
462 getPreferenceStore().setDefault(CHECKLIST_ID_IN_VOCABULARY
, true);
463 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
, true);
464 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_AUTHORSHIP
, true);
465 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_HYBRID
, true);
466 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_LSID
, true);
467 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP
, true);
468 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NAMECACHE
, true);
469 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE
, true);
470 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_REFERENCE
, true);
471 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_STATUS
, true);
472 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_PROTOLOGUE
, true);
473 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_RANK
, true);
474 getPreferenceStore().setDefault(SHOW_NAME_DETAILS_SECTION_TYPE_DESIGNATION
, true);
479 * checkNomenclaturalCode
482 public static void checkNomenclaturalCode() {
483 // First time Editor is opened, no nomenclatural code has been set
486 if (PreferencesUtil
.getPreferredNomenclaturalCode(true) == null) {
487 PreferencesUtil
.setPreferredNomenclaturalCode(NomenclaturalCode
.ICNAFP
, true);
490 StoreUtil.info("No nomencatural code set.");
492 Shell shell = StoreUtil.getShell();
494 Query user re: preferred nom. code
495 Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
498 // Short message confirming user's choice
499 NomenclaturalCode code = PreferencesUtil
500 .getPreferredNomenclaturalCode();
504 "Nomenclatural code set",
505 "The following has been set as your preferred nomenclatural code:\n\n\t"
506 + NomenclaturalCodeHelper
507 .getDescription(code)
508 + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");*/
512 public static void checkDefaultLanguage(){
513 if(PreferencesUtil
.getPreferredDefaultLangugae() == null){
514 Shell shell
= AbstractUtility
.getShell();
515 int open
= new DefaultLanguageDialog(shell
).open();
516 if(open
== Window
.OK
){
517 PlatformUI
.getWorkbench().restart();
520 //TODO:In case of a reinstall, the config.ini will be overwritten
521 // here you create config.ini with the stored key from preferences
527 * getMapServiceAccessPoint
530 * @return a {@link java.lang.String} object.
532 public static String
getMapServiceAccessPoint() {
533 return getPreferenceStore().getString(EDIT_MAP_SERVICE_ACCES_POINT
);
538 * shouldConnectAtStartUp
543 public static boolean shouldConnectAtStartUp() {
544 //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
545 //return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
551 * getDefaultFeatureTreeForTextualDescription
554 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
556 public static FeatureTree
getDefaultFeatureTreeForTextualDescription() {
557 String uuidString
= getPreferenceStore().getString(
558 FEATURE_TREE_DEFAULT_TEXT
);
559 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
560 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
565 * getDefaultFeatureTreeForStructuredDescription
568 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
570 public static FeatureTree
getDefaultFeatureTreeForStructuredDescription() {
571 String uuidString
= getPreferenceStore().getString(
572 FEATURE_TREE_DEFAULT_STRUCTURE
);
573 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
574 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
579 * setSortRanksHierarchichally
585 public static void setSortRanksHierarchichally(boolean selection
) {
586 getPreferenceStore().setValue(SORT_RANKS_HIERARCHICHALLY
, selection
);
591 * getSortRanksHierarchichally
596 public static boolean getSortRanksHierarchichally() {
597 return getPreferenceStore().getBoolean(SORT_RANKS_HIERARCHICHALLY
);
600 public static boolean isMultilanguageTextEditingCapability() {
601 return getPreferenceStore().getBoolean(
602 MULTILANGUAGE_TEXT_EDITING_CAPABILITY
);
605 public static Language
getGlobalLanguage() {
608 String languageUuidString
= getPreferenceStore().getString(
609 GLOBAL_LANGUAGE_UUID
);
611 if(!CdmStore
.isActive()) {
612 MessagingUtils
.noDataSourceWarningDialog(languageUuidString
);
616 if (CdmUtils
.isBlank(languageUuidString
)) {
617 return Language
.getDefaultLanguage();
620 UUID languageUuid
= UUID
.fromString(languageUuidString
);
621 return (Language
) CdmStore
.getService(ITermService
.class).load(
625 public static void setGlobalLanguage(Language language
) {
626 if(language
!= null) {
627 getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID
,language
.getUuid().toString());
628 CdmStore
.setDefaultLanguage(language
);
636 public static Map
<MarkerType
, Boolean
> getEditMarkerTypePreferences() {
637 List
<MarkerType
> markerTypes
= CdmStore
.getTermManager()
638 .getPreferredTerms(MarkerType
.class);
640 Map
<MarkerType
, Boolean
> result
= new HashMap
<MarkerType
, Boolean
>();
642 for (MarkerType markerType
: markerTypes
) {
643 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
644 Boolean value
= getPreferenceStore().getBoolean(name
);
646 result
.put(markerType
, value
);
653 * @param markerTypeEditingMap
655 public static void setEditMarkerTypePreferences(
656 Map
<MarkerType
, Boolean
> markerTypeEditingMap
) {
657 for (MarkerType markerType
: markerTypeEditingMap
.keySet()) {
658 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
659 getPreferenceStore().setValue(name
,
660 markerTypeEditingMap
.get(markerType
));
665 private static String
getMarkerTypeEditingPreferenceKey(
666 MarkerType markerType
) {
667 markerType
= HibernateProxyHelper
.deproxy(markerType
);
668 return markerType
.getClass().getName() + EDIT_MARKER_TYPE_PREFIX
;
673 * setEditMarkerTypePreference
677 * a {@link org.eclipse.ui.IEditorInput} object.
679 * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
683 public static void setEditMarkerTypePreference(MarkerType markerType
,
685 getPreferenceStore().setValue(
686 getMarkerTypeEditingPreferenceKey(markerType
), edit
);
692 public static DerivedUnitFacadeConfigurator
getDerivedUnitConfigurator() {
693 DerivedUnitFacadeConfigurator configurator
= DerivedUnitFacadeConfigurator
695 configurator
.setMoveDerivedUnitMediaToGallery(true);
696 configurator
.setMoveFieldObjectMediaToGallery(true);
701 * This method will write language properties to the config.ini located in the configuration folder
702 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
704 * @param setLanguage 0 is for german and 1 for english.
705 * @throws IOException
707 public void writePropertyToConfigFile(int setLanguage
) throws IOException
{
708 File file
= org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
.INSTANCE
.getLocation().toFile();
709 //give warning to user if the directory has no write access
711 throw new IOException();
713 Properties properties
= load(file
.getAbsolutePath()+"/config.ini");
716 properties
.setProperty("osgi.nl", "de");
717 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "de");
720 properties
.setProperty("osgi.nl", "en");
721 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "en");
726 save(file
+"/config.ini", properties
);
730 * This method loads a property from a given file and returns it.
734 * @throws IOException
736 private Properties
load(String filename
) throws IOException
{
737 FileInputStream in
= new FileInputStream(filename
);
738 Properties prop
= new Properties();
745 * This method saves a property to the specified file.
749 * @throws IOException
751 private void save(String filename
, Properties properties
) throws IOException
{
752 FileOutputStream fos
= new FileOutputStream(filename
);
753 properties
.store(fos
, "");
758 * Saves a list of P2 Metadata Repositories as string with specified delimiters
762 public static void setP2Repositories(List
<MetadataRepositoryElement
> p2Repos
) {
763 StringBuilder sb
= new StringBuilder();
764 for(MetadataRepositoryElement p2Repo
: p2Repos
) {
765 sb
.append(P2_REPOSITORIES_DELIM
);
766 if(p2Repo
.getName() == null || p2Repo
.getName().isEmpty()) {
769 sb
.append(p2Repo
.getName());
771 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
772 sb
.append(p2Repo
.getLocation().toString());
773 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
774 sb
.append(String
.valueOf(p2Repo
.isEnabled()));
776 getPreferenceStore().setValue(P2_REPOSITORY_LIST
, sb
.toString());
781 * Retrieves a list of previously saved P2 repositories
785 public static List
<MetadataRepositoryElement
> getP2Repositories() {
786 List
<MetadataRepositoryElement
> p2Repos
= new ArrayList
<MetadataRepositoryElement
>();
787 String p2ReposPref
= getPreferenceStore().getString(P2_REPOSITORY_LIST
);
788 if(p2ReposPref
!= null && !p2ReposPref
.isEmpty()) {
789 StringTokenizer p2ReposPrefST
= new StringTokenizer(p2ReposPref
,P2_REPOSITORIES_DELIM
);
791 while(p2ReposPrefST
.hasMoreTokens()) {
792 String p2RepoStr
= p2ReposPrefST
.nextToken();
793 StringTokenizer p2ReposStrST
= new StringTokenizer(p2RepoStr
,P2_REPOSITORY_FIELDS_DELIM
);
794 if(p2ReposStrST
.countTokens()==3) {
795 String nickname
= p2ReposStrST
.nextToken();
798 uri
= new URI(p2ReposStrST
.nextToken());
799 } catch (URISyntaxException e
) {
802 boolean enabled
= Boolean
.parseBoolean(p2ReposStrST
.nextToken());
803 MetadataRepositoryElement mre
= new MetadataRepositoryElement(null, uri
, true);
804 mre
.setNickname(nickname
);
805 mre
.setEnabled(enabled
);
815 * enables/disables nested composite. <br>
817 * @param ctrl - Composite to be en-/disabeld
818 * @param enabled - boolean
820 public static void recursiveSetEnabled(Control ctrl
, boolean enabled
) {
821 if (ctrl
instanceof Composite
) {
822 Composite comp
= (Composite
) ctrl
;
823 for (Control c
: comp
.getChildren()) {
824 recursiveSetEnabled(c
, enabled
);
827 ctrl
.setEnabled(enabled
);
833 * getSortRanksNaturally
838 public static boolean getSortNodesNaturally() {
839 return getPreferenceStore().getBoolean(SORT_NODES_NATURALLY
);
844 * setSortRanksNaturally
850 public static void setSortNodesNaturally(boolean selection
) {
851 getPreferenceStore().setValue(SORT_NODES_NATURALLY
, selection
);
857 * getSortRanksNaturally
862 public static boolean getSortNodesStrictlyAlphabetically() {
863 return getPreferenceStore().getBoolean(SORT_NODES_ALPHABETICALLY
);
868 * setSortRanksNaturally
874 public static void setSortNodesStrictlyAlphabetically(boolean selection
) {
875 getPreferenceStore().setValue(SORT_NODES_ALPHABETICALLY
, selection
);
880 * setStoreNavigatorState
886 public static boolean isStoreNavigatorState() {
887 return getPreferenceStore().getBoolean(RESTORE_NAVIGATOR_STATE
);
893 * setStoreNavigatorState
899 public static void setStoreNavigatorState(boolean selection
) {
900 getPreferenceStore().setValue(RESTORE_NAVIGATOR_STATE
, selection
);
907 public static boolean isShowUpWidgetIsDisposedMessages() {
908 return getPreferenceStore().getBoolean(IS_SHOW_UP_WIDGET_IS_DISPOSED
);
910 public static void setShowUpWidgetIsDisposedMessages(boolean selection
) {
911 getPreferenceStore().setValue(IS_SHOW_UP_WIDGET_IS_DISPOSED
, selection
);
917 public static boolean isShowIdInVocabularyInChecklistEditor() {
918 return getPreferenceStore().getBoolean(IPreferenceKeys
.CHECKLIST_ID_IN_VOCABULARY
);
920 public static void setShowIdInVocabularyInChecklistEditor(boolean selection
) {
921 getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY
, selection
);
927 public static boolean isShowRankInChecklistEditor() {
928 return getPreferenceStore().getBoolean(IPreferenceKeys
.CHECKLIST_SHOW_RANK
);
930 public static void setShowRankInChecklistEditor(boolean selection
) {
931 getPreferenceStore().setValue(CHECKLIST_SHOW_RANK
, selection
);