Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / SpecimenOrObservationPreferences.java
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.events.SelectionListener;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Combo;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Label;
21
22 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
23 import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
24 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
25 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
26 import eu.etaxonomy.taxeditor.l10n.Messages;
27 import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 * @author pplitzner
32 * @date 13.02.2014
33 *
34 */
35 public class SpecimenOrObservationPreferences extends CdmPreferencePage implements SelectionListener{
36
37 private static final String LOCAL_SETTINGS_NOT_ALLOWED = Messages.SpecimenOrObservationPreferences_0;
38 private static final String DESCRIPTION = Messages.SpecimenOrObservationPreferences_1;
39
40 protected Boolean isShowSpecimenRelatedIssues;
41 protected boolean allowOverrideShowSpecimenRelatedIssues;
42 protected boolean overrideShowSpecimenRelatedIssues;
43 protected Boolean isShowCollectingAreaInGeneralSection;
44 protected boolean allowOverrideShowCollectingAreaInGeneralSection;
45 protected boolean overrideShowCollectionAreaInGeneralSection;
46 protected Boolean isDeterminationOnlyForFieldUnits;
47 protected boolean allowOverrideDeterminationOnlyForFieldUnits;
48 protected boolean overrideDeterminationOnlyForFieldUnits;
49 protected Boolean isShowTaxonAssociation;
50 protected boolean allowOverrideShowTaxonAssociation;
51 protected boolean overrideShowTaxonAssociation;
52 protected Boolean isShowLifeForm;
53 protected boolean allowOverrideShowLifeForm;
54 protected boolean overrideShowLifeForm;
55 protected Boolean isShowListEditor;
56 protected boolean allowOverrideShowListEditor;
57 protected boolean overrideShowListEditor;
58
59 Composite composite;
60
61 protected Combo showSpecimenButton;
62 protected Button allowOverrideIsShowSpecimenRelatedIssuesButton;
63 protected Combo showCollectingAreaInGeneralSectionButton;
64 protected Button allowOverrideShowCollectingAreaButton;
65 protected Combo determinationOnlyForFieldUnitsButton;
66 protected Button allowOverridesDeterminationOnlyForFieldUnitsButton;
67 protected Combo showTaxonAssociationButton;
68 protected Button allowOverrideIsShowTaxonAssociationButton;
69 protected Button allowOverrideShowLifeFormButton;
70 protected Combo showLifeFormButton;
71 protected Button allowOverrideShowListEditorButton;
72 protected Combo showListEditorButton;
73
74 CdmPreference showSpecimenPref;
75 CdmPreference showCollectingAreaInGeneralSection;
76 CdmPreference showDeterminationOnlyForFieldUnits;
77 CdmPreference showTaxonAssociation;
78 CdmPreference showLifeForm;
79 CdmPreference showListEditor;
80
81 @Override
82 public void init() {
83 super.init();
84 // setPreferenceStore(PreferencesUtil.getPreferenceStore());
85 if(!CdmStore.isActive()){
86 return;
87 }
88
89
90 }
91
92 /**
93 * {@inheritDoc}
94 */
95 @Override
96 protected Control createContents(Composite parent) {
97 getValues();
98
99 boolean isEditingAllowed = true;
100 if(!isAdminPreference){
101 CdmPreferenceCache cache = CdmPreferenceCache.instance();
102
103 if (showSpecimenPref != null){
104 if (!showSpecimenPref.isAllowOverride() ){
105 isEditingAllowed = false;
106 }
107 }
108 }
109 if (isEditingAllowed){
110 Label label = new Label(parent, SWT.NONE);
111 label.setText(DESCRIPTION);
112 }else{
113 Label label = new Label(parent, SWT.NONE);
114 label.setText(LOCAL_SETTINGS_NOT_ALLOWED);
115 this.noDefaultAndApplyButton();
116 return parent;
117 }
118 Composite titleComp = createComposite(parent);
119 GridData gridData = createTextGridData();
120
121 Label separator= new Label(titleComp, SWT.HORIZONTAL | SWT.SEPARATOR);
122 separator.setLayoutData(gridData);
123 separator.setVisible(false);
124 showSpecimenButton = createBooleanCombo(titleComp, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowSpecimen, Messages.DatabasePreferncesPage_Show_Specimen, isAdminPreference);
125
126 showSpecimenButton.addSelectionListener(this);
127 int index = 0;
128 for (String itemLabel : showSpecimenButton.getItems()) {
129 if (isShowSpecimenRelatedIssues == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
130 showSpecimenButton.select(index);
131 break;
132 }
133 if (isShowSpecimenRelatedIssues != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowSpecimenRelatedIssues){
134 showSpecimenButton.select(index);
135 break;
136 }
137 if (isShowSpecimenRelatedIssues != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowSpecimenRelatedIssues){
138 showSpecimenButton.select(index);
139 break;
140 }
141 index++;
142 }
143 showSpecimenButton.setEnabled(isEditingAllowed);
144
145 if (isAdminPreference){
146 allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
147 allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
148 // allowOverrideIsShowSpecimenRelatedIssuesButton.setEnabled(isShowSpecimenRelatedIssues != null);
149 allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
150 @Override
151 public void widgetSelected(SelectionEvent e) {
152 setApply(true);
153 allowOverrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
154 }
155 });
156 }
157
158 composite = createComposite(parent);
159 //composite.setEnabled(isShowSpecimenRelatedIssues);
160 gridData = createTextGridData();
161
162 separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
163 separator.setLayoutData(gridData);
164
165 showListEditorButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowSpecimenListEditor, Messages.DatabasePreferncesPage_Show_Specimen_List_Editor, isAdminPreference);
166
167 showListEditorButton.addSelectionListener(this);
168 index = 0;
169 for (String itemLabel : showListEditorButton.getItems()) {
170 if (isShowListEditor == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
171 showListEditorButton.select(index);
172 break;
173 }
174 if (isShowListEditor != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowListEditor){
175 showListEditorButton.select(index);
176 break;
177 }
178 if (isShowListEditor != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowListEditor){
179 showListEditorButton.select(index);
180 break;
181 }
182 index++;
183 }
184 if (isAdminPreference){
185 allowOverrideShowListEditorButton = createAllowOverrideButton(composite);
186 allowOverrideShowListEditorButton.setSelection(allowOverrideShowListEditor);
187 // allowOverrideShowCollectingAreaButton.setEnabled(isShowCollectingAreaInGeneralSection != null);
188 allowOverrideShowListEditorButton.addSelectionListener(new SelectionAdapter(){
189 @Override
190 public void widgetSelected(SelectionEvent e) {
191 setApply(true);
192 allowOverrideShowListEditor = allowOverrideShowListEditorButton.getSelection();
193 }
194 });
195 }
196 isEditingAllowed = true;
197 if (showListEditor != null && !showListEditor.isAllowOverride() ){
198 isEditingAllowed = false;
199 }
200 showListEditorButton.setEnabled(isEditingAllowed);
201
202 showCollectingAreaInGeneralSectionButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowCollectingAreasInGeneralSection, Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section, isAdminPreference);
203
204 showCollectingAreaInGeneralSectionButton.addSelectionListener(this);
205 index = 0;
206 for (String itemLabel : showCollectingAreaInGeneralSectionButton.getItems()) {
207 if (isShowCollectingAreaInGeneralSection == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
208 showCollectingAreaInGeneralSectionButton.select(index);
209 break;
210 }
211 if (isShowCollectingAreaInGeneralSection != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowCollectingAreaInGeneralSection){
212 showCollectingAreaInGeneralSectionButton.select(index);
213 break;
214 }
215 if (isShowCollectingAreaInGeneralSection != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowCollectingAreaInGeneralSection){
216 showCollectingAreaInGeneralSectionButton.select(index);
217 break;
218 }
219 index++;
220 }
221 if (isAdminPreference){
222 allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
223 allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
224 // allowOverrideShowCollectingAreaButton.setEnabled(isShowCollectingAreaInGeneralSection != null);
225 allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
226 @Override
227 public void widgetSelected(SelectionEvent e) {
228 setApply(true);
229 allowOverrideShowCollectingAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
230 }
231 });
232 }
233 isEditingAllowed = true;
234 if (showCollectingAreaInGeneralSection != null && !showCollectingAreaInGeneralSection.isAllowOverride() ){
235 isEditingAllowed = false;
236 }
237 showCollectingAreaInGeneralSectionButton.setEnabled(isEditingAllowed);
238 determinationOnlyForFieldUnitsButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.DeterminationOnlyForFieldUnits, Messages.DatabasePreferncesPage_Determination_only_for_field_unnits, isAdminPreference);
239
240
241 determinationOnlyForFieldUnitsButton.addSelectionListener(this);
242 index = 0;
243 for (String itemLabel : determinationOnlyForFieldUnitsButton.getItems()) {
244 if (isDeterminationOnlyForFieldUnits == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
245 determinationOnlyForFieldUnitsButton.select(index);
246 break;
247 }
248 if (isDeterminationOnlyForFieldUnits != null && itemLabel.equals(Messages.GeneralPreference_yes) && isDeterminationOnlyForFieldUnits){
249 determinationOnlyForFieldUnitsButton.select(index);
250 break;
251 }
252 if (isDeterminationOnlyForFieldUnits != null && itemLabel.equals(Messages.GeneralPreference_no) && !isDeterminationOnlyForFieldUnits){
253 determinationOnlyForFieldUnitsButton.select(index);
254 break;
255 }
256 index++;
257 }
258 isEditingAllowed = true;
259 if (showDeterminationOnlyForFieldUnits != null && !showDeterminationOnlyForFieldUnits.isAllowOverride() ){
260 isEditingAllowed = false;
261 }
262
263 determinationOnlyForFieldUnitsButton.setEnabled(isEditingAllowed);
264 if (isAdminPreference){
265 allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
266 allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
267 // allowOverridesDeterminationOnlyForFieldUnitsButton.setEnabled(showDeterminationOnlyForFieldUnits != null);
268 allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
269 @Override
270 public void widgetSelected(SelectionEvent e) {
271 setApply(true);
272 allowOverrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
273 }
274 });
275 }
276
277 showTaxonAssociationButton =createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowTaxonAssociations, Messages.DatabasePreferncesPage_Taxon_Associations, isAdminPreference);
278
279
280 showTaxonAssociationButton.addSelectionListener(this);
281 index = 0;
282 for (String itemLabel : showTaxonAssociationButton.getItems()) {
283 if (isShowTaxonAssociation == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
284 showTaxonAssociationButton.select(index);
285 break;
286 }
287 if (isShowTaxonAssociation != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowTaxonAssociation){
288 showTaxonAssociationButton.select(index);
289 break;
290 }
291 if (isShowTaxonAssociation != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowTaxonAssociation){
292 showTaxonAssociationButton.select(index);
293 break;
294 }
295 index++;
296 }
297 isEditingAllowed = true;
298 if (showTaxonAssociation != null && !showTaxonAssociation.isAllowOverride() ){
299 isEditingAllowed = false;
300 }
301 showTaxonAssociationButton.setEnabled(isEditingAllowed);
302 if (isAdminPreference){
303 allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
304 allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
305 // allowOverrideIsShowTaxonAssociationButton.setEnabled(showTaxonAssociation != null);
306 allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
307 @Override
308 public void widgetSelected(SelectionEvent e) {
309 setApply(true);
310 allowOverrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
311 }
312 });
313 }
314
315 showLifeFormButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowLifeForm, Messages.DatabasePreferncesPage_Life_Form, isAdminPreference);
316 showLifeFormButton.addSelectionListener(this);
317
318 index = 0;
319 for (String itemLabel: showLifeFormButton.getItems()) {
320 if (isShowLifeForm == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
321 showLifeFormButton.select(index);
322 break;
323 }
324 if (isShowLifeForm != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowLifeForm){
325 showLifeFormButton.select(index);
326 break;
327 }
328 if (isShowLifeForm != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowLifeForm){
329 showLifeFormButton.select(index);
330 break;
331 }
332 index++;
333 }
334 isEditingAllowed = true;
335 if (showLifeForm != null && !showLifeForm.isAllowOverride() ){
336 isEditingAllowed = false;
337 }
338 showLifeFormButton.setEnabled(isEditingAllowed);
339 if (isAdminPreference){
340 allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
341 allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
342 // allowOverrideShowLifeFormButton.setEnabled(showLifeForm != null);
343 allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
344 @Override
345 public void widgetSelected(SelectionEvent e) {
346 setApply(true);
347 allowOverrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
348 }
349 });
350 }
351
352 if (!isEditingAllowed){
353 PreferencesUtil.recursiveSetEnabled(composite, false);
354 }
355
356 return composite;
357 }
358
359
360 /**
361 * {@inheritDoc}
362 */
363 @Override
364 protected void getValues() {
365 CdmPreferenceCache cache = CdmPreferenceCache.instance();
366
367
368 overrideShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(
369 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()), true) != null? PreferencesUtil.getBooleanValue(
370 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()), true): false;
371
372 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
373 showSpecimenPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowSpecimen);
374
375
376 if (showSpecimenPref != null) {
377 if (showSpecimenPref.isAllowOverride() ) {
378 if (overrideShowSpecimenRelatedIssues){
379 isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), true);
380 }
381 } else {
382 isShowSpecimenRelatedIssues = Boolean.valueOf(showSpecimenPref.getValue());
383 }
384
385 } else {
386 if(!overrideShowSpecimenRelatedIssues){
387 isShowSpecimenRelatedIssues = null;
388 }else{
389 isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), true);
390 }
391 showSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, PreferencePredicate.ShowSpecimen.getDefaultValue() != null ? PreferencePredicate.ShowSpecimen.getDefaultValue().toString(): null);
392 }
393
394 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimenListEditor);
395 showListEditor = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowSpecimenListEditor);
396
397 overrideShowListEditor = PreferencesUtil.getBooleanValue(
398 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimenListEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
399 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimenListEditor.getKey()), true): false;
400 if (showListEditor != null) {
401 if (showListEditor.isAllowOverride() ) {
402 if (overrideShowListEditor){
403 isShowListEditor = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimenListEditor.getKey(), true);
404 }
405 } else {
406 isShowListEditor = Boolean.valueOf(showListEditor.getValue());
407 }
408
409 } else {
410 if(!overrideShowListEditor){
411 isShowListEditor = null;
412 }else{
413 isShowListEditor = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimenListEditor.getKey(), true);
414 }
415 showListEditor = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimenListEditor, PreferencePredicate.ShowSpecimenListEditor.getDefaultValue() != null ? PreferencePredicate.ShowSpecimenListEditor.getDefaultValue().toString(): null);
416 }
417
418
419
420 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
421 showCollectingAreaInGeneralSection = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
422 overrideShowCollectionAreaInGeneralSection = PreferencesUtil.getBooleanValue(
423 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true) != null? PreferencesUtil.getBooleanValue(
424 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true): false;
425 allowOverrideShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSection != null ? showCollectingAreaInGeneralSection.isAllowOverride():true;
426 if (showCollectingAreaInGeneralSection != null) {
427 if (showCollectingAreaInGeneralSection.isAllowOverride() ) {
428 if (overrideShowCollectionAreaInGeneralSection){
429 isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), true);
430 }
431
432 } else {
433 isShowCollectingAreaInGeneralSection = Boolean.valueOf(showCollectingAreaInGeneralSection.getValue());
434
435 }
436
437 } else {
438 if(!overrideShowCollectionAreaInGeneralSection){
439 isShowCollectingAreaInGeneralSection = null;
440 }else{
441 isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), true);
442 }
443 showCollectingAreaInGeneralSection = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue() != null ? PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue().toString(): null);
444 }
445
446
447 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
448 showDeterminationOnlyForFieldUnits = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
449 overrideDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(
450 PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true) != null? PreferencesUtil.getBooleanValue(
451 PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true): false;
452 if (showDeterminationOnlyForFieldUnits != null) {
453 if (showDeterminationOnlyForFieldUnits.isAllowOverride() ) {
454 if (overrideDeterminationOnlyForFieldUnits){
455 isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
456 }
457
458 } else {
459 isDeterminationOnlyForFieldUnits = Boolean.valueOf(showDeterminationOnlyForFieldUnits.getValue());
460
461 }
462
463 } else {
464 if(!overrideDeterminationOnlyForFieldUnits){
465 isDeterminationOnlyForFieldUnits = null;
466 }else{
467 isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), true);
468 }
469 showDeterminationOnlyForFieldUnits = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue() != null ? PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue().toString(): null);
470 }
471
472 allowOverrideDeterminationOnlyForFieldUnits = showDeterminationOnlyForFieldUnits != null ? showDeterminationOnlyForFieldUnits.isAllowOverride():true;
473
474
475 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
476 showTaxonAssociation = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
477 overrideShowTaxonAssociation = PreferencesUtil.getBooleanValue(
478 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()), true) != null? PreferencesUtil.getBooleanValue(
479 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()), true): false;
480 if (showTaxonAssociation != null) {
481 if (showTaxonAssociation.isAllowOverride() ) {
482 if (overrideShowTaxonAssociation){
483 isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
484 }
485
486 } else {
487 isShowTaxonAssociation = Boolean.valueOf(showTaxonAssociation.getValue());
488
489 }
490
491 } else {
492 if(!overrideShowTaxonAssociation){
493 isShowTaxonAssociation = null;
494 }else{
495 isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey(), true);
496 }
497 showTaxonAssociation = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, PreferencePredicate.ShowTaxonAssociations.getDefaultValue() != null ? PreferencePredicate.ShowTaxonAssociations.getDefaultValue().toString(): null);
498 }
499
500 allowOverrideShowTaxonAssociation = showTaxonAssociation != null ? showTaxonAssociation.isAllowOverride():true;
501
502
503 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
504 showLifeForm = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
505 overrideShowLifeForm = PreferencesUtil.getBooleanValue(
506 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()), true) != null? PreferencesUtil.getBooleanValue(
507 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()), true): false;
508 if (showLifeForm != null) {
509 if (showLifeForm.isAllowOverride() ) {
510 if (overrideShowLifeForm){
511 isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
512 }
513
514 } else {
515 isShowLifeForm = Boolean.valueOf(showLifeForm.getValue());
516
517 }
518
519 } else {
520 if(!overrideShowLifeForm){
521 isShowLifeForm = null;
522 }else{
523 isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey(), true);
524 }
525 showLifeForm = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, PreferencePredicate.ShowLifeForm.getDefaultValue() != null ? PreferencePredicate.ShowLifeForm.getDefaultValue().toString(): null);
526 }
527
528 allowOverrideShowLifeForm = showLifeForm != null ? showLifeForm.isAllowOverride():true;
529
530
531 }
532
533 @Override
534 public boolean performOk() {
535
536 boolean override = false;
537 if (isShowSpecimenRelatedIssues != null ) {
538 override = true;
539 PreferencesUtil.setStringValue(PreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues.toString());
540 }
541 PreferencesUtil.setBooleanValue(
542 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()),
543 override);
544 override = false;
545 if (isShowListEditor != null ) {
546 override = true;
547 PreferencesUtil.setStringValue(PreferencePredicate.ShowSpecimenListEditor.getKey(), isShowListEditor.toString());
548 }
549 PreferencesUtil.setBooleanValue(
550 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimenListEditor.getKey()),
551 override);
552
553 override = false;
554 if (isShowCollectingAreaInGeneralSection != null ) {
555 override = true;
556 PreferencesUtil.setStringValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), isShowCollectingAreaInGeneralSection.toString());
557 }
558 PreferencesUtil.setBooleanValue(
559 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()),
560 override);
561
562 override = false;
563 if (isDeterminationOnlyForFieldUnits != null ) {
564 override = true;
565 PreferencesUtil.setStringValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), isDeterminationOnlyForFieldUnits.toString());
566 }
567 PreferencesUtil.setBooleanValue(
568 PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()),
569 override);
570
571 override = false;
572 if (isShowTaxonAssociation != null ) {
573 override = true;
574 PreferencesUtil.setStringValue(PreferencePredicate.ShowTaxonAssociations.getKey(), isShowTaxonAssociation.toString());
575 }
576 PreferencesUtil.setBooleanValue(
577 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()),
578 override);
579
580 override = false;
581 if (isShowLifeForm != null ) {
582 override = true;
583 PreferencesUtil.setStringValue(PreferencePredicate.ShowLifeForm.getKey(), isShowLifeForm.toString());
584 }
585 PreferencesUtil.setBooleanValue(
586 PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()),
587 override);
588
589 return true;
590 }
591
592
593
594 @Override
595 protected void performDefaults() {
596 isShowSpecimenRelatedIssues = null;
597 showSpecimenButton.select(0);
598
599 if (allowOverrideIsShowSpecimenRelatedIssuesButton != null){
600 allowOverrideShowSpecimenRelatedIssues = true;
601 allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
602 }
603
604 isShowListEditor = null;
605 showListEditorButton.select(0);
606
607 if (allowOverrideShowListEditorButton != null){
608 allowOverrideShowListEditor = true;
609 allowOverrideShowListEditorButton.setSelection(allowOverrideShowListEditor);
610 }
611
612 isShowCollectingAreaInGeneralSection = null;
613 showCollectingAreaInGeneralSectionButton.select(0);
614
615 if (allowOverrideShowCollectingAreaButton != null){
616 allowOverrideShowCollectingAreaInGeneralSection = true;
617 allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
618 }
619 isDeterminationOnlyForFieldUnits = null;
620 determinationOnlyForFieldUnitsButton.select(0);
621
622 if (allowOverridesDeterminationOnlyForFieldUnitsButton != null){
623 allowOverrideDeterminationOnlyForFieldUnits = true;
624 allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
625 }
626
627 isShowTaxonAssociation = null;
628 showTaxonAssociationButton.select(0);
629
630 if (allowOverrideIsShowTaxonAssociationButton != null){
631 allowOverrideShowTaxonAssociation = true;
632 allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
633 }
634
635
636 isShowLifeForm = null;
637
638 showLifeFormButton.select(0);
639
640 if (allowOverrideShowLifeFormButton != null){
641 allowOverrideShowLifeForm = true;
642 allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
643 }
644 setApply(true);
645
646 super.performDefaults();
647 }
648
649 /**
650 * {@inheritDoc}
651 */
652 @Override
653 public void widgetSelected(SelectionEvent e) {
654 setApply(true);
655 if (e.getSource().equals(this.showSpecimenButton)) {
656 String text = showSpecimenButton.getText();
657 if(text.startsWith(Messages.Preference_Use_Default)){
658 isShowSpecimenRelatedIssues = null;
659 return;
660 }
661
662 if (text.equals(Messages.GeneralPreference_yes)){
663 isShowSpecimenRelatedIssues = true;
664 }else{
665 isShowSpecimenRelatedIssues = false;
666 }
667 }
668
669 if (e.getSource().equals(this.showListEditorButton)) {
670 String text = showListEditorButton.getText();
671 if(text.startsWith(Messages.Preference_Use_Default)){
672 isShowListEditor = null;
673 return;
674 }
675
676 if (text.equals(Messages.GeneralPreference_yes)){
677 isShowListEditor = true;
678 }else{
679 isShowListEditor = false;
680 }
681 }
682
683 if (e.getSource().equals(this.showCollectingAreaInGeneralSectionButton)) {
684 String text = showCollectingAreaInGeneralSectionButton.getText();
685 if(text.startsWith(Messages.Preference_Use_Default)){
686 isShowCollectingAreaInGeneralSection = null;
687 return;
688 }
689
690 if (text.equals(Messages.GeneralPreference_yes)){
691 isShowCollectingAreaInGeneralSection = true;
692 }else{
693 isShowCollectingAreaInGeneralSection = false;
694 }
695 }
696
697 if (e.getSource().equals(this.determinationOnlyForFieldUnitsButton)) {
698 String text = determinationOnlyForFieldUnitsButton.getText();
699 if(text.startsWith(Messages.Preference_Use_Default)){
700 isDeterminationOnlyForFieldUnits = null;
701 return;
702 }
703 if (text.equals(Messages.GeneralPreference_yes)){
704 isDeterminationOnlyForFieldUnits = true;
705 }else{
706 isDeterminationOnlyForFieldUnits = false;
707 }
708 }
709
710 if (e.getSource().equals(this.showTaxonAssociationButton)) {
711 String text = showTaxonAssociationButton.getText();
712 if(text.startsWith(Messages.Preference_Use_Default)){
713 isShowTaxonAssociation = null;
714 return;
715 }
716
717 if (text.equals(Messages.GeneralPreference_yes)){
718 isShowTaxonAssociation = true;
719 }else{
720 isShowTaxonAssociation = false;
721 }
722 }
723
724 if (e.getSource().equals(this.showLifeFormButton)) {
725 String text = showLifeFormButton.getText();
726 if(text.startsWith(Messages.Preference_Use_Default)){
727 isShowLifeForm = null;
728 return;
729 }
730
731 if (text.equals(Messages.GeneralPreference_yes)){
732 isShowLifeForm = true;
733 }else{
734 isShowLifeForm = false;
735 }
736 }
737
738 }
739
740 /**
741 * {@inheritDoc}
742 */
743 @Override
744 public void widgetDefaultSelected(SelectionEvent e) {
745 // TODO Auto-generated method stub
746
747 }
748
749
750
751
752 }