Project

General

Profile

Download (12.8 KB) Statistics
| Branch: | Tag: | Revision:
1 729887cf n.hoffmann
/**
2
* Copyright (C) 2007 EDIT
3 0f595da2 Patric Plitzner
* European Distributed Institute of Taxonomy
4 729887cf n.hoffmann
* http://www.e-taxonomy.eu
5 0f595da2 Patric Plitzner
*
6 729887cf n.hoffmann
* 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 f211dd28 n.hoffmann
package eu.etaxonomy.taxeditor.ui.section.name;
11 729887cf n.hoffmann
12
import java.util.Arrays;
13 a452be91 Katja Luther
import java.util.Collection;
14 b32cbeab Katja Luther
import java.util.Comparator;
15 729887cf n.hoffmann
16 0f595da2 Patric Plitzner
import org.apache.log4j.Logger;
17 729887cf n.hoffmann
import org.eclipse.swt.SWT;
18
19 ccc7ac6f Patric Plitzner
import eu.etaxonomy.cdm.model.common.TermType;
20 e3a4a3ff Andreas Müller
import eu.etaxonomy.cdm.model.name.IFungusName;
21
import eu.etaxonomy.cdm.model.name.INonViralName;
22
import eu.etaxonomy.cdm.model.name.IZoologicalName;
23 5f7b8a18 Andreas Müller
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
24 729887cf n.hoffmann
import eu.etaxonomy.cdm.model.name.Rank;
25 e48774bc Andreas Müller
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
26 729887cf n.hoffmann
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
27 4db49a38 Alexander Oppermann
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
28
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
29 b9a0d300 l.morris
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
30 78222507 n.hoffmann
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
31
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
32 dacb59c9 Patric Plitzner
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
33 78222507 n.hoffmann
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
34
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
35
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
36
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
37 89f83939 n.hoffmann
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
38 729887cf n.hoffmann
39
/**
40 3be6ef3e n.hoffmann
 * <p>NameDetailElement class.</p>
41
 *
42 729887cf n.hoffmann
 * @author n.hoffmann
43
 * @created Feb 26, 2010
44
 */
45 e3a4a3ff Andreas Müller
public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<INonViralName> implements ISelectableElement, IEnableableFormElement{
46 729887cf n.hoffmann
47 0f595da2 Patric Plitzner
    private final Logger logger = Logger.getLogger(NameDetailElement.class);
48
49 b9a0d300 l.morris
	private TermComboElement<Rank> combo_rank;
50 729887cf n.hoffmann
	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 32e6766e Katja Luther
	//private NumberWithLabelElement text_publicationYear;
59
	//private NumberWithLabelElement text_originalPublicationYear;
60 729887cf n.hoffmann
	private int cursorPosition;
61 0f595da2 Patric Plitzner
62 3be6ef3e n.hoffmann
	/**
63
	 * <p>Constructor for NameDetailElement.</p>
64
	 *
65 78222507 n.hoffmann
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
66
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
67 3be6ef3e n.hoffmann
	 * @param style a int.
68
	 */
69 729887cf n.hoffmann
	public NameDetailElement(CdmFormFactory cdmFormFactory, ICdmFormElement formElement,
70
			int style) {
71
		super(cdmFormFactory, formElement);
72 0bae5e5a Patrick Plitzner
		// make this element selectable
73 729887cf n.hoffmann
		if(cdmFormFactory.getSelectionProvider() != null){
74
			selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
75
		}
76
	}
77
78 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
79 729887cf n.hoffmann
	@Override
80 e3a4a3ff Andreas Müller
	protected void createControls(ICdmFormElement formElement, INonViralName nonViralName, int style) {
81 b32cbeab Katja Luther
		Comparator<Rank> comparator = null;
82
		if(PreferencesUtil.getSortRanksHierarchichally()){
83
			comparator = new Comparator<Rank>(){
84 0f595da2 Patric Plitzner
85 b32cbeab Katja Luther
			@Override
86
			public int compare(Rank o1, Rank o2) {
87
				return o2.compareTo(o1);
88
			}
89
90
		};
91
		}
92 1bfcc747 Katja Luther
	    if (isAdvancedView){
93 76b874f8 Katja Luther
	    	toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
94 b32cbeab Katja Luther
	    	
95
	    	combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style, comparator);
96 fa39cfe4 Katja Luther
	    	createGenusOrUninomialControls(this, nonViralName, style);
97
            createInfragenerericEpithetControls(this, nonViralName, style);
98
            createSpecificEpithetControls(this, nonViralName, style);
99
            createInfraSpecificEpithetControls(this, nonViralName, style);
100
            createSpecificNameParts(this, nonViralName, style);
101
            text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
102 76b874f8 Katja Luther
	    }else{
103
	    	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE)){
104
	    		toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
105
        	}
