1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.databaseAdmin.preferencePage;
|
10
|
|
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;
|
19
|
|
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.IPreferenceKeys;
|
26
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
27
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* @author k.luther
|
32
|
* @since 23.03.2018
|
33
|
*
|
34
|
*/
|
35
|
public class PublishFlagPreference extends CdmPreferencePage implements IE4AdminPreferencePage{
|
36
|
|
37
|
boolean setPublish;
|
38
|
boolean setNotPublish;
|
39
|
boolean inheritFromParent;
|
40
|
|
41
|
String do_not_publish = "DO NOT PUBLISH";
|
42
|
String inherit_from_parent = "PARENT";
|
43
|
String publish = "PUBLISH";
|
44
|
|
45
|
@Override
|
46
|
public void init() {
|
47
|
super.init();
|
48
|
CdmPreference pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
|
49
|
if (pref != null){
|
50
|
if (pref.getValue().equals(IPreferenceKeys.DO_NOT_PUBLISH)){
|
51
|
setNotPublish = true;
|
52
|
setPublish = false;
|
53
|
inheritFromParent = false;
|
54
|
}
|
55
|
|
56
|
if (pref.getValue().equals(IPreferenceKeys.INHERIT_FROM_PARENT)){
|
57
|
setNotPublish = false;
|
58
|
setPublish = false;
|
59
|
inheritFromParent = true;
|
60
|
}
|
61
|
|
62
|
if (pref.getValue().equals(IPreferenceKeys.PUBLISH)){
|
63
|
setNotPublish = false;
|
64
|
setPublish = true;
|
65
|
inheritFromParent = false;
|
66
|
}
|
67
|
}else{
|
68
|
setNotPublish = false;
|
69
|
setPublish = true;
|
70
|
inheritFromParent = false;
|
71
|
}
|
72
|
|
73
|
}
|
74
|
/**
|
75
|
* {@inheritDoc}
|
76
|
*/
|
77
|
@Override
|
78
|
protected Control createContents(Composite parent) {
|
79
|
final Composite composite = new Composite(parent, SWT.NULL);
|
80
|
|
81
|
GridLayout gridLayout = new GridLayout();
|
82
|
composite.setLayout(gridLayout);
|
83
|
final CLabel description = new CLabel(composite, SWT.NULL);
|
84
|
description.setText(Messages.PublishFlagPreference_description);
|
85
|
gridLayout.numColumns = 1;
|
86
|
gridLayout.horizontalSpacing= 10;
|
87
|
gridLayout.makeColumnsEqualWidth = true;
|
88
|
|
89
|
Button setPublishFlagAsDefault = new Button(composite, SWT.RADIO);
|
90
|
setPublishFlagAsDefault.setText(Messages.PublishFlagPreference_set);
|
91
|
setPublishFlagAsDefault.setSelection(setPublish);
|
92
|
setPublishFlagAsDefault.addSelectionListener(new SelectionAdapter() {
|
93
|
@Override
|
94
|
public void widgetSelected(SelectionEvent e) {
|
95
|
setPublish = !setPublish;
|
96
|
}
|
97
|
});
|
98
|
Button setNotPublishFlagAsDefault = new Button(composite, SWT.RADIO);
|
99
|
setNotPublishFlagAsDefault.setText(Messages.PublishFlagPreference_do_not_set);
|
100
|
setNotPublishFlagAsDefault.setSelection(setNotPublish);
|
101
|
setNotPublishFlagAsDefault.addSelectionListener(new SelectionAdapter() {
|
102
|
@Override
|
103
|
public void widgetSelected(SelectionEvent e) {
|
104
|
setNotPublish = !setNotPublish;
|
105
|
}
|
106
|
});
|
107
|
|
108
|
Button setInheritFromParent = new Button(composite, SWT.RADIO);
|
109
|
setInheritFromParent.setText(Messages.PublishFlagPreference_inherit);
|
110
|
setInheritFromParent.setSelection(inheritFromParent);
|
111
|
setInheritFromParent.addSelectionListener(new SelectionAdapter() {
|
112
|
@Override
|
113
|
public void widgetSelected(SelectionEvent e) {
|
114
|
inheritFromParent = !inheritFromParent;
|
115
|
}
|
116
|
});
|
117
|
|
118
|
return composite;
|
119
|
|
120
|
}
|
121
|
|
122
|
|
123
|
@Override
|
124
|
public boolean performOk() {
|
125
|
String preferenceValue = null;
|
126
|
if (setPublish){
|
127
|
preferenceValue = publish;
|
128
|
}else if (setNotPublish){
|
129
|
preferenceValue = do_not_publish;
|
130
|
} else{
|
131
|
preferenceValue = inherit_from_parent;
|
132
|
}
|
133
|
CdmPreference pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DefaultBehaviourForPublishFlag, preferenceValue);
|
134
|
pref.setAllowOverride(true);
|
135
|
|
136
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
137
|
if (controller == null){
|
138
|
return false;
|
139
|
}
|
140
|
IPreferenceService service = controller.getPreferenceService();
|
141
|
service.set(pref);
|
142
|
|
143
|
return true;
|
144
|
}
|
145
|
|
146
|
|
147
|
|
148
|
|
149
|
}
|