Revision 5c9c924c
Added by Katja Luther over 6 years ago
eu.etaxonomy.taxeditor.store/plugin.xml | ||
---|---|---|
14 | 14 |
class="eu.etaxonomy.taxeditor.preference.AdminGeneralPreferences" |
15 | 15 |
id="eu.etaxonomy.taxeditor.preferences.adminGeneral" |
16 | 16 |
name="%page.name.38"> |
17 |
</page>-->
|
|
17 |
</page> |
|
18 | 18 |
<page |
19 | 19 |
category="eu.etaxonomy.taxeditor.preferences.admin" |
20 | 20 |
class="eu.etaxonomy.taxeditor.databasePreferences.AdminNomenclaturalCode" |
21 | 21 |
id="eu.etaxonomy.taxeditor.preferences.adminNomenclaturalCode" |
22 | 22 |
name="%page.name.39"> |
23 |
</page> |
|
23 |
</page>-->
|
|
24 | 24 |
<page |
25 | 25 |
category="eu.etaxonomy.taxeditor.preferences.general" |
26 | 26 |
class="eu.etaxonomy.taxeditor.preference.NameDetailsViewConfiguration" |
... | ... | |
53 | 53 |
</page> |
54 | 54 |
<page |
55 | 55 |
category="eu.etaxonomy.taxeditor.preferences.taxonomic" |
56 |
class="eu.etaxonomy.taxeditor.preference.NomenclaturalCodePreferences" |
|
56 |
class="eu.etaxonomy.taxeditor.preference.menu.NomenclaturalCodePreferences"
|
|
57 | 57 |
id="eu.etaxonomy.taxeditor.preferences.nomenclatural" |
58 | 58 |
name="%page.name.4"> |
59 | 59 |
</page> |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCodePreferences.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.preference; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
import org.eclipse.jface.preference.BooleanFieldEditor; |
|
14 |
import org.eclipse.jface.preference.ComboFieldEditor; |
|
15 |
import org.eclipse.jface.preference.FieldEditorPreferencePage; |
|
16 |
import org.eclipse.ui.IWorkbench; |
|
17 |
import org.eclipse.ui.IWorkbenchPreferencePage; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
20 |
import eu.etaxonomy.cdm.api.service.IPreferenceService; |
|
21 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference; |
|
22 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey; |
|
23 |
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate; |
|
24 |
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject; |
|
25 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
26 |
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper; |
|
27 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
28 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
29 |
|
|
30 |
/** |
|
31 |
* <p> |
|
32 |
* NomenclaturalCodePreferences class. |
|
33 |
* </p> |
|
34 |
* |
|
35 |
* @author p.ciardelli |
|
36 |
* @created 16.09.2008 |
|
37 |
*/ |
|
38 |
public class NomenclaturalCodePreferences extends FieldEditorPreferencePage |
|
39 |
implements IWorkbenchPreferencePage { |
|
40 |
|
|
41 |
@Override |
|
42 |
protected void createFieldEditors() { |
|
43 |
PreferencesUtil.setPreferredNomenclaturalCode(null, false); |
|
44 |
if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)) { |
|
45 |
addField(new ComboFieldEditor( |
|
46 |
IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY, |
|
47 |
"Available Codes", getLabelAndValues(), |
|
48 |
getFieldEditorParent())); |
|
49 |
|
|
50 |
addField(new BooleanFieldEditor( |
|
51 |
IPreferenceKeys.OVERRIDE_NOMENCLATURAL_CODE_KEY, |
|
52 |
"Use local nomenclatural code", |
|
53 |
getFieldEditorParent())); |
|
54 |
} else { |
|
55 |
setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator."); |
|
56 |
} |
|
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* @return |
|
62 |
*/ |
|
63 |
private String[][] getLabelAndValues() { |
|
64 |
List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper |
|
65 |
.getSupportedCodes(); |
|
66 |
String[][] labelAndValues = new String[supportedCodes.size()][2]; |
|
67 |
for (int i = 0; i < supportedCodes.size(); i++) { |
|
68 |
labelAndValues[i][0] = NomenclaturalCodeHelper |
|
69 |
.getDescription(supportedCodes.get(i)); |
|
70 |
labelAndValues[i][1] = PreferencesUtil |
|
71 |
.getPreferenceKey(supportedCodes.get(i)); |
|
72 |
} |
|
73 |
return labelAndValues; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* {@inheritDoc} |
|
78 |
* |
|
79 |
* Initialize the preference page |
|
80 |
*/ |
|
81 |
@Override |
|
82 |
public void init(IWorkbench workbench) { |
|
83 |
|
|
84 |
setPreferenceStore(TaxeditorStorePlugin.getDefault() |
|
85 |
.getPreferenceStore()); |
|
86 |
|
|
87 |
ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration(); |
|
88 |
if (controller != null){ |
|
89 |
IPreferenceService service = controller.getPreferenceService(); |
|
90 |
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); |
|
91 |
CdmPreference pref = service.find(key); |
|
92 |
getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, pref == null? true : pref.isAllowOverride()); |
|
93 |
} |
|
94 |
|
|
95 |
if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)) { |
|
96 |
setDescription("Choose which nomenclatural code you would like to use in your local application for scientific names unless otherwise specified."); |
|
97 |
}else{ |
|
98 |
setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator."); |
|
99 |
|
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public boolean performOk() { |
|
105 |
|
|
106 |
boolean result = super.performOk(); |
|
107 |
// if (result){ |
|
108 |
// String value = getPreferenceStore().getString(IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY); |
|
109 |
// CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value); |
|
110 |
// ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration(); |
|
111 |
// if (controller == null){ |
|
112 |
// return false; |
|
113 |
// } |
|
114 |
// IPreferenceService service = controller.getPreferenceService(); |
|
115 |
// service.set(pref); |
|
116 |
// } |
|
117 |
return result; |
|
118 |
} |
|
119 |
|
|
120 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/NomenclaturalCodePreferences.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.preference.menu; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
import org.eclipse.jface.preference.BooleanFieldEditor; |
|
14 |
import org.eclipse.jface.preference.ComboFieldEditor; |
|
15 |
import org.eclipse.jface.preference.FieldEditorPreferencePage; |
|
16 |
import org.eclipse.ui.IWorkbench; |
|
17 |
import org.eclipse.ui.IWorkbenchPreferencePage; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
20 |
import eu.etaxonomy.cdm.api.service.IPreferenceService; |
|
21 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference; |
|
22 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey; |
|
23 |
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate; |
|
24 |
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject; |
|
25 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
26 |
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper; |
|
27 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
|
28 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
29 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
30 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
31 |
|
|
32 |
/** |
|
33 |
* <p> |
|
34 |
* NomenclaturalCodePreferences class. |
|
35 |
* </p> |
|
36 |
* |
|
37 |
* @author p.ciardelli |
|
38 |
* @created 16.09.2008 |
|
39 |
*/ |
|
40 |
public class NomenclaturalCodePreferences extends FieldEditorPreferencePage |
|
41 |
implements IWorkbenchPreferencePage { |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void createFieldEditors() { |
|
45 |
PreferencesUtil.setPreferredNomenclaturalCode(null, false); |
|
46 |
if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)) { |
|
47 |
addField(new ComboFieldEditor( |
|
48 |
IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY, |
|
49 |
"Available Codes", getLabelAndValues(), |
|
50 |
getFieldEditorParent())); |
|
51 |
|
|
52 |
addField(new BooleanFieldEditor( |
|
53 |
IPreferenceKeys.OVERRIDE_NOMENCLATURAL_CODE_KEY, |
|
54 |
"Use local nomenclatural code", |
|
55 |
getFieldEditorParent())); |
|
56 |
} else { |
|
57 |
setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator."); |
|
58 |
} |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* @return |
|
64 |
*/ |
|
65 |
private String[][] getLabelAndValues() { |
|
66 |
List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper |
|
67 |
.getSupportedCodes(); |
|
68 |
String[][] labelAndValues = new String[supportedCodes.size()][2]; |
|
69 |
for (int i = 0; i < supportedCodes.size(); i++) { |
|
70 |
labelAndValues[i][0] = NomenclaturalCodeHelper |
|
71 |
.getDescription(supportedCodes.get(i)); |
|
72 |
labelAndValues[i][1] = PreferencesUtil |
|
73 |
.getPreferenceKey(supportedCodes.get(i)); |
|
74 |
} |
|
75 |
return labelAndValues; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* {@inheritDoc} |
|
80 |
* |
|
81 |
* Initialize the preference page |
|
82 |
*/ |
|
83 |
@Override |
|
84 |
public void init(IWorkbench workbench) { |
|
85 |
|
|
86 |
setPreferenceStore(TaxeditorStorePlugin.getDefault() |
|
87 |
.getPreferenceStore()); |
|
88 |
|
|
89 |
ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration(); |
|
90 |
if (controller != null){ |
|
91 |
IPreferenceService service = controller.getPreferenceService(); |
|
92 |
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode); |
|
93 |
CdmPreference pref = service.find(key); |
|
94 |
getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, pref == null? true : pref.isAllowOverride()); |
|
95 |
} |
|
96 |
|
|
97 |
if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)) { |
|
98 |
setDescription("Choose which nomenclatural code you would like to use in your local application for scientific names unless otherwise specified."); |
|
99 |
}else{ |
|
100 |
setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator."); |
|
101 |
|
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public boolean performOk() { |
|
107 |
|
|
108 |
boolean result = super.performOk(); |
|
109 |
// if (result){ |
|
110 |
// String value = getPreferenceStore().getString(IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY); |
|
111 |
// CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value); |
|
112 |
// ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration(); |
|
113 |
// if (controller == null){ |
|
114 |
// return false; |
|
115 |
// } |
|
116 |
// IPreferenceService service = controller.getPreferenceService(); |
|
117 |
// service.set(pref); |
|
118 |
// } |
|
119 |
return result; |
|
120 |
} |
|
121 |
|
|
122 |
} |
Also available in: Unified diff
deduplicate the nomenclatural code preference page in preferences menu