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 org.apache.commons.lang.StringUtils;
|
12
|
import org.eclipse.jface.layout.GridLayoutFactory;
|
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;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
22
|
import eu.etaxonomy.cdm.ext.geo.CondensedDistributionRecipe;
|
23
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
24
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
|
25
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
26
|
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
|
27
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
28
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
29
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
30
|
|
31
|
/**
|
32
|
* @author k.luther
|
33
|
* @since 02.07.2019
|
34
|
*
|
35
|
*/
|
36
|
public class DistributionGeneralPreference extends CdmPreferencePage implements SelectionListener {
|
37
|
protected CdmPreference preferenceCondensedDistribtionRecipe;
|
38
|
protected boolean isAllowOverrideCondensedDistributionRecipe;
|
39
|
protected boolean isOverrideCondensedDistributionRecipe;
|
40
|
Combo comboDistributionStringRecipe;
|
41
|
Button allowOverrideDistributionStringRecipe;
|
42
|
protected CondensedDistributionRecipe recipe;
|
43
|
|
44
|
|
45
|
@Override
|
46
|
protected Control createContents(Composite parent) {
|
47
|
getValues();
|
48
|
Composite composite = createComposite(parent);
|
49
|
comboDistributionStringRecipe = createCombo(composite, CondensedDistributionRecipe.values(), PreferencePredicate.CondensedDistributionRecipe, "Condensed Distribution String recipe", isAdminPreference);
|
50
|
|
51
|
// GridData gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
|
52
|
// gridData.horizontalIndent = 9;
|
53
|
// comboDistributionStringRecipe.setLayoutData(gridData);
|
54
|
GridLayoutFactory.fillDefaults();
|
55
|
|
56
|
comboDistributionStringRecipe.addSelectionListener(this);
|
57
|
// comboDistributionStringRecipe.setEnabled((isExportCondensedDistribution != null && isExportCondensedDistribution )|| (isExportCondensedDistribution == null) && Boolean.valueOf(preferenceIsExportCondensedDistribution.getValue()));
|
58
|
int index = 0;
|
59
|
|
60
|
for (String itemLabel : comboDistributionStringRecipe.getItems()) {
|
61
|
if (itemLabel.startsWith(Messages.Preference_Use_Default) && recipe == null){
|
62
|
comboDistributionStringRecipe.select(index);
|
63
|
break;
|
64
|
}
|
65
|
if (itemLabel.equals(recipe.getLabel())) {
|
66
|
comboDistributionStringRecipe.select(index);
|
67
|
break;
|
68
|
}
|
69
|
|
70
|
index++;
|
71
|
}
|
72
|
if (isAdminPreference){
|
73
|
allowOverrideDistributionStringRecipe = createAllowOverrideButton(composite);
|
74
|
allowOverrideDistributionStringRecipe.setSelection(this.preferenceCondensedDistribtionRecipe != null? this.preferenceCondensedDistribtionRecipe.isAllowOverride(): true);
|
75
|
allowOverrideDistributionStringRecipe.addSelectionListener(new SelectionAdapter() {
|
76
|
@Override
|
77
|
public void widgetSelected(SelectionEvent e) {
|
78
|
setApply(true);
|
79
|
isAllowOverrideCondensedDistributionRecipe = !isAllowOverrideCondensedDistributionRecipe;
|
80
|
}
|
81
|
});
|
82
|
}else{
|
83
|
comboDistributionStringRecipe.setEnabled(isAllowOverrideCondensedDistributionRecipe);
|
84
|
|
85
|
}
|
86
|
|
87
|
return composite;
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
protected void getValues(){
|
92
|
isAdminPreference = false;
|
93
|
ICdmRepository controller;
|
94
|
controller = CdmStore.getCurrentApplicationConfiguration();
|
95
|
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.CondensedDistributionRecipe);
|
96
|
preferenceCondensedDistribtionRecipe = controller.getPreferenceService().find(key);
|
97
|
|
98
|
if (preferenceCondensedDistribtionRecipe != null ){
|
99
|
isAllowOverrideCondensedDistributionRecipe = preferenceCondensedDistribtionRecipe.isAllowOverride();
|
100
|
}else{
|
101
|
preferenceCondensedDistribtionRecipe = CdmPreference.NewDatabaseInstance(PreferencePredicate.CondensedDistributionRecipe,
|
102
|
PreferencePredicate.CondensedDistributionRecipe.getDefaultValue() != null? PreferencePredicate.CondensedDistributionRecipe.getDefaultValue().toString(): null);
|
103
|
isAllowOverrideCondensedDistributionRecipe = true;
|
104
|
}
|
105
|
|
106
|
isOverrideCondensedDistributionRecipe = PreferencesUtil.getBooleanValue(
|
107
|
PreferencesUtil.prefOverrideKey(PreferencePredicate.CondensedDistributionRecipe.getKey()), true) != null? PreferencesUtil.getBooleanValue(
|
108
|
PreferencesUtil.prefOverrideKey(PreferencePredicate.CondensedDistributionRecipe.getKey()), true):false;
|
109
|
|
110
|
if (isAllowOverrideCondensedDistributionRecipe && isOverrideCondensedDistributionRecipe){
|
111
|
String configString = PreferencesUtil.getStringValue(PreferencePredicate.CondensedDistributionRecipe.getKey(), true);
|
112
|
if (StringUtils.isNotBlank(configString)){
|
113
|
recipe = CondensedDistributionRecipe.valueOf(configString);
|
114
|
}
|
115
|
}else{
|
116
|
if (preferenceCondensedDistribtionRecipe.getValue() != null){
|
117
|
recipe = CondensedDistributionRecipe.valueOf(preferenceCondensedDistribtionRecipe.getValue());
|
118
|
}
|
119
|
}
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
public void widgetSelected(SelectionEvent e) {
|
124
|
setApply(true);
|
125
|
if (e.getSource().equals(this.comboDistributionStringRecipe)){
|
126
|
int selIndex = comboDistributionStringRecipe.getSelectionIndex();
|
127
|
if (selIndex == 0){
|
128
|
isOverrideCondensedDistributionRecipe = false;
|
129
|
}else{
|
130
|
isOverrideCondensedDistributionRecipe = true;
|
131
|
}
|
132
|
recipe = (CondensedDistributionRecipe) comboDistributionStringRecipe.getData(comboDistributionStringRecipe.getText());
|
133
|
|
134
|
}
|
135
|
|
136
|
}
|
137
|
|
138
|
@Override
|
139
|
public void widgetDefaultSelected(SelectionEvent e) {
|
140
|
// TODO Auto-generated method stub
|
141
|
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
public boolean performOk() {
|
146
|
if (!isApply()){
|
147
|
return true;
|
148
|
}
|
149
|
|
150
|
if(isOverrideCondensedDistributionRecipe){
|
151
|
PreferencesUtil.setStringValue(PreferencePredicate.CondensedDistributionRecipe.getKey(), recipe.getKey());
|
152
|
PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.CondensedDistributionRecipe.getKey()), isOverrideCondensedDistributionRecipe);
|
153
|
}else{
|
154
|
PreferencesUtil.setBooleanValue( PreferencesUtil.prefOverrideKey(PreferencePredicate.CondensedDistributionRecipe.getKey()), isOverrideCondensedDistributionRecipe);
|
155
|
}
|
156
|
return true;
|
157
|
}
|
158
|
|
159
|
}
|