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.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
|
29
|
/**
|
30
|
* @author k.luther
|
31
|
* @since 23.03.2018
|
32
|
*
|
33
|
*/
|
34
|
public class PublishFlagPreference extends CdmPreferencePage implements IE4AdminPreferencePage{
|
35
|
|
36
|
boolean setPublish = true;
|
37
|
boolean setNotPublish = false;
|
38
|
boolean inheritFromParent = false;
|
39
|
|
40
|
@Override
|
41
|
public void init() {
|
42
|
super.init();
|
43
|
CdmPreference pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
|
44
|
|
45
|
}
|
46
|
/**
|
47
|
* {@inheritDoc}
|
48
|
*/
|
49
|
@Override
|
50
|
protected Control createContents(Composite parent) {
|
51
|
final Composite composite = new Composite(parent, SWT.NULL);
|
52
|
|
53
|
GridLayout gridLayout = new GridLayout();
|
54
|
composite.setLayout(gridLayout);
|
55
|
final CLabel description = new CLabel(composite, SWT.NULL);
|
56
|
description.setText(Messages.PublishFlagPreference_description);
|
57
|
gridLayout.numColumns = 1;
|
58
|
gridLayout.horizontalSpacing= 10;
|
59
|
gridLayout.makeColumnsEqualWidth = true;
|
60
|
|
61
|
Button setPublishFlagAsDefault = new Button(composite, SWT.RADIO);
|
62
|
setPublishFlagAsDefault.setText(Messages.PublishFlagPreference_set);
|
63
|
setPublishFlagAsDefault.setSelection(setPublish);
|
64
|
setPublishFlagAsDefault.addSelectionListener(new SelectionAdapter() {
|
65
|
@Override
|
66
|
public void widgetSelected(SelectionEvent e) {
|
67
|
setPublish = !setPublish;
|
68
|
}
|
69
|
});
|
70
|
Button setNotPublishFlagAsDefault = new Button(composite, SWT.RADIO);
|
71
|
setNotPublishFlagAsDefault.setText(Messages.PublishFlagPreference_do_not_set);
|
72
|
setNotPublishFlagAsDefault.setSelection(setNotPublish);
|
73
|
setNotPublishFlagAsDefault.addSelectionListener(new SelectionAdapter() {
|
74
|
@Override
|
75
|
public void widgetSelected(SelectionEvent e) {
|
76
|
setNotPublish = !setNotPublish;
|
77
|
}
|
78
|
});
|
79
|
|
80
|
Button setInheritFromParent = new Button(composite, SWT.RADIO);
|
81
|
setInheritFromParent.setText(Messages.PublishFlagPreference_inherit);
|
82
|
setInheritFromParent.setSelection(inheritFromParent);
|
83
|
setInheritFromParent.addSelectionListener(new SelectionAdapter() {
|
84
|
@Override
|
85
|
public void widgetSelected(SelectionEvent e) {
|
86
|
inheritFromParent = !inheritFromParent;
|
87
|
}
|
88
|
});
|
89
|
|
90
|
return composite;
|
91
|
|
92
|
}
|
93
|
|
94
|
|
95
|
@Override
|
96
|
public boolean performOk() {
|
97
|
String preferenceValue = null;
|
98
|
if (setPublish){
|
99
|
preferenceValue = Messages.PublishFlagPreference_set;
|
100
|
}else if (setNotPublish){
|
101
|
preferenceValue = Messages.PublishFlagPreference_do_not_set;
|
102
|
} else{
|
103
|
preferenceValue = Messages.PublishFlagPreference_inherit;
|
104
|
}
|
105
|
CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.DefaultBehaviourForPublishFlag, preferenceValue);
|
106
|
pref.setAllowOverride(true);
|
107
|
|
108
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
109
|
if (controller == null){
|
110
|
return false;
|
111
|
}
|
112
|
IPreferenceService service = controller.getPreferenceService();
|
113
|
service.set(pref);
|
114
|
|
115
|
return true;
|
116
|
}
|
117
|
|
118
|
|
119
|
|
120
|
|
121
|
}
|