1
|
/**
|
2
|
* Copyright (C) 2015 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.menu;
|
10
|
|
11
|
import org.eclipse.jface.preference.PreferencePage;
|
12
|
import org.eclipse.jface.resource.ImageDescriptor;
|
13
|
import org.eclipse.swt.SWT;
|
14
|
import org.eclipse.swt.custom.CLabel;
|
15
|
import org.eclipse.swt.layout.GridData;
|
16
|
import org.eclipse.swt.layout.GridLayout;
|
17
|
import org.eclipse.swt.widgets.Button;
|
18
|
import org.eclipse.swt.widgets.Combo;
|
19
|
import org.eclipse.swt.widgets.Composite;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.metadata.IKeyLabel;
|
22
|
import eu.etaxonomy.cdm.model.metadata.IPreferencePredicate;
|
23
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
24
|
import eu.etaxonomy.taxeditor.preference.IE4PreferencePage;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
|
27
|
/**
|
28
|
* @author cmathew
|
29
|
* @date 30 Jul 2015
|
30
|
*
|
31
|
*/
|
32
|
public abstract class CdmPreferencePage extends PreferencePage implements IE4PreferencePage {
|
33
|
|
34
|
|
35
|
private boolean isDefaultButtonActivated = true;
|
36
|
|
37
|
protected boolean isAdminPreference;
|
38
|
|
39
|
private boolean isApply;
|
40
|
|
41
|
|
42
|
|
43
|
public CdmPreferencePage() {
|
44
|
this(null, null);
|
45
|
}
|
46
|
|
47
|
public CdmPreferencePage(String title) {
|
48
|
this(title, null);
|
49
|
}
|
50
|
|
51
|
public CdmPreferencePage(String title, ImageDescriptor image) {
|
52
|
super(title, image);
|
53
|
|
54
|
init();
|
55
|
}
|
56
|
|
57
|
|
58
|
|
59
|
public void init() {
|
60
|
setPreferenceStore(PreferencesUtil.getPreferenceStore());
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
public void createControl(Composite parent){
|
65
|
super.createControl(parent);
|
66
|
if (getApplyButton() != null){
|
67
|
this.getApplyButton().setEnabled(false);
|
68
|
}
|
69
|
if (getDefaultsButton() != null){
|
70
|
this.getDefaultsButton().setEnabled(isDefaultButtonActivated);
|
71
|
}
|
72
|
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public boolean performOk() {
|
77
|
if (isValid()){
|
78
|
return super.performOk();
|
79
|
}return false;
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public boolean performCancel() {
|
84
|
|
85
|
return super.performCancel();
|
86
|
}
|
87
|
|
88
|
@Override
|
89
|
public void performApply() {
|
90
|
setApply(true);
|
91
|
super.performApply();
|
92
|
setApply(false);
|
93
|
}
|
94
|
|
95
|
protected Composite createComposite(Composite composite) {
|
96
|
Composite activateComp = new Composite(composite, SWT.NULL);
|
97
|
GridLayout layout = new GridLayout();
|
98
|
layout.numColumns = 2;
|
99
|
|
100
|
activateComp.setLayout(layout);
|
101
|
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
102
|
|
103
|
activateComp.setLayoutData(gridData);
|
104
|
|
105
|
return activateComp;
|
106
|
}
|
107
|
|
108
|
|
109
|
protected GridData createTextGridData() {
|
110
|
GridData sepGrid = new GridData(GridData.FILL_HORIZONTAL);
|
111
|
sepGrid.horizontalSpan = 2;
|
112
|
return sepGrid;
|
113
|
}
|
114
|
|
115
|
protected void getValues(){
|
116
|
|
117
|
}
|
118
|
|
119
|
|
120
|
protected Button createAllowOverrideButton(Composite activateComp) {
|
121
|
final Button allowOverrideCheckButton = new Button(activateComp, SWT.CHECK);
|
122
|
String overrideString;
|
123
|
if (isAdminPreference){
|
124
|
overrideString = Messages.GeneralPreference_allowOverride;
|
125
|
}else{
|
126
|
overrideString = Messages.GeneralPreference_override;
|
127
|
}
|
128
|
allowOverrideCheckButton.setText(overrideString);
|
129
|
GridData grid = new GridData();
|
130
|
grid.horizontalAlignment = SWT.END;
|
131
|
allowOverrideCheckButton.setLayoutData(grid);
|
132
|
return allowOverrideCheckButton;
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public boolean isApply() {
|
137
|
return isApply;
|
138
|
}
|
139
|
|
140
|
public void setApply(boolean isApply) {
|
141
|
this.isApply = isApply;
|
142
|
if (this.getApplyButton() != null){
|
143
|
this.getApplyButton().setEnabled(this.isApply);
|
144
|
}
|
145
|
}
|
146
|
|
147
|
public boolean isDefaultButtonActivated() {
|
148
|
return isDefaultButtonActivated;
|
149
|
}
|
150
|
|
151
|
public void setDefaultButtonActivated(boolean isDefaultButtonActivated) {
|
152
|
this.isDefaultButtonActivated = isDefaultButtonActivated;
|
153
|
}
|
154
|
|
155
|
public Combo createBooleanCombo(Composite parent, String textTrue, String textFalse, IPreferencePredicate predicate, String labelText, boolean isAdminPage) {
|
156
|
final CLabel rankDescription = new CLabel(parent, SWT.NULL);
|
157
|
rankDescription.setText(labelText);
|
158
|
GridData textGrid = createTextGridData();
|
159
|
textGrid.verticalSpan = 2;
|
160
|
rankDescription.setLayoutData(textGrid);
|
161
|
|
162
|
Combo booleanCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
|
163
|
|
164
|
// CdmPreference dbPref = PreferencesUtil.getPreferenceFromDB(predicate);
|
165
|
// boolean defaultValue = true;
|
166
|
// if (dbPref != null && !isAdminPage){
|
167
|
// defaultValue = Boolean.valueOf(dbPref.getValue());
|
168
|
// }else{
|
169
|
boolean defaultValue = (Boolean)predicate.getDefaultValue();
|
170
|
String defaultString;
|
171
|
if (defaultValue){
|
172
|
defaultString = " ("+textTrue+")";
|
173
|
}else{
|
174
|
defaultString = " ("+textFalse+")";
|
175
|
}
|
176
|
// }
|
177
|
// if (defaultValue){
|
178
|
booleanCombo.add(Messages.Preference_Use_Default + defaultString);
|
179
|
booleanCombo.add(textTrue);
|
180
|
booleanCombo.add(textFalse);
|
181
|
// }else{
|
182
|
//
|
183
|
// booleanCombo.add(textFalse + Messages.Preference_Use_Default);
|
184
|
// }
|
185
|
return booleanCombo;
|
186
|
|
187
|
}
|
188
|
|
189
|
|
190
|
public Combo createCombo(Composite parent, IKeyLabel[] enumValues, IPreferencePredicate predicate, String labelText, boolean isAdminPage) {
|
191
|
final CLabel description = new CLabel(parent, SWT.NULL);
|
192
|
description.setText(labelText);
|
193
|
GridData textGrid = createTextGridData();
|
194
|
textGrid.verticalSpan = 2;
|
195
|
description.setLayoutData(textGrid);
|
196
|
|
197
|
Combo booleanCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
|
198
|
|
199
|
|
200
|
String defaultValue = null;
|
201
|
|
202
|
Object defaultObject = predicate.getDefaultValue();
|
203
|
if (defaultObject != null){
|
204
|
if (defaultObject instanceof IKeyLabel){
|
205
|
defaultValue = ((IKeyLabel)defaultObject).getKey();
|
206
|
}else{
|
207
|
defaultValue = predicate.getDefaultValue().toString();
|
208
|
}
|
209
|
}
|
210
|
|
211
|
booleanCombo.add(Messages.Preference_Use_Default + " ("+defaultValue+")");;
|
212
|
for (IKeyLabel value: enumValues){
|
213
|
booleanCombo.add(value.getLabel());
|
214
|
}
|
215
|
|
216
|
return booleanCombo;
|
217
|
|
218
|
}
|
219
|
|
220
|
|
221
|
|
222
|
|
223
|
}
|