Project

General

Profile

Download (4.23 KB) Statistics
| Branch: | Tag: | Revision:
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
				@Override
81
                public void widgetSelected(SelectionEvent e) {
82
					setPreferredCode(code);
83
				}
84
			});
85
		}
86

    
87
		// More dialog text
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.");
93
		//
94
		return container;
95
	}
96

    
97
	/**
98
	 * <p>Setter for the field <code>preferredCode</code>.</p>
99
	 *
100
	 * @param code a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
101
	 */
102
	protected void setPreferredCode(NomenclaturalCode code) {
103
		this.preferredCode = code;
104
	}
105

    
106
	/**
107
	 * {@inheritDoc}
108
	 *
109
	 * Return the initial size of the dialog
110
	 */
111
	@Override
112
	protected Point getInitialSize() {
113
		return new Point(500, 375);
114
	}
115

    
116
	/** {@inheritDoc} */
117
	@Override
118
    protected void configureShell(Shell newShell) {
119
		super.configureShell(newShell);
120
		newShell.setText("Choose a nomenclatural code");
121
	}
122

    
123
	/**
124
	 * <p>close</p>
125
	 *
126
	 * @return a boolean.
127
	 */
128
	@Override
129
    public boolean close() {
130

    
131
		// Save preferred nomenclatural code before closing
132
		PreferencesUtil.setPreferredNomenclaturalCode(PreferencesUtil.getPreferenceKey(preferredCode), true);
133

    
134
		return super.close();
135
	}
136

    
137

    
138
}
(9-9/25)