Project

General

Profile

Download (7.32 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 eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
15
import eu.etaxonomy.cdm.model.name.INonViralName;
16
import eu.etaxonomy.cdm.model.name.IZoologicalName;
17
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
19
import eu.etaxonomy.taxeditor.event.EventUtility;
20
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
21
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
22
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
27
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
28
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
29

    
30
/**
31
 * <p>
32
 * AuthorshipDetailElement class.
33
 * </p>
34
 *
35
 * @author n.hoffmann
36
 * @created Mar 4, 2010
37
 * @version 1.0
38
 */
39
public class AuthorshipDetailElement extends
40
	AbstractIdentifiableEntityDetailElement<INonViralName> {
41

    
42
    private EntitySelectionElement<TeamOrPersonBase> selectionExBasionymAuthor;
43
    private EntitySelectionElement<TeamOrPersonBase> selectionBasionymAuthor;
44
    private EntitySelectionElement<TeamOrPersonBase> selectionExCombinationAuthor;
45
    private EntitySelectionElement<TeamOrPersonBase> selectionCombinationAuthor;
46

    
47
    private NumberWithLabelElement text_publicationYear;
48
    private NumberWithLabelElement text_originalPublicationYear;
49
	/**
50
	 * <p>
51
	 * Constructor for AuthorshipDetailElement.
52
	 * </p>
53
	 *
54
	 * @param cdmFormFactory
55
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
56
	 *            object.
57
	 * @param formElement
58
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
59
	 *            object.
60
	 * @param style
61
	 *            a int.
62
	 */
63
	public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
64
			ICdmFormElement formElement, int style) {
65
		super(cdmFormFactory, formElement);
66
	}
67

    
68
	/** {@inheritDoc} */
69
	@Override
70
	protected void createControls(ICdmFormElement formElement,
71
			INonViralName entity, int style) {
72
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE)){
73
	        toggleable_cache = formFactory.createToggleableTextField(this,
74
				"Authorship Cache", entity.getAuthorshipCache(),
75
				entity.isProtectedAuthorshipCache(), style);
76
	        addElement(toggleable_cache);
77
	   }
78
	    NomenclaturalCode code = entity.getNomenclaturalCode();
79

    
80
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
81
            selectionCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
82
    				getConversationHolder(),
83
    				formElement, "Author",
84
    				entity.getCombinationAuthorship(),
85
    				EntitySelectionElement.ALL, style);
86
    		addElement(selectionCombinationAuthor);
87
    		selectionExCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
88
    				getConversationHolder(),
89
    				formElement, "Ex Author",
90
    				entity.getExCombinationAuthorship(),
91
    				EntitySelectionElement.ALL, style);
92
    		addElement(selectionExCombinationAuthor);
93
    		if (code != null){
94
                if (code.equals(NomenclaturalCode.ICZN)){
95
                    text_publicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Publication Year", ((IZoologicalName)entity).getPublicationYear(), style);
96

    
97
                }
98
             }
99
    		selectionBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
100
                    formElement, "Basionym Author", entity.getBasionymAuthorship(),
101
                    EntitySelectionElement.ALL, style);
102
    		addElement(selectionBasionymAuthor);
103
    		selectionExBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
104
    		        formElement, "Ex Basionym Author",entity.getExBasionymAuthorship(),
105
    		        EntitySelectionElement.ALL, style);
106

    
107
    		addElement(selectionExBasionymAuthor);
108
    		 if (code != null){
109
    	            if (code.equals(NomenclaturalCode.ICZN)){
110

    
111
    	                text_originalPublicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Orig. Publication Year", ((IZoologicalName)entity).getOriginalPublicationYear(), style);
112

    
113
    	            }
114
    	         }
115

    
116
	    }
117

    
118
	}
119

    
120
	/** {@inheritDoc} */
121
	@Override
122
	public void updateContent() {
123
		if (getEntity() == null) {
124
			setEntity(TaxonNameFactory.NewNonViralInstance(null));
125
		}
126

    
127
		super.updateContent();
128
		if (toggleable_cache != null){
129
    		toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
130

    
131

    
132
    		if (this.isIrrelevant()) {
133
    			setIrrelevant(isIrrelevant());
134
    		} else {
135
    			setIrrelevant(toggleable_cache.getState(),
136
    					Arrays.asList(new Object[] { toggleable_cache }));
137
    		}
138
		}
139
	}
140

    
141
	/** {@inheritDoc} */
142
	@Override
143
	public void handleEvent(Object eventSource) {
144
		if (eventSource == toggleable_cache) {
145
			getEntity().setAuthorshipCache(toggleable_cache.getText(),
146
					toggleable_cache.getState());
147
			if (!isIrrelevant()){
148
				setIrrelevant(toggleable_cache.getState(),
149
						Arrays.asList(new Object[] { toggleable_cache }));
150
			}
151
		} else if (eventSource == selectionCombinationAuthor) {
152
			getEntity().setCombinationAuthorship(
153
					selectionCombinationAuthor.getSelection());
154
		} else if (eventSource == selectionExCombinationAuthor) {
155
			getEntity().setExCombinationAuthorship(
156
					selectionExCombinationAuthor.getSelection());
157
		} else if (eventSource == selectionBasionymAuthor) {
158
			getEntity().setBasionymAuthorship(
159
					selectionBasionymAuthor.getSelection());
160
		} else if (eventSource == selectionExBasionymAuthor) {
161
			getEntity().setExBasionymAuthorship(
162
					selectionExBasionymAuthor.getSelection());
163
		} else if (eventSource == text_originalPublicationYear) {
164
            ((IZoologicalName)getEntity()).setOriginalPublicationYear(text_originalPublicationYear.getInteger());
165
        } else if (eventSource == text_publicationYear) {
166
            ((IZoologicalName)getEntity()).setPublicationYear(text_publicationYear.getInteger());
167
        }
168

    
169
//		if (eventSource != toggleable_cache) {
170
//			toggleable_cache.setText(getEntity().getAuthorshipCache());
171
//		}
172

    
173
//		 we have to notify the parent if this is embedded in the nonviral name
174
//		 section
175
//		 maybe we can handle this a little bit more elegant
176
//		if (getParentElement() instanceof AbstractCdmDetailSection)
177
			firePropertyChangeEvent(new CdmPropertyChangeEvent(
178
					getParentElement(), null));
179
			EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, true);
180
	}
181

    
182
	@Override
183
	public void updateToggleableCacheField() {
184
	    if (toggleable_cache != null){
185
    		if(! getEntity().isProtectedAuthorshipCache()){
186
    			toggleable_cache.setText(getEntity().getAuthorshipCache());
187
    		}
188
	    }
189
	}
190
}
(2-2/21)