106 fa39cfe4 Katja Luther
107
    	    if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK)){
108 b32cbeab Katja Luther
    	        combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style, comparator);
109 fa39cfe4 Katja Luther
    	    }
110
111
    		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS)){
112
    			createGenusOrUninomialControls(this, nonViralName, style);
113
    			createInfragenerericEpithetControls(this, nonViralName, style);
114
    			createSpecificEpithetControls(this, nonViralName, style);
115
    			createInfraSpecificEpithetControls(this, nonViralName, style);
116
    			createSpecificNameParts(this, nonViralName, style);
117
    		}
118
    		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE)){
119
    				text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
120
           	}
121 1bfcc747 Katja Luther
	    }
122 a452be91 Katja Luther
123 729887cf n.hoffmann
	}
124
125 3be6ef3e n.hoffmann
	/**
126
	 * <p>clearCheckRankWarnings</p>
127
	 */
128 729887cf n.hoffmann
	protected void clearCheckRankWarnings() {
129
		if(getEntity().hasProblem(ParserProblem.CheckRank)){
130
			getEntity().removeParsingProblem(ParserProblem.CheckRank);
131 0f595da2 Patric Plitzner
132 f211dd28 n.hoffmann
			// FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
133
//			TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
134
//			nameEditor.getSelectedContainer().getNameViewer().clearErrors();
135 729887cf n.hoffmann
		}
136
	}
137 0f595da2 Patric Plitzner
138 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
139 729887cf n.hoffmann
	@Override
140
	protected void updateContent() {
141
		if(getEntity() == null){
142 e48774bc Andreas Müller
			setEntity(TaxonNameFactory.NewNonViralInstance(null));
143 729887cf n.hoffmann
		}
144 0f595da2 Patric Plitzner
145 729887cf n.hoffmann
		super.updateContent();
146 994548e2 Katja Luther
		if (toggleable_cache != null){
147
		    toggleable_cache.setEnabled(getEntity().isProtectedNameCache());
148
149
    		if (isAdvancedView){
150
        		if(isIrrelevant()){
151
        			setIrrelevant(isIrrelevant());
152
        		}else{
153
        			setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
154
        		}
155 1bfcc747 Katja Luther
    		}
156 729887cf n.hoffmann
		}
157
	}
