Project

General

Profile

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

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

    
40
	private NomenclaturalAuthorTeamSelectionElement selection_exBasionymAuthorTeam;
41
	private NomenclaturalAuthorTeamSelectionElement selection_basionymAuthorTeam;
42
	private NomenclaturalAuthorTeamSelectionElement selection_exCombinationAuthorTeam;
43
	private NomenclaturalAuthorTeamSelectionElement selection_combinationAuthorTeam;
44

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

    
64
	/** {@inheritDoc} */
65
	@Override
66
	protected void createControls(ICdmFormElement formElement,
67
			NonViralName entity, int style) {
68
		toggleable_cache = formFactory.createToggleableTextField(this,
69
				"Authorship Cache", entity.getAuthorshipCache(),
70
				entity.isProtectedAuthorshipCache(), style);
71
		selection_combinationAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
72
				getConversationHolder(),
73
				formElement, "Author",
74
				AuthorHelper.getAuthor(entity.getCombinationAuthorTeam()),
75
				EntitySelectionElement.ALL, style);
76
		addElement(selection_combinationAuthorTeam);
77
		selection_exCombinationAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
78
				getConversationHolder(),
79
				formElement, "Ex Author",
80
				AuthorHelper.getAuthor(entity.getExCombinationAuthorTeam()),
81
				EntitySelectionElement.ALL, style);
82
		addElement(selection_exCombinationAuthorTeam);
83
		selection_basionymAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
84
				getConversationHolder(),
85
				formElement, "Basionym Author",
86
				AuthorHelper.getAuthor(entity.getBasionymAuthorTeam()),
87
				EntitySelectionElement.ALL, style);
88
		addElement(selection_basionymAuthorTeam);
89
		selection_exBasionymAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
90
				getConversationHolder(),
91
				formElement, "Ex Basionym Author",
92
				AuthorHelper.getAuthor(entity.getExBasionymAuthorTeam()),
93
				EntitySelectionElement.ALL, style);
94
		addElement(selection_exBasionymAuthorTeam);
95
	}
96

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

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

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

    
142
//		if (eventSource != toggleable_cache) {
143
//			toggleable_cache.setText(getEntity().getAuthorshipCache());
144
//		}
145

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