1
|
/**
|
2
|
* Copyright (C) 2019 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.preference;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
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;
|
23
|
|
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;
|
29
|
|
30
|
/**
|
31
|
* @author k.luther
|
32
|
* @since 08.01.2019
|
33
|
*
|
34
|
*/
|
35
|
public class PublishFlagLocalPreference extends CdmPreferencePage {
|
36
|
|
37
|
protected PublishEnum publishBehaviour;
|
38
|
|
39
|
protected Combo publishFlagBehaviour;
|
40
|
protected CdmPreference pref = null;
|
41
|
Button allowOverrideButton;
|
42
|
|
43
|
protected boolean allowOverride;
|
44
|
|
45
|
|
46
|
@Override
|
47
|
public void init() {
|
48
|
super.init();
|
49
|
|
50
|
|
51
|
}
|
52
|
/**
|
53
|
* {@inheritDoc}
|
54
|
*/
|
55
|
@Override
|
56
|
protected Control createContents(Composite parent) {
|
57
|
getValues();
|
58
|
pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
|
59
|
if (pref == null){
|
60
|
pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DefaultBehaviourForPublishFlag, PreferencePredicate.DefaultBehaviourForPublishFlag.getDefaultValue().toString());
|
61
|
}
|
62
|
allowOverride = pref.isAllowOverride();
|
63
|
Composite composite = createComposite(parent);
|
64
|
|
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());
|
69
|
return composite;
|
70
|
}
|
71
|
|
72
|
|
73
|
// description.setText(Messages.PublishFlagPreference_description);
|
74
|
// description.setLayoutData(createTextGridData());
|
75
|
// publishFlagBehaviour = new Combo(composite, SWT.READ_ONLY);
|
76
|
List<String> enumValues = new ArrayList();
|
77
|
|
78
|
publishFlagBehaviour = createCombo(composite, PublishEnum.values(), PreferencePredicate.DefaultBehaviourForPublishFlag, Messages.PublishFlagPreference_description, isAdminPreference);
|
79
|
|
80
|
// publishFlagBehaviour.setFont(parent.getFont());
|
81
|
// for(PublishEnum display: PublishEnum.values()){
|
82
|
// if (pref.getValue().equals(display.getKey())){
|
83
|
// publishFlagBehaviour.add(display.getLabel() + " (Default)");
|
84
|
// }
|
85
|
// else
|
86
|
// }
|
87
|
|
88
|
publishFlagBehaviour.addSelectionListener(new SelectionListener() {
|
89
|
|
90
|
@Override
|
91
|
public void widgetSelected(SelectionEvent e) {
|
92
|
setApply(true);
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public void widgetDefaultSelected(SelectionEvent e) {
|
97
|
// TODO Auto-generated method stub
|
98
|
|
99
|
}
|
100
|
});
|
101
|
if (this.isAdminPreference){
|
102
|
allowOverrideButton = createAllowOverrideButton(composite);
|
103
|
allowOverrideButton.setText(Messages.GeneralPreference_override);
|
104
|
allowOverrideButton.setSelection(allowOverride);
|
105
|
allowOverrideButton.addSelectionListener(new SelectionAdapter(){
|
106
|
@Override
|
107
|
public void widgetSelected(SelectionEvent e) {
|
108
|
allowOverride = !allowOverride;
|
109
|
setApply(true);
|
110
|
}
|
111
|
});
|
112
|
}
|
113
|
int index = 0;
|
114
|
|
115
|
|
116
|
for (String itemLabel : publishFlagBehaviour.getItems()){
|
117
|
if (itemLabel.startsWith(publishBehaviour.getLabel())){
|
118
|
publishFlagBehaviour.select(index);
|
119
|
break;
|
120
|
}
|
121
|
index++;
|
122
|
}
|
123
|
|
124
|
return composite;
|
125
|
|
126
|
}
|
127
|
|
128
|
|
129
|
@Override
|
130
|
public boolean performOk() {
|
131
|
if (publishFlagBehaviour != null){
|
132
|
String text = publishFlagBehaviour.getText();
|
133
|
for (PublishEnum display: PublishEnum.values()){
|
134
|
if (text.startsWith(display.getLabel())){
|
135
|
text = display.getKey();
|
136
|
break;
|
137
|
}
|
138
|
}
|
139
|
PreferencesUtil.setStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey(), text);
|
140
|
PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey()), allowOverride);
|
141
|
}
|
142
|
return true;
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
public void getValues(){
|
147
|
|
148
|
try{
|
149
|
publishBehaviour = PublishEnum.valueOf(PreferencesUtil.getStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey(), true));
|
150
|
}catch (IllegalArgumentException e){
|
151
|
publishBehaviour = PublishEnum.InheritFromParent;
|
152
|
}
|
153
|
}
|
154
|
|
155
|
@Override
|
156
|
protected void performDefaults() {
|
157
|
publishBehaviour = PublishEnum.valueOf(pref.getValue());
|
158
|
allowOverride = true;
|
159
|
int index = 0;
|
160
|
for (String itemLabel : publishFlagBehaviour.getItems()){
|
161
|
if (itemLabel.startsWith(publishBehaviour.getLabel())){
|
162
|
publishFlagBehaviour.select(index);
|
163
|
break;
|
164
|
}
|
165
|
index++;
|
166
|
}
|
167
|
|
168
|
super.performDefaults();
|
169
|
}
|
170
|
|
171
|
|
172
|
}
|