158
159
160
	private void createSpecificNameParts(ICdmFormElement formElement,
161 e3a4a3ff Andreas Müller
			INonViralName nonViralName, int style) {
162 5f7b8a18 Andreas Müller
		NomenclaturalCode code = nonViralName.getNomenclaturalCode();
163
		if (code != null){
164
			switch(nonViralName.getNomenclaturalCode()){
165 49a64920 Cherian Mathew
			case ICNAFP :
166 e3a4a3ff Andreas Müller
				//nothing do add
167
				createBotanicalNameParts(formElement, nonViralName, style);
168
				break;
169
			case Fungi :
170
				if (isAdvancedView){
171
					createFungusNameParts(formElement, nonViralName, style);
172 4db49a38 Alexander Oppermann
				}
173 5f7b8a18 Andreas Müller
				break;
174
			case ICZN:
175
				createZoologicalNameParts(formElement, nonViralName, style);
176
				break;
177 5a35a97d Patric Plitzner
            case ICVCN:
178 0f595da2 Patric Plitzner
                //TODO implement
179 5a35a97d Patric Plitzner
                logger.warn("ICVCN not yet implemented");
180
                break;
181
            case ICNB:
182 0f595da2 Patric Plitzner
                //TODO implement
183 5a35a97d Patric Plitzner
                logger.warn("ICNB not yet implemented");
184
                break;
185
            case ICNCP:
186
                //TODO implement
187
                logger.warn("ICNCP not yet implemented");
188
                break;
189 2ffb3ef3 Patrick Plitzner
            case NonViral:
190
                //TODO implement
191
                logger.warn("NonViral not yet implemented");
192
                break;
193 5a35a97d Patric Plitzner
            }
194 729887cf n.hoffmann
		}
195
	}
196 0f595da2 Patric Plitzner
197 2ffb3ef3 Patrick Plitzner
198 e3a4a3ff Andreas Müller
	private void createBotanicalNameParts(ICdmFormElement formElement, INonViralName nonViralName, int style){
199
		//nothing to do
200
	}
201 2ffb3ef3 Patrick Plitzner
202 e3a4a3ff Andreas Müller
	private void createFungusNameParts(ICdmFormElement formElement, INonViralName nonViralName, int style){
203
		IFungusName fungusName = (IFungusName)nonViralName;
204
		checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", fungusName.isAnamorphic(), style);
205 729887cf n.hoffmann
	}
206
207 e3a4a3ff Andreas Müller
	private void createZoologicalNameParts(ICdmFormElement formElement, INonViralName nonViralName, int style){
208
		IZoologicalName zoologicalName = (IZoologicalName) nonViralName;
209 32e6766e Katja Luther
210 c7a160ba Katja Luther
		if (isAdvancedView){
211
		    text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
212
		}
213 729887cf n.hoffmann
	}
214 0f595da2 Patric Plitzner
215 e3a4a3ff Andreas Müller
	private void createGenusOrUninomialControls(ICdmFormElement element, INonViralName nonViralName, int style){
216 729887cf n.hoffmann
		String title = "Genus";
217
		Rank rank = nonViralName.getRank();
218
		if(rank != null && rank.isSupraGeneric()){
219 0f595da2 Patric Plitzner
			title = "Uninomial";
220 729887cf n.hoffmann
		}
221
		text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
222
	}
223 0f595da2 Patric Plitzner
224 e3a4a3ff Andreas Müller
	private void createInfragenerericEpithetControls(ICdmFormElement element, INonViralName nonViralName, int style){
225 e29e2ebd Katja Luther
		if (nonViralName.getNomenclaturalCode() == null || nonViralName.getNomenclaturalCode().equals(NomenclaturalCode.ICZN)){
226 288cde13 Katja Luther
			if(nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS()) ){
227
				text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
228
			}
229
		} else{
230
			if((nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS())) && !nonViralName.getRank().isLower(Rank.SPECIES()) && !nonViralName.getRank().isSpeciesAggregate()){
231
				text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
232
			}
233 729887cf n.hoffmann
		}
234
	}
235 0f595da2 Patric Plitzner
236 e3a4a3ff Andreas Müller
	private void createSpecificEpithetControls(ICdmFormElement element, INonViralName nonViralName, int style){
237 729887cf n.hoffmann
		if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies()  || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
238
			text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
239
		}
240
	}
241 0f595da2 Patric Plitzner
242 e3a4a3ff Andreas Müller
	private void createInfraSpecificEpithetControls(ICdmFormElement element, INonViralName nonViralName, int style){
243 729887cf n.hoffmann
		if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
244
			text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
245
		}
246
	}
247 0f595da2 Patric Plitzner
248 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
249 729887cf n.hoffmann
	@Override
