2 * Copyright (C) 2019 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
.events
.SelectionListener
;
15 import org
.eclipse
.swt
.widgets
.Button
;
16 import org
.eclipse
.swt
.widgets
.Combo
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Control
;
19 import org
.eclipse
.swt
.widgets
.Label
;
21 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
23 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
31 public class FactualDataPreference
extends CdmPreferencePage
implements SelectionListener
{
34 protected Boolean isShowModifier
;
36 protected Combo comboShowModifier
;
37 protected CdmPreference pref
= null;
38 Button allowOverrideButton
;
40 protected boolean allowOverride
;
41 private boolean isOverride
= true;
43 protected Boolean isShowModifierFreeText
;
45 protected Combo comboShowModifierFreeText
;
46 protected CdmPreference prefFreeText
= null;
47 Button allowOverrideFreeTextButton
;
49 protected boolean allowOverrideFreeText
;
50 private boolean isOverrideFreeText
= true;
63 protected Control
createContents(Composite parent
) {
66 Composite composite
= createComposite(parent
);
67 Label description
= new Label(composite
, SWT
.NULL
);
68 description
.setText(Messages
.FactualData_description
);
70 comboShowModifier
= createBooleanCombo(composite
, SHOW
, DO_NOT_SHOW
, PreferencePredicate
.ShowModifier
, Messages
.FactualData_showModifier
, isAdminPreference
);
71 comboShowModifier
.addSelectionListener(this);
72 if (this.isAdminPreference
){
73 allowOverrideButton
= createAllowOverrideButton(composite
);
74 allowOverrideButton
.setSelection(allowOverride
);
75 allowOverrideButton
.addSelectionListener(new SelectionAdapter(){
77 public void widgetSelected(SelectionEvent e
) {
78 allowOverride
= !allowOverride
;
84 if(isShowModifier
==null){
85 comboShowModifier
.select(0);
87 for (String itemLabel
: comboShowModifier
.getItems()){
88 if (itemLabel
.startsWith(this.SHOW
) && isShowModifier
){
89 comboShowModifier
.select(index
);
92 if (itemLabel
.startsWith(DO_NOT_SHOW
) && !isShowModifier
){
93 comboShowModifier
.select(index
);
99 if (!isAdminPreference
){
100 comboShowModifier
.setEnabled(allowOverride
);
103 comboShowModifierFreeText
= createBooleanCombo(composite
, SHOW
, DO_NOT_SHOW
, PreferencePredicate
.ShowModifierFreeText
, Messages
.FactualData_showModifier_FreeText
, isAdminPreference
);
104 comboShowModifierFreeText
.addSelectionListener(this);
105 if (this.isAdminPreference
){
106 allowOverrideFreeTextButton
= createAllowOverrideButton(composite
);
107 allowOverrideFreeTextButton
.setSelection(allowOverrideFreeText
);
108 allowOverrideFreeTextButton
.addSelectionListener(new SelectionAdapter(){
110 public void widgetSelected(SelectionEvent e
) {
111 allowOverrideFreeText
= !allowOverrideFreeText
;
117 if(isShowModifierFreeText
==null){
118 comboShowModifierFreeText
.select(0);
120 for (String itemLabel
: comboShowModifierFreeText
.getItems()){
121 if (itemLabel
.startsWith(this.SHOW
) && isShowModifierFreeText
){
122 comboShowModifierFreeText
.select(index
);
125 if (itemLabel
.startsWith(DO_NOT_SHOW
) && !isShowModifierFreeText
){
126 comboShowModifierFreeText
.select(index
);
132 if (!isAdminPreference
){
133 comboShowModifierFreeText
.setEnabled(allowOverrideFreeText
);
141 public boolean performOk() {
143 if (isShowModifier
!= null){
144 PreferencesUtil
.setStringValue(PreferencePredicate
.ShowModifier
.getKey(), Boolean
.toString(isShowModifier
));
145 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowModifier
.getKey()), true);
148 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowModifier
.getKey()), false);
150 if (isShowModifierFreeText
!= null){
151 PreferencesUtil
.setStringValue(PreferencePredicate
.ShowModifierFreeText
.getKey(), Boolean
.toString(isShowModifierFreeText
));
152 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowModifierFreeText
.getKey()), true);
155 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowModifierFreeText
.getKey()), false);
163 public void getValues(){
164 // get modifier values
165 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowModifier
);
167 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.ShowModifier
, PreferencePredicate
.ShowModifier
.getDefaultValue().toString());
169 allowOverride
= pref
.isAllowOverride();
170 isShowModifier
= null;
171 String showModifierString
= PreferencesUtil
.getStringValue(PreferencePredicate
.ShowModifier
.getKey(), true);
172 if (showModifierString
!= null){
173 isShowModifier
= Boolean
.valueOf(showModifierString
);
176 isOverride
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowModifier
.getKey()));
178 isShowModifier
= null;
181 //get modifier freetext values
182 prefFreeText
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.ShowModifierFreeText
);
183 if (prefFreeText
== null){
184 prefFreeText
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.ShowModifierFreeText
, PreferencePredicate
.ShowModifierFreeText
.getDefaultValue().toString());
186 allowOverrideFreeText
= prefFreeText
.isAllowOverride();
187 isShowModifierFreeText
= null;
188 String showModifierStringFreeText
= PreferencesUtil
.getStringValue(PreferencePredicate
.ShowModifierFreeText
.getKey(), true);
189 if (showModifierStringFreeText
!= null){
190 isShowModifierFreeText
= Boolean
.valueOf(showModifierStringFreeText
);
193 isOverrideFreeText
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowModifierFreeText
.getKey()));
194 if (!isOverrideFreeText
){
195 isShowModifierFreeText
= null;
201 protected void performDefaults() {
202 isShowModifier
= null;
203 allowOverride
= true;
205 comboShowModifier
.select(0);
206 if (isAdminPreference
){
207 allowOverrideButton
.setSelection(allowOverride
);
210 isShowModifierFreeText
= null;
211 allowOverrideFreeText
= true;
213 comboShowModifierFreeText
.select(0);
214 if (isAdminPreference
){
215 allowOverrideFreeTextButton
.setSelection(allowOverrideFreeText
);
219 super.performDefaults();
222 public void widgetSelected(SelectionEvent e
) {
223 if (e
.getSource().equals(this.comboShowModifier
)) {
224 String text
= comboShowModifier
.getText();
225 if (text
.startsWith(Messages
.Preference_Use_Default
)){
227 isShowModifier
= null;
229 }else if (text
.equals(SHOW
)){
230 isShowModifier
= true;
233 isShowModifier
= false;
239 if (e
.getSource().equals(this.comboShowModifierFreeText
)) {
240 String text
= comboShowModifierFreeText
.getText();
241 if (text
.startsWith(Messages
.Preference_Use_Default
)){
242 isOverrideFreeText
= false;
243 isShowModifierFreeText
= null;
245 }else if (text
.equals(SHOW
)){
246 isShowModifierFreeText
= true;
247 isOverrideFreeText
= true;
249 isShowModifierFreeText
= false;
250 isOverrideFreeText
= true;
259 public void widgetDefaultSelected(SelectionEvent e
) {