2 * Copyright (C) 2018 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.
9 package eu
.etaxonomy
.taxeditor
.databaseAdmin
.preferencePage
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.events
.SelectionAdapter
;
13 import org
.eclipse
.swt
.events
.SelectionEvent
;
14 import org
.eclipse
.swt
.layout
.GridData
;
15 import org
.eclipse
.swt
.layout
.GridLayout
;
16 import org
.eclipse
.swt
.widgets
.Button
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Control
;
19 import org
.eclipse
.swt
.widgets
.Label
;
21 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IPreferenceService
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
25 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
26 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
27 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
28 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
29 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
30 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 public class SpecimenAdminPreferences
extends CdmPreferencePage
implements IE4AdminPreferencePage
{
38 public SpecimenAdminPreferences() {
42 boolean isShowSpecimenRelatedIssues
;
43 boolean isShowCollectingAreaInGeneralSection
;
44 boolean isDeterminationOnlyForFieldUnits
;
45 boolean isShowTaxonAssociation
;
46 boolean isShowLifeForm
;
47 boolean isUseLocalPreference
;
51 protected Control
createContents(Composite parent
) {
56 final Button showSpecimenButton
= new Button(parent
, SWT
.CHECK
);
58 showSpecimenButton
.setText(Messages
.DatabasePreferncesPage_Show_Specimen
);
60 showSpecimenButton
.setSelection(isShowSpecimenRelatedIssues
);
61 showSpecimenButton
.addSelectionListener(new SelectionAdapter(){
63 public void widgetSelected(SelectionEvent e
) {
64 isShowSpecimenRelatedIssues
= showSpecimenButton
.getSelection();
65 if(isShowSpecimenRelatedIssues
){
66 composite
.setVisible(true);
67 composite
.setEnabled(true);
69 composite
.setVisible(false);
70 composite
.setEnabled(false);
74 composite
= new Composite(parent
, SWT
.NULL
);
75 GridLayout gridLayout
= new GridLayout();
76 composite
.setLayout(gridLayout
);
77 composite
.setEnabled(isShowSpecimenRelatedIssues
);
78 Label separator
= new Label(composite
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
79 separator
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
81 final Button showCollectingAreaInGeneralSectionButton
= new Button(composite
, SWT
.CHECK
);
83 showCollectingAreaInGeneralSectionButton
.setText(Messages
.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section
);
85 showCollectingAreaInGeneralSectionButton
.setSelection(isShowCollectingAreaInGeneralSection
);
86 showCollectingAreaInGeneralSectionButton
.addSelectionListener(new SelectionAdapter(){
88 public void widgetSelected(SelectionEvent e
) {
89 isShowCollectingAreaInGeneralSection
= showCollectingAreaInGeneralSectionButton
.getSelection();
94 final Button determinationOnlyForFieldUnitsButton
= new Button(composite
, SWT
.CHECK
);
96 determinationOnlyForFieldUnitsButton
.setText(Messages
.DatabasePreferncesPage_Determination_only_for_field_unnits
);
98 determinationOnlyForFieldUnitsButton
.setSelection(isDeterminationOnlyForFieldUnits
);
99 determinationOnlyForFieldUnitsButton
.addSelectionListener(new SelectionAdapter(){
101 public void widgetSelected(SelectionEvent e
) {
102 isDeterminationOnlyForFieldUnits
= determinationOnlyForFieldUnitsButton
.getSelection();
106 final Button showTaxonAssociationButton
= new Button(composite
, SWT
.CHECK
);
108 showTaxonAssociationButton
.setText(Messages
.DatabasePreferncesPage_Taxon_Associations
);
110 showTaxonAssociationButton
.setSelection(isShowTaxonAssociation
);
111 showTaxonAssociationButton
.addSelectionListener(new SelectionAdapter(){
113 public void widgetSelected(SelectionEvent e
) {
114 isShowTaxonAssociation
= showTaxonAssociationButton
.getSelection();
119 final Button showLifeFormButton
= new Button(composite
, SWT
.CHECK
);
120 showLifeFormButton
.setText(Messages
.DatabasePreferncesPage_Life_Form
);
121 showLifeFormButton
.setSelection(isShowLifeForm
);
122 showLifeFormButton
.addSelectionListener(new SelectionAdapter(){
124 public void widgetSelected(SelectionEvent e
) {
125 isShowLifeForm
= showLifeFormButton
.getSelection();
130 // Composite useLocalComp = new Composite(composite, SWT.NONE);
133 final Button useLocalPreference
= new Button(composite
, SWT
.CHECK
);
135 useLocalPreference
.setText(Messages
.DatabasePreferencesPage_UseLocalPreferences
);
136 GridData gridData
= new GridData(SWT
.FILL
, SWT
.BOTTOM
, false, false);
137 gridData
.verticalIndent
= 10;
138 useLocalPreference
.setLayoutData(gridData
);
140 useLocalPreference
.setSelection(isUseLocalPreference
);
141 useLocalPreference
.addSelectionListener(new SelectionAdapter(){
143 public void widgetSelected(SelectionEvent e
) {
144 isUseLocalPreference
= useLocalPreference
.getSelection();
154 if(!CdmStore
.isActive()){
162 private void getValues(){
163 ICdmRepository controller
= CdmStore
.getCurrentApplicationConfiguration();
164 if (controller
!= null){
165 IPreferenceService service
= controller
.getPreferenceService();
166 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewEditorInstance(), PreferencePredicate
.ShowSpecimen
);
167 CdmPreference isShowSpecimenPref
= service
.find(key
);
168 if (isShowSpecimenPref
!= null){
169 this.isShowSpecimenRelatedIssues
= Boolean
.valueOf(isShowSpecimenPref
.getValue());
171 this.isShowSpecimenRelatedIssues
= true;
175 key
= CdmPreference
.NewKey(PreferenceSubject
.NewEditorInstance(), PreferencePredicate
.ShowCollectingAreasInGeneralSection
);
176 CdmPreference isShowCollectingAreaInGeneralSectionPref
= service
.find(key
);
177 if (isShowCollectingAreaInGeneralSectionPref
!= null){
178 this.isShowCollectingAreaInGeneralSection
= Boolean
.valueOf(isShowCollectingAreaInGeneralSectionPref
.getValue());
181 key
= CdmPreference
.NewKey(PreferenceSubject
.NewEditorInstance(), PreferencePredicate
.DeterminationOnlyForFieldUnits
);
182 CdmPreference isDeterminationOnlyForFieldUnitsPref
= service
.find(key
);
183 if (isDeterminationOnlyForFieldUnitsPref
!= null){
184 this.isDeterminationOnlyForFieldUnits
= Boolean
.valueOf(isDeterminationOnlyForFieldUnitsPref
.getValue());
186 key
= CdmPreference
.NewKey(PreferenceSubject
.NewEditorInstance(), PreferencePredicate
.ShowTaxonAssociations
);
187 CdmPreference isShowTaxonAssociationPref
= service
.find(key
);
188 if (isShowTaxonAssociationPref
!= null){
189 this.isShowTaxonAssociation
= Boolean
.valueOf(isShowTaxonAssociationPref
.getValue());
190 isUseLocalPreference
= isShowTaxonAssociationPref
.isAllowOverride();
193 key
= CdmPreference
.NewKey(PreferenceSubject
.NewEditorInstance(), PreferencePredicate
.ShowLifeForm
);
194 CdmPreference isShowLifeFormPref
= service
.find(key
);
195 if (isShowLifeFormPref
!= null){
196 this.isShowLifeForm
= Boolean
.valueOf(isShowLifeFormPref
.getValue());
206 public boolean performOk() {
207 ICdmRepository controller
= CdmStore
.getCurrentApplicationConfiguration();
208 if (controller
!= null){
209 IPreferenceService service
= controller
.getPreferenceService();
211 CdmPreference pref
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.ShowCollectingAreasInGeneralSection
, Boolean
.toString(this.isShowCollectingAreaInGeneralSection
));
212 pref
.setAllowOverride(isUseLocalPreference
);
214 pref
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.ShowSpecimen
, Boolean
.toString(this.isShowSpecimenRelatedIssues
));
215 pref
.setAllowOverride(isUseLocalPreference
);
218 pref
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.DeterminationOnlyForFieldUnits
, Boolean
.toString(this.isDeterminationOnlyForFieldUnits
));
219 pref
.setAllowOverride(isUseLocalPreference
);
222 pref
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.ShowTaxonAssociations
, Boolean
.toString(this.isShowTaxonAssociation
));
223 pref
.setAllowOverride(isUseLocalPreference
);
226 pref
= CdmPreference
.NewDatabaseInstance(PreferencePredicate
.ShowLifeForm
, Boolean
.toString(this.isShowLifeForm
));
227 pref
.setAllowOverride(isUseLocalPreference
);
229 PreferencesUtil
.updateDBPreferences();