250
	public void handleEvent(Object eventSource){
251 bc10e3ef n.hoffmann
		if (eventSource == toggleable_cache) {
252
			getEntity().setNameCache(toggleable_cache.getText(),
253
					toggleable_cache.getState());
254 a452be91 Katja Luther
			//if (!isIrrelevant()) {
255 0f595da2 Patric Plitzner
                setIrrelevant(toggleable_cache.getState(),
256 bc10e3ef n.hoffmann
						Arrays.asList(new Object[] { toggleable_cache }));
257 a452be91 Katja Luther
            //}
258 bc10e3ef n.hoffmann
		}
259
		else if(eventSource == combo_rank){
260 729887cf n.hoffmann
			getEntity().setRank(combo_rank.getSelection());
261 e0b35bf1 n.hoffmann
			clearCheckRankWarnings();
262
			updateContent();
263 0f595da2 Patric Plitzner
		}
264 729887cf n.hoffmann
		else if(eventSource == text_appendedPhrase){
265
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
266
		}
267
		else if(eventSource == text_infragenericEpithet){
268
			getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
269
		}
270
		else if(eventSource == text_infraspecificEpithet){
271
			getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
272
		}
273
		else if(eventSource == text_specificEpithet){
274
			getEntity().setSpecificEpithet(text_specificEpithet.getText());
275
		}
276
		else if(eventSource == text_uninomial){
277
			getEntity().setGenusOrUninomial(text_uninomial.getText());
278 0f595da2 Patric Plitzner
		}
279 729887cf n.hoffmann
		else if(eventSource == checkbox_anamorphic){
280 e3a4a3ff Andreas Müller
			((IFungusName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
281 32e6766e Katja Luther
		}else if(eventSource == text_breed){
282 e3a4a3ff Andreas Müller
            ((IZoologicalName)getEntity()).setBreed(text_breed.getText());
283 32e6766e Katja Luther
        }
284
285 729887cf n.hoffmann
	}
286 0f595da2 Patric Plitzner
287 729887cf n.hoffmann
	/*
288
	 * (non-Javadoc)
289
	 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
290
	 */
291 3be6ef3e n.hoffmann
	/**
292
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
293
	 *
294 78222507 n.hoffmann
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
295 3be6ef3e n.hoffmann
	 */
296 0f595da2 Patric Plitzner
	@Override
297
    public SelectionArbitrator getSelectionArbitrator() {
298 729887cf n.hoffmann
		return selectionArbitrator;
299
	}
300 0f595da2 Patric Plitzner
301 89f83939 n.hoffmann
	@Override
302
	public void updateToggleableCacheField() {
303 1bfcc747 Katja Luther
	    if (toggleable_cache != null){
304
    		if(! getEntity().isProtectedNameCache()){
305
    			toggleable_cache.setText(getEntity().getNameCache());
306
    		}
307
	    }
308 89f83939 n.hoffmann
	}
309 1bfcc747 Katja Luther
310 d812f38a Katja Luther
	@Override
311
	protected void handleToggleableCacheField() {
312
        boolean pushedState = toggleable_cache.getState();
313
314
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
315
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, text_appendedPhrase, checkbox_anamorphic }));
316
        updateToggleableCacheField();
317 1bfcc747 Katja Luther
    }
318
319 a452be91 Katja Luther
	@Override
320
	public void setIrrelevant(boolean irrelevant, Collection<Object> except){
321
	    if (toggleable_cache != null){
322
    	    if (toggleable_cache.getState() == irrelevant){
323
    	        super.setIrrelevant(irrelevant, except);
324
    	    }
325
    	    if (except == null || except.isEmpty()){
326
    	        toggleable_cache.setIrrelevant(irrelevant);
327
    	    }
328
	    }
329
330
	}
331
332 1bfcc747 Katja Luther
333 d812f38a Katja Luther
334
335 729887cf n.hoffmann
}