3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.section
.name
;
13 import java
.util
.Arrays
;
15 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
16 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
17 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
18 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
19 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
21 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
;
22 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
.SelectionType
;
23 import eu
.etaxonomy
.taxeditor
.forms
.CdmPropertyChangeEvent
;
24 import eu
.etaxonomy
.taxeditor
.forms
.ICdmFormElement
;
25 import eu
.etaxonomy
.taxeditor
.forms
.IEnableableFormElement
;
26 import eu
.etaxonomy
.taxeditor
.forms
.ToggleableTextElement
;
27 import eu
.etaxonomy
.taxeditor
.forms
.selection
.AbstractSelectionElement
;
28 import eu
.etaxonomy
.taxeditor
.model
.AuthorHelper
;
29 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailElement
;
30 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailSection
;
33 * <p>AuthorshipDetailElement class.</p>
36 * @created Mar 4, 2010
39 public class AuthorshipDetailElement
extends AbstractCdmDetailElement
<NonViralName
> implements IEnableableFormElement
{
41 private ToggleableTextElement toggleable_cache
;
43 private AbstractSelectionElement selection_exBasionymAuthorTeam
;
44 private AbstractSelectionElement selection_basionymAuthorTeam
;
45 private AbstractSelectionElement selection_exCombinationAuthorTeam
;
46 private AbstractSelectionElement selection_combinationAuthorTeam
;
49 * <p>Constructor for AuthorshipDetailElement.</p>
51 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
52 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
55 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory
,
56 ICdmFormElement formElement
, int style
) {
57 super(cdmFormFactory
, formElement
);
62 protected void createControls(ICdmFormElement formElement
, NonViralName entity
, int style
) {
63 toggleable_cache
= formFactory
.createToggleableTextField(this, "Authorship Cache", entity
.getAuthorshipCache(), entity
.isProtectedAuthorshipCache(), style
);
65 selection_combinationAuthorTeam
= formFactory
.createSelectionElement(SelectionType
.AUTHOR_TEAM
, getConversationHolder(),
66 formElement
, "Author", AuthorHelper
.getAuthor(entity
.getCombinationAuthorTeam()), style
);
67 addElement(selection_combinationAuthorTeam
);
68 selection_exCombinationAuthorTeam
= formFactory
.createSelectionElement(SelectionType
.AUTHOR_TEAM
, getConversationHolder(),
69 formElement
, "Ex Author", AuthorHelper
.getAuthor(entity
.getExCombinationAuthorTeam()), style
);
70 addElement(selection_exCombinationAuthorTeam
);
71 selection_basionymAuthorTeam
= formFactory
.createSelectionElement(SelectionType
.AUTHOR_TEAM
, getConversationHolder(),
72 formElement
, "Basionym Author", AuthorHelper
.getAuthor(entity
.getBasionymAuthorTeam()), style
);
73 addElement(selection_basionymAuthorTeam
);
74 selection_exBasionymAuthorTeam
= formFactory
.createSelectionElement(SelectionType
.AUTHOR_TEAM
, getConversationHolder(),
75 formElement
, "Ex Basionym Author", AuthorHelper
.getAuthor(entity
.getExBasionymAuthorTeam()), style
);
76 addElement(selection_exBasionymAuthorTeam
);
81 public void updateContent() {
82 if(getEntity() == null){
83 setEntity(NonViralName
.NewInstance(null));
85 NonViralName nonViralName
= getEntity();
87 super.updateContent();
88 toggleable_cache
.setEnabled(getEntity().isProtectedAuthorshipCache());
90 if(this.isIrrelevant()){
91 setIrrelevant(isIrrelevant());
93 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
100 public void handleEvent(Object eventSource
) {
101 if(eventSource
== toggleable_cache
){
102 getEntity().setAuthorshipCache(toggleable_cache
.getText(), toggleable_cache
.getState());
103 if(! isIrrelevant()) setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
105 else if(eventSource
== selection_combinationAuthorTeam
){
106 getEntity().setCombinationAuthorTeam((INomenclaturalAuthor
) selection_combinationAuthorTeam
.getSelection());
108 else if(eventSource
== selection_exCombinationAuthorTeam
){
109 getEntity().setExCombinationAuthorTeam((INomenclaturalAuthor
) selection_exCombinationAuthorTeam
.getSelection());
111 else if(eventSource
== selection_basionymAuthorTeam
){
112 getEntity().setBasionymAuthorTeam((INomenclaturalAuthor
) selection_basionymAuthorTeam
.getSelection());
114 else if(eventSource
== selection_exBasionymAuthorTeam
){
115 getEntity().setExBasionymAuthorTeam((INomenclaturalAuthor
) selection_exBasionymAuthorTeam
.getSelection());
118 if(eventSource
!= toggleable_cache
){
119 toggleable_cache
.setText(getEntity().getAuthorshipCache());
122 // we have to notify the parent if this is embedded in the nonviral name section
123 // maybe we can handle this a little bit more elegant
124 if(getParentElement() instanceof AbstractCdmDetailSection
)
125 firePropertyChangeEvent(new CdmPropertyChangeEvent(getParentElement(), null));