2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.store
.preference
;
11 import org
.eclipse
.jface
.preference
.PreferencePage
;
12 import org
.eclipse
.swt
.SWT
;
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 import org
.eclipse
.ui
.IWorkbench
;
20 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
22 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
23 import eu
.etaxonomy
.taxeditor
.store
.model
.Resources
;
30 public class NomenclaturalCodePreferences
extends PreferencePage
implements
31 IWorkbenchPreferencePage
{
33 public static final String PLUGIN_ID
= "eu.etaxonomy.taxeditor.preferences.nomenclatural";
35 private Button icznButton
;
36 private Button icbnButton
;
38 private String preferredCode
;
40 public NomenclaturalCodePreferences() {
42 setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified.");
46 * Create contents of the preference page
50 public Control
createContents(Composite parent
) {
53 Composite container
= new Composite(parent
, SWT
.NULL
);
54 container
.setLayout(new GridLayout());
56 icbnButton
= new Button(container
, SWT
.RADIO
);
57 icbnButton
.setText("Botanical (ICBN)");
58 icbnButton
.addSelectionListener(new SelectionAdapter() {
59 public void widgetSelected(SelectionEvent e
) {
60 preferredCode
= Resources
.CODE_PREFERENCE_ICBN
;
64 icznButton
= new Button(container
, SWT
.RADIO
);
65 icznButton
.setText("Zoological (ICZN)");
66 icznButton
.addSelectionListener(new SelectionAdapter() {
67 public void widgetSelected(SelectionEvent e
) {
68 preferredCode
= Resources
.CODE_PREFERENCE_ICZN
;
72 preferredCode
= getPreferenceStore().getString(Resources
.CODE_PREFERENCE
);
73 if (preferredCode
== null) {
74 getPreferenceStore().setValue(
75 Resources
.CODE_PREFERENCE
, Resources
.DEFAULT_CODE_PREFERENCE
);
77 setButton(preferredCode
);
83 * Initialize the preference page
85 public void init(IWorkbench workbench
) {
86 setPreferenceStore(TaxeditorStorePlugin
.getDefault().getPreferenceStore());
89 protected void performDefaults() {
90 setButton(Resources
.DEFAULT_CODE_PREFERENCE
);
93 public boolean performOk() {
94 getPreferenceStore().setValue(
95 Resources
.CODE_PREFERENCE
, preferredCode
);
99 private void setButton(String preferredCode
) {
100 this.preferredCode
= preferredCode
;
102 if (preferredCode
.equals(Resources
.CODE_PREFERENCE_ICBN
)) {
103 icbnButton
.setSelection(true);
104 icznButton
.setSelection(false);
106 if (preferredCode
.equals(Resources
.CODE_PREFERENCE_ICZN
)) {
107 icbnButton
.setSelection(false);
108 icznButton
.setSelection(true);