Project

General

Profile

Download (11.1 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
	    }else{
84
	    	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE)){
85
	    		toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
86
        	}
87
	    }
88
		combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
89
		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS)){
90
			createGenusOrUninomialControls(this, nonViralName, style);
91
			createInfragenerericEpithetControls(this, nonViralName, style);
92
			createSpecificEpithetControls(this, nonViralName, style);
93
			createInfraSpecificEpithetControls(this, nonViralName, style);
94
			createSpecificNameParts(this, nonViralName, style);
95
		}
96
		if (isAdvancedView){
97
		    //createSpecificNameParts(this, nonViralName, style);
98
			text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
99
		}else{
100
			if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE)){
101
				text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
102
        	}
103
		}
104
	}
105

    
106
	/**
107
	 * <p>clearCheckRankWarnings</p>
108
	 */
109
	protected void clearCheckRankWarnings() {
110
		if(getEntity().hasProblem(ParserProblem.CheckRank)){
111
			getEntity().removeParsingProblem(ParserProblem.CheckRank);
112

    
113
			// FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
114
//			TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
115
//			nameEditor.getSelectedContainer().getNameViewer().clearErrors();
116
		}
117
	}
118

    
119
	/** {@inheritDoc} */
120
	@Override
121
	protected void updateContent() {
122
		if(getEntity() == null){
123
			setEntity(NonViralName.NewInstance(null));
124
		}
125

    
126
		super.updateContent();
127
		if (isAdvancedView){
128
    		if(isIrrelevant()){
129
    			setIrrelevant(isIrrelevant());
130
    		}else{
131
    			setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
132
    		}
133
		}
134
	}
135

    
136

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

    
168
	private void createBotanicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
169
		BotanicalName botanicalName = (BotanicalName) nonViralName;
170
		checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", botanicalName.isAnamorphic(), style);
171
	}
172

    
173
	private void createZoologicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
174
		ZoologicalName zoologicalName = (ZoologicalName) nonViralName;
175

    
176
		if (isAdvancedView){
177
		    text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
178
		}
179
	}
180

    
181
	private void createGenusOrUninomialControls(ICdmFormElement element, NonViralName nonViralName, int style){
182
		String title = "Genus";
183
		Rank rank = nonViralName.getRank();
184
		if(rank != null && rank.isSupraGeneric()){
185
			title = "Uninomial";
186
		}
187
		text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
188
	}
189

    
190
	private void createInfragenerericEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
191
		if (nonViralName.getNomenclaturalCode() == null || nonViralName.getNomenclaturalCode().equals(NomenclaturalCode.ICZN)){
192
			if(nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS()) ){
193
				text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
194
			}
195
		} else{
196
			if((nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS())) && !nonViralName.getRank().isLower(Rank.SPECIES()) && !nonViralName.getRank().isSpeciesAggregate()){
197
				text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
198
			}
199
		}
200
	}
201

    
202
	private void createSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
203
		if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies()  || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
204
			text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
205
		}
206
	}
207

    
208
	private void createInfraSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
209
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
210
			text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
211
		}
212
	}
213

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

    
251
	}
252

    
253
	/*
254
	 * (non-Javadoc)
255
	 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
256
	 */
257
	/**
258
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
259
	 *
260
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
261
	 */
262
	@Override
263
    public SelectionArbitrator getSelectionArbitrator() {
264
		return selectionArbitrator;
265
	}
266

    
267
	@Override
268
	public void updateToggleableCacheField() {
269
	    if (toggleable_cache != null){
270
    		if(! getEntity().isProtectedNameCache()){
271
    			toggleable_cache.setText(getEntity().getNameCache());
272
    		}
273
	    }
274
	}
275

    
276
	@Override
277
	protected void handleToggleableCacheField() {
278
        boolean pushedState = toggleable_cache.getState();
279

    
280
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
281
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, text_appendedPhrase, checkbox_anamorphic }));
282
        updateToggleableCacheField();
283
    }
284

    
285

    
286

    
287

    
288
}
(6-6/25)