2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.preference
;
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
;
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
;
30 public class SpecimenOrObservationPreferences
extends CdmPreferencePage
{
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.";
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
;
56 // setPreferenceStore(PreferencesUtil.getPreferenceStore());
57 if(!CdmStore
.isActive()){
68 protected Control
createContents(Composite parent
) {
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;
85 Label label
= new Label(parent
, SWT
.NONE
);
86 label
.setText(DESCRIPTION
);
87 Composite titleComp
= createComposite(parent
);
89 final Button showSpecimenButton
= new Button(titleComp
, SWT
.CHECK
);
91 showSpecimenButton
.setText(Messages
.DatabasePreferncesPage_Show_Specimen
);
93 showSpecimenButton
.setSelection(isShowSpecimenRelatedIssues
);
94 showSpecimenButton
.addSelectionListener(new SelectionAdapter(){
96 public void widgetSelected(SelectionEvent e
) {
97 isShowSpecimenRelatedIssues
= showSpecimenButton
.getSelection();
98 if(isShowSpecimenRelatedIssues
){
99 composite
.setVisible(true);
100 composite
.setEnabled(true);
102 composite
.setVisible(false);
103 composite
.setEnabled(false);
107 Button allowOverrideIsShowSpecimenRelatedIssuesButton
= createAllowOverrideButton(titleComp
);
108 if (isAdminPreference
){
109 allowOverrideIsShowSpecimenRelatedIssuesButton
.setSelection(allowOverrideShowSpecimenRelatedIssues
);
110 allowOverrideIsShowSpecimenRelatedIssuesButton
.addSelectionListener(new SelectionAdapter(){
112 public void widgetSelected(SelectionEvent e
) {
113 allowOverrideShowSpecimenRelatedIssues
= allowOverrideIsShowSpecimenRelatedIssuesButton
.getSelection();
117 allowOverrideIsShowSpecimenRelatedIssuesButton
.setSelection(overrideShowSpecimenRelatedIssues
);
118 allowOverrideIsShowSpecimenRelatedIssuesButton
.addSelectionListener(new SelectionAdapter(){
120 public void widgetSelected(SelectionEvent e
) {
121 overrideShowSpecimenRelatedIssues
= allowOverrideIsShowSpecimenRelatedIssuesButton
.getSelection();
124 if (!allowOverrideShowSpecimenRelatedIssues
){
125 showSpecimenButton
.setEnabled(false);
126 allowOverrideIsShowSpecimenRelatedIssuesButton
.setEnabled(false);
129 composite
= createComposite(parent
);
130 composite
.setEnabled(isShowSpecimenRelatedIssues
);
131 GridData gridData
= createTextGridData();
133 Label separator
= new Label(composite
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
134 separator
.setLayoutData(gridData
);
136 final Button showCollectingAreaInGeneralSectionButton
= new Button(composite
, SWT
.CHECK
);
138 showCollectingAreaInGeneralSectionButton
.setText(Messages
.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section
);
140 showCollectingAreaInGeneralSectionButton
.setSelection(isShowCollectingAreaInGeneralSection
);
141 showCollectingAreaInGeneralSectionButton
.addSelectionListener(new SelectionAdapter(){
143 public void widgetSelected(SelectionEvent e
) {
144 isShowCollectingAreaInGeneralSection
= showCollectingAreaInGeneralSectionButton
.getSelection();
148 Button allowOverrideShowCollectingAreaButton
= createAllowOverrideButton(composite
);
149 if (isAdminPreference
){
150 allowOverrideShowCollectingAreaButton
.setSelection(allowOverrideShowCollectingAreaInGeneralSection
);
151 allowOverrideShowCollectingAreaButton
.addSelectionListener(new SelectionAdapter(){
153 public void widgetSelected(SelectionEvent e
) {
154 allowOverrideShowCollectingAreaInGeneralSection
= allowOverrideShowCollectingAreaButton
.getSelection();
158 allowOverrideShowCollectingAreaButton
.setSelection(overrideShowCollectionAreaInGeneralSection
);
159 allowOverrideShowCollectingAreaButton
.addSelectionListener(new SelectionAdapter(){
161 public void widgetSelected(SelectionEvent e
) {
162 overrideShowCollectionAreaInGeneralSection
= allowOverrideShowCollectingAreaButton
.getSelection();
165 if (!allowOverrideShowCollectingAreaInGeneralSection
){
166 showCollectingAreaInGeneralSectionButton
.setEnabled(false);
167 allowOverrideShowCollectingAreaButton
.setEnabled(false);
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(){
176 public void widgetSelected(SelectionEvent e
) {
177 isDeterminationOnlyForFieldUnits
= determinationOnlyForFieldUnitsButton
.getSelection();
181 Button allowOverridesDeterminationOnlyForFieldUnitsButton
= createAllowOverrideButton(composite
);
182 if (isAdminPreference
){
183 allowOverridesDeterminationOnlyForFieldUnitsButton
.setSelection(allowOverrideDeterminationOnlyForFieldUnits
);
184 allowOverridesDeterminationOnlyForFieldUnitsButton
.addSelectionListener(new SelectionAdapter(){
186 public void widgetSelected(SelectionEvent e
) {
187 allowOverrideDeterminationOnlyForFieldUnits
= allowOverridesDeterminationOnlyForFieldUnitsButton
.getSelection();
191 allowOverridesDeterminationOnlyForFieldUnitsButton
.setSelection(overrideDeterminationOnlyForFieldUnits
);
192 allowOverridesDeterminationOnlyForFieldUnitsButton
.addSelectionListener(new SelectionAdapter(){
194 public void widgetSelected(SelectionEvent e
) {
195 overrideDeterminationOnlyForFieldUnits
= allowOverridesDeterminationOnlyForFieldUnitsButton
.getSelection();
198 if (!allowOverrideDeterminationOnlyForFieldUnits
){
199 determinationOnlyForFieldUnitsButton
.setEnabled(false);
200 allowOverridesDeterminationOnlyForFieldUnitsButton
.setEnabled(false);
204 final Button showTaxonAssociationButton
= new Button(composite
, SWT
.CHECK
);
206 showTaxonAssociationButton
.setText(Messages
.DatabasePreferncesPage_Taxon_Associations
);
208 showTaxonAssociationButton
.setSelection(isShowTaxonAssociation
);
209 showTaxonAssociationButton
.addSelectionListener(new SelectionAdapter(){
211 public void widgetSelected(SelectionEvent e
) {
212 isShowTaxonAssociation
= showTaxonAssociationButton
.getSelection();
216 Button allowOverrideIsShowTaxonAssociationButton
= createAllowOverrideButton(composite
);
217 if (isAdminPreference
){
218 allowOverrideIsShowTaxonAssociationButton
.setSelection(allowOverrideShowTaxonAssociation
);
219 allowOverrideIsShowTaxonAssociationButton
.addSelectionListener(new SelectionAdapter(){
221 public void widgetSelected(SelectionEvent e
) {
222 allowOverrideShowTaxonAssociation
= allowOverrideIsShowTaxonAssociationButton
.getSelection();
226 allowOverrideIsShowTaxonAssociationButton
.setSelection(overrideShowTaxonAssociation
);
227 allowOverrideIsShowTaxonAssociationButton
.addSelectionListener(new SelectionAdapter(){
229 public void widgetSelected(SelectionEvent e
) {
230 overrideShowTaxonAssociation
= allowOverrideIsShowTaxonAssociationButton
.getSelection();
233 if (!allowOverrideShowTaxonAssociation
){
234 showTaxonAssociationButton
.setEnabled(false);
235 allowOverrideIsShowTaxonAssociationButton
.setEnabled(false);
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(){
244 public void widgetSelected(SelectionEvent e
) {
245 isShowLifeForm
= showLifeFormButton
.getSelection();
250 Button allowOverrideShowLifeFormButton
= createAllowOverrideButton(composite
);
251 if (isAdminPreference
){
252 allowOverrideShowLifeFormButton
.setSelection(allowOverrideShowLifeForm
);
253 allowOverrideShowLifeFormButton
.addSelectionListener(new SelectionAdapter(){
255 public void widgetSelected(SelectionEvent e
) {
256 allowOverrideShowLifeForm
= allowOverrideShowLifeFormButton
.getSelection();
260 allowOverrideShowLifeFormButton
.setSelection(overrideShowLifeForm
);
261 allowOverrideShowLifeFormButton
.addSelectionListener(new SelectionAdapter(){
263 public void widgetSelected(SelectionEvent e
) {
264 overrideShowLifeForm
= allowOverrideShowLifeFormButton
.getSelection();
267 if (!allowOverrideShowLifeForm
){
268 showLifeFormButton
.setEnabled(false);
269 allowOverrideShowLifeFormButton
.setEnabled(false);
273 if (!isEditingAllowed
){
274 PreferencesUtil
.recursiveSetEnabled(composite
, false);
284 protected void getValues() {
285 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
287 isShowSpecimenRelatedIssues
= PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.ShowSpecimen
.getKey());
288 allowOverrideShowSpecimenRelatedIssues
= cache
.get(EditorPreferencePredicate
.ShowSpecimen
.getKey())!= null ? cache
.get(EditorPreferencePredicate
.ShowSpecimen
.getKey()).isAllowOverride():true;
290 isShowCollectingAreaInGeneralSection
= PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.ShowCollectingAreasInGeneralSection
.getKey());
291 allowOverrideShowCollectingAreaInGeneralSection
= cache
.get(EditorPreferencePredicate
.ShowCollectingAreasInGeneralSection
.getKey())!= null ? cache
.get(EditorPreferencePredicate
.ShowCollectingAreasInGeneralSection
.getKey()).isAllowOverride():true;
293 isDeterminationOnlyForFieldUnits
= PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.DeterminationOnlyForFieldUnits
.getKey());
294 allowOverrideDeterminationOnlyForFieldUnits
= cache
.get(EditorPreferencePredicate
.DeterminationOnlyForFieldUnits
.getKey())!= null ? cache
.get(EditorPreferencePredicate
.DeterminationOnlyForFieldUnits
.getKey()).isAllowOverride():true;
296 isShowTaxonAssociation
= PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.ShowTaxonAssociations
.getKey());
297 allowOverrideShowTaxonAssociation
= cache
.get(EditorPreferencePredicate
.ShowTaxonAssociations
.getKey())!= null ? cache
.get(EditorPreferencePredicate
.ShowTaxonAssociations
.getKey()).isAllowOverride():true;
299 isShowLifeForm
= PreferencesUtil
.getBooleanValue(EditorPreferencePredicate
.ShowLifeForm
.getKey());
300 allowOverrideShowLifeForm
= cache
.get(EditorPreferencePredicate
.ShowLifeForm
.getKey())!= null ? cache
.get(EditorPreferencePredicate
.ShowLifeForm
.getKey()).isAllowOverride():true;
306 public boolean performOk() {
307 if (allowOverrideShowSpecimenRelatedIssues
){
308 PreferencesUtil
.setBooleanValue(EditorPreferencePredicate
.ShowSpecimen
.getKey(), isShowSpecimenRelatedIssues
);
310 if (allowOverrideShowCollectingAreaInGeneralSection
){
311 PreferencesUtil
.setBooleanValue(EditorPreferencePredicate
.ShowCollectingAreasInGeneralSection
.getKey(), isShowCollectingAreaInGeneralSection
);
313 if (allowOverrideDeterminationOnlyForFieldUnits
){
314 PreferencesUtil
.setBooleanValue(EditorPreferencePredicate
.DeterminationOnlyForFieldUnits
.getKey(), isDeterminationOnlyForFieldUnits
);
316 if (allowOverrideShowTaxonAssociation
){
317 PreferencesUtil
.setBooleanValue(EditorPreferencePredicate
.ShowTaxonAssociations
.getKey(), isShowTaxonAssociation
);
319 if (allowOverrideShowLifeForm
){
320 PreferencesUtil
.setBooleanValue(EditorPreferencePredicate
.ShowLifeForm
.getKey(), isShowLifeForm
);