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
|
setApply(true);
|
98
|
isShowSpecimenRelatedIssues = showSpecimenButton.getSelection();
|
99
|
if(isShowSpecimenRelatedIssues){
|
100
|
composite.setVisible(true);
|
101
|
composite.setEnabled(true);
|
102
|
}else{
|
103
|
composite.setVisible(false);
|
104
|
composite.setEnabled(false);
|
105
|
}
|
106
|
}
|
107
|
});
|
108
|
Button allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
|
109
|
if (isAdminPreference){
|
110
|
allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
|
111
|
allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
|
112
|
@Override
|
113
|
public void widgetSelected(SelectionEvent e) {
|
114
|
setApply(true);
|
115
|
allowOverrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
|
116
|
}
|
117
|
});
|
118
|
}else{
|
119
|
allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(overrideShowSpecimenRelatedIssues);
|
120
|
allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
|
121
|
@Override
|
122
|
public void widgetSelected(SelectionEvent e) {
|
123
|
setApply(true);
|
124
|
overrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
|
125
|
}
|
126
|
});
|
127
|
if (!allowOverrideShowSpecimenRelatedIssues){
|
128
|
showSpecimenButton.setEnabled(false);
|
129
|
allowOverrideIsShowSpecimenRelatedIssuesButton.setEnabled(false);
|
130
|
}
|
131
|
}
|
132
|
composite = createComposite(parent);
|
133
|
composite.setEnabled(isShowSpecimenRelatedIssues);
|
134
|
GridData gridData = createTextGridData();
|
135
|
|
136
|
Label separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
|
137
|
separator.setLayoutData(gridData);
|
138
|
|
139
|
final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
|
140
|
|
141
|
showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
|
142
|
|
143
|
showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
|
144
|
showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
|
145
|
@Override
|
146
|
public void widgetSelected(SelectionEvent e) {
|
147
|
setApply(true);
|
148
|
isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
|
149
|
|
150
|
}
|
151
|
});
|
152
|
Button allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
|
153
|
if (isAdminPreference){
|
154
|
allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
|
155
|
allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
|
156
|
@Override
|
157
|
public void widgetSelected(SelectionEvent e) {
|
158
|
setApply(true);
|
159
|
allowOverrideShowCollectingAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
|
160
|
}
|
161
|
});
|
162
|
}else{
|
163
|
allowOverrideShowCollectingAreaButton.setSelection(overrideShowCollectionAreaInGeneralSection);
|
164
|
allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
|
165
|
@Override
|
166
|
public void widgetSelected(SelectionEvent e) {
|
167
|
setApply(true);
|
168
|
overrideShowCollectionAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
|
169
|
}
|
170
|
});
|
171
|
if (!allowOverrideShowCollectingAreaInGeneralSection){
|
172
|
showCollectingAreaInGeneralSectionButton.setEnabled(false);
|
173
|
allowOverrideShowCollectingAreaButton.setEnabled(false);
|
174
|
}
|
175
|
}
|
176
|
|
177
|
final Button determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
|
178
|
determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
|
179
|
determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
|
180
|
determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
|
181
|
@Override
|
182
|
public void widgetSelected(SelectionEvent e) {
|
183
|
setApply(true);
|
184
|
isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
|
185
|
}
|
186
|
});
|
187
|
|
188
|
Button allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
|
189
|
if (isAdminPreference){
|
190
|
allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
|
191
|
allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
|
192
|
@Override
|
193
|
public void widgetSelected(SelectionEvent e) {
|
194
|
setApply(true);
|
195
|
allowOverrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
|
196
|
}
|
197
|
});
|
198
|
}else{
|
199
|
allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(overrideDeterminationOnlyForFieldUnits);
|
200
|
allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
|
201
|
@Override
|
202
|
public void widgetSelected(SelectionEvent e) {
|
203
|
setApply(true);
|
204
|
overrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
|
205
|
}
|
206
|
});
|
207
|
if (!allowOverrideDeterminationOnlyForFieldUnits){
|
208
|
determinationOnlyForFieldUnitsButton.setEnabled(false);
|
209
|
allowOverridesDeterminationOnlyForFieldUnitsButton.setEnabled(false);
|
210
|
}
|
211
|
}
|
212
|
|
213
|
final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
|
214
|
|
215
|
showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
|
216
|
|
217
|
showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
|
218
|
showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
|
219
|
@Override
|
220
|
public void widgetSelected(SelectionEvent e) {
|
221
|
setApply(true);
|
222
|
isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
|
223
|
|
224
|
}
|
225
|
});
|
226
|
Button allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
|
227
|
if (isAdminPreference){
|
228
|
allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
|
229
|
allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
|
230
|
@Override
|
231
|
public void widgetSelected(SelectionEvent e) {
|
232
|
setApply(true);
|
233
|
allowOverrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
|
234
|
}
|
235
|
});
|
236
|
}else{
|
237
|
allowOverrideIsShowTaxonAssociationButton.setSelection(overrideShowTaxonAssociation);
|
238
|
allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
|
239
|
@Override
|
240
|
public void widgetSelected(SelectionEvent e) {
|
241
|
setApply(true);
|
242
|
overrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
|
243
|
}
|
244
|
});
|
245
|
if (!allowOverrideShowTaxonAssociation){
|
246
|
showTaxonAssociationButton.setEnabled(false);
|
247
|
allowOverrideIsShowTaxonAssociationButton.setEnabled(false);
|
248
|
}
|
249
|
}
|
250
|
|
251
|
final Button showLifeFormButton = new Button(composite, SWT.CHECK);
|
252
|
showLifeFormButton.setText(Messages.DatabasePreferncesPage_Life_Form);
|
253
|
showLifeFormButton.setSelection(isShowLifeForm);
|
254
|
showLifeFormButton.addSelectionListener(new SelectionAdapter(){
|
255
|
@Override
|
256
|
public void widgetSelected(SelectionEvent e) {
|
257
|
setApply(true);
|
258
|
isShowLifeForm = showLifeFormButton.getSelection();
|
259
|
|
260
|
}
|
261
|
});
|
262
|
|
263
|
Button allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
|
264
|
if (isAdminPreference){
|
265
|
allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
|
266
|
allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
|
267
|
@Override
|
268
|
public void widgetSelected(SelectionEvent e) {
|
269
|
setApply(true);
|
270
|
allowOverrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
|
271
|
}
|
272
|
});
|
273
|
}else{
|
274
|
allowOverrideShowLifeFormButton.setSelection(overrideShowLifeForm);
|
275
|
allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
|
276
|
@Override
|
277
|
public void widgetSelected(SelectionEvent e) {
|
278
|
setApply(true);
|
279
|
overrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
|
280
|
}
|
281
|
});
|
282
|
if (!allowOverrideShowLifeForm){
|
283
|
showLifeFormButton.setEnabled(false);
|
284
|
allowOverrideShowLifeFormButton.setEnabled(false);
|
285
|
}
|
286
|
}
|
287
|
|
288
|
if (!isEditingAllowed){
|
289
|
PreferencesUtil.recursiveSetEnabled(composite, false);
|
290
|
}
|
291
|
return composite;
|
292
|
}
|
293
|
|
294
|
|
295
|
/**
|
296
|
* {@inheritDoc}
|
297
|
*/
|
298
|
@Override
|
299
|
protected void getValues() {
|
300
|
CdmPreferenceCache cache = CdmPreferenceCache.instance();
|
301
|
|
302
|
isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.ShowSpecimen.getKey());
|
303
|
allowOverrideShowSpecimenRelatedIssues = cache.get(EditorPreferencePredicate.ShowSpecimen.getKey())!= null ? cache.get(EditorPreferencePredicate.ShowSpecimen.getKey()).isAllowOverride():true;
|
304
|
|
305
|
isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
|
306
|
allowOverrideShowCollectingAreaInGeneralSection = cache.get(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey())!= null ? cache.get(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()).isAllowOverride():true;
|
307
|
|
308
|
isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
|
309
|
allowOverrideDeterminationOnlyForFieldUnits = cache.get(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey())!= null ? cache.get(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey()).isAllowOverride():true;
|
310
|
|
311
|
isShowTaxonAssociation = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.ShowTaxonAssociations.getKey());
|
312
|
allowOverrideShowTaxonAssociation = cache.get(EditorPreferencePredicate.ShowTaxonAssociations.getKey())!= null ? cache.get(EditorPreferencePredicate.ShowTaxonAssociations.getKey()).isAllowOverride():true;
|
313
|
|
314
|
isShowLifeForm = PreferencesUtil.getBooleanValue(EditorPreferencePredicate.ShowLifeForm.getKey());
|
315
|
allowOverrideShowLifeForm = cache.get(EditorPreferencePredicate.ShowLifeForm.getKey())!= null ? cache.get(EditorPreferencePredicate.ShowLifeForm.getKey()).isAllowOverride():true;
|
316
|
|
317
|
|
318
|
}
|
319
|
|
320
|
@Override
|
321
|
public boolean performOk() {
|
322
|
if (allowOverrideShowSpecimenRelatedIssues){
|
323
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues);
|
324
|
}
|
325
|
if (allowOverrideShowCollectingAreaInGeneralSection){
|
326
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), isShowCollectingAreaInGeneralSection);
|
327
|
}
|
328
|
if (allowOverrideDeterminationOnlyForFieldUnits){
|
329
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), isDeterminationOnlyForFieldUnits);
|
330
|
}
|
331
|
if (allowOverrideShowTaxonAssociation){
|
332
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.ShowTaxonAssociations.getKey(), isShowTaxonAssociation);
|
333
|
}
|
334
|
if (allowOverrideShowLifeForm){
|
335
|
PreferencesUtil.setBooleanValue(EditorPreferencePredicate.ShowLifeForm.getKey(), isShowLifeForm);
|
336
|
}
|
337
|
return true;
|
338
|
}
|
339
|
|
340
|
|
341
|
}
|