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
.taxeditor
.l10n
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
31 public class PublishFlagLocalPreference
extends CdmPreferencePage
{
33 PublishEnum publishBehaviour
;
35 Combo publishFlagBehaviour
;
36 CdmPreference pref
= null;
38 protected boolean allowOverride
;
50 protected Control
createContents(Composite parent
) {
51 pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DefaultBehaviourForPublishFlag
);
53 pref
= CdmPreference
.NewTaxEditorInstance(EditorPreferencePredicate
.DefaultBehaviourForPublishFlag
, EditorPreferencePredicate
.DefaultBehaviourForPublishFlag
.getDefaultValue().toString());
55 allowOverride
= pref
.isAllowOverride();
56 Composite composite
= createComposite(parent
);
57 final CLabel description
= new CLabel(composite
, SWT
.NULL
);
59 description
.setText(Messages
.PublishFlagPreference_description_not_allowed
);
60 description
.setLayoutData(createTextGridData());
63 PublishEnum publishFlag
;
65 publishFlag
= PublishEnum
.valueOf(PreferencesUtil
.getStringValue(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey(), true));
66 }catch (IllegalArgumentException e
){
67 publishFlag
= PublishEnum
.InheritFromParent
;
70 description
.setText(Messages
.PublishFlagPreference_description
);
71 description
.setLayoutData(createTextGridData());
72 publishFlagBehaviour
= new Combo(composite
, SWT
.READ_ONLY
);
74 publishFlagBehaviour
.setFont(parent
.getFont());
75 for(PublishEnum display
: PublishEnum
.values()){
76 publishFlagBehaviour
.add(display
.getLabel());
79 publishFlagBehaviour
.addSelectionListener(new SelectionListener() {
82 public void widgetSelected(SelectionEvent e
) {
87 public void widgetDefaultSelected(SelectionEvent e
) {
88 // TODO Auto-generated method stub
92 Button allowOverrideButton
= createAllowOverrideButton(composite
);
93 allowOverrideButton
.setText(Messages
.GeneralPreference_override
);
94 allowOverrideButton
.setSelection(allowOverride
);
95 allowOverrideButton
.addSelectionListener(new SelectionAdapter(){
97 public void widgetSelected(SelectionEvent e
) {
98 allowOverride
= allowOverrideButton
.getSelection();
106 for (String itemLabel
: publishFlagBehaviour
.getItems()){
107 if (itemLabel
.equalsIgnoreCase(publishFlag
.getLabel())){
108 publishFlagBehaviour
.select(index
);
120 public boolean performOk() {
121 String text
= publishFlagBehaviour
.getText();
122 for (PublishEnum display
: PublishEnum
.values()){
123 if (display
.getLabel().equals(text
)){
124 text
= display
.getKey();
128 PreferencesUtil
.setStringValue(PreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey(), text
);
129 PreferencesUtil
.setBooleanValue(PreferencesUtil
.prefOverrideKey(EditorPreferencePredicate
.DefaultBehaviourForPublishFlag
.getKey()), allowOverride
);