editor now updatable via updateSite
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / preference / InitNomenclaturalCodePrefDialog.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
10 package eu.etaxonomy.taxeditor.store.preference;
11
12 import org.eclipse.jface.dialogs.Dialog;
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.graphics.Point;
17 import org.eclipse.swt.layout.GridData;
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.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Shell;
24
25 import eu.etaxonomy.taxeditor.store.model.Resources;
26
27 /**
28 * @author p.ciardelli
29 * @created 05.12.2008
30 * @version 1.0
31 */
32 public class InitNomenclaturalCodePrefDialog extends Dialog {
33
34 private Button icbnButton;
35 private Button icznButton;
36
37 /**
38 * If the user makes no chance, or cancels, preferred nom. code will be set to the default
39 */
40 private String preferredCode = Resources.DEFAULT_CODE_PREFERENCE;
41
42 /**
43 * Create the dialog
44 * @param parentShell
45 */
46 public InitNomenclaturalCodePrefDialog(Shell parentShell) {
47 super(parentShell);
48 }
49
50 /**
51 * Create contents of the dialog
52 * @param parent
53 */
54 @Override
55 protected Control createDialogArea(Composite parent) {
56
57 Composite container = (Composite) super.createDialogArea(parent);
58
59 // Create label with description of dialog
60 final Label chooseANomenclaturalLabel = new Label(container, SWT.WRAP);
61 chooseANomenclaturalLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
62 chooseANomenclaturalLabel.setText("Welcome to the EDIT Taxonomic Editor.\n\nBefore proceeding, please choose a nomenclatural code. This code will be used to create new names and to parse name text.");
63
64 // Create composite to show radio buttons
65 final Composite buttonsComposite = new Composite(container, SWT.NONE);
66 final GridData gd_buttonsComposite = new GridData();
67 gd_buttonsComposite.horizontalIndent = 20;
68 buttonsComposite.setLayoutData(gd_buttonsComposite);
69 buttonsComposite.setLayout(new GridLayout());
70
71 // Create ICBN radio button
72 icbnButton = new Button(buttonsComposite, SWT.RADIO);
73 icbnButton.setText("International Code of Botanical Nomenclature (ICBN)");
74 icbnButton.addSelectionListener(new SelectionAdapter() {
75 public void widgetSelected(SelectionEvent e) {
76 setPreferredCode(Resources.CODE_PREFERENCE_ICBN);
77 }
78 });
79
80 // Create ICZN radio button
81 icznButton = new Button(buttonsComposite, SWT.RADIO);
82 icznButton.setText("International Code of Zoological Nomenclature (ICZN)");
83 icznButton.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent e) {
85 setPreferredCode(Resources.CODE_PREFERENCE_ICZN);
86 }
87 });
88
89 // More dialog text
90 final Label chooseANomenclaturalLabel_1 = new Label(container, SWT.WRAP);
91 chooseANomenclaturalLabel_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
92 chooseANomenclaturalLabel_1.setText("If you hit \"Cancel\", & the International Code of Botanical Nomenclature (ICBN) will be set as your default nomenclatural code.\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
93 //
94 return container;
95 }
96
97 protected void setPreferredCode(String preferredCode) {
98 this.preferredCode = preferredCode;
99 }
100
101 /**
102 * Return the initial size of the dialog
103 */
104 @Override
105 protected Point getInitialSize() {
106 return new Point(500, 375);
107 }
108
109 protected void configureShell(Shell newShell) {
110 super.configureShell(newShell);
111 newShell.setText("Choose a nomenclatural code");
112 }
113
114 public boolean close() {
115
116 // Save preferred nomenclatural code before closing
117 PreferencesUtil.setNomenclaturalCode(preferredCode);
118
119 return super.close();
120 }
121
122
123 }