Project

General

Profile

Download (9.67 KB) Statistics
| Branch: | Tag: | Revision:
1 729887cf n.hoffmann
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4 0f595da2 Patric Plitzner
* European Distributed Institute of Taxonomy
5 729887cf n.hoffmann
* http://www.e-taxonomy.eu
6 0f595da2 Patric Plitzner
*
7 729887cf n.hoffmann
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
11 f211dd28 n.hoffmann
package eu.etaxonomy.taxeditor.ui.section.name;
12 729887cf n.hoffmann
13
import java.util.Arrays;
14
15 0f595da2 Patric Plitzner
import org.apache.log4j.Logger;
16 729887cf n.hoffmann
import org.eclipse.swt.SWT;
17
18 ccc7ac6f Patric Plitzner
import eu.etaxonomy.cdm.model.common.TermType;
19 729887cf n.hoffmann
import eu.etaxonomy.cdm.model.name.BotanicalName;
20 5f7b8a18 Andreas Müller
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
21 729887cf n.hoffmann
import eu.etaxonomy.cdm.model.name.NonViralName;
22
import eu.etaxonomy.cdm.model.name.Rank;
23
import eu.etaxonomy.cdm.model.name.ZoologicalName;
24
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
25 4db49a38 Alexander Oppermann
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
26
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27 b9a0d300 l.morris
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
28 78222507 n.hoffmann
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
29
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
30 dacb59c9 Patric Plitzner
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
31 78222507 n.hoffmann
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
32
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
33
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
34
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
35
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
36 89f83939 n.hoffmann
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
37 729887cf n.hoffmann
38
/**
39 3be6ef3e n.hoffmann
 * <p>NameDetailElement class.</p>
40
 *
41 729887cf n.hoffmann
 * @author n.hoffmann
42
 * @created Feb 26, 2010
43
 * @version 1.0
44
 */
45 89f83939 n.hoffmann
public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<NonViralName> implements ISelectableElement, IEnableableFormElement{
46 729887cf n.hoffmann
47 0f595da2 Patric Plitzner
    private final Logger logger = Logger.getLogger(NameDetailElement.class);
48
49 b9a0d300 l.morris
	private TermComboElement<Rank> combo_rank;
50 729887cf n.hoffmann
	private TextWithLabelElement text_appendedPhrase;
51
	private TextWithLabelElement text_uninomial;
52
	private TextWithLabelElement text_infragenericEpithet;
53
	private TextWithLabelElement text_specificEpithet;
54
	private TextWithLabelElement text_infraspecificEpithet;
55
	private SelectionArbitrator selectionArbitrator;
56
	private CheckboxElement checkbox_anamorphic;
57
	private TextWithLabelElement text_breed;
58 cfcb0ce6 n.hoffmann
	private NumberWithLabelElement text_publicationYear;
59
	private NumberWithLabelElement text_originalPublicationYear;
60 729887cf n.hoffmann
	private int cursorPosition;
61 0f595da2 Patric Plitzner
62 3be6ef3e n.hoffmann
	/**
63
	 * <p>Constructor for NameDetailElement.</p>
64
	 *
65 78222507 n.hoffmann
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
66
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
67 3be6ef3e n.hoffmann
	 * @param style a int.
68
	 */
69 729887cf n.hoffmann
	public NameDetailElement(CdmFormFactory cdmFormFactory, ICdmFormElement formElement,
70
			int style) {
71
		super(cdmFormFactory, formElement);
72
		// register as selection listener
73
		if(cdmFormFactory.getSelectionProvider() != null){
74
			selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
75
		}
76
	}
77
78 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
79 729887cf n.hoffmann
	@Override
80
	protected void createControls(ICdmFormElement formElement, NonViralName nonViralName, int style) {
81 0f595da2 Patric Plitzner
82 729887cf n.hoffmann
		toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
83 0f595da2 Patric Plitzner
84 ccc7ac6f Patric Plitzner
		combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
85 0f595da2 Patric Plitzner
86 729887cf n.hoffmann
		createGenusOrUninomialControls(this, nonViralName, style);
87
		createInfragenerericEpithetControls(this, nonViralName, style);
88
		createSpecificEpithetControls(this, nonViralName, style);
89
		createInfraSpecificEpithetControls(this, nonViralName, style);
90 0f595da2 Patric Plitzner
91 729887cf n.hoffmann
		createSpecificNameParts(this, nonViralName, style);
92 0f595da2 Patric Plitzner
93 729887cf n.hoffmann
		text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
94 0f595da2 Patric Plitzner
95 729887cf n.hoffmann
	}
96
97 3be6ef3e n.hoffmann
	/**
98
	 * <p>clearCheckRankWarnings</p>
99
	 */
100 729887cf n.hoffmann
	protected void clearCheckRankWarnings() {
101
		if(getEntity().hasProblem(ParserProblem.CheckRank)){
102
			getEntity().removeParsingProblem(ParserProblem.CheckRank);
103 0f595da2 Patric Plitzner
104 f211dd28 n.hoffmann
			// FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
105
//			TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
106
//			nameEditor.getSelectedContainer().getNameViewer().clearErrors();
107 729887cf n.hoffmann
		}
108
	}
109 0f595da2 Patric Plitzner
110 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
111 729887cf n.hoffmann
	@Override
112
	protected void updateContent() {
113
		if(getEntity() == null){
114
			setEntity(NonViralName.NewInstance(null));
115
		}
116 0f595da2 Patric Plitzner
117 729887cf n.hoffmann
		super.updateContent();
118 0f595da2 Patric Plitzner
119 729887cf n.hoffmann
		if(isIrrelevant()){
120
			setIrrelevant(isIrrelevant());
121
		}else{
122
			setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
123
		}
124
	}
125
126
127
	private void createSpecificNameParts(ICdmFormElement formElement,
128
			NonViralName nonViralName, int style) {
129 5f7b8a18 Andreas Müller
		NomenclaturalCode code = nonViralName.getNomenclaturalCode();
130
		if (code != null){
131
			switch(nonViralName.getNomenclaturalCode()){
132 49a64920 Cherian Mathew
			case ICNAFP :
133 4db49a38 Alexander Oppermann
				// TODO RL
134
				if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL))
135
				{
136
					createBotanicalNameParts(formElement, nonViralName, style);
137
				}
138 5f7b8a18 Andreas Müller
				break;
139
			case ICZN:
140
				createZoologicalNameParts(formElement, nonViralName, style);
141
				break;
142 5a35a97d Patric Plitzner
            case ICVCN:
143 0f595da2 Patric Plitzner
                //TODO implement
144 5a35a97d Patric Plitzner
                logger.warn("ICVCN not yet implemented");
145
                break;
146
            case ICNB:
147 0f595da2 Patric Plitzner
                //TODO implement
148 5a35a97d Patric Plitzner
                logger.warn("ICNB not yet implemented");
149
                break;
150
            case ICNCP:
151
                //TODO implement
152
                logger.warn("ICNCP not yet implemented");
153
                break;
154
            }
155 729887cf n.hoffmann
		}
