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
.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
;
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
;
34 public class SupplementalDataSourcePreferences
extends CdmPreferencePage
implements SelectionListener
{
36 protected Boolean isShowIDNamespace
;
37 protected Boolean isShowIDSource
;
39 protected boolean isAllowOverrideShowIDNamespace
;
40 protected boolean isAllowOverrideShowIDSource
;
42 protected boolean isOverrideShowIDNamespace
;
43 protected boolean isOverrideShowIDSource
;
45 protected Combo showIDNamespaceButton
;
46 protected Button allowOverrideShowIDNamespaceButton
;
47 protected Combo showIDSourceButton
;
48 protected Button allowOverrideIDSourceButton
;
50 final String SHOW
= Messages
.GeneralPreference_yes
;
51 final String DO_NOT_SHOW
= Messages
.GeneralPreference_no
;
54 protected Control
createContents(Composite parent
) {
56 final Composite composite
= createComposite(parent
);
58 GridData gridData
= createTextGridData();
60 Label separator
= new Label(composite
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
61 separator
.setLayoutData(gridData
);
62 separator
.setVisible(false);
64 showIDSourceButton
= createBooleanCombo(composite
, SHOW
, DO_NOT_SHOW
, PreferencePredicate
.ShowIdInSource
, Messages
.SupplementalDataSourcePreferences_SHOW_ID
,
66 showIDSourceButton
.addSelectionListener(this);
67 if (isShowIDSource
== null || (!isOverrideShowIDSource
&& !isAdminPreference
)){
68 showIDSourceButton
.select(0);
69 }else if (isShowIDSource
){
70 showIDSourceButton
.select(1);
72 showIDSourceButton
.select(2);
75 if (isAdminPreference
){
76 allowOverrideIDSourceButton
= createAllowOverrideButton(composite
);
77 allowOverrideIDSourceButton
.setSelection(isAllowOverrideShowIDSource
);
78 allowOverrideIDSourceButton
.addSelectionListener(new SelectionAdapter(){
80 public void widgetSelected(SelectionEvent e
) {
81 isAllowOverrideShowIDSource
= allowOverrideIDSourceButton
.getSelection();
87 showIDNamespaceButton
= createBooleanCombo(composite
, SHOW
, DO_NOT_SHOW
, PreferencePredicate
.ShowNamespaceInSource
, Messages
.SupplementalDataSourcePreferences_SHOW_NAMESPACE
,
90 showIDNamespaceButton
.addSelectionListener(this);
92 if (isShowIDNamespace
== null || (!isOverrideShowIDNamespace
&& !isAdminPreference
)){
93 showIDNamespaceButton
.select(0);
94 }else if (isShowIDNamespace
){
95 showIDNamespaceButton
.select(1);
97 showIDNamespaceButton
.select(2);
99 if (isAdminPreference
){
100 allowOverrideShowIDNamespaceButton
= createAllowOverrideButton(composite
);
101 allowOverrideShowIDNamespaceButton
.setSelection(isAllowOverrideShowIDNamespace
);
102 allowOverrideShowIDNamespaceButton
.addSelectionListener(new SelectionAdapter(){
104 public void widgetSelected(SelectionEvent e
) {
105 isAllowOverrideShowIDNamespace
= allowOverrideShowIDNamespaceButton
.getSelection();
111 if (!isAllowOverrideShowIDNamespace
&& !isAdminPreference
){
112 showIDNamespaceButton
.setEnabled(false);
114 if (!isAllowOverrideShowIDSource
&& !isAdminPreference
){
115 showIDSourceButton
.setEnabled(false);
121 public boolean performOk() {
122 if (isAllowOverrideShowIDSource
){
123 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowIdInSource
.getKey()), isOverrideShowIDSource
);
124 if(isShowIDSource
!= null){
125 PreferencesUtil
.setBooleanValue(PreferencePredicate
.ShowIdInSource
.getKey(), isShowIDSource
);
128 if (isAllowOverrideShowIDNamespace
){
129 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowNamespaceInSource
.getKey()), isOverrideShowIDNamespace
);
130 if (isShowIDNamespace
!= null){
131 PreferencesUtil
.setBooleanValue(PreferencePredicate
.ShowNamespaceInSource
.getKey(), isShowIDNamespace
);
137 protected void getValues(){
138 isAdminPreference
= false;
140 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
141 isShowIDSource
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowIdInSource
.getKey(), true);
142 isOverrideShowIDSource
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowIdInSource
.getKey()), true) != null?PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowIdInSource
.getKey()), true): false;
143 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowIdInSource
);
144 CdmPreference pref
= cache
.findBestMatching(key
);
146 isAllowOverrideShowIDSource
= pref
.isAllowOverride();
148 isAllowOverrideShowIDSource
= true;
151 isShowIDNamespace
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowNamespaceInSource
.getKey(), true);
152 isOverrideShowIDNamespace
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowNamespaceInSource
.getKey()), true) != null? PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowNamespaceInSource
.getKey()), true):false;
153 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowNamespaceInSource
);
154 pref
= cache
.findBestMatching(key
);
156 isAllowOverrideShowIDNamespace
= pref
.isAllowOverride();
158 isAllowOverrideShowIDNamespace
= true;
163 public void widgetSelected(SelectionEvent e
) {
164 if (e
.getSource().equals(this.showIDNamespaceButton
)) {
165 String text
= showIDNamespaceButton
.getText();
167 if (text
.startsWith(Messages
.Preference_Use_Default
)){
168 isShowIDNamespace
= null;
169 isOverrideShowIDNamespace
= false;
171 isOverrideShowIDNamespace
= true;
172 if (text
.equals(SHOW
)){
173 isShowIDNamespace
= true;
176 isShowIDNamespace
= false;
181 if (e
.getSource().equals(this.showIDSourceButton
)) {
182 String text
= showIDSourceButton
.getText();
183 if (text
.startsWith(Messages
.Preference_Use_Default
)){
184 isShowIDSource
= null;
185 isOverrideShowIDSource
= false;
187 isOverrideShowIDSource
= true;
188 if (text
.equals(SHOW
)){
189 isShowIDSource
= true;
191 isShowIDSource
= false;
201 public void widgetDefaultSelected(SelectionEvent e
) {
205 protected void performDefaults() {
206 showIDNamespaceButton
.select(0);
207 isShowIDNamespace
= null;
208 isAllowOverrideShowIDNamespace
=true;
209 isOverrideShowIDNamespace
= false;
210 isOverrideShowIDSource
= false;
211 if (isAdminPreference
){
212 allowOverrideIDSourceButton
.setSelection(true);
213 allowOverrideShowIDNamespaceButton
.setSelection(true);
217 showIDSourceButton
.select(0);
218 isShowIDSource
= null;
219 isAllowOverrideShowIDSource
=true;
221 super.performDefaults();