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
.ui
.section
.name
;
13 import java
.util
.Arrays
;
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
.forms
.CdmFormFactory
;
19 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.SelectionType
;
20 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmPropertyChangeEvent
;
21 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IEnableableFormElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ToggleableTextElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.selection
.AbstractSelectionElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.selection
.NomenclaturalAuthorTeamSelectionElement
;
31 * AuthorshipDetailElement class.
35 * @created Mar 4, 2010
38 public class AuthorshipDetailElement
extends
39 AbstractCdmDetailElement
<NonViralName
> implements
40 IEnableableFormElement
{
42 private ToggleableTextElement toggleable_cache
;
44 private AbstractSelectionElement selection_exBasionymAuthorTeam
;
45 private AbstractSelectionElement selection_basionymAuthorTeam
;
46 private AbstractSelectionElement selection_exCombinationAuthorTeam
;
47 private AbstractSelectionElement selection_combinationAuthorTeam
;
51 * Constructor for AuthorshipDetailElement.
54 * @param cdmFormFactory
55 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
58 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
63 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory
,
64 ICdmFormElement formElement
, int style
) {
65 super(cdmFormFactory
, formElement
);
70 protected void createControls(ICdmFormElement formElement
,
71 NonViralName entity
, int style
) {
72 toggleable_cache
= formFactory
.createToggleableTextField(this,
73 "Authorship Cache", entity
.getAuthorshipCache(),
74 entity
.isProtectedAuthorshipCache(), style
);
76 selection_combinationAuthorTeam
= formFactory
.createSelectionElement(
77 SelectionType
.AUTHOR_TEAM
, getConversationHolder(),
78 formElement
, "Author",
79 AuthorHelper
.getAuthor(entity
.getCombinationAuthorTeam()),
80 NomenclaturalAuthorTeamSelectionElement
.DEFAULT
, style
);
81 addElement(selection_combinationAuthorTeam
);
82 selection_exCombinationAuthorTeam
= formFactory
.createSelectionElement(
83 SelectionType
.AUTHOR_TEAM
, getConversationHolder(),
84 formElement
, "Ex Author",
85 AuthorHelper
.getAuthor(entity
.getExCombinationAuthorTeam()),
86 NomenclaturalAuthorTeamSelectionElement
.DEFAULT
, style
);
87 addElement(selection_exCombinationAuthorTeam
);
88 selection_basionymAuthorTeam
= formFactory
.createSelectionElement(
89 SelectionType
.AUTHOR_TEAM
, getConversationHolder(),
90 formElement
, "Basionym Author",
91 AuthorHelper
.getAuthor(entity
.getBasionymAuthorTeam()),
92 NomenclaturalAuthorTeamSelectionElement
.DEFAULT
, style
);
93 addElement(selection_basionymAuthorTeam
);
94 selection_exBasionymAuthorTeam
= formFactory
.createSelectionElement(
95 SelectionType
.AUTHOR_TEAM
, getConversationHolder(),
96 formElement
, "Ex Basionym Author",
97 AuthorHelper
.getAuthor(entity
.getExBasionymAuthorTeam()),
98 NomenclaturalAuthorTeamSelectionElement
.DEFAULT
, style
);
99 addElement(selection_exBasionymAuthorTeam
);
104 public void updateContent() {
105 if (getEntity() == null) {
106 setEntity(NonViralName
.NewInstance(null));
108 NonViralName nonViralName
= getEntity();
110 super.updateContent();
111 toggleable_cache
.setEnabled(getEntity().isProtectedAuthorshipCache());
113 if (this.isIrrelevant()) {
114 setIrrelevant(isIrrelevant());
116 setIrrelevant(toggleable_cache
.getState(),
117 Arrays
.asList(new Object
[] { toggleable_cache
}));
123 public void handleEvent(Object eventSource
) {
124 if (eventSource
== toggleable_cache
) {
125 getEntity().setAuthorshipCache(toggleable_cache
.getText(),
126 toggleable_cache
.getState());
128 setIrrelevant(toggleable_cache
.getState(),
129 Arrays
.asList(new Object
[] { toggleable_cache
}));
130 } else if (eventSource
== selection_combinationAuthorTeam
) {
131 getEntity().setCombinationAuthorTeam(
132 (INomenclaturalAuthor
) selection_combinationAuthorTeam
134 } else if (eventSource
== selection_exCombinationAuthorTeam
) {
135 getEntity().setExCombinationAuthorTeam(
136 (INomenclaturalAuthor
) selection_exCombinationAuthorTeam
138 } else if (eventSource
== selection_basionymAuthorTeam
) {
139 getEntity().setBasionymAuthorTeam(
140 (INomenclaturalAuthor
) selection_basionymAuthorTeam
142 } else if (eventSource
== selection_exBasionymAuthorTeam
) {
143 getEntity().setExBasionymAuthorTeam(
144 (INomenclaturalAuthor
) selection_exBasionymAuthorTeam
148 if (eventSource
!= toggleable_cache
) {
149 toggleable_cache
.setText(getEntity().getAuthorshipCache());
152 // we have to notify the parent if this is embedded in the nonviral name
154 // maybe we can handle this a little bit more elegant
155 if (getParentElement() instanceof AbstractCdmDetailSection
)
156 firePropertyChangeEvent(new CdmPropertyChangeEvent(
157 getParentElement(), null));