Project

General

Profile

Download (8.72 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* 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
package eu.etaxonomy.taxeditor.ui.section.name;
12

    
13
import java.util.Arrays;
14

    
15
import org.eclipse.swt.SWT;
16

    
17
import eu.etaxonomy.cdm.model.name.BotanicalName;
18
import eu.etaxonomy.cdm.model.name.NonViralName;
19
import eu.etaxonomy.cdm.model.name.Rank;
20
import eu.etaxonomy.cdm.model.name.ZoologicalName;
21
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
22
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
27
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
28
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
29
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
30
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
31
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
32

    
33
/**
34
 * <p>NameDetailElement class.</p>
35
 *
36
 * @author n.hoffmann
37
 * @created Feb 26, 2010
38
 * @version 1.0
39
 */
40
public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<NonViralName> implements ISelectableElement, IEnableableFormElement{
41

    
42
	private TermComboElement<Rank> combo_rank;
43
	private TextWithLabelElement text_appendedPhrase;
44
	private TextWithLabelElement text_uninomial;
45
	private TextWithLabelElement text_infragenericEpithet;
46
	private TextWithLabelElement text_specificEpithet;
47
	private TextWithLabelElement text_infraspecificEpithet;
48
	private SelectionArbitrator selectionArbitrator;
49
	private CheckboxElement checkbox_anamorphic;
50
	private TextWithLabelElement text_breed;
51
	private NumberWithLabelElement text_publicationYear;
52
	private NumberWithLabelElement text_originalPublicationYear;
53
	private int cursorPosition;
54
	
55
	/**
56
	 * <p>Constructor for NameDetailElement.</p>
57
	 *
58
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
59
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
60
	 * @param style a int.
61
	 */
62
	public NameDetailElement(CdmFormFactory cdmFormFactory, ICdmFormElement formElement,
63
			int style) {
64
		super(cdmFormFactory, formElement);
65
		// register as selection listener
66
		if(cdmFormFactory.getSelectionProvider() != null){
67
			selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
68
		}
69
	}
70

    
71
	/** {@inheritDoc} */
72
	@Override
73
	protected void createControls(ICdmFormElement formElement, NonViralName nonViralName, int style) {
74
		
75
		toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
76
		
77
		combo_rank = formFactory.createTermComboElement(Rank.class, this, "Rank", nonViralName.getRank(), style);
78

    
79
		createGenusOrUninomialControls(this, nonViralName, style);
80
		createInfragenerericEpithetControls(this, nonViralName, style);
81
		createSpecificEpithetControls(this, nonViralName, style);
82
		createInfraSpecificEpithetControls(this, nonViralName, style);
83
		
84
		createSpecificNameParts(this, nonViralName, style);
85
		
86
		text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
87
		
88
	}
89

    
90
	/**
91
	 * <p>clearCheckRankWarnings</p>
92
	 */
93
	protected void clearCheckRankWarnings() {
94
		if(getEntity().hasProblem(ParserProblem.CheckRank)){
95
			getEntity().removeParsingProblem(ParserProblem.CheckRank);
96
			
97
			// FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
98
//			TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
99
//			nameEditor.getSelectedContainer().getNameViewer().clearErrors();
100
		}
101
	}
102
	
103
	/** {@inheritDoc} */
104
	@Override
105
	protected void updateContent() {
106
		if(getEntity() == null){
107
			setEntity(NonViralName.NewInstance(null));
108
		}
109
		
110
		super.updateContent();
111
		
112
		if(isIrrelevant()){
113
			setIrrelevant(isIrrelevant());
114
		}else{
115
			setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
116
		}
117
	}
118

    
119

    
120
	private void createSpecificNameParts(ICdmFormElement formElement,
121
			NonViralName nonViralName, int style) {
122
		switch(nonViralName.getNomenclaturalCode()){
123
		case ICBN:
124
			createBotanicalNameParts(formElement, nonViralName, style);
125
			break;
126
		case ICZN:
127
			createZoologicalNameParts(formElement, nonViralName, style);
128
			break;
129
		}
130
	}
131
	
132
	private void createBotanicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
133
		BotanicalName botanicalName = (BotanicalName) nonViralName;
134
		checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", botanicalName.isAnamorphic(), style);
135
	}
136

    
137
	private void createZoologicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
138
		ZoologicalName zoologicalName = (ZoologicalName) nonViralName;
139
		text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
140
		text_publicationYear = formFactory.createIntegerTextWithLabelElement(formElement, "Publication Year", zoologicalName.getPublicationYear(), style);
141
		text_originalPublicationYear = formFactory.createIntegerTextWithLabelElement(formElement, "Orig. Publication Year", zoologicalName.getOriginalPublicationYear(), style);
142
	}
143
	
144
	private void createGenusOrUninomialControls(ICdmFormElement element, NonViralName nonViralName, int style){		
145
		String title = "Genus";
146
		Rank rank = nonViralName.getRank();
147
		if(rank != null && rank.isSupraGeneric()){
148
			title = "Uninomial";			
149
		}
150
		text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
151
	}
152
	
153
	private void createInfragenerericEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
154
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraGeneric() && !nonViralName.getRank().isSpeciesAggregate()){
155
			text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
156
		}
157
	}
158
	
159
	private void createSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
160
		if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies()  || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
161
			text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
162
		}
163
	}
164
	
165
	private void createInfraSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
166
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
167
			text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
168
		}
169
	}
170
	
171
	/** {@inheritDoc} */
172
	@Override
173
	public void handleEvent(Object eventSource){
174
		if (eventSource == toggleable_cache) {
175
			getEntity().setNameCache(toggleable_cache.getText(),
176
					toggleable_cache.getState());
177
			if (!isIrrelevant())
178
				setIrrelevant(toggleable_cache.getState(),
179
						Arrays.asList(new Object[] { toggleable_cache }));
180
		}
181
		else if(eventSource == combo_rank){
182
			getEntity().setRank(combo_rank.getSelection());
183
			clearCheckRankWarnings();
184
			updateContent();
185
		}		
186
		else if(eventSource == text_appendedPhrase){
187
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
188
		}
189
		else if(eventSource == text_infragenericEpithet){
190
			getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
191
		}
192
		else if(eventSource == text_infraspecificEpithet){
193
			getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
194
		}
195
		else if(eventSource == text_specificEpithet){
196
			getEntity().setSpecificEpithet(text_specificEpithet.getText());
197
		}
198
		else if(eventSource == text_uninomial){
199
			getEntity().setGenusOrUninomial(text_uninomial.getText());
200
		}		
201
		else if(eventSource == checkbox_anamorphic){
202
			((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
203
		}
204
	}
205
		
206
	/*
207
	 * (non-Javadoc)
208
	 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
209
	 */
210
	/**
211
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
212
	 *
213
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
214
	 */
215
	public SelectionArbitrator getSelectionArbitrator() {
216
		return selectionArbitrator;
217
	}
218
	
219
	@Override
220
	public void updateToggleableCacheField() {
221
		if(! getEntity().isProtectedNameCache()){
222
			toggleable_cache.setText(getEntity().getNameCache());
223
		}
224
	}
225
}
(6-6/21)