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 SupplementalDataPreferences
extends CdmPreferencePage
implements SelectionListener
{
37 protected Boolean isShowIDNamspace
;
38 protected Boolean isShowNamespace
;
40 protected boolean isAllowOverrideShowIDNamspace
;
41 protected boolean isAllowOverrideShowNamspace
;
43 protected boolean isOverrideShowIDNamspace
;
44 protected boolean isOverrideShowNamspace
;
47 protected Combo showIDNamspaceButton
;
48 protected Button allowOverrideShowIDNamspaceButton
;
49 protected Combo showNamspaceButton
;
50 protected Button allowOverrideNamspaceButton
;
52 final String SHOW
= Messages
.GeneralPreference_yes
;
53 final String DO_NOT_SHOW
= Messages
.GeneralPreference_no
;
58 protected Control
createContents(Composite parent
) {
60 final Composite composite
= createComposite(parent
);
62 GridData gridData
= createTextGridData();
64 Label separator
= new Label(composite
, SWT
.HORIZONTAL
| SWT
.SEPARATOR
);
65 separator
.setLayoutData(gridData
);
66 separator
.setVisible(false);
68 showIDNamspaceButton
= createBooleanCombo(composite
, SHOW
, DO_NOT_SHOW
, PreferencePredicate
.ShowIdInSource
, "Show ID in Namespace in Source",
71 showIDNamspaceButton
.addSelectionListener(this);
73 if (isShowIDNamspace
== null || (!isOverrideShowIDNamspace
&& !isAdminPreference
)){
74 showIDNamspaceButton
.select(0);
75 }else if (isShowIDNamspace
){
76 showIDNamspaceButton
.select(1);
78 showIDNamspaceButton
.select(2);
80 if (isAdminPreference
){
81 allowOverrideShowIDNamspaceButton
= createAllowOverrideButton(composite
);
83 allowOverrideShowIDNamspaceButton
.setSelection(isAllowOverrideShowIDNamspace
);
84 allowOverrideShowIDNamspaceButton
.addSelectionListener(new SelectionAdapter(){
86 public void widgetSelected(SelectionEvent e
) {
87 isAllowOverrideShowIDNamspace
= allowOverrideShowIDNamspaceButton
.getSelection();
94 showNamspaceButton
= createBooleanCombo(composite
, SHOW
, DO_NOT_SHOW
, PreferencePredicate
.ShowNamespaceInSource
, "Show Namespace in Source",
97 showNamspaceButton
.addSelectionListener(this);
98 if (isShowNamespace
== null || (!isOverrideShowNamspace
&& !isAdminPreference
)){
99 showNamspaceButton
.select(0);
100 }else if (isShowNamespace
){
101 showNamspaceButton
.select(1);
103 showNamspaceButton
.select(2);
106 if (isAdminPreference
){
107 allowOverrideNamspaceButton
= createAllowOverrideButton(composite
);
108 allowOverrideNamspaceButton
.setSelection(isAllowOverrideShowNamspace
);
109 allowOverrideNamspaceButton
.addSelectionListener(new SelectionAdapter(){
111 public void widgetSelected(SelectionEvent e
) {
112 isAllowOverrideShowNamspace
= allowOverrideNamspaceButton
.getSelection();
117 if (!isAllowOverrideShowIDNamspace
&& !isAdminPreference
){
118 showIDNamspaceButton
.setEnabled(false);
120 if (!isAllowOverrideShowNamspace
&& !isAdminPreference
){
121 showNamspaceButton
.setEnabled(false);
131 public boolean performOk() {
132 if (isAllowOverrideShowIDNamspace
){
133 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowIdInSource
.getKey()), isOverrideShowIDNamspace
);
134 PreferencesUtil
.setBooleanValue(PreferencePredicate
.ShowIdInSource
.getKey(), isShowIDNamspace
);
136 if (isAllowOverrideShowNamspace
){
137 PreferencesUtil
.setBooleanValue(PreferencePredicate
.ShowNamespaceInSource
.getKey(), isShowNamespace
);
138 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowNamespaceInSource
.getKey()), isOverrideShowNamspace
);
145 protected void getValues(){
146 isAdminPreference
= false;
148 CdmPreferenceCache cache
= CdmPreferenceCache
.instance();
149 isShowIDNamspace
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowIdInSource
.getKey(), true);
150 isOverrideShowIDNamspace
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowIdInSource
.getKey()), true) != null?PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowIdInSource
.getKey()), true): false;
151 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowIdInSource
);
152 CdmPreference pref
= cache
.findBestMatching(key
);
154 isAllowOverrideShowIDNamspace
= pref
.isAllowOverride();
156 isAllowOverrideShowIDNamspace
= true;
159 isShowNamespace
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowNamespaceInSource
.getKey(), true);
160 isOverrideShowNamspace
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowNamespaceInSource
.getKey()), true) != null? PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.ShowNamespaceInSource
.getKey()), true):false;
161 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowNamespaceInSource
);
162 pref
= cache
.findBestMatching(key
);
164 isAllowOverrideShowNamspace
= pref
.isAllowOverride();
166 isAllowOverrideShowNamspace
= true;
178 public void widgetSelected(SelectionEvent e
) {
179 if (e
.getSource().equals(this.showIDNamspaceButton
)) {
180 String text
= showIDNamspaceButton
.getText();
181 // text = text.replace(Messages.Preference_Use_Default, "");
182 if (text
.equals(Messages
.Preference_Use_Default
)){
183 isOverrideShowIDNamspace
= false;
185 isOverrideShowIDNamspace
= true;
187 if (text
.equals(SHOW
)){
188 isShowIDNamspace
= true;
191 isShowIDNamspace
= false;
194 if (e
.getSource().equals(this.showNamspaceButton
)) {
195 String text
= showNamspaceButton
.getText();
196 if (text
.equals(Messages
.Preference_Use_Default
)){
197 isOverrideShowNamspace
= false;
199 isOverrideShowNamspace
= true;
201 if (text
.equals(SHOW
)){
202 isShowNamespace
= true;
204 isShowNamespace
= false;
219 public void widgetDefaultSelected(SelectionEvent e
) {
220 // TODO Auto-generated method stub