Project

General

Profile

Download (5.82 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 eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
16
import eu.etaxonomy.cdm.model.name.NonViralName;
17
import eu.etaxonomy.taxeditor.model.AuthorHelper;
18
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.SelectionType;
23
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
24
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
25
import eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement;
26
import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
27

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

    
41
	private AbstractSelectionElement selection_exBasionymAuthorTeam;
42
	private AbstractSelectionElement selection_basionymAuthorTeam;
43
	private AbstractSelectionElement selection_exCombinationAuthorTeam;
44
	private AbstractSelectionElement selection_combinationAuthorTeam;
45

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

    
65
	/** {@inheritDoc} */
66
	@Override
67
	protected void createControls(ICdmFormElement formElement,
68
			NonViralName entity, int style) {
69
		toggleable_cache = formFactory.createToggleableTextField(this,
70
				"Authorship Cache", entity.getAuthorshipCache(),
71
				entity.isProtectedAuthorshipCache(), style);
72

    
73
		selection_combinationAuthorTeam = formFactory.createSelectionElement(
74
				SelectionType.AUTHOR_TEAM, getConversationHolder(),
75
				formElement, "Author",
76
				AuthorHelper.getAuthor(entity.getCombinationAuthorTeam()),
77
				NomenclaturalAuthorTeamSelectionElement.DEFAULT, style);
78
		addElement(selection_combinationAuthorTeam);
79
		selection_exCombinationAuthorTeam = formFactory.createSelectionElement(
80
				SelectionType.AUTHOR_TEAM, getConversationHolder(),
81
				formElement, "Ex Author",
82
				AuthorHelper.getAuthor(entity.getExCombinationAuthorTeam()),
83
				NomenclaturalAuthorTeamSelectionElement.DEFAULT, style);
84
		addElement(selection_exCombinationAuthorTeam);
85
		selection_basionymAuthorTeam = formFactory.createSelectionElement(
86
				SelectionType.AUTHOR_TEAM, getConversationHolder(),
87
				formElement, "Basionym Author",
88
				AuthorHelper.getAuthor(entity.getBasionymAuthorTeam()),
89
				NomenclaturalAuthorTeamSelectionElement.DEFAULT, style);
90
		addElement(selection_basionymAuthorTeam);
91
		selection_exBasionymAuthorTeam = formFactory.createSelectionElement(
92
				SelectionType.AUTHOR_TEAM, getConversationHolder(),
93
				formElement, "Ex Basionym Author",
94
				AuthorHelper.getAuthor(entity.getExBasionymAuthorTeam()),
95
				NomenclaturalAuthorTeamSelectionElement.DEFAULT, style);
96
		addElement(selection_exBasionymAuthorTeam);
97
	}
98

    
99
	/** {@inheritDoc} */
100
	@Override
101
	public void updateContent() {
102
		if (getEntity() == null) {
103
			setEntity(NonViralName.NewInstance(null));
104
		}
105
		NonViralName nonViralName = getEntity();
106

    
107
		super.updateContent();
108
		toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
109

    
110
		if (this.isIrrelevant()) {
111
			setIrrelevant(isIrrelevant());
112
		} else {
113
			setIrrelevant(toggleable_cache.getState(),
114
					Arrays.asList(new Object[] { toggleable_cache }));
115
		}
116
	}
117

    
118
	/** {@inheritDoc} */
119
	@Override
120
	public void handleEvent(Object eventSource) {
121
		if (eventSource == toggleable_cache) {
122
			getEntity().setAuthorshipCache(toggleable_cache.getText(),
123
					toggleable_cache.getState());
124
			if (!isIrrelevant())
125
				setIrrelevant(toggleable_cache.getState(),
126
						Arrays.asList(new Object[] { toggleable_cache }));
127
		} else if (eventSource == selection_combinationAuthorTeam) {
128
			getEntity().setCombinationAuthorTeam(
129
					(INomenclaturalAuthor) selection_combinationAuthorTeam
130
							.getSelection());
131
		} else if (eventSource == selection_exCombinationAuthorTeam) {
132
			getEntity().setExCombinationAuthorTeam(
133
					(INomenclaturalAuthor) selection_exCombinationAuthorTeam
134
							.getSelection());
135
		} else if (eventSource == selection_basionymAuthorTeam) {
136
			getEntity().setBasionymAuthorTeam(
137
					(INomenclaturalAuthor) selection_basionymAuthorTeam
138
							.getSelection());
139
		} else if (eventSource == selection_exBasionymAuthorTeam) {
140
			getEntity().setExBasionymAuthorTeam(
141
					(INomenclaturalAuthor) selection_exBasionymAuthorTeam
142
							.getSelection());
143
		}
144

    
145
//		if (eventSource != toggleable_cache) {
146
//			toggleable_cache.setText(getEntity().getAuthorshipCache());
147
//		}
148

    
149
//		 we have to notify the parent if this is embedded in the nonviral name
150
//		 section
151
//		 maybe we can handle this a little bit more elegant
152
//		if (getParentElement() instanceof AbstractCdmDetailSection)
153
			firePropertyChangeEvent(new CdmPropertyChangeEvent(
154
					getParentElement(), null));
155
	}
156
	
157
	@Override
158
	public void updateToggleableCacheField() {
159
		if(! getEntity().isProtectedAuthorshipCache()){
160
			toggleable_cache.setText(getEntity().getAuthorshipCache());
161
		}
162
	}
163
}
(2-2/21)