Re-implemented taxonomic tree using Common Navigator Framework.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / preference / NomenclaturalCodePreferences.java
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.store.preference;
10
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;
21
22 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
23 import eu.etaxonomy.taxeditor.store.model.Resources;
24
25 /**
26 * @author p.ciardelli
27 * @created 16.09.2008
28 * @version 1.0
29 */
30 public class NomenclaturalCodePreferences extends PreferencePage implements
31 IWorkbenchPreferencePage {
32
33 public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.nomenclatural";
34
35 private Button icznButton;
36 private Button icbnButton;
37
38 private String preferredCode;
39
40 public NomenclaturalCodePreferences() {
41 super();
42 setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified.");
43 }
44
45 /**
46 * Create contents of the preference page
47 * @param parent
48 */
49 @Override
50 public Control createContents(Composite parent) {
51
52
53 Composite container = new Composite(parent, SWT.NULL);
54 container.setLayout(new GridLayout());
55
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;
61 }
62 });
63
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;
69 }
70 });
71
72 preferredCode = getPreferenceStore().getString(Resources.CODE_PREFERENCE);
73 if (preferredCode == null) {
74 getPreferenceStore().setValue(
75 Resources.CODE_PREFERENCE, Resources.DEFAULT_CODE_PREFERENCE);
76 }
77 setButton(preferredCode);
78
79 return container;
80 }
81
82 /**
83 * Initialize the preference page
84 */
85 public void init(IWorkbench workbench) {
86 setPreferenceStore(TaxeditorStorePlugin.getDefault().getPreferenceStore());
87 }
88
89 protected void performDefaults() {
90 setButton(Resources.DEFAULT_CODE_PREFERENCE);
91 }
92
93 public boolean performOk() {
94 getPreferenceStore().setValue(
95 Resources.CODE_PREFERENCE, preferredCode);
96 return true;
97 }
98
99 private void setButton(String preferredCode) {
100 this.preferredCode = preferredCode;
101
102 if (preferredCode.equals(Resources.CODE_PREFERENCE_ICBN)) {
103 icbnButton.setSelection(true);
104 icznButton.setSelection(false);
105 }
106 if (preferredCode.equals(Resources.CODE_PREFERENCE_ICZN)) {
107 icbnButton.setSelection(false);
108 icznButton.setSelection(true);
109 }
110 }
111 }