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