Project

General

Profile

Download (10.4 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.SelectionArbitrator;
34
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
35
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
36

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

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

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

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

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

    
81
	    if (isAdvancedView){
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
		createSpecificNameParts(this, nonViralName, style);
91
		if (isAdvancedView){
92
		    //createSpecificNameParts(this, nonViralName, style);
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
		if (isAdvancedView){
119
    		if(isIrrelevant()){
120
    			setIrrelevant(isIrrelevant());
121
    		}else{
122
    			setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
123
    		}
124
		}
125
	}
126

    
127

    
128
	private void createSpecificNameParts(ICdmFormElement formElement,
129
			NonViralName nonViralName, int style) {
130
		NomenclaturalCode code = nonViralName.getNomenclaturalCode();
131
		if (code != null){
132
			switch(nonViralName.getNomenclaturalCode()){
133
			case ICNAFP :
134
				// TODO RL
135
				if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL) && isAdvancedView)
136
				{
137
					createBotanicalNameParts(formElement, nonViralName, style);
138
				}
139
				break;
140
			case ICZN:
141
				createZoologicalNameParts(formElement, nonViralName, style);
142
				break;
143
            case ICVCN:
144
                //TODO implement
145
                logger.warn("ICVCN not yet implemented");
146
                break;
147
            case ICNB:
148
                //TODO implement
149
                logger.warn("ICNB not yet implemented");
150
                break;
151
            case ICNCP:
152
                //TODO implement
153
                logger.warn("ICNCP not yet implemented");
154
                break;
155
            }
156
		}
157
	}
158

    
159
	private void createBotanicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
160
		BotanicalName botanicalName = (BotanicalName) nonViralName;
161
		checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", botanicalName.isAnamorphic(), style);
162
	}
163

    
164
	private void createZoologicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
165
		ZoologicalName zoologicalName = (ZoologicalName) nonViralName;
166

    
167
		if (isAdvancedView){
168
		    text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
169
		}
170
	}
171

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

    
181
	private void createInfragenerericEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
182
		if (nonViralName.getNomenclaturalCode().equals(NomenclaturalCode.ICZN)){
183
			if(nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS()) ){
184
				text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
185
			}
186
		} else{
187
			if((nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS())) && !nonViralName.getRank().isLower(Rank.SPECIES()) && !nonViralName.getRank().isSpeciesAggregate()){
188
				text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
189
			}
190
		}
191
	}
192

    
193
	private void createSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
194
		if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies()  || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
195
			text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
196
		}
197
	}
198

    
199
	private void createInfraSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
200
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
201
			text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
202
		}
203
	}
204

    
205
	/** {@inheritDoc} */
206
	@Override
207
	public void handleEvent(Object eventSource){
208
		if (eventSource == toggleable_cache) {
209
			getEntity().setNameCache(toggleable_cache.getText(),
210
					toggleable_cache.getState());
211
			if (!isIrrelevant()) {
212
                setIrrelevant(toggleable_cache.getState(),
213
						Arrays.asList(new Object[] { toggleable_cache }));
214
            }
215
		}
216
		else if(eventSource == combo_rank){
217
			getEntity().setRank(combo_rank.getSelection());
218
			clearCheckRankWarnings();
219
			updateContent();
220
		}
221
		else if(eventSource == text_appendedPhrase){
222
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
223
		}
224
		else if(eventSource == text_infragenericEpithet){
225
			getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
226
		}
227
		else if(eventSource == text_infraspecificEpithet){
228
			getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
229
		}
230
		else if(eventSource == text_specificEpithet){
231
			getEntity().setSpecificEpithet(text_specificEpithet.getText());
232
		}
233
		else if(eventSource == text_uninomial){
234
			getEntity().setGenusOrUninomial(text_uninomial.getText());
235
		}
236
		else if(eventSource == checkbox_anamorphic){
237
			((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
238
		}else if(eventSource == text_breed){
239
            ((ZoologicalName)getEntity()).setBreed(text_breed.getText());
240
        }
241

    
242
	}
243

    
244
	/*
245
	 * (non-Javadoc)
246
	 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
247
	 */
248
	/**
249
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
250
	 *
251
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
252
	 */
253
	@Override
254
    public SelectionArbitrator getSelectionArbitrator() {
255
		return selectionArbitrator;
256
	}
257

    
258
	@Override
259
	public void updateToggleableCacheField() {
260
	    if (toggleable_cache != null){
261
    		if(! getEntity().isProtectedNameCache()){
262
    			toggleable_cache.setText(getEntity().getNameCache());
263
    		}
264
	    }
265
	}
266

    
267
	@Override
268
	protected void handleToggleableCacheField() {
269
        boolean pushedState = toggleable_cache.getState();
270

    
271
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
272
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, text_appendedPhrase, checkbox_anamorphic }));
273
        updateToggleableCacheField();
274
    }
275

    
276

    
277

    
278

    
279
}
(6-6/25)