Project

General

Profile

Download (10 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.common.TermType;
19
import eu.etaxonomy.cdm.model.name.BotanicalName;
20
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
21
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
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
26
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
28
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
29
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
30
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
31
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
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
37

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

    
47
    private final Logger logger = Logger.getLogger(NameDetailElement.class);
48

    
49
	private TermComboElement<Rank> combo_rank;
50
	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
	private NumberWithLabelElement text_publicationYear;
59
	private NumberWithLabelElement text_originalPublicationYear;
60
	private int cursorPosition;
61

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

    
78
	/** {@inheritDoc} */
79
	@Override
80
	protected void createControls(ICdmFormElement formElement, NonViralName nonViralName, int style) {
81

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

    
84
		combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
85

    
86
		createGenusOrUninomialControls(this, nonViralName, style);
87
		createInfragenerericEpithetControls(this, nonViralName, style);
88
		createSpecificEpithetControls(this, nonViralName, style);
89
		createInfraSpecificEpithetControls(this, nonViralName, style);
90

    
91
		createSpecificNameParts(this, nonViralName, style);
92

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

    
95
	}
96

    
97
	/**
98
	 * <p>clearCheckRankWarnings</p>
99
	 */
100
	protected void clearCheckRankWarnings() {
101
		if(getEntity().hasProblem(ParserProblem.CheckRank)){
102
			getEntity().removeParsingProblem(ParserProblem.CheckRank);
103

    
104
			// 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
		}
108
	}
109

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

    
117
		super.updateContent();
118

    
119
		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
		NomenclaturalCode code = nonViralName.getNomenclaturalCode();
130
		if (code != null){
131
			switch(nonViralName.getNomenclaturalCode()){
132
			case ICNAFP :
133
				// TODO RL
134
				if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL))
135
				{
136
					createBotanicalNameParts(formElement, nonViralName, style);
137
				}
138
				break;
139
			case ICZN:
140
				createZoologicalNameParts(formElement, nonViralName, style);
141
				break;
142
            case ICVCN:
143
                //TODO implement
144
                logger.warn("ICVCN not yet implemented");
145
                break;
146
            case ICNB:
147
                //TODO implement
148
                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
		}
156
	}
157

    
158
	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
		text_publicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Publication Year", zoologicalName.getPublicationYear(), style);
167
		text_originalPublicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Orig. Publication Year", zoologicalName.getOriginalPublicationYear(), style);
168
	}
169

    
170
	private void createGenusOrUninomialControls(ICdmFormElement element, NonViralName nonViralName, int style){
171
		String title = "Genus";
172
		Rank rank = nonViralName.getRank();
173
		if(rank != null && rank.isSupraGeneric()){
174
			title = "Uninomial";
175
		}
176
		text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
177
	}
178

    
179
	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

    
185
	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

    
191
	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

    
197
	/** {@inheritDoc} */
198
	@Override
199
	public void handleEvent(Object eventSource){
200
		if (eventSource == toggleable_cache) {
201
			getEntity().setNameCache(toggleable_cache.getText(),
202
					toggleable_cache.getState());
203
			if (!isIrrelevant()) {
204
                setIrrelevant(toggleable_cache.getState(),
205
						Arrays.asList(new Object[] { toggleable_cache }));
206
            }
207
		}
208
		else if(eventSource == combo_rank){
209
			getEntity().setRank(combo_rank.getSelection());
210
			clearCheckRankWarnings();
211
			updateContent();
212
		}
213
		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
		}
228
		else if(eventSource == checkbox_anamorphic){
229
			((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
230
		}
231
	}
232

    
233
	/*
234
	 * (non-Javadoc)
235
	 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
236
	 */
237
	/**
238
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
239
	 *
240
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
241
	 */
242
	@Override
243
    public SelectionArbitrator getSelectionArbitrator() {
244
		return selectionArbitrator;
245
	}
246

    
247
	@Override
248
	public void updateToggleableCacheField() {
249
		if(! getEntity().isProtectedNameCache()){
250
			toggleable_cache.setText(getEntity().getNameCache());
251
		}
252
	}
253
	
254
	@Override
255
	protected void handleToggleableCacheField() {
256
        boolean pushedState = toggleable_cache.getState();
257

    
258
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
259
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, text_appendedPhrase, checkbox_anamorphic }));
260
        updateToggleableCacheField();
261
    }	
262

    
263

    
264
}
(6-6/25)