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
.IPreferenceService
;
41 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
42 import eu
.etaxonomy
.cdm
.api
.service
.config
.FindTaxaAndNamesConfiguratorImpl
;
43 import eu
.etaxonomy
.cdm
.api
.service
.config
.IFindTaxaAndNamesConfigurator
;
44 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
45 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
46 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
47 import eu
.etaxonomy
.cdm
.model
.common
.IDefinedTerm
;
48 import eu
.etaxonomy
.cdm
.model
.common
.ISimpleTerm
;
49 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
50 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
51 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
52 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
53 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
54 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
55 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
56 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
57 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
58 import eu
.etaxonomy
.cdm
.strategy
.match
.DefaultMatchStrategy
;
59 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchStrategy
;
60 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchException
;
61 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchMode
;
62 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
63 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
64 import eu
.etaxonomy
.taxeditor
.model
.NomenclaturalCodeHelper
;
65 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
66 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
67 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.DefaultLanguageDialog
;
71 * PreferencesUtil class.
79 public class PreferencesUtil
implements IPreferenceKeys
{
84 public static final String PREFERRED_TERMS_CHANGE
= "preferred_terms";
86 public static final String P2_REPOSITORIES_DELIM
= ",";
87 public static final String P2_REPOSITORY_FIELDS_DELIM
= ";";
96 * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
98 public static IPreferenceStore
getPreferenceStore() {
99 return TaxeditorStorePlugin
.getDefault().getPreferenceStore();
104 * setPreferredNomenclaturalCode
107 * @param preferredCode
108 * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
111 public static void setPreferredNomenclaturalCode(
112 NomenclaturalCode preferredCode
) {
113 ICdmApplicationConfiguration controller
;
114 controller
= CdmStore
.getCurrentApplicationConfiguration();
115 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
116 CdmPreference preference
= null;
117 if (controller
== null){
120 if (preferredCode
== null){
121 preference
= controller
.getPreferenceService().find(key
);
122 if (preference
== null){
125 int index
= StringUtils
.lastIndexOf(preference
.getValue(), ".");
126 UUID uuid
= UUID
.fromString(preference
.getValue().substring(index
+1, preference
.getValue().length()));
127 preferredCode
= NomenclaturalCode
.getByUuid(uuid
);
130 preference
= CdmPreference
.NewInstance(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
, preferredCode
.getKey());
131 controller
.getPreferenceService().set(preference
);
135 getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY
,
136 getPreferenceKey(preferredCode
));
139 public static NomenclaturalCode
getPreferredNomenclaturalCode(){
140 return getPreferredNomenclaturalCode(false);
145 * getPreferredNomenclaturalCode
148 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
150 public static NomenclaturalCode
getPreferredNomenclaturalCode(boolean preConnected
) {
151 ICdmApplicationConfiguration controller
;
152 CdmPreference pref
= null;
155 controller
= CdmStore
.getCurrentApplicationConfiguration();
156 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), PreferencePredicate
.NomenclaturalCode
);
157 pref
= controller
.getPreferenceService().find(key
);
163 String preferredCode
;
165 preferredCode
= getPreferenceStore().getString(
166 PREFERRED_NOMENCLATURAL_CODE_KEY
);
168 preferredCode
= pref
.getValue();
171 for (NomenclaturalCode code
: NomenclaturalCodeHelper
.getAllCodes()) {
172 // String preferredCode = getPreferenceStore().getString(
173 // PREFERRED_NOMENCLATURAL_CODE_KEY);
174 if (getPreferenceKey(code
).equals(preferredCode
)) {
181 public static String
getPreferredDefaultLangugae(){
182 String preferredLanguage
= getPreferenceStore().getString(DEFAULT_LANGUAGE_EDITOR
);
183 if(StringUtils
.isNotEmpty(preferredLanguage
) && StringUtils
.isNotBlank(preferredLanguage
)){
184 return preferredLanguage
;
190 * Get the match strategy for the given class that was stored in preferences
191 * or the default strategy if it was not stored in preferences
194 * a {@link java.lang.Class} object.
195 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
197 public static IMatchStrategy
getMatchStrategy(Class clazz
) {
198 String className
= clazz
.getName();
199 if (getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX
+ className
)) {
200 IMatchStrategy matchStrategy
= getDefaultMatchStrategy(clazz
);
202 for (String fieldName
: matchStrategy
.getMatchFieldPropertyNames()) {
203 String matchModeName
= getPreferenceStore().getString(
204 getMatchStrategyFieldName(className
, fieldName
));
205 MatchMode matchMode
= MatchMode
.valueOf(matchModeName
);
207 matchStrategy
.setMatchMode(fieldName
, matchMode
);
208 } catch (MatchException e
) {
209 MessagingUtils
.error(PreferencesUtil
.class, e
);
210 throw new RuntimeException(e
);
214 return matchStrategy
;
216 return getDefaultMatchStrategy(clazz
);
220 * Stores a matchStrategy into the preference store.
222 * @param matchStrategy
223 * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
226 public static void setMatchStrategy(IMatchStrategy matchStrategy
) {
227 String className
= matchStrategy
.getMatchClass().getName();
228 getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX
+ className
, true);
230 Set
<String
> matchFields
= matchStrategy
.getMatchFieldPropertyNames();
232 for (String fieldName
: matchFields
) {
233 getPreferenceStore().setValue(
234 getMatchStrategyFieldName(className
, fieldName
),
235 matchStrategy
.getMatchMode(fieldName
).name());
240 * Helper method to create the preference property for a match field.
246 private static String
getMatchStrategyFieldName(String className
,
248 return MATCH_STRATEGY_PREFIX
+ className
+ "." + fieldName
;
252 * Returns the default match strategy for a given class.
255 * a {@link java.lang.Class} object.
256 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
258 public static IMatchStrategy
getDefaultMatchStrategy(Class clazz
) {
259 return DefaultMatchStrategy
.NewInstance(clazz
);
264 * getDateFormatPattern
267 * @return a {@link java.lang.String} object.
269 public static String
getDateFormatPattern() {
270 // TODO make this configurable in properties
271 String pattern
= "Y-M-d H:m";
277 * addTermToPreferredTerms
285 public static <T
extends TermBase
> void addTermToPreferredTerms(T term
) {
287 // VocabularyEnum vocabulary =
288 // VocabularyEnum.getVocabularyEnum(term.getClass());
290 // getPreferenceStore().setValue(getPreferenceKey(term),
291 // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
293 // firePreferencesChanged(term.getClass());
297 * Construct a unique key using the CdmBase object's uuid
302 private static String
getPreferenceKey(ICdmBase cdmBase
) {
303 cdmBase
= HibernateProxyHelper
.deproxy(cdmBase
);
305 String key
= cdmBase
.getClass().getName().concat(".")
306 .concat(cdmBase
.getUuid().toString());
307 if (key
.contains("javassist")) {
308 MessagingUtils
.info("proxy");
314 * Construct a unique key using the CdmBase object's uuid
319 public static String
getPreferenceKey(ISimpleTerm simpleTerm
) {
320 simpleTerm
= HibernateProxyHelper
.deproxy(simpleTerm
);
321 String key
= simpleTerm
.getClass().getName().concat(".")
322 .concat(simpleTerm
.getUuid().toString());
323 if (key
.contains("javassist")) {
324 MessagingUtils
.warn(PreferencesUtil
.class,
325 "Trying to persist a preference based on a proxy class.");
333 * Construct a unique key using the CdmBase object's uuid
338 public static String
getPreferenceKey(IDefinedTerm definedTerm
) {
339 definedTerm
= HibernateProxyHelper
.deproxy(definedTerm
);
340 String key
= definedTerm
.getClass().getName().concat(".")
341 .concat(definedTerm
.getUuid().toString());
342 if (key
.contains("javassist")) {
343 MessagingUtils
.warn(PreferencesUtil
.class,
344 "Trying to persist a preference based on a proxy class.");
350 * Retrieves search preferences from the preference store
352 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
354 public static IFindTaxaAndNamesConfigurator
getSearchConfigurator() {
355 IFindTaxaAndNamesConfigurator configurator
= initializeSearchConfigurator();
357 configurator
.setDoTaxa(getPreferenceStore().getBoolean(
358 TAXON_SERVICE_CONFIGURATOR_TAXA
));
359 configurator
.setDoSynonyms(getPreferenceStore().getBoolean(
360 TAXON_SERVICE_CONFIGURATOR_SYNONYMS
));
361 configurator
.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(
362 TAXON_SERVICE_CONFIGURATOR_NAMES
));
363 configurator
.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(
364 TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
));
365 //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getPreferenceStore().getString(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
371 * create new preferences, setting all search options to true
374 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
377 public static IFindTaxaAndNamesConfigurator
initializeSearchConfigurator() {
378 IFindTaxaAndNamesConfigurator configurator
= new FindTaxaAndNamesConfiguratorImpl();
380 configurator
.setDoTaxa(true);
381 configurator
.setDoSynonyms(true);
382 configurator
.setDoNamesWithoutTaxa(true);
383 configurator
.setDoTaxaByCommonNames(true);
385 configurator
.setTaxonPropertyPath(Arrays
.asList("$", "titleCache",
386 "name", "name.$", "relationsFromThisTaxon.$"));
388 configurator
.setSynonymPropertyPath(Arrays
.asList("$", "titleCache",
389 "name", "name.$", "synonymRelations.relatedTo.*"));
392 // match mode is a simple like, actually all other match modes are kind
395 .setMatchMode(eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
.ANYWHERE
);
396 // we set page number and size here as this should always be unlimited
397 configurator
.setPageNumber(0);
398 // TODO currently limit results to 10000
399 configurator
.setPageSize(10000);
405 * Store search preferences
407 * @param configurator
409 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
412 public static void setSearchConfigurator(
413 IFindTaxaAndNamesConfigurator configurator
) {
414 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA
,
415 configurator
.isDoTaxa());
416 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
417 configurator
.isDoSynonyms());
418 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES
,
419 configurator
.isDoNamesWithoutTaxa());
420 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES
,
421 configurator
.isDoTaxaByCommonNames());
426 * firePreferencesChanged
430 * a {@link java.lang.Class} object.
432 public static void firePreferencesChanged(Class clazz
) {
433 getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE
,
438 * Set default values for preferences
440 public static void setDefaults() {
441 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA
, true);
442 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS
,
444 getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT
,
445 "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
446 //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
447 getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP
, false);
448 getPreferenceStore().setDefault(OPENURL_ACCESS_POINT
,
449 "http://www.biodiversitylibrary.org/openurl");
450 getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH
, "1000");
451 getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT
, "1000");
452 getPreferenceStore().setDefault(IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
, false);
453 getPreferenceStore().setDefault(CHECKLIST_ID_IN_VOCABULARY
, true);
458 * checkNomenclaturalCode
461 public static void checkNomenclaturalCode() {
462 // First time Editor is opened, no nomenclatural code has been set
465 if (PreferencesUtil
.getPreferredNomenclaturalCode(true) == null) {
466 PreferencesUtil
.setPreferredNomenclaturalCode(NomenclaturalCode
.ICNAFP
);
469 StoreUtil.info("No nomencatural code set.");
471 Shell shell = StoreUtil.getShell();
473 Query user re: preferred nom. code
474 Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
477 // Short message confirming user's choice
478 NomenclaturalCode code = PreferencesUtil
479 .getPreferredNomenclaturalCode();
483 "Nomenclatural code set",
484 "The following has been set as your preferred nomenclatural code:\n\n\t"
485 + NomenclaturalCodeHelper
486 .getDescription(code)
487 + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");*/
491 public static void checkDefaultLanguage(){
492 if(PreferencesUtil
.getPreferredDefaultLangugae() == null){
493 Shell shell
= AbstractUtility
.getShell();
494 int open
= new DefaultLanguageDialog(shell
).open();
495 if(open
== Window
.OK
){
496 PlatformUI
.getWorkbench().restart();
499 //TODO:In case of a reinstall, the config.ini will be overwritten
500 // here you create config.ini with the stored key from preferences
506 * getMapServiceAccessPoint
509 * @return a {@link java.lang.String} object.
511 public static String
getMapServiceAccessPoint() {
512 return getPreferenceStore().getString(EDIT_MAP_SERVICE_ACCES_POINT
);
517 * shouldConnectAtStartUp
522 public static boolean shouldConnectAtStartUp() {
523 //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
524 //return getPreferenceStore().getBoolean(SHOULD_CONNECT_AT_STARTUP);
530 * getDefaultFeatureTreeForTextualDescription
533 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
535 public static FeatureTree
getDefaultFeatureTreeForTextualDescription() {
536 String uuidString
= getPreferenceStore().getString(
537 FEATURE_TREE_DEFAULT_TEXT
);
538 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
539 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
544 * getDefaultFeatureTreeForStructuredDescription
547 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object.
549 public static FeatureTree
getDefaultFeatureTreeForStructuredDescription() {
550 String uuidString
= getPreferenceStore().getString(
551 FEATURE_TREE_DEFAULT_STRUCTURE
);
552 return CdmUtils
.isEmpty(uuidString
) ?
null : CdmStore
.getService(
553 IFeatureTreeService
.class).load(UUID
.fromString(uuidString
));
558 * setSortRanksHierarchichally
564 public static void setSortRanksHierarchichally(boolean selection
) {
565 getPreferenceStore().setValue(SORT_RANKS_HIERARCHICHALLY
, selection
);
570 * getSortRanksHierarchichally
575 public static boolean getSortRanksHierarchichally() {
576 return getPreferenceStore().getBoolean(SORT_RANKS_HIERARCHICHALLY
);
579 public static boolean isMultilanguageTextEditingCapability() {
580 return getPreferenceStore().getBoolean(
581 MULTILANGUAGE_TEXT_EDITING_CAPABILITY
);
584 public static Language
getGlobalLanguage() {
587 String languageUuidString
= getPreferenceStore().getString(
588 GLOBAL_LANGUAGE_UUID
);
590 if(!CdmStore
.isActive()) {
591 MessagingUtils
.noDataSourceWarningDialog(languageUuidString
);
595 if (CdmUtils
.isBlank(languageUuidString
)) {
596 return Language
.getDefaultLanguage();
599 UUID languageUuid
= UUID
.fromString(languageUuidString
);
600 return (Language
) CdmStore
.getService(ITermService
.class).load(
604 public static void setGlobalLanguage(Language language
) {
605 if(language
!= null) {
606 getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID
,language
.getUuid().toString());
607 CdmStore
.setDefaultLanguage(language
);
615 public static Map
<MarkerType
, Boolean
> getEditMarkerTypePreferences() {
616 List
<MarkerType
> markerTypes
= CdmStore
.getTermManager()
617 .getPreferredTerms(MarkerType
.class);
619 Map
<MarkerType
, Boolean
> result
= new HashMap
<MarkerType
, Boolean
>();
621 for (MarkerType markerType
: markerTypes
) {
622 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
623 Boolean value
= getPreferenceStore().getBoolean(name
);
625 result
.put(markerType
, value
);
632 * @param markerTypeEditingMap
634 public static void setEditMarkerTypePreferences(
635 Map
<MarkerType
, Boolean
> markerTypeEditingMap
) {
636 for (MarkerType markerType
: markerTypeEditingMap
.keySet()) {
637 String name
= getMarkerTypeEditingPreferenceKey(markerType
);
638 getPreferenceStore().setValue(name
,
639 markerTypeEditingMap
.get(markerType
));
644 private static String
getMarkerTypeEditingPreferenceKey(
645 MarkerType markerType
) {
646 markerType
= HibernateProxyHelper
.deproxy(markerType
);
647 return markerType
.getClass().getName() + EDIT_MARKER_TYPE_PREFIX
;
652 * setEditMarkerTypePreference
656 * a {@link org.eclipse.ui.IEditorInput} object.
658 * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
662 public static void setEditMarkerTypePreference(MarkerType markerType
,
664 getPreferenceStore().setValue(
665 getMarkerTypeEditingPreferenceKey(markerType
), edit
);
671 public static DerivedUnitFacadeConfigurator
getDerivedUnitConfigurator() {
672 DerivedUnitFacadeConfigurator configurator
= DerivedUnitFacadeConfigurator
674 configurator
.setMoveDerivedUnitMediaToGallery(true);
675 configurator
.setMoveFieldObjectMediaToGallery(true);
680 * This method will write language properties to the config.ini located in the configuration folder
681 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
683 * @param setLanguage 0 is for german and 1 for english.
684 * @throws IOException
686 public void writePropertyToConfigFile(int setLanguage
) throws IOException
{
687 File file
= org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
.INSTANCE
.getLocation().toFile();
688 //give warning to user if the directory has no write access
690 throw new IOException();
692 Properties properties
= load(file
.getAbsolutePath()+"/config.ini");
695 properties
.setProperty("osgi.nl", "de");
696 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "de");
699 properties
.setProperty("osgi.nl", "en");
700 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "en");
705 save(file
+"/config.ini", properties
);
709 * This method loads a property from a given file and returns it.
713 * @throws IOException
715 private Properties
load(String filename
) throws IOException
{
716 FileInputStream in
= new FileInputStream(filename
);
717 Properties prop
= new Properties();
724 * This method saves a property to the specified file.
728 * @throws IOException
730 private void save(String filename
, Properties properties
) throws IOException
{
731 FileOutputStream fos
= new FileOutputStream(filename
);
732 properties
.store(fos
, "");
737 * Saves a list of P2 Metadata Repositories as string with specified delimiters
741 public static void setP2Repositories(List
<MetadataRepositoryElement
> p2Repos
) {
742 StringBuilder sb
= new StringBuilder();
743 for(MetadataRepositoryElement p2Repo
: p2Repos
) {
744 sb
.append(P2_REPOSITORIES_DELIM
);
745 if(p2Repo
.getName() == null || p2Repo
.getName().isEmpty()) {
748 sb
.append(p2Repo
.getName());
750 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
751 sb
.append(p2Repo
.getLocation().toString());
752 sb
.append(P2_REPOSITORY_FIELDS_DELIM
);
753 sb
.append(String
.valueOf(p2Repo
.isEnabled()));
755 getPreferenceStore().setValue(P2_REPOSITORY_LIST
, sb
.toString());
760 * Retrieves a list of previously saved P2 repositories
764 public static List
<MetadataRepositoryElement
> getP2Repositories() {
765 List
<MetadataRepositoryElement
> p2Repos
= new ArrayList
<MetadataRepositoryElement
>();
766 String p2ReposPref
= getPreferenceStore().getString(P2_REPOSITORY_LIST
);
767 if(p2ReposPref
!= null && !p2ReposPref
.isEmpty()) {
768 StringTokenizer p2ReposPrefST
= new StringTokenizer(p2ReposPref
,P2_REPOSITORIES_DELIM
);
770 while(p2ReposPrefST
.hasMoreTokens()) {
771 String p2RepoStr
= p2ReposPrefST
.nextToken();
772 StringTokenizer p2ReposStrST
= new StringTokenizer(p2RepoStr
,P2_REPOSITORY_FIELDS_DELIM
);
773 if(p2ReposStrST
.countTokens()==3) {
774 String nickname
= p2ReposStrST
.nextToken();
777 uri
= new URI(p2ReposStrST
.nextToken());
778 } catch (URISyntaxException e
) {
781 boolean enabled
= Boolean
.parseBoolean(p2ReposStrST
.nextToken());
782 MetadataRepositoryElement mre
= new MetadataRepositoryElement(null, uri
, true);
783 mre
.setNickname(nickname
);
784 mre
.setEnabled(enabled
);
794 * enables/disables nested composite. <br>
796 * @param ctrl - Composite to be en-/disabeld
797 * @param enabled - boolean
799 public static void recursiveSetEnabled(Control ctrl
, boolean enabled
) {
800 if (ctrl
instanceof Composite
) {
801 Composite comp
= (Composite
) ctrl
;
802 for (Control c
: comp
.getChildren()) {
803 recursiveSetEnabled(c
, enabled
);
806 ctrl
.setEnabled(enabled
);
812 * getSortRanksNaturally
817 public static boolean getSortNodesNaturally() {
818 return getPreferenceStore().getBoolean(SORT_NODES_NATURALLY
);
823 * setSortRanksNaturally
829 public static void setSortNodesNaturally(boolean selection
) {
830 getPreferenceStore().setValue(SORT_NODES_NATURALLY
, selection
);
836 * getSortRanksNaturally
841 public static boolean getSortNodesStrictlyAlphabetically() {
842 return getPreferenceStore().getBoolean(SORT_NODES_ALPHABETICALLY
);
847 * setSortRanksNaturally
853 public static void setSortNodesStrictlyAlphabetically(boolean selection
) {
854 getPreferenceStore().setValue(SORT_NODES_ALPHABETICALLY
, selection
);
859 * setStoreNavigatorState
865 public static boolean isStoreNavigatorState() {
866 return getPreferenceStore().getBoolean(RESTORE_NAVIGATOR_STATE
);
872 * setStoreNavigatorState
878 public static void setStoreNavigatorState(boolean selection
) {
879 getPreferenceStore().setValue(RESTORE_NAVIGATOR_STATE
, selection
);
886 public static boolean isShowUpWidgetIsDisposedMessages() {
887 return getPreferenceStore().getBoolean(IS_SHOW_UP_WIDGET_IS_DISPOSED
);
889 public static void setShowUpWidgetIsDisposedMessages(boolean selection
) {
890 getPreferenceStore().setValue(IS_SHOW_UP_WIDGET_IS_DISPOSED
, selection
);
896 public static boolean isShowIdInVocabularyInChecklistEditor() {
897 return getPreferenceStore().getBoolean(IPreferenceKeys
.CHECKLIST_ID_IN_VOCABULARY
);
899 public static void setShowIdInVocabularyInChecklistEditor(boolean selection
) {
900 getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY
, selection
);
906 public static boolean isShowRankInChecklistEditor() {
907 return getPreferenceStore().getBoolean(IPreferenceKeys
.CHECKLIST_SHOW_RANK
);
909 public static void setShowRankInChecklistEditor(boolean selection
) {
910 getPreferenceStore().setValue(CHECKLIST_SHOW_RANK
, selection
);