Project

General

Profile

Download (7.31 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
package eu.etaxonomy.taxeditor.ui.section.name;
10

    
11
import java.util.Arrays;
12

    
13
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
14
import eu.etaxonomy.cdm.model.name.INonViralName;
15
import eu.etaxonomy.cdm.model.name.IZoologicalName;
16
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
17
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
18
import eu.etaxonomy.taxeditor.event.EventUtility;
19
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
20
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
21
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
26
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
27
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28

    
29
/**
30
 * AuthorshipDetailElement class.
31
 *
32
 * @author n.hoffmann
33
 * @created Mar 4, 2010
34
 */
35
public class AuthorshipDetailElement
36
		extends AbstractIdentifiableEntityDetailElement<INonViralName> {
37

    
38
    @SuppressWarnings("rawtypes")
39
    private EntitySelectionElement<TeamOrPersonBase> selectionExBasionymAuthor;
40
    @SuppressWarnings("rawtypes")
41
    private EntitySelectionElement<TeamOrPersonBase> selectionBasionymAuthor;
42
    @SuppressWarnings("rawtypes")
43
    private EntitySelectionElement<TeamOrPersonBase> selectionExCombinationAuthor;
44
    @SuppressWarnings("rawtypes")
45
    private EntitySelectionElement<TeamOrPersonBase> selectionCombinationAuthor;
46

    
47
    private NumberWithLabelElement text_publicationYear;
48
    private NumberWithLabelElement text_originalPublicationYear;
49

    
50
    /**
51
	 * Constructor for AuthorshipDetailElement.
52
	 */
53
	public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
54
			ICdmFormElement formElement, int style) {
55
		super(cdmFormFactory, formElement);
56
	}
57

    
58
	@Override
59
	protected void createControls(ICdmFormElement formElement,
60
			INonViralName entity, int style) {
61
	    NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
62
	    if (config == null || config.isAuthorCacheActivated()){
63
	        toggleable_cache = formFactory.createToggleableTextField(this,
64
				"Authorship Cache", entity.getAuthorshipCache(),
65
				entity.isProtectedAuthorshipCache(), style);
66
	        addElement(toggleable_cache);
67
	    }
68
	    NomenclaturalCode code = entity.getNameType();
69

    
70
	    if (config == null || config.isAuthorshipSectionActivated()){
71
            selectionCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
72
    				getConversationHolder(),
73
    				formElement, "Author",
74
    				entity.getCombinationAuthorship(),
75
    				EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
76
    		addElement(selectionCombinationAuthor);
77
    		selectionExCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
78
    				getConversationHolder(),
79
    				formElement, "Ex Author",
80
    				entity.getExCombinationAuthorship(),
81
    				EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
82
    		addElement(selectionExCombinationAuthor);
83
    		if (code != null){
84
                if (code.equals(NomenclaturalCode.ICZN)){
85
                    text_publicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Publication Year", ((IZoologicalName)entity).getPublicationYear(), style);
86
                }
87
            }
88
    		selectionBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
89
                    formElement, "Basionym Author", entity.getBasionymAuthorship(),
90
                    EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
91
    		addElement(selectionBasionymAuthor);
92
    		selectionExBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
93
    		        formElement, "Ex Basionym Author",entity.getExBasionymAuthorship(),
94
    		        EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
95

    
96
    		addElement(selectionExBasionymAuthor);
97
    		if (code != null){
98
    	        if (code.equals(NomenclaturalCode.ICZN)){
99
	                text_originalPublicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Orig. Publication Year", ((IZoologicalName)entity).getOriginalPublicationYear(), style);
100
	            }
101
    	    }
102
	    }
103
	}
104

    
105
    @Override
106
	public void updateContent() {
107
		if (getEntity() == null) {
108
			setEntity(TaxonNameFactory.NewNonViralInstance(null));
109
		}
110

    
111
		super.updateContent();
112
		if (toggleable_cache != null){
113
    		toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
114

    
115
    		if (this.isIrrelevant()) {
116
    			setIrrelevant(isIrrelevant());
117
    		} else {
118
    			setIrrelevant(toggleable_cache.getState(),
119
    					Arrays.asList(new Object[] { toggleable_cache }));
120
    		}
121
		}
122
	}
123

    
124
	@Override
125
	public void handleEvent(Object eventSource) {
126
		if (eventSource == toggleable_cache) {
127
			getEntity().setAuthorshipCache(toggleable_cache.getText(),
128
					toggleable_cache.getState());
129
			if (!isIrrelevant()){
130
				setIrrelevant(toggleable_cache.getState(),
131
						Arrays.asList(new Object[] { toggleable_cache }));
132
			}
133
		} else if (eventSource == selectionCombinationAuthor) {
134
			getEntity().setCombinationAuthorship(
135
					selectionCombinationAuthor.getSelection());
136
		} else if (eventSource == selectionExCombinationAuthor) {
137
			getEntity().setExCombinationAuthorship(
138
					selectionExCombinationAuthor.getSelection());
139
		} else if (eventSource == selectionBasionymAuthor) {
140
			getEntity().setBasionymAuthorship(
141
					selectionBasionymAuthor.getSelection());
142
		} else if (eventSource == selectionExBasionymAuthor) {
143
			getEntity().setExBasionymAuthorship(
144
					selectionExBasionymAuthor.getSelection());
145
		} else if (eventSource == text_originalPublicationYear) {
146
            ((IZoologicalName)getEntity()).setOriginalPublicationYear(text_originalPublicationYear.getInteger());
147
        } else if (eventSource == text_publicationYear) {
148
            ((IZoologicalName)getEntity()).setPublicationYear(text_publicationYear.getInteger());
149
        }
150

    
151
//		if (eventSource != toggleable_cache) {
152
//			toggleable_cache.setText(getEntity().getAuthorshipCache());
153
//		}
154

    
155
//		we have to notify the parent if this is embedded in the nonviral name
156
//		section
157
//		maybe we can handle this a little bit more elegant
158
//		if (getParentElement() instanceof AbstractCdmDetailSection)
159
			firePropertyChangeEvent(new CdmPropertyChangeEvent(
160
					getParentElement(), null));
161
			EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, this.getEntity());
162
	}
163

    
164
	@Override
165
	public void updateToggleableCacheField() {
166
	    if (toggleable_cache != null){
167
    		if(! getEntity().isProtectedAuthorshipCache()){
168
    			toggleable_cache.setText(getEntity().getAuthorshipCache());
169
    		}
170
	    }
171
	}
172
}
(2-2/21)