156
	}
157 0f595da2 Patric Plitzner
158 729887cf n.hoffmann
	private void createBotanicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
159
		BotanicalName botanicalName = (BotanicalName) nonViralName;
160
		checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", botanicalName.isAnamorphic(), style);
161
	}
162
163
	private void createZoologicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
164
		ZoologicalName zoologicalName = (ZoologicalName) nonViralName;
165
		text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
166 d2d8e95d Cherian Mathew
		text_publicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Publication Year", zoologicalName.getPublicationYear(), style);
167
		text_originalPublicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Orig. Publication Year", zoologicalName.getOriginalPublicationYear(), style);
168 729887cf n.hoffmann
	}
169 0f595da2 Patric Plitzner
170
	private void createGenusOrUninomialControls(ICdmFormElement element, NonViralName nonViralName, int style){
171 729887cf n.hoffmann
		String title = "Genus";
172
		Rank rank = nonViralName.getRank();
173
		if(rank != null && rank.isSupraGeneric()){
174 0f595da2 Patric Plitzner
			title = "Uninomial";
175 729887cf n.hoffmann
		}
176
		text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
177
	}
178 0f595da2 Patric Plitzner
179 729887cf n.hoffmann
	private void createInfragenerericEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
180
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraGeneric() && !nonViralName.getRank().isSpeciesAggregate()){
181
			text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
182
		}
183
	}
184 0f595da2 Patric Plitzner
185 729887cf n.hoffmann
	private void createSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
186
		if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies()  || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
187
			text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
188
		}
189
	}
190 0f595da2 Patric Plitzner
191 729887cf n.hoffmann
	private void createInfraSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
192
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
193
			text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
194
		}
195
	}
196 0f595da2 Patric Plitzner
197 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
198 729887cf n.hoffmann
	@Override
199
	public void handleEvent(Object eventSource){
200 bc10e3ef n.hoffmann
		if (eventSource == toggleable_cache) {
201
			getEntity().setNameCache(toggleable_cache.getText(),
202
					toggleable_cache.getState());
203 0f595da2 Patric Plitzner
			if (!isIrrelevant()) {
204
                setIrrelevant(toggleable_cache.getState(),
205 bc10e3ef n.hoffmann
						Arrays.asList(new Object[] { toggleable_cache }));
206 0f595da2 Patric Plitzner
            }
207 bc10e3ef n.hoffmann
		}
208
		else if(eventSource == combo_rank){
209 729887cf n.hoffmann
			getEntity().setRank(combo_rank.getSelection());
210 e0b35bf1 n.hoffmann
			clearCheckRankWarnings();
211
			updateContent();
212 0f595da2 Patric Plitzner
		}
213 729887cf n.hoffmann
		else if(eventSource == text_appendedPhrase){
214
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
215
		}
216
		else if(eventSource == text_infragenericEpithet){
217
			getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
218
		}
219
		else if(eventSource == text_infraspecificEpithet){
220
			getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
221
		}
222
		else if(eventSource == text_specificEpithet){
223
			getEntity().setSpecificEpithet(text_specificEpithet.getText());
224
		}
225
		else if(eventSource == text_uninomial){
226
			getEntity().setGenusOrUninomial(text_uninomial.getText());
227 0f595da2 Patric Plitzner
		}
228 729887cf n.hoffmann
		else if(eventSource == checkbox_anamorphic){
229
			((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
230
		}
231
	}
232 0f595da2 Patric Plitzner
233 729887cf n.hoffmann
	/*
234
	 * (non-Javadoc)
235
	 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
236
	 */
237 3be6ef3e n.hoffmann
	/**
238
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
239
	 *
240 78222507 n.hoffmann
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
241 3be6ef3e n.hoffmann
	 */
242 0f595da2 Patric Plitzner
	@Override
243
    public SelectionArbitrator getSelectionArbitrator() {
244 729887cf n.hoffmann
		return selectionArbitrator;
245
	}
246 0f595da2 Patric Plitzner
247 89f83939 n.hoffmann
	@Override
248
	public void updateToggleableCacheField() {
249
		if(! getEntity().isProtectedNameCache()){
250
			toggleable_cache.setText(getEntity().getNameCache());
251
		}
252
	}
253 729887cf n.hoffmann
}