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.layout.GridData;
|
14
|
import org.eclipse.swt.layout.GridLayout;
|
15
|
import org.eclipse.swt.widgets.Combo;
|
16
|
import org.eclipse.swt.widgets.Composite;
|
17
|
import org.eclipse.swt.widgets.Control;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
20
|
import eu.etaxonomy.cdm.api.service.IPreferenceService;
|
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.EditorPreferencePredicate;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.preference.PublishEnum;
|
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
|
PublishEnum publishBehaviour;
|
38
|
|
39
|
Combo publishFlagBehaviour;
|
40
|
CdmPreference pref = null;
|
41
|
|
42
|
@Override
|
43
|
public void init() {
|
44
|
super.init();
|
45
|
|
46
|
|
47
|
}
|
48
|
/**
|
49
|
* {@inheritDoc}
|
50
|
*/
|
51
|
@Override
|
52
|
protected Control createContents(Composite parent) {
|
53
|
pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
|
54
|
if (pref == null){
|
55
|
pref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.DefaultBehaviourForPublishFlag, EditorPreferencePredicate.DefaultBehaviourForPublishFlag.getDefaultValue().toString());
|
56
|
}
|
57
|
|
58
|
final Composite composite = new Composite(parent, SWT.NULL);
|
59
|
|
60
|
GridLayout gridLayout = new GridLayout();
|
61
|
composite.setLayout(gridLayout);
|
62
|
final CLabel description = new CLabel(composite, SWT.NULL);
|
63
|
description.setText(Messages.PublishFlagPreference_description);
|
64
|
|
65
|
GridData gridData = new GridData();
|
66
|
gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
|
67
|
gridData.horizontalIndent = 5;
|
68
|
|
69
|
publishFlagBehaviour = new Combo(composite, SWT.BORDER| SWT.READ_ONLY);
|
70
|
publishFlagBehaviour.setLayoutData(gridData);
|
71
|
|
72
|
for(PublishEnum display: PublishEnum.values()){
|
73
|
publishFlagBehaviour.add(display.getLabel());
|
74
|
}
|
75
|
|
76
|
int index = 0;
|
77
|
|
78
|
PublishEnum publishFlag = PublishEnum.valueOf(pref.getValue());
|
79
|
for (String itemLabel : publishFlagBehaviour.getItems()){
|
80
|
if (itemLabel.equalsIgnoreCase(publishFlag.getLabel())){
|
81
|
publishFlagBehaviour.select(index);
|
82
|
break;
|
83
|
}
|
84
|
index++;
|
85
|
}
|
86
|
|
87
|
|
88
|
return composite;
|
89
|
|
90
|
}
|
91
|
|
92
|
|
93
|
@Override
|
94
|
public boolean performOk() {
|
95
|
if (pref == null){
|
96
|
return true;
|
97
|
}
|
98
|
|
99
|
CdmPreference pref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.DefaultBehaviourForPublishFlag, publishFlagBehaviour.getText());
|
100
|
pref.setAllowOverride(true);
|
101
|
|
102
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
103
|
if (controller == null){
|
104
|
return false;
|
105
|
}
|
106
|
IPreferenceService service = controller.getPreferenceService();
|
107
|
service.set(pref);
|
108
|
PreferencesUtil.updateDBPreferences();
|
109
|
|
110
|
return true;
|
111
|
}
|
112
|
|
113
|
|
114
|
|
115
|
|
116
|
}
|