1
|
/**
|
2
|
* Copyright (C) 2007 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 java.util.HashMap;
|
12
|
import java.util.Map;
|
13
|
|
14
|
import org.eclipse.jface.preference.PreferencePage;
|
15
|
import org.eclipse.swt.SWT;
|
16
|
import org.eclipse.swt.events.SelectionAdapter;
|
17
|
import org.eclipse.swt.events.SelectionEvent;
|
18
|
import org.eclipse.swt.layout.GridLayout;
|
19
|
import org.eclipse.swt.widgets.Button;
|
20
|
import org.eclipse.swt.widgets.Composite;
|
21
|
import org.eclipse.swt.widgets.Control;
|
22
|
import org.eclipse.ui.IWorkbench;
|
23
|
import org.eclipse.ui.IWorkbenchPreferencePage;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
26
|
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
|
27
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
28
|
|
29
|
/**
|
30
|
* <p>NomenclaturalCodePreferences class.</p>
|
31
|
*
|
32
|
* @author p.ciardelli
|
33
|
* @created 16.09.2008
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class NomenclaturalCodePreferences extends PreferencePage implements
|
37
|
IWorkbenchPreferencePage {
|
38
|
|
39
|
/** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.preferences.nome"{trunked}</code> */
|
40
|
public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.nomenclatural";
|
41
|
|
42
|
private NomenclaturalCode preferredCode;
|
43
|
|
44
|
private Map<NomenclaturalCode, Button> buttons = new HashMap<NomenclaturalCode, Button>();
|
45
|
|
46
|
/**
|
47
|
* <p>Constructor for NomenclaturalCodePreferences.</p>
|
48
|
*/
|
49
|
public NomenclaturalCodePreferences() {
|
50
|
super();
|
51
|
setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified.");
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* {@inheritDoc}
|
56
|
*
|
57
|
* Create contents of the preference page
|
58
|
*/
|
59
|
@Override
|
60
|
public Control createContents(Composite parent) {
|
61
|
|
62
|
Composite container = new Composite(parent, SWT.NULL);
|
63
|
container.setLayout(new GridLayout());
|
64
|
|
65
|
for (final NomenclaturalCode code : NomenclaturalCodeHelper.getSupportedCodes()) {
|
66
|
Button button = new Button(container, SWT.RADIO);
|
67
|
button.setText(NomenclaturalCodeHelper.getDescription(code));
|
68
|
button.addSelectionListener(new SelectionAdapter() {
|
69
|
public void widgetSelected(SelectionEvent e) {
|
70
|
preferredCode = code;
|
71
|
}
|
72
|
});
|
73
|
buttons.put(code, button);
|
74
|
}
|
75
|
|
76
|
preferredCode = PreferencesUtil.getPreferredNomenclaturalCode();
|
77
|
if (preferredCode == null) {
|
78
|
preferredCode = NomenclaturalCodeHelper.getDefaultCode();
|
79
|
PreferencesUtil.setPreferredNomenclaturalCode(preferredCode);
|
80
|
}
|
81
|
setButton(preferredCode);
|
82
|
|
83
|
return container;
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* {@inheritDoc}
|
88
|
*
|
89
|
* Initialize the preference page
|
90
|
*/
|
91
|
public void init(IWorkbench workbench) {
|
92
|
setPreferenceStore(TaxeditorStorePlugin.getDefault().getPreferenceStore());
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* <p>performDefaults</p>
|
97
|
*/
|
98
|
protected void performDefaults() {
|
99
|
setButton(NomenclaturalCodeHelper.getDefaultCode());
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* <p>performOk</p>
|
104
|
*
|
105
|
* @return a boolean.
|
106
|
*/
|
107
|
public boolean performOk() {
|
108
|
PreferencesUtil.setPreferredNomenclaturalCode(preferredCode);
|
109
|
return true;
|
110
|
}
|
111
|
|
112
|
private void setButton(NomenclaturalCode preferredCode) {
|
113
|
this.preferredCode = preferredCode;
|
114
|
for (NomenclaturalCode code : buttons.keySet()) {
|
115
|
buttons.get(code).setSelection(code.equals(preferredCode));
|
116
|
}
|
117
|
}
|
118
|
}
|