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