Project

General

Profile

Download (11.8 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.ui.section.name;
11

    
12
import java.util.Arrays;
13

    
14
import org.apache.log4j.Logger;
15
import org.eclipse.swt.SWT;
16

    
17
import eu.etaxonomy.cdm.model.common.TermType;
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.TaxonNameBase;
23
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
24
import eu.etaxonomy.cdm.model.name.ZoologicalName;
25
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
26
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
28
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
29
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
30
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
31
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
32
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
33
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
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
	    if (isAdvancedView){
83
	    	toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
84
	    	combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
85
	    	createGenusOrUninomialControls(this, nonViralName, style);
86
            createInfragenerericEpithetControls(this, nonViralName, style);
87
            createSpecificEpithetControls(this, nonViralName, style);
88
            createInfraSpecificEpithetControls(this, nonViralName, style);
89
            createSpecificNameParts(this, nonViralName, style);
90
            text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
91
	    }else{
92
	    	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE)){
93
	    		toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
94
        	}
95

    
96
    	    if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK)){
97
    	        combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
98
    	    }
99

    
100
    		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS)){
101
    			createGenusOrUninomialControls(this, nonViralName, style);
102
    			createInfragenerericEpithetControls(this, nonViralName, style);
103
    			createSpecificEpithetControls(this, nonViralName, style);
104
    			createInfraSpecificEpithetControls(this, nonViralName, style);
105
    			createSpecificNameParts(this, nonViralName, style);
106
    		}
107
    		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE)){
108
    				text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
109
           	}
110
	    }
111
	}
112

    
113
	/**
114
	 * <p>clearCheckRankWarnings</p>
115
	 */
116
	protected void clearCheckRankWarnings() {
117
		if(getEntity().hasProblem(ParserProblem.CheckRank)){
118
			getEntity().removeParsingProblem(ParserProblem.CheckRank);
119

    
120
			// FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
121
//			TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
122
//			nameEditor.getSelectedContainer().getNameViewer().clearErrors();
123
		}
124
	}
125

    
126
	/** {@inheritDoc} */
127
	@Override
128
	protected void updateContent() {
129
		if(getEntity() == null){
130
			setEntity(TaxonNameFactory.NewNonViralInstance(null));
131
		}
132

    
133
		super.updateContent();
134
		if (isAdvancedView){
135
    		if(isIrrelevant()){
136
    			setIrrelevant(isIrrelevant());
137
    		}else{
138
    			setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
139
    		}
140
		}
141
	}
142

    
143

    
144
	private void createSpecificNameParts(ICdmFormElement formElement,
145
			NonViralName nonViralName, int style) {
146
		NomenclaturalCode code = nonViralName.getNomenclaturalCode();
147
		if (code != null){
148
			switch(nonViralName.getNomenclaturalCode()){
149
			case ICNAFP :
150
				// TODO RL
151
				if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL) && isAdvancedView)
152
				{
153
					createBotanicalNameParts(formElement, nonViralName, style);
154
				}
155
				break;
156
			case ICZN:
157
				createZoologicalNameParts(formElement, nonViralName, style);
158
				break;
159
            case ICVCN:
160
                //TODO implement
161
                logger.warn("ICVCN not yet implemented");
162
                break;
163
            case ICNB:
164
                //TODO implement
165
                logger.warn("ICNB not yet implemented");
166
                break;
167
            case ICNCP:
168
                //TODO implement
169
                logger.warn("ICNCP not yet implemented");
170
                break;
171
            }
172
		}
173
	}
174

    
175
	private void createBotanicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
176
		BotanicalName botanicalName = (BotanicalName) nonViralName;
177
		checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", botanicalName.isAnamorphic(), style);
178
	}
179

    
180
	private void createZoologicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
181
		ZoologicalName zoologicalName = (ZoologicalName) nonViralName;
182

    
183
		if (isAdvancedView){
184
		    text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
185
		}
186
	}
187

    
188
	private void createGenusOrUninomialControls(ICdmFormElement element, NonViralName nonViralName, int style){
189
		String title = "Genus";
190
		Rank rank = nonViralName.getRank();
191
		if(rank != null && rank.isSupraGeneric()){
192
			title = "Uninomial";
193
		}
194
		text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
195
	}
196

    
197
	private void createInfragenerericEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
198
		if (nonViralName.getNomenclaturalCode() == null || nonViralName.getNomenclaturalCode().equals(NomenclaturalCode.ICZN)){
199
			if(nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS()) ){
200
				text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
201
			}
202
		} else{
203
			if((nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS())) && !nonViralName.getRank().isLower(Rank.SPECIES()) && !nonViralName.getRank().isSpeciesAggregate()){
204
				text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
205
			}
206
		}
207
	}
208

    
209
	private void createSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
210
		if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies()  || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
211
			text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
212
		}
213
	}
214

    
215
	private void createInfraSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
216
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
217
			text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
218
		}
219
	}
220

    
221
	/** {@inheritDoc} */
222
	@Override
223
	public void handleEvent(Object eventSource){
224
		if (eventSource == toggleable_cache) {
225
			getEntity().setNameCache(toggleable_cache.getText(),
226
					toggleable_cache.getState());
227
			if (!isIrrelevant()) {
228
                setIrrelevant(toggleable_cache.getState(),
229
						Arrays.asList(new Object[] { toggleable_cache }));
230
            }
231
		}
232
		else if(eventSource == combo_rank){
233
			getEntity().setRank(combo_rank.getSelection());
234
			clearCheckRankWarnings();
235
			updateContent();
236
		}
237
		else if(eventSource == text_appendedPhrase){
238
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
239
		}
240
		else if(eventSource == text_infragenericEpithet){
241
			getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
242
		}
243
		else if(eventSource == text_infraspecificEpithet){
244
			getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
245
		}
246
		else if(eventSource == text_specificEpithet){
247
			getEntity().setSpecificEpithet(text_specificEpithet.getText());
248
		}
249
		else if(eventSource == text_uninomial){
250
			getEntity().setGenusOrUninomial(text_uninomial.getText());
251
		}
252
		else if(eventSource == checkbox_anamorphic){
253
			((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
254
		}else if(eventSource == text_breed){
255
            ((ZoologicalName)getEntity()).setBreed(text_breed.getText());
256
        }
257

    
258
	}
259

    
260
	/*
261
	 * (non-Javadoc)
262
	 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
263
	 */
264
	/**
265
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
266
	 *
267
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
268
	 */
269
	@Override
270
    public SelectionArbitrator getSelectionArbitrator() {
271
		return selectionArbitrator;
272
	}
273

    
274
	@Override
275
	public void updateToggleableCacheField() {
276
	    if (toggleable_cache != null){
277
    		if(! getEntity().isProtectedNameCache()){
278
    			toggleable_cache.setText(getEntity().getNameCache());
279
    		}
280
	    }
281
	}
282

    
283
	@Override
284
	protected void handleToggleableCacheField() {
285
        boolean pushedState = toggleable_cache.getState();
286

    
287
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
288
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, text_appendedPhrase, checkbox_anamorphic }));
289
        updateToggleableCacheField();
290
    }
291

    
292

    
293

    
294

    
295
}
(6-6/21)