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 java
.util
.ArrayList
;
12 import java
.util
.List
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.custom
.CLabel
;
16 import org
.eclipse
.swt
.events
.SelectionAdapter
;
17 import org
.eclipse
.swt
.events
.SelectionEvent
;
18 import org
.eclipse
.swt
.events
.SelectionListener
;
19 import org
.eclipse
.swt
.widgets
.Button
;
20 import org
.eclipse
.swt
.widgets
.Combo
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Control
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
25 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
26 import eu
.etaxonomy
.cdm
.model
.metadata
.PublishEnum
;
27 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
28 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
35 public class PublishFlagLocalPreference
extends CdmPreferencePage
{
37 protected PublishEnum publishBehaviour
;
39 protected Combo publishFlagBehaviour
;
40 protected CdmPreference pref
= null;
41 Button allowOverrideButton
;
43 protected boolean allowOverride
;
56 protected Control
createContents(Composite parent
) {
58 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DefaultBehaviourForPublishFlag
);
60 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.DefaultBehaviourForPublishFlag
, PreferencePredicate
.DefaultBehaviourForPublishFlag
.getDefaultValue().toString());
62 allowOverride
= pref
.isAllowOverride();
63 Composite composite
= createComposite(parent
);
65 if (!allowOverride
&& !isAdminPreference
){
66 final CLabel description
= new CLabel(composite
, SWT
.NULL
);
67 description
.setText(Messages
.PublishFlagPreference_description_not_allowed
);
68 description
.setLayoutData(createTextGridData());
73 // description.setText(Messages.PublishFlagPreference_description);
74 // description.setLayoutData(createTextGridData());
75 // publishFlagBehaviour = new Combo(composite, SWT.READ_ONLY);
76 List
<String
> enumValues
= new ArrayList();
78 publishFlagBehaviour
= createCombo(composite
, PublishEnum
.values(), PreferencePredicate
.DefaultBehaviourForPublishFlag
, Messages
.PublishFlagPreference_description
, isAdminPreference
);
80 // publishFlagBehaviour.setFont(parent.getFont());
81 // for(PublishEnum display: PublishEnum.values()){
82 // if (pref.getValue().equals(display.getKey())){
83 // publishFlagBehaviour.add(display.getLabel() + " (Default)");
88 publishFlagBehaviour
.addSelectionListener(new SelectionListener() {
91 public void widgetSelected(SelectionEvent e
) {
96 public void widgetDefaultSelected(SelectionEvent e
) {
97 // TODO Auto-generated method stub
101 if (this.isAdminPreference
){
102 allowOverrideButton
= createAllowOverrideButton(composite
);
103 allowOverrideButton
.setText(Messages
.GeneralPreference_override
);
104 allowOverrideButton
.setSelection(allowOverride
);
105 allowOverrideButton
.addSelectionListener(new SelectionAdapter(){
107 public void widgetSelected(SelectionEvent e
) {
108 allowOverride
= !allowOverride
;
115 if(publishBehaviour
==null){
116 publishFlagBehaviour
.select(0);
119 for (String itemLabel
: publishFlagBehaviour
.getItems()){
120 if (itemLabel
.startsWith(publishBehaviour
.getLabel())){
121 publishFlagBehaviour
.select(index
);
134 public boolean performOk() {
135 if (publishFlagBehaviour
!= null){
136 String text
= publishFlagBehaviour
.getText();
137 for (PublishEnum display
: PublishEnum
.values()){
138 if (text
.startsWith(display
.getLabel())){
139 text
= display
.getKey();
143 PreferencesUtil
.setStringValue(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey(), text
);
144 if (pref
== null || !pref
.getValue().equals(text
)){
145 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey()), true);
147 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey()), false);
154 public void getValues(){
157 publishBehaviour
= PublishEnum
.valueOf(PreferencesUtil
.getStringValue(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey(), true));
158 }catch (IllegalArgumentException e
){
159 publishBehaviour
= PublishEnum
.InheritFromParent
;
164 protected void performDefaults() {
165 publishBehaviour
= PublishEnum
.valueOf(pref
.getValue());
166 allowOverride
= true;
168 for (String itemLabel
: publishFlagBehaviour
.getItems()){
169 if (itemLabel
.startsWith(publishBehaviour
.getLabel())){
170 publishFlagBehaviour
.select(index
);
176 super.performDefaults();