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
.custom
.CLabel
;
13 import org
.eclipse
.swt
.events
.SelectionAdapter
;
14 import org
.eclipse
.swt
.events
.SelectionEvent
;
15 import org
.eclipse
.swt
.events
.SelectionListener
;
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
;
21 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.PublishEnum
;
24 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
25 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
32 public class PublishFlagLocalPreference
extends CdmPreferencePage
{
34 protected PublishEnum publishBehaviour
;
36 protected Combo publishFlagBehaviour
;
37 protected CdmPreference pref
= null;
38 Button allowOverrideButton
;
40 protected boolean allowOverride
;
41 private boolean override
= true;
54 protected Control
createContents(Composite parent
) {
56 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DefaultBehaviourForPublishFlag
);
58 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.DefaultBehaviourForPublishFlag
, PreferencePredicate
.DefaultBehaviourForPublishFlag
.getDefaultValue().toString());
60 allowOverride
= pref
.isAllowOverride();
61 Composite composite
= createComposite(parent
);
63 if (!allowOverride
&& !isAdminPreference
){
64 final CLabel description
= new CLabel(composite
, SWT
.NULL
);
65 description
.setText(Messages
.PublishFlagPreference_description_not_allowed
);
66 description
.setLayoutData(createTextGridData());
70 publishFlagBehaviour
= createCombo(composite
, PublishEnum
.values(), PreferencePredicate
.DefaultBehaviourForPublishFlag
, Messages
.PublishFlagPreference_description
, isAdminPreference
);
71 publishFlagBehaviour
.addSelectionListener(new SelectionListener() {
74 public void widgetSelected(SelectionEvent e
) {
76 if (!publishFlagBehaviour
.getText().startsWith(Messages
.Preference_Use_Default
)){
77 publishBehaviour
= (PublishEnum
)publishFlagBehaviour
.getData(publishFlagBehaviour
.getText());
79 publishBehaviour
= null;
85 public void widgetDefaultSelected(SelectionEvent e
) {
86 // TODO Auto-generated method stub
90 if (this.isAdminPreference
){
91 allowOverrideButton
= createAllowOverrideButton(composite
);
92 allowOverrideButton
.setSelection(allowOverride
);
93 allowOverrideButton
.addSelectionListener(new SelectionAdapter(){
95 public void widgetSelected(SelectionEvent e
) {
96 allowOverride
= !allowOverride
;
103 if(publishBehaviour
==null){
104 publishFlagBehaviour
.select(0);
107 for (String itemLabel
: publishFlagBehaviour
.getItems()){
108 if (itemLabel
.startsWith(publishBehaviour
.getLabel())){
109 publishFlagBehaviour
.select(index
);
122 public boolean performOk() {
124 if (publishBehaviour
!= null){
125 String text
= publishFlagBehaviour
.getText();
126 for (PublishEnum display
: PublishEnum
.values()){
127 if (text
.startsWith(display
.getLabel())){
128 text
= display
.getKey();
132 PreferencesUtil
.setStringValue(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey(), text
);
133 if (pref
== null || !pref
.getValue().equals(text
)){
134 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey()), true);
137 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey()), false);
144 public void getValues(){
145 publishBehaviour
= null;
147 String publishString
= PreferencesUtil
.getStringValue(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey(), true);
149 if (publishString
!= null){
150 publishBehaviour
= PublishEnum
.valueOf(publishString
);
152 }catch (IllegalArgumentException e
){
153 publishBehaviour
= PublishEnum
.InheritFromParent
;
156 override
= PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey()));
158 publishBehaviour
= null;
163 protected void performDefaults() {
164 publishBehaviour
= null;
165 allowOverride
= true;
168 for (String itemLabel
: publishFlagBehaviour
.getItems()){
169 if (itemLabel
.startsWith(Messages
.Preference_Use_Default
)){
170 publishFlagBehaviour
.select(index
);
175 if (isAdminPreference
){
176 allowOverrideButton
.setSelection(allowOverride
);
179 super.performDefaults();