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
.preference
;
11 import org
.apache
.log4j
.Logger
;
12 import org
.eclipse
.jface
.preference
.PreferencePage
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.SelectionAdapter
;
15 import org
.eclipse
.swt
.events
.SelectionEvent
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Button
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.ui
.IWorkbench
;
21 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
23 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
24 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
31 public class NomenclaturalCodePreferences
extends PreferencePage
implements
32 IWorkbenchPreferencePage
{
33 private static final Logger logger
= Logger
34 .getLogger(NomenclaturalCodePreferences
.class);
36 public static final String PLUGIN_ID
= "eu.etaxonomy.taxeditor.preferences.nomenclatural";
38 private Button icznButton
;
39 private Button icbnButton
;
41 private String preferredCode
;
43 public NomenclaturalCodePreferences() {
45 setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified.");
49 * Create contents of the preference page
53 public Control
createContents(Composite parent
) {
56 Composite container
= new Composite(parent
, SWT
.NULL
);
57 container
.setLayout(new GridLayout());
59 icbnButton
= new Button(container
, SWT
.RADIO
);
60 icbnButton
.setText("Botanical (ICBN)");
61 icbnButton
.addSelectionListener(new SelectionAdapter() {
62 public void widgetSelected(SelectionEvent e
) {
63 preferredCode
= ITaxEditorConstants
.CODE_PREFERENCE_ICBN
;
67 icznButton
= new Button(container
, SWT
.RADIO
);
68 icznButton
.setText("Zoological (ICZN)");
69 icznButton
.addSelectionListener(new SelectionAdapter() {
70 public void widgetSelected(SelectionEvent e
) {
71 preferredCode
= ITaxEditorConstants
.CODE_PREFERENCE_ICZN
;
75 preferredCode
= getPreferenceStore().getString(ITaxEditorConstants
.CODE_PREFERENCE
);
76 if (preferredCode
== null) {
77 getPreferenceStore().setValue(
78 ITaxEditorConstants
.CODE_PREFERENCE
, ITaxEditorConstants
.DEFAULT_CODE_PREFERENCE
);
80 setButton(preferredCode
);
86 * Initialize the preference page
88 public void init(IWorkbench workbench
) {
89 setPreferenceStore(TaxEditorPlugin
.getDefault().getPreferenceStore());
92 protected void performDefaults() {
93 setButton(ITaxEditorConstants
.DEFAULT_CODE_PREFERENCE
);
96 public boolean performOk() {
97 getPreferenceStore().setValue(
98 ITaxEditorConstants
.CODE_PREFERENCE
, preferredCode
);
102 private void setButton(String preferredCode
) {
103 this.preferredCode
= preferredCode
;
105 if (preferredCode
.equals(ITaxEditorConstants
.CODE_PREFERENCE_ICBN
)) {
106 icbnButton
.setSelection(true);
107 icznButton
.setSelection(false);
109 if (preferredCode
.equals(ITaxEditorConstants
.CODE_PREFERENCE_ICZN
)) {
110 icbnButton
.setSelection(false);
111 icznButton
.setSelection(true);