Project

General

Profile

Download (9.39 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.apache.log4j.Logger;
16
import org.eclipse.swt.SWT;
17

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

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

    
44
    private final Logger logger = Logger.getLogger(NameDetailElement.class);
45

    
46
	private TermComboElement<Rank> combo_rank;
47
	private TextWithLabelElement text_appendedPhrase;
48
	private TextWithLabelElement text_uninomial;
49
	private TextWithLabelElement text_infragenericEpithet;
50
	private TextWithLabelElement text_specificEpithet;
51
	private TextWithLabelElement text_infraspecificEpithet;
52
	private SelectionArbitrator selectionArbitrator;
53
	private CheckboxElement checkbox_anamorphic;
54
	private TextWithLabelElement text_breed;
55
	private NumberWithLabelElement text_publicationYear;
56
	private NumberWithLabelElement text_originalPublicationYear;
57
	private int cursorPosition;
58

    
59
	/**
60
	 * <p>Constructor for NameDetailElement.</p>
61
	 *
62
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
63
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
64
	 * @param style a int.
65
	 */
66
	public NameDetailElement(CdmFormFactory cdmFormFactory, ICdmFormElement formElement,
67
			int style) {
68
		super(cdmFormFactory, formElement);
69
		// register as selection listener
70
		if(cdmFormFactory.getSelectionProvider() != null){
71
			selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
72
		}
73
	}
74

    
75
	/** {@inheritDoc} */
76
	@Override
77
	protected void createControls(ICdmFormElement formElement, NonViralName nonViralName, int style) {
78

    
79
		toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
80

    
81
		combo_rank = formFactory.createTermComboElement(Rank.class, this, "Rank", nonViralName.getRank(), style);
82

    
83
		createGenusOrUninomialControls(this, nonViralName, style);
84
		createInfragenerericEpithetControls(this, nonViralName, style);
85
		createSpecificEpithetControls(this, nonViralName, style);
86
		createInfraSpecificEpithetControls(this, nonViralName, style);
87

    
88
		createSpecificNameParts(this, nonViralName, style);
89

    
90
		text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
91

    
92
	}
93

    
94
	/**
95
	 * <p>clearCheckRankWarnings</p>
96
	 */
97
	protected void clearCheckRankWarnings() {
98
		if(getEntity().hasProblem(ParserProblem.CheckRank)){
99
			getEntity().removeParsingProblem(ParserProblem.CheckRank);
100

    
101
			// FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
102
//			TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
103
//			nameEditor.getSelectedContainer().getNameViewer().clearErrors();
104
		}
105
	}
106

    
107
	/** {@inheritDoc} */
108
	@Override
109
	protected void updateContent() {
110
		if(getEntity() == null){
111
			setEntity(NonViralName.NewInstance(null));
112
		}
113

    
114
		super.updateContent();
115

    
116
		if(isIrrelevant()){
117
			setIrrelevant(isIrrelevant());
118
		}else{
119
			setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
120
		}
121
	}
122

    
123

    
124
	private void createSpecificNameParts(ICdmFormElement formElement,
125
			NonViralName nonViralName, int style) {
126
		NomenclaturalCode code = nonViralName.getNomenclaturalCode();
127
		if (code != null){
128
			switch(nonViralName.getNomenclaturalCode()){
129
			case ICNAFP :
130
				createBotanicalNameParts(formElement, nonViralName, style);
131
				break;
132
			case ICZN:
133
				createZoologicalNameParts(formElement, nonViralName, style);
134
				break;
135
            case ICVCN:
136
                //TODO implement
137
                logger.warn("ICVCN not yet implemented");
138
                break;
139
            case ICNB:
140
                //TODO implement
141
                logger.warn("ICNB not yet implemented");
142
                break;
143
            case ICNCP:
144
                //TODO implement
145
                logger.warn("ICNCP not yet implemented");
146
                break;
147
            }
148
		}
149
	}
150

    
151
	private void createBotanicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
152
		BotanicalName botanicalName = (BotanicalName) nonViralName;
153
		checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", botanicalName.isAnamorphic(), style);
154
	}
155

    
156
	private void createZoologicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
157
		ZoologicalName zoologicalName = (ZoologicalName) nonViralName;
158
		text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
159
		text_publicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Publication Year", zoologicalName.getPublicationYear(), style);
160
		text_originalPublicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Orig. Publication Year", zoologicalName.getOriginalPublicationYear(), style);
161
	}
162

    
163
	private void createGenusOrUninomialControls(ICdmFormElement element, NonViralName nonViralName, int style){
164
		String title = "Genus";
165
		Rank rank = nonViralName.getRank();
166
		if(rank != null && rank.isSupraGeneric()){
167
			title = "Uninomial";
168
		}
169
		text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
170
	}
171

    
172
	private void createInfragenerericEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
173
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraGeneric() && !nonViralName.getRank().isSpeciesAggregate()){
174
			text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
175
		}
176
	}
177

    
178
	private void createSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
179
		if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies()  || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
180
			text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
181
		}
182
	}
183

    
184
	private void createInfraSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
185
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
186
			text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
187
		}
188
	}
189

    
190
	/** {@inheritDoc} */
191
	@Override
192
	public void handleEvent(Object eventSource){
193
		if (eventSource == toggleable_cache) {
194
			getEntity().setNameCache(toggleable_cache.getText(),
195
					toggleable_cache.getState());
196
			if (!isIrrelevant()) {
197
                setIrrelevant(toggleable_cache.getState(),
198
						Arrays.asList(new Object[] { toggleable_cache }));
199
            }
200
		}
201
		else if(eventSource == combo_rank){
202
			getEntity().setRank(combo_rank.getSelection());
203
			clearCheckRankWarnings();
204
			updateContent();
205
		}
206
		else if(eventSource == text_appendedPhrase){
207
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
208
		}
209
		else if(eventSource == text_infragenericEpithet){
210
			getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
211
		}
212
		else if(eventSource == text_infraspecificEpithet){
213
			getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
214
		}
215
		else if(eventSource == text_specificEpithet){
216
			getEntity().setSpecificEpithet(text_specificEpithet.getText());
217
		}
218
		else if(eventSource == text_uninomial){
219
			getEntity().setGenusOrUninomial(text_uninomial.getText());
220
		}
221
		else if(eventSource == checkbox_anamorphic){
222
			((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
223
		}
224
	}
225

    
226
	/*
227
	 * (non-Javadoc)
228
	 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
229
	 */
230
	/**
231
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
232
	 *
233
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
234
	 */
235
	@Override
236
    public SelectionArbitrator getSelectionArbitrator() {
237
		return selectionArbitrator;
238
	}
239

    
240
	@Override
241
	public void updateToggleableCacheField() {
242
		if(! getEntity().isProtectedNameCache()){
243
			toggleable_cache.setText(getEntity().getNameCache());
244
		}
245
	}
246
}
(6-6/21)