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.events.SelectionAdapter;
|
13
|
import org.eclipse.swt.events.SelectionEvent;
|
14
|
import org.eclipse.swt.layout.GridData;
|
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.CdmPreference.PrefKey;
|
24
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
25
|
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
|
26
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
27
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* @author k.luther
|
32
|
* @since 27.04.2018
|
33
|
*
|
34
|
*/
|
35
|
public class SpecimenAdminPreferences extends CdmPreferencePage implements IE4AdminPreferencePage {
|
36
|
|
37
|
|
38
|
|
39
|
boolean isShowCollectingAreaInGeneralSection;
|
40
|
boolean isDeterminationOnlyForFieldUnits;
|
41
|
boolean isShowTaxonAssociation;
|
42
|
boolean isShowLifeForm;
|
43
|
boolean isUseLocalPreference;
|
44
|
|
45
|
|
46
|
@Override
|
47
|
protected Control createContents(Composite parent) {
|
48
|
Composite composite = new Composite(parent, SWT.NULL);
|
49
|
getValues();
|
50
|
GridLayout gridLayout = new GridLayout();
|
51
|
composite.setLayout(gridLayout);
|
52
|
final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
|
53
|
|
54
|
showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
|
55
|
|
56
|
showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
|
57
|
showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
|
58
|
@Override
|
59
|
public void widgetSelected(SelectionEvent e) {
|
60
|
isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
|
61
|
|
62
|
}
|
63
|
});
|
64
|
|
65
|
final Button determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
|
66
|
|
67
|
determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
|
68
|
|
69
|
determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
|
70
|
determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
|
71
|
@Override
|
72
|
public void widgetSelected(SelectionEvent e) {
|
73
|
isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
|
74
|
}
|
75
|
});
|
76
|
|
77
|
final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
|
78
|
|
79
|
showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
|
80
|
|
81
|
showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
|
82
|
showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
|
83
|
@Override
|
84
|
public void widgetSelected(SelectionEvent e) {
|
85
|
isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
|
86
|
|
87
|
}
|
88
|
});
|
89
|
|
90
|
final Button showLifeFormButton = new Button(composite, SWT.CHECK);
|
91
|
showLifeFormButton.setText(Messages.DatabasePreferncesPage_Life_Form);
|
92
|
showLifeFormButton.setSelection(isShowLifeForm);
|
93
|
showLifeFormButton.addSelectionListener(new SelectionAdapter(){
|
94
|
@Override
|
95
|
public void widgetSelected(SelectionEvent e) {
|
96
|
isShowLifeForm = showLifeFormButton.getSelection();
|
97
|
|
98
|
}
|
99
|
});
|
100
|
|
101
|
// Composite useLocalComp = new Composite(composite, SWT.NONE);
|
102
|
|
103
|
|
104
|
final Button useLocalPreference = new Button(composite, SWT.CHECK);
|
105
|
|
106
|
useLocalPreference.setText(Messages.DatabasePreferencesPage_UseLocalPreferences);
|
107
|
GridData gridData = new GridData(SWT.FILL, SWT.BOTTOM, false, false);
|
108
|
gridData.verticalIndent = 10;
|
109
|
useLocalPreference.setLayoutData(gridData);
|
110
|
|
111
|
useLocalPreference.setSelection(isUseLocalPreference);
|
112
|
useLocalPreference.addSelectionListener(new SelectionAdapter(){
|
113
|
@Override
|
114
|
public void widgetSelected(SelectionEvent e) {
|
115
|
isUseLocalPreference = useLocalPreference.getSelection();
|
116
|
|
117
|
}
|
118
|
});
|
119
|
return composite;
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
public void init() {
|
124
|
super.init();
|
125
|
if(!CdmStore.isActive()){
|
126
|
return;
|
127
|
}
|
128
|
|
129
|
|
130
|
|
131
|
}
|
132
|
|
133
|
private void getValues(){
|
134
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
135
|
if (controller != null){
|
136
|
IPreferenceService service = controller.getPreferenceService();
|
137
|
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
|
138
|
CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
|
139
|
if (isShowCollectingAreaInGeneralSectionPref != null){
|
140
|
this.isShowCollectingAreaInGeneralSection = Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue());
|
141
|
}
|
142
|
|
143
|
key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
|
144
|
CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
|
145
|
if (isDeterminationOnlyForFieldUnitsPref != null){
|
146
|
this.isDeterminationOnlyForFieldUnits = Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue());
|
147
|
}
|
148
|
key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowTaxonAssociations);
|
149
|
CdmPreference isShowTaxonAssociationPref = service.find(key);
|
150
|
if (isShowTaxonAssociationPref != null){
|
151
|
this.isShowTaxonAssociation = Boolean.valueOf(isShowTaxonAssociationPref.getValue());
|
152
|
isUseLocalPreference = isShowTaxonAssociationPref.isAllowOverride();
|
153
|
}
|
154
|
|
155
|
key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowLifeForm);
|
156
|
CdmPreference isShowLifeFormPref = service.find(key);
|
157
|
if (isShowLifeFormPref != null){
|
158
|
this.isShowLifeForm = Boolean.valueOf(isShowLifeFormPref.getValue());
|
159
|
}
|
160
|
|
161
|
|
162
|
|
163
|
|
164
|
}
|
165
|
}
|
166
|
|
167
|
@Override
|
168
|
public boolean performOk() {
|
169
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
170
|
if (controller != null){
|
171
|
IPreferenceService service = controller.getPreferenceService();
|
172
|
|
173
|
CdmPreference pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
|
174
|
pref.setAllowOverride(isUseLocalPreference);
|
175
|
service.set(pref);
|
176
|
|
177
|
pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
|
178
|
pref.setAllowOverride(isUseLocalPreference);
|
179
|
service.set(pref);
|
180
|
|
181
|
pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
|
182
|
pref.setAllowOverride(isUseLocalPreference);
|
183
|
service.set(pref);
|
184
|
|
185
|
pref = CdmPreference.NewDatabaseInstance(PreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
|
186
|
pref.setAllowOverride(isUseLocalPreference);
|
187
|
service.set(pref);
|
188
|
|
189
|
|
190
|
}
|
191
|
return true;
|
192
|
}
|
193
|
|
194
|
}
|