2 * Copyright (C) 2018 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
.databaseAdmin
.preferencePage
;
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
.layout
.GridLayout
;
16 import org
.eclipse
.swt
.widgets
.Button
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Control
;
20 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IPreferenceService
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
24 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
25 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
26 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 public class PublishFlagPreference
extends CdmPreferencePage
implements IE4AdminPreferencePage
{
37 boolean setNotPublish
;
38 boolean inheritFromParent
;
43 CdmPreference pref
= PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.DefaultBehaviourForPublishFlag
);
45 if (pref
.getValue().equals(Messages
.PublishFlagPreference_do_not_set
)){
48 inheritFromParent
= false;
51 if (pref
.getValue().equals(Messages
.PublishFlagPreference_inherit
)){
52 setNotPublish
= false;
54 inheritFromParent
= true;
57 if (pref
.getValue().equals(Messages
.PublishFlagPreference_set
)){
58 setNotPublish
= false;
60 inheritFromParent
= false;
63 setNotPublish
= false;
65 inheritFromParent
= false;
73 protected Control
createContents(Composite parent
) {
74 final Composite composite
= new Composite(parent
, SWT
.NULL
);
76 GridLayout gridLayout
= new GridLayout();
77 composite
.setLayout(gridLayout
);
78 final CLabel description
= new CLabel(composite
, SWT
.NULL
);
79 description
.setText(Messages
.PublishFlagPreference_description
);
80 gridLayout
.numColumns
= 1;
81 gridLayout
.horizontalSpacing
= 10;
82 gridLayout
.makeColumnsEqualWidth
= true;
84 Button setPublishFlagAsDefault
= new Button(composite
, SWT
.RADIO
);
85 setPublishFlagAsDefault
.setText(Messages
.PublishFlagPreference_set
);
86 setPublishFlagAsDefault
.setSelection(setPublish
);
87 setPublishFlagAsDefault
.addSelectionListener(new SelectionAdapter() {
89 public void widgetSelected(SelectionEvent e
) {
90 setPublish
= !setPublish
;
93 Button setNotPublishFlagAsDefault
= new Button(composite
, SWT
.RADIO
);
94 setNotPublishFlagAsDefault
.setText(Messages
.PublishFlagPreference_do_not_set
);
95 setNotPublishFlagAsDefault
.setSelection(setNotPublish
);
96 setNotPublishFlagAsDefault
.addSelectionListener(new SelectionAdapter() {
98 public void widgetSelected(SelectionEvent e
) {
99 setNotPublish
= !setNotPublish
;
103 Button setInheritFromParent
= new Button(composite
, SWT
.RADIO
);
104 setInheritFromParent
.setText(Messages
.PublishFlagPreference_inherit
);
105 setInheritFromParent
.setSelection(inheritFromParent
);
106 setInheritFromParent
.addSelectionListener(new SelectionAdapter() {
108 public void widgetSelected(SelectionEvent e
) {
109 inheritFromParent
= !inheritFromParent
;
119 public boolean performOk() {
120 String preferenceValue
= null;
122 preferenceValue
= Messages
.PublishFlagPreference_set
;
123 }else if (setNotPublish
){
124 preferenceValue
= Messages
.PublishFlagPreference_do_not_set
;
126 preferenceValue
= Messages
.PublishFlagPreference_inherit
;
128 CdmPreference pref
= CdmPreference
.NewDatabaseInstance( PreferencePredicate
.DefaultBehaviourForPublishFlag
, preferenceValue
);
129 pref
.setAllowOverride(true);
131 ICdmRepository controller
= CdmStore
.getCurrentApplicationConfiguration();
132 if (controller
== null){
135 IPreferenceService service
= controller
.getPreferenceService();