Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-store/src/main/java/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 java.util.HashMap; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import org.eclipse.jface.preference.PreferencePage; |
|
15 |
import org.eclipse.swt.SWT; |
|
16 |
import org.eclipse.swt.events.SelectionAdapter; |
|
17 |
import org.eclipse.swt.events.SelectionEvent; |
|
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.ui.IWorkbench; |
|
23 |
import org.eclipse.ui.IWorkbenchPreferencePage; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
26 |
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper; |
|
27 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
28 |
|
|
29 |
/** |
|
30 |
* @author p.ciardelli |
|
31 |
* @created 16.09.2008 |
|
32 |
* @version 1.0 |
|
33 |
*/ |
|
34 |
public class NomenclaturalCodePreferences extends PreferencePage implements |
|
35 |
IWorkbenchPreferencePage { |
|
36 |
|
|
37 |
public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.nomenclatural"; |
|
38 |
|
|
39 |
private NomenclaturalCode preferredCode; |
|
40 |
|
|
41 |
private Map<NomenclaturalCode, Button> buttons = new HashMap<NomenclaturalCode, Button>(); |
|
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 |
Composite container = new Composite(parent, SWT.NULL); |
|
56 |
container.setLayout(new GridLayout()); |
|
57 |
|
|
58 |
for (final NomenclaturalCode code : NomenclaturalCodeHelper.getSupportedCodes()) { |
|
59 |
Button button = new Button(container, SWT.RADIO); |
|
60 |
button.setText(NomenclaturalCodeHelper.getDescription(code)); |
|
61 |
button.addSelectionListener(new SelectionAdapter() { |
|
62 |
public void widgetSelected(SelectionEvent e) { |
|
63 |
preferredCode = code; |
|
64 |
} |
|
65 |
}); |
|
66 |
buttons.put(code, button); |
|
67 |
} |
|
68 |
|
|
69 |
preferredCode = PreferencesUtil.getPreferredNomenclaturalCode(); |
|
70 |
if (preferredCode == null) { |
|
71 |
preferredCode = NomenclaturalCodeHelper.getDefaultCode(); |
|
72 |
PreferencesUtil.setPreferredNomenclaturalCode(preferredCode); |
|
73 |
} |
|
74 |
setButton(preferredCode); |
|
75 |
|
|
76 |
return container; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Initialize the preference page |
|
81 |
*/ |
|
82 |
public void init(IWorkbench workbench) { |
|
83 |
setPreferenceStore(TaxeditorStorePlugin.getDefault().getPreferenceStore()); |
|
84 |
} |
|
85 |
|
|
86 |
protected void performDefaults() { |
|
87 |
setButton(NomenclaturalCodeHelper.getDefaultCode()); |
|
88 |
} |
|
89 |
|
|
90 |
public boolean performOk() { |
|
91 |
PreferencesUtil.setPreferredNomenclaturalCode(preferredCode); |
|
92 |
return true; |
|
93 |
} |
|
94 |
|
|
95 |
private void setButton(NomenclaturalCode preferredCode) { |
|
96 |
this.preferredCode = preferredCode; |
|
97 |
for (NomenclaturalCode code : buttons.keySet()) { |
|
98 |
buttons.get(code).setSelection(code.equals(preferredCode)); |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
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 java.util.HashMap; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import org.eclipse.jface.preference.PreferencePage; |
|
15 |
import org.eclipse.swt.SWT; |
|
16 |
import org.eclipse.swt.events.SelectionAdapter; |
|
17 |
import org.eclipse.swt.events.SelectionEvent; |
|
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.ui.IWorkbench; |
|
23 |
import org.eclipse.ui.IWorkbenchPreferencePage; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
26 |
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper; |
|
27 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
28 |
|
|
29 |
/** |
|
30 |
* <p>NomenclaturalCodePreferences class.</p> |
|
31 |
* |
|
32 |
* @author p.ciardelli |
|
33 |
* @created 16.09.2008 |
|
34 |
* @version 1.0 |
|
35 |
*/ |
|
36 |
public class NomenclaturalCodePreferences extends PreferencePage implements |
|
37 |
IWorkbenchPreferencePage { |
|
38 |
|
|
39 |
/** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.preferences.nome"{trunked}</code> */ |
|
40 |
public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.nomenclatural"; |
|
41 |
|
|
42 |
private NomenclaturalCode preferredCode; |
|
43 |
|
|
44 |
private Map<NomenclaturalCode, Button> buttons = new HashMap<NomenclaturalCode, Button>(); |
|
45 |
|
|
46 |
/** |
|
47 |
* <p>Constructor for NomenclaturalCodePreferences.</p> |
|
48 |
*/ |
|
49 |
public NomenclaturalCodePreferences() { |
|
50 |
super(); |
|
51 |
setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified."); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* {@inheritDoc} |
|
56 |
* |
|
57 |
* Create contents of the preference page |
|
58 |
*/ |
|
59 |
@Override |
|
60 |
public Control createContents(Composite parent) { |
|
61 |
|
|
62 |
Composite container = new Composite(parent, SWT.NULL); |
|
63 |
container.setLayout(new GridLayout()); |
|
64 |
|
|
65 |
for (final NomenclaturalCode code : NomenclaturalCodeHelper.getSupportedCodes()) { |
|
66 |
Button button = new Button(container, SWT.RADIO); |
|
67 |
button.setText(NomenclaturalCodeHelper.getDescription(code)); |
|
68 |
button.addSelectionListener(new SelectionAdapter() { |
|
69 |
public void widgetSelected(SelectionEvent e) { |
|
70 |
preferredCode = code; |
|
71 |
} |
|
72 |
}); |
|
73 |
buttons.put(code, button); |
|
74 |
} |
|
75 |
|
|
76 |
preferredCode = PreferencesUtil.getPreferredNomenclaturalCode(); |
|
77 |
if (preferredCode == null) { |
|
78 |
preferredCode = NomenclaturalCodeHelper.getDefaultCode(); |
|
79 |
PreferencesUtil.setPreferredNomenclaturalCode(preferredCode); |
|
80 |
} |
|
81 |
setButton(preferredCode); |
|
82 |
|
|
83 |
return container; |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* {@inheritDoc} |
|
88 |
* |
|
89 |
* Initialize the preference page |
|
90 |
*/ |
|
91 |
public void init(IWorkbench workbench) { |
|
92 |
setPreferenceStore(TaxeditorStorePlugin.getDefault().getPreferenceStore()); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* <p>performDefaults</p> |
|
97 |
*/ |
|
98 |
protected void performDefaults() { |
|
99 |
setButton(NomenclaturalCodeHelper.getDefaultCode()); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* <p>performOk</p> |
|
104 |
* |
|
105 |
* @return a boolean. |
|
106 |
*/ |
|
107 |
public boolean performOk() { |
|
108 |
PreferencesUtil.setPreferredNomenclaturalCode(preferredCode); |
|
109 |
return true; |
|
110 |
} |
|
111 |
|
|
112 |
private void setButton(NomenclaturalCode preferredCode) { |
|
113 |
this.preferredCode = preferredCode; |
|
114 |
for (NomenclaturalCode code : buttons.keySet()) { |
|
115 |
buttons.get(code).setSelection(code.equals(preferredCode)); |
|
116 |
} |
|
117 |
} |
|
118 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation