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