performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / 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.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.cdm.model.name.NomenclaturalCode;
26 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
27
28 /**
29 * <p>InitNomenclaturalCodePrefDialog class.</p>
30 *
31 * @author p.ciardelli
32 * @created 05.12.2008
33 * @version 1.0
34 */
35 public class InitNomenclaturalCodePrefDialog extends Dialog {
36
37 /**
38 * If the user makes no change, or cancels, preferred nom. code will be set to the default
39 */
40 private NomenclaturalCode preferredCode = NomenclaturalCodeHelper.getDefaultCode();
41
42 /**
43 * Create the dialog
44 *
45 * @param parentShell a {@link org.eclipse.swt.widgets.Shell} object.
46 */
47 public InitNomenclaturalCodePrefDialog(Shell parentShell) {
48 super(parentShell);
49 }
50
51 /**
52 * {@inheritDoc}
53 *
54 * Create contents of the dialog
55 */
56 @Override
57 protected Control createDialogArea(Composite parent) {
58
59 Composite container = (Composite) super.createDialogArea(parent);
60
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.");
65
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());
72
73 NomenclaturalCode defaultCode = NomenclaturalCodeHelper.getDefaultCode();
74
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() {
80 public void widgetSelected(SelectionEvent e) {
81 setPreferredCode(code);
82 }
83 });
84 }
85
86 // More dialog text
87 String defaultCodeDescription = NomenclaturalCodeHelper.getDescription(defaultCode);
88 final Label chooseANomenclaturalLabel_1 = new Label(container, SWT.WRAP);
89 chooseANomenclaturalLabel_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
90 chooseANomenclaturalLabel_1.setText("If you hit \"Cancel\", " + defaultCodeDescription +
91 " will be set as your default nomenclatural code.\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
92 //
93 return container;
94 }
95
96 /**
97 * <p>Setter for the field <code>preferredCode</code>.</p>
98 *
99 * @param code a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
100 */
101 protected void setPreferredCode(NomenclaturalCode code) {
102 this.preferredCode = code;
103 }
104
105 /**
106 * {@inheritDoc}
107 *
108 * Return the initial size of the dialog
109 */
110 @Override
111 protected Point getInitialSize() {
112 return new Point(500, 375);
113 }
114
115 /** {@inheritDoc} */
116 protected void configureShell(Shell newShell) {
117 super.configureShell(newShell);
118 newShell.setText("Choose a nomenclatural code");
119 }
120
121 /**
122 * <p>close</p>
123 *
124 * @return a boolean.
125 */
126 public boolean close() {
127
128 // Save preferred nomenclatural code before closing
129 PreferencesUtil.setPreferredNomenclaturalCode(preferredCode);
130
131 return super.close();
132 }
133
134
135 }