1
|
/**
|
2
|
* Copyright (C) 2018 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.databaseAdmin.preferencePage;
|
10
|
|
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;
|
20
|
|
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.IPreferenceKeys;
|
29
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
30
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
31
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32
|
|
33
|
/**
|
34
|
* @author k.luther
|
35
|
* @since 27.04.2018
|
36
|
*
|
37
|
*/
|
38
|
public class SpecimenAdminPreferences extends CdmPreferencePage implements IE4AdminPreferencePage {
|
39
|
public SpecimenAdminPreferences() {
|
40
|
}
|
41
|
|
42
|
boolean isShowSpecimenRelatedIssues;
|
43
|
boolean isShowCollectingAreaInGeneralSection;
|
44
|
boolean isDeterminationOnlyForFieldUnits;
|
45
|
boolean isShowTaxonAssociation;
|
46
|
boolean isShowLifeForm;
|
47
|
boolean isUseLocalPreference;
|
48
|
Composite composite;
|
49
|
CdmPreference isShowSpecimenPref = null;
|
50
|
|
51
|
@Override
|
52
|
protected Control createContents(Composite parent) {
|
53
|
|
54
|
getValues();
|
55
|
|
56
|
final Button showSpecimenButton = new Button(parent, SWT.CHECK);
|
57
|
|
58
|
showSpecimenButton.setText(Messages.DatabasePreferncesPage_Show_Specimen);
|
59
|
|
60
|
showSpecimenButton.setSelection(isShowSpecimenRelatedIssues);
|
61
|
showSpecimenButton.addSelectionListener(new SelectionAdapter(){
|
62
|
@Override
|
63
|
public void widgetSelected(SelectionEvent e) {
|
64
|
isShowSpecimenRelatedIssues = showSpecimenButton.getSelection();
|
65
|
if(isShowSpecimenRelatedIssues){
|
66
|
composite.setVisible(true);
|
67
|
composite.setEnabled(true);
|
68
|
}else{
|
69
|
composite.setVisible(false);
|
70
|
composite.setEnabled(false);
|
71
|
}
|
72
|
}
|
73
|
});
|
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));
|
80
|
|
81
|
final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
|
82
|
|
83
|
showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
|
84
|
|
85
|
showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
|
86
|
showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
|
87
|
@Override
|
88
|
public void widgetSelected(SelectionEvent e) {
|
89
|
isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
|
90
|
|
91
|
}
|
92
|
});
|
93
|
|
94
|
final Button determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
|
95
|
|
96
|
determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
|
97
|
|
98
|
determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
|
99
|
determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
|
100
|
@Override
|
101
|
public void widgetSelected(SelectionEvent e) {
|
102
|
isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
|
103
|
}
|
104
|
});
|
105
|
|
106
|
final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
|
107
|
|
108
|
showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
|
109
|
|
110
|
showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
|
111
|
showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
|
112
|
@Override
|
113
|
public void widgetSelected(SelectionEvent e) {
|
114
|
isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
|
115
|
|
116
|
}
|
117
|
});
|
118
|
|
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(){
|
123
|
@Override
|
124
|
public void widgetSelected(SelectionEvent e) {
|
125
|
isShowLifeForm = showLifeFormButton.getSelection();
|
126
|
|
127
|
}
|
128
|
});
|
129
|
|
130
|
// Composite useLocalComp = new Composite(composite, SWT.NONE);
|
131
|
|
132
|
|
133
|
final Button useLocalPreference = new Button(composite, SWT.CHECK);
|
134
|
|
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);
|
139
|
|
140
|
useLocalPreference.setSelection(isUseLocalPreference);
|
141
|
useLocalPreference.addSelectionListener(new SelectionAdapter(){
|
142
|
@Override
|
143
|
public void widgetSelected(SelectionEvent e) {
|
144
|
isUseLocalPreference = useLocalPreference.getSelection();
|
145
|
PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SPECIMEN_ALLOW_OVERRIDE, isUseLocalPreference);
|
146
|
}
|
147
|
});
|
148
|
return composite;
|
149
|
}
|
150
|
|
151
|
@Override
|
152
|
public void init() {
|
153
|
super.init();
|
154
|
if(!CdmStore.isActive()){
|
155
|
return;
|
156
|
}
|
157
|
}
|
158
|
|
159
|
private void getValues(){
|
160
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
161
|
if (controller != null){
|
162
|
IPreferenceService service = controller.getPreferenceService();
|
163
|
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
|
164
|
isShowSpecimenPref = service.find(key);
|
165
|
if (isShowSpecimenPref != null){
|
166
|
this.isShowSpecimenRelatedIssues = Boolean.valueOf(isShowSpecimenPref.getValue());
|
167
|
}else{
|
168
|
isShowSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(true));
|
169
|
this.isShowSpecimenRelatedIssues = true;
|
170
|
}
|
171
|
|
172
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
|
173
|
CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
|
174
|
if (isShowCollectingAreaInGeneralSectionPref != null){
|
175
|
this.isShowCollectingAreaInGeneralSection = Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue());
|
176
|
}
|
177
|
|
178
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
|
179
|
CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
|
180
|
if (isDeterminationOnlyForFieldUnitsPref != null){
|
181
|
this.isDeterminationOnlyForFieldUnits = Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue());
|
182
|
}
|
183
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
|
184
|
CdmPreference isShowTaxonAssociationPref = service.find(key);
|
185
|
if (isShowTaxonAssociationPref != null){
|
186
|
this.isShowTaxonAssociation = Boolean.valueOf(isShowTaxonAssociationPref.getValue());
|
187
|
}
|
188
|
|
189
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
|
190
|
CdmPreference isShowLifeFormPref = service.find(key);
|
191
|
if (isShowLifeFormPref != null){
|
192
|
this.isShowLifeForm = Boolean.valueOf(isShowLifeFormPref.getValue());
|
193
|
}
|
194
|
|
195
|
}
|
196
|
}
|
197
|
|
198
|
@Override
|
199
|
public boolean performOk() {
|
200
|
if (isShowSpecimenPref == null){
|
201
|
return true;
|
202
|
}
|
203
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
204
|
if (controller != null){
|
205
|
IPreferenceService service = controller.getPreferenceService();
|
206
|
|
207
|
CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
|
208
|
pref.setAllowOverride(isUseLocalPreference);
|
209
|
service.set(pref);
|
210
|
pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(this.isShowSpecimenRelatedIssues));
|
211
|
pref.setAllowOverride(isUseLocalPreference);
|
212
|
service.set(pref);
|
213
|
|
214
|
pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
|
215
|
pref.setAllowOverride(isUseLocalPreference);
|
216
|
service.set(pref);
|
217
|
|
218
|
pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
|
219
|
pref.setAllowOverride(isUseLocalPreference);
|
220
|
service.set(pref);
|
221
|
|
222
|
pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
|
223
|
pref.setAllowOverride(isUseLocalPreference);
|
224
|
service.set(pref);
|
225
|
PreferencesUtil.updateDBPreferences();
|
226
|
|
227
|
|
228
|
}
|
229
|
return true;
|
230
|
}
|
231
|
|
232
|
}
|