1
|
/**
|
2
|
* Copyright (C) 2014 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 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.widgets.Button;
|
16
|
import org.eclipse.swt.widgets.Composite;
|
17
|
import org.eclipse.swt.widgets.Control;
|
18
|
import org.eclipse.swt.widgets.Label;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
21
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
22
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
23
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24
|
|
25
|
/**
|
26
|
* @author pplitzner
|
27
|
* @date 13.02.2014
|
28
|
*
|
29
|
*/
|
30
|
public class SpecimenOrObservationPreferences extends CdmPreferencePage {
|
31
|
|
32
|
private static final String LOCAL_SETTINGS_NOT_ALLOWED = "The CDM settings don't allow to set the preferences for the display of specimen and obeservations locally. If you need to make local settings, please ask an administrator.";
|
33
|
private static final String DESCRIPTION = "Set the preferences for the display of specimen and observations.";
|
34
|
|
35
|
protected boolean isShowSpecimenRelatedIssues;
|
36
|
protected boolean allowOverrideShowSpecimenRelatedIssues;
|
37
|
protected boolean overrideShowSpecimenRelatedIssues;
|
38
|
protected boolean isShowCollectingAreaInGeneralSection;
|
39
|
protected boolean allowOverrideShowCollectingAreaInGeneralSection;
|
40
|
protected boolean overrideShowCollectionAreaInGeneralSection;
|
41
|
protected boolean isDeterminationOnlyForFieldUnits;
|
42
|
protected boolean allowOverrideDeterminationOnlyForFieldUnits;
|
43
|
protected boolean overrideDeterminationOnlyForFieldUnits;
|
44
|
protected boolean isShowTaxonAssociation;
|
45
|
protected boolean allowOverrideShowTaxonAssociation;
|
46
|
protected boolean overrideShowTaxonAssociation;
|
47
|
protected boolean isShowLifeForm;
|
48
|
protected boolean allowOverrideShowLifeForm;
|
49
|
protected boolean overrideShowLifeForm;
|
50
|
Composite composite;
|
51
|
|
52
|
|
53
|
@Override
|
54
|
public void init() {
|
55
|
super.init();
|
56
|
// setPreferenceStore(PreferencesUtil.getPreferenceStore());
|
57
|
if(!CdmStore.isActive()){
|
58
|
return;
|
59
|
}
|
60
|
|
61
|
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* {@inheritDoc}
|
66
|
*/
|
67
|
@Override
|
68
|
protected Control createContents(Composite parent) {
|
69
|
getValues();
|
70
|
|
71
|
boolean isEditingAllowed = true;
|
72
|
if(!isAdminPreference){
|
73
|
CdmPreferenceCache cache = CdmPreferenceCache.instance();
|
74
|
CdmPreference showSpecimenPref = cache.get(EditorPreferencePredicate.ShowSpecimen.getKey());
|
75
|
if (showSpecimenPref != null){
|
76
|
if (!showSpecimenPref.isAllowOverride() ){
|
77
|
Label label = new Label(parent, SWT.NONE);
|
78
|
label.setText(LOCAL_SETTINGS_NOT_ALLOWED);
|
79
|
isEditingAllowed = false;
|
80
|
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
|
85
|
Label label = new Label(parent, SWT.NONE);
|
86
|
label.setText(DESCRIPTION);
|
87
|
Composite titleComp = createComposite(parent);
|
88
|
|
89
|
final Button showSpecimenButton = new Button(titleComp, SWT.CHECK);
|
90
|
|
91
|
showSpecimenButton.setText(Messages.DatabasePreferncesPage_Show_Specimen);
|
92
|
|
93
|
showSpecimenButton.setSelection(isShowSpecimenRelatedIssues);
|
94
|
showSpecimenButton.addSelectionListener(new SelectionAdapter(){
|
95
|
@Override
|
96
|
public void widgetSelected(SelectionEvent e) {
|
97
|
isShowSpecimenRelatedIssues = showSpecimenButton.getSelection();
|
98
|
if(isShowSpecimenRelatedIssues){
|
99
|
composite.setVisible(true);
|
100
|
composite.setEnabled(true);
|
101
|
}else{
|
102
|
composite.setVisible(false);
|
103
|
composite.setEnabled(false);
|
104
|
}
|
105
|
}
|
106
|
});
|
107
|
Button allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
|
108
|
if (isAdminPreference){
|
109
|
allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
|
110
|
allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
|
111
|
@Override
|
112
|
public void widgetSelected(SelectionEvent e) {
|
113
|
allowOverrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
|
114
|
}
|
115
|
});
|
116
|
}else{
|
117
|
allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(overrideShowSpecimenRelatedIssues);
|
118
|
allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
|
119
|
@Override
|
120
|
public void widgetSelected(SelectionEvent e) {
|
121
|
overrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
|
122
|
}
|
123
|
});
|
124
|
if (!allowOverrideShowSpecimenRelatedIssues){
|
125
|
showSpecimenButton.setEnabled(false);
|
126
|
allowOverrideIsShowSpecimenRelatedIssuesButton.setEnabled(false);
|
127
|
}
|
128
|
}
|
129
|
composite = createComposite(parent);
|
130
|
composite.setEnabled(isShowSpecimenRelatedIssues);
|
131
|
GridData gridData = createTextGridData();
|
132
|
|
133
|
Label separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
|
134
|
separator.setLayoutData(gridData);
|
135
|
|
136
|
final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
|
137
|
|
138
|
showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
|
139
|
|
140
|
showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
|
141
|
showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
|
142
|
@Override
|
143
|
public void widgetSelected(SelectionEvent e) {
|
144
|
isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
|
145
|
|
146
|
}
|
147
|
});
|
148
|
Button allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
|
149
|
if (isAdminPreference){
|
150
|
allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
|
151
|
allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
|
152
|
@Override
|
153
|
public void widgetSelected(SelectionEvent e) {
|
154
|
allowOverrideShowCollectingAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
|
155
|
}
|
156
|
});
|
157
|
}else{
|
158
|
allowOverrideShowCollectingAreaButton.setSelection(overrideShowCollectionAreaInGeneralSection);
|
159
|
allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
|
160
|
@Override
|
161
|
public void widgetSelected(SelectionEvent e) {
|
162
|
overrideShowCollectionAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
|
163
|
}
|
164
|
});
|
165
|
if (!allowOverrideShowCollectingAreaInGeneralSection){
|
166
|
showCollectingAreaInGeneralSectionButton.setEnabled(false);
|
167
|
allowOverrideShowCollectingAreaButton.setEnabled(false);
|
168
|
}
|
169
|
}
|
170
|
|
171
|
final Button determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
|
172
|
determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
|
173
|
determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
|
174
|
determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
|
175
|
@Override
|
176
|
public void widgetSelected(SelectionEvent e) {
|
177
|
isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
|
178
|
}
|
179
|
});
|
180
|
|
181
|
Button allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
|
182
|
if (isAdminPreference){
|
183
|
allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
|
184
|
allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
|
185
|
@Override
|
186
|
public void widgetSelected(SelectionEvent e) {
|
187
|
allowOverrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
|
188
|
}
|
189
|
});
|
190
|
}else{
|
191
|
allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(overrideDeterminationOnlyForFieldUnits);
|
192
|
allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
|
193
|
@Override
|
194
|
public void widgetSelected(SelectionEvent e) {
|
195
|
overrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
|
196
|
}
|
197
|
});
|
198
|
if (!allowOverrideDeterminationOnlyForFieldUnits){
|
199
|
determinationOnlyForFieldUnitsButton.setEnabled(false);
|
200
|
allowOverridesDeterminationOnlyForFieldUnitsButton.setEnabled(false);
|
201
|
}
|
202
|
}
|
203
|
|
204
|
final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
|
205
|
|
206
|
showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
|
207
|
|
208
|
showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
|
209
|
showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
|
210
|
@Override
|
211
|
public void widgetSelected(SelectionEvent e) {
|
212
|
isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
|
213
|
|
214
|
}
|
215
|
});
|
216
|
Button allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
|
217
|
if (isAdminPreference){
|
218
|
allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
|
219
|
allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
|
220
|
@Override
|
221
|
public void widgetSelected(SelectionEvent e) {
|
222
|
allowOverrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
|
223
|
}
|
224
|
});
|
225
|
}else{
|
226
|
allowOverrideIsShowTaxonAssociationButton.setSelection(overrideShowTaxonAssociation);
|
227
|
allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
|
228
|
@Override
|
229
|
public void widgetSelected(SelectionEvent e) {
|
230
|
overrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
|
231
|
}
|
232
|
});
|
233
|
if (!allowOverrideShowTaxonAssociation){
|
234
|
showTaxonAssociationButton.setEnabled(false);
|
235
|
allowOverrideIsShowTaxonAssociationButton.setEnabled(false);
|
236
|
}
|
237
|
}
|
238
|
|
239
|
final Button showLifeFormButton = new Button(composite, SWT.CHECK);
|
240
|
showLifeFormButton.setText(Messages.DatabasePreferncesPage_Life_Form);
|
241
|
showLifeFormButton.setSelection(isShowLifeForm);
|
242
|
showLifeFormButton.addSelectionListener(new SelectionAdapter(){
|
243
|
@Override
|
244
|
public void widgetSelected(SelectionEvent e) {
|
245
|
isShowLifeForm = showLifeFormButton.getSelection();
|
246
|
|
247
|
}
|
248
|
});
|
249
|
|
250
|
Button allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
|
251
|
if (isAdminPreference){
|
252
|
allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
|
253
|
allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
|
254
|
@Override
|
255
|
public void widgetSelected(SelectionEvent e) {
|
256
|
allowOverrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
|
257
|
}
|
258
|
});
|
259
|
}else{
|
260
|
allowOverrideShowLifeFormButton.setSelection(overrideShowLifeForm);
|
261
|
allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
|
262
|
@Override
|
263
|
public void widgetSelected(SelectionEvent e) {
|
264
|
overrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
|
265
|
}
|
266
|
});
|
267
|
if (!allowOverrideShowLifeForm){
|
268
|
showLifeFormButton.setEnabled(false);
|
269
|
allowOverrideShowLifeFormButton.setEnabled(false);
|
270
|
}
|
271
|
}
|
272
|
|
273
|
if (!isEditingAllowed){
|
274
|
PreferencesUtil.recursiveSetEnabled(composite, false);
|
275
|
}
|
276
|
return composite;
|
277
|
}
|
278
|
|
279
|
|
280
|
/**
|
281
|
* {@inheritDoc}
|
282
|
*/
|
283
|
@Override
|
284
|
protected void getValues() {
|
285
|
CdmPreferenceCache cache = CdmPreferenceCache.instance();
|
286
|
|
287
|
isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.ShowSpecimen.getKey());
|
288
|
allowOverrideShowSpecimenRelatedIssues = cache.get(EditorPreferencePredicate.ShowSpecimen.getKey())!= null ? cache.get(EditorPreferencePredicate.ShowSpecimen.getKey()).isAllowOverride():true;
|
289
|
|
290
|
isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
|
291
|
allowOverrideShowCollectingAreaInGeneralSection = cache.get(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey())!= null ? cache.get(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()).isAllowOverride():true;
|
292
|
|
293
|
isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
|
294
|
allowOverrideDeterminationOnlyForFieldUnits = cache.get(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey())!= null ? cache.get(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey()).isAllowOverride():true;
|
295
|
|
296
|
isShowTaxonAssociation = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.ShowTaxonAssociations.getKey());
|
297
|
allowOverrideShowTaxonAssociation = cache.get(EditorPreferencePredicate.ShowTaxonAssociations.getKey())!= null ? cache.get(EditorPreferencePredicate.ShowTaxonAssociations.getKey()).isAllowOverride():true;
|
298
|
|
299
|
isShowLifeForm = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.ShowLifeForm.getKey());
|
300
|
allowOverrideShowLifeForm = cache.get(EditorPreferencePredicate.ShowLifeForm.getKey())!= null ? cache.get(EditorPreferencePredicate.ShowLifeForm.getKey()).isAllowOverride():true;
|
301
|
overrideString = Messages.GeneralPreference_override;
|
302
|
|
303
|
}
|
304
|
|
305
|
@Override
|
306
|
public boolean performOk() {
|
307
|
if (allowOverrideShowSpecimenRelatedIssues){
|
308
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues);
|
309
|
}
|
310
|
if (allowOverrideShowCollectingAreaInGeneralSection){
|
311
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), isShowCollectingAreaInGeneralSection);
|
312
|
}
|
313
|
if (allowOverrideDeterminationOnlyForFieldUnits){
|
314
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), isDeterminationOnlyForFieldUnits);
|
315
|
}
|
316
|
if (allowOverrideShowTaxonAssociation){
|
317
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.ShowTaxonAssociations.getKey(), isShowTaxonAssociation);
|
318
|
}
|
319
|
if (allowOverrideShowLifeForm){
|
320
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.ShowLifeForm.getKey(), isShowLifeForm);
|
321
|
}
|
322
|
return true;
|
323
|
}
|
324
|
|
325
|
|
326
|
}
|