adapt to new return type for name authors
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / AuthorshipDetailElement.java
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.name.NonViralName;
16 import eu.etaxonomy.taxeditor.model.AuthorHelper;
17 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
18 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
19 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
20 import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
21 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
22 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
23 import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
24
25 /**
26 * <p>
27 * AuthorshipDetailElement class.
28 * </p>
29 *
30 * @author n.hoffmann
31 * @created Mar 4, 2010
32 * @version 1.0
33 */
34 public class AuthorshipDetailElement extends
35 AbstractIdentifiableEntityDetailElement<NonViralName> implements
36 IEnableableFormElement {
37
38 private NomenclaturalAuthorTeamSelectionElement selection_exBasionymAuthorTeam;
39 private NomenclaturalAuthorTeamSelectionElement selection_basionymAuthorTeam;
40 private NomenclaturalAuthorTeamSelectionElement selection_exCombinationAuthorTeam;
41 private NomenclaturalAuthorTeamSelectionElement selection_combinationAuthorTeam;
42
43 /**
44 * <p>
45 * Constructor for AuthorshipDetailElement.
46 * </p>
47 *
48 * @param cdmFormFactory
49 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
50 * object.
51 * @param formElement
52 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
53 * object.
54 * @param style
55 * a int.
56 */
57 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
58 ICdmFormElement formElement, int style) {
59 super(cdmFormFactory, formElement);
60 }
61
62 /** {@inheritDoc} */
63 @Override
64 protected void createControls(ICdmFormElement formElement,
65 NonViralName entity, int style) {
66 toggleable_cache = formFactory.createToggleableTextField(this,
67 "Authorship Cache", entity.getAuthorshipCache(),
68 entity.isProtectedAuthorshipCache(), style);
69 selection_combinationAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
70 getConversationHolder(),
71 formElement, "Author",
72 AuthorHelper.getAuthor(entity.getCombinationAuthorTeam()),
73 EntitySelectionElement.ALL, style);
74 addElement(selection_combinationAuthorTeam);
75 selection_exCombinationAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
76 getConversationHolder(),
77 formElement, "Ex Author",
78 AuthorHelper.getAuthor(entity.getExCombinationAuthorTeam()),
79 EntitySelectionElement.ALL, style);
80 addElement(selection_exCombinationAuthorTeam);
81 selection_basionymAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
82 getConversationHolder(),
83 formElement, "Basionym Author",
84 AuthorHelper.getAuthor(entity.getBasionymAuthorTeam()),
85 EntitySelectionElement.ALL, style);
86 addElement(selection_basionymAuthorTeam);
87 selection_exBasionymAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
88 getConversationHolder(),
89 formElement, "Ex Basionym Author",
90 AuthorHelper.getAuthor(entity.getExBasionymAuthorTeam()),
91 EntitySelectionElement.ALL, style);
92 addElement(selection_exBasionymAuthorTeam);
93 }
94
95 /** {@inheritDoc} */
96 @Override
97 public void updateContent() {
98 if (getEntity() == null) {
99 setEntity(NonViralName.NewInstance(null));
100 }
101
102 super.updateContent();
103 toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
104
105 if (this.isIrrelevant()) {
106 setIrrelevant(isIrrelevant());
107 } else {
108 setIrrelevant(toggleable_cache.getState(),
109 Arrays.asList(new Object[] { toggleable_cache }));
110 }
111 }
112
113 /** {@inheritDoc} */
114 @Override
115 public void handleEvent(Object eventSource) {
116 if (eventSource == toggleable_cache) {
117 getEntity().setAuthorshipCache(toggleable_cache.getText(),
118 toggleable_cache.getState());
119 if (!isIrrelevant()){
120 setIrrelevant(toggleable_cache.getState(),
121 Arrays.asList(new Object[] { toggleable_cache }));
122 }
123 } else if (eventSource == selection_combinationAuthorTeam) {
124 getEntity().setCombinationAuthorTeam(
125 selection_combinationAuthorTeam.getSelection());
126 } else if (eventSource == selection_exCombinationAuthorTeam) {
127 getEntity().setExCombinationAuthorTeam(
128 selection_exCombinationAuthorTeam.getSelection());
129 } else if (eventSource == selection_basionymAuthorTeam) {
130 getEntity().setBasionymAuthorTeam(
131 selection_basionymAuthorTeam.getSelection());
132 } else if (eventSource == selection_exBasionymAuthorTeam) {
133 getEntity().setExBasionymAuthorTeam(
134 selection_exBasionymAuthorTeam.getSelection());
135 }
136
137 // if (eventSource != toggleable_cache) {
138 // toggleable_cache.setText(getEntity().getAuthorshipCache());
139 // }
140
141 // we have to notify the parent if this is embedded in the nonviral name
142 // section
143 // maybe we can handle this a little bit more elegant
144 // if (getParentElement() instanceof AbstractCdmDetailSection)
145 firePropertyChangeEvent(new CdmPropertyChangeEvent(
146 getParentElement(), null));
147 }
148
149 @Override
150 public void updateToggleableCacheField() {
151 if(! getEntity().isProtectedAuthorshipCache()){
152 toggleable_cache.setText(getEntity().getAuthorshipCache());
153 }
154 }
155 }