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.
10 package eu
.etaxonomy
.taxeditor
.preference
;
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
;
25 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
26 import eu
.etaxonomy
.taxeditor
.model
.NomenclaturalCodeHelper
;
29 * <p>InitNomenclaturalCodePrefDialog class.</p>
35 public class InitNomenclaturalCodePrefDialog
extends Dialog
{
38 * If the user makes no change, or cancels, preferred nom. code will be set to the default
40 private NomenclaturalCode preferredCode
= NomenclaturalCodeHelper
.getDefaultCode();
45 * @param parentShell a {@link org.eclipse.swt.widgets.Shell} object.
47 public InitNomenclaturalCodePrefDialog(Shell parentShell
) {
54 * Create contents of the dialog
57 protected Control
createDialogArea(Composite parent
) {
59 Composite container
= (Composite
) super.createDialogArea(parent
);
61 // Create label with description of dialog
62 final Label chooseANomenclaturalLabel
= new Label(container
, SWT
.WRAP
);
63 chooseANomenclaturalLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
64 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.");
66 // Create composite to show radio buttons
67 final Composite buttonsComposite
= new Composite(container
, SWT
.NONE
);
68 final GridData gd_buttonsComposite
= new GridData();
69 gd_buttonsComposite
.horizontalIndent
= 20;
70 buttonsComposite
.setLayoutData(gd_buttonsComposite
);
71 buttonsComposite
.setLayout(new GridLayout());
73 NomenclaturalCode defaultCode
= NomenclaturalCodeHelper
.getDefaultCode();
75 for (final NomenclaturalCode code
: NomenclaturalCodeHelper
.getSupportedCodes()) {
76 Button button
= new Button(buttonsComposite
, SWT
.RADIO
);
77 button
.setText(NomenclaturalCodeHelper
.getDescription(code
));
78 button
.setSelection(defaultCode
.equals(code
));
79 button
.addSelectionListener(new SelectionAdapter() {
81 public void widgetSelected(SelectionEvent e
) {
82 setPreferredCode(code
);
88 String defaultCodeDescription
= NomenclaturalCodeHelper
.getDescription(defaultCode
);
89 final Label chooseANomenclaturalLabel_1
= new Label(container
, SWT
.WRAP
);
90 chooseANomenclaturalLabel_1
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
91 chooseANomenclaturalLabel_1
.setText("If you hit \"Cancel\", " + defaultCodeDescription
+
92 " will be set as your default nomenclatural code.\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
98 * <p>Setter for the field <code>preferredCode</code>.</p>
100 * @param code a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
102 protected void setPreferredCode(NomenclaturalCode code
) {
103 this.preferredCode
= code
;
109 * Return the initial size of the dialog
112 protected Point
getInitialSize() {
113 return new Point(500, 375);
118 protected void configureShell(Shell newShell
) {
119 super.configureShell(newShell
);
120 newShell
.setText("Choose a nomenclatural code");
129 public boolean close() {
131 // Save preferred nomenclatural code before closing
132 PreferencesUtil
.setPreferredNomenclaturalCode(preferredCode
, true);
134 return super.close();