performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / 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.section.name;
12
13 import java.util.Arrays;
14
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;
31
32 /**
33 * <p>AuthorshipDetailElement class.</p>
34 *
35 * @author n.hoffmann
36 * @created Mar 4, 2010
37 * @version 1.0
38 */
39 public class AuthorshipDetailElement extends AbstractCdmDetailElement<NonViralName> implements IEnableableFormElement {
40
41 private ToggleableTextElement toggleable_cache;
42
43 private AbstractSelectionElement selection_exBasionymAuthorTeam;
44 private AbstractSelectionElement selection_basionymAuthorTeam;
45 private AbstractSelectionElement selection_exCombinationAuthorTeam;
46 private AbstractSelectionElement selection_combinationAuthorTeam;
47
48 /**
49 * <p>Constructor for AuthorshipDetailElement.</p>
50 *
51 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
52 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
53 * @param style a int.
54 */
55 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
56 ICdmFormElement formElement, int style) {
57 super(cdmFormFactory, formElement);
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 protected void createControls(ICdmFormElement formElement, NonViralName entity, int style) {
63 toggleable_cache = formFactory.createToggleableTextField(this, "Authorship Cache", entity.getAuthorshipCache(), entity.isProtectedAuthorshipCache(), style);
64
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);
77 }
78
79 /** {@inheritDoc} */
80 @Override
81 public void updateContent() {
82 if(getEntity() == null){
83 setEntity(NonViralName.NewInstance(null));
84 }
85 NonViralName nonViralName = getEntity();
86
87 super.updateContent();
88 toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
89
90 if(this.isIrrelevant()){
91 setIrrelevant(isIrrelevant());
92 }else{
93 setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
94 }
95 }
96
97
98 /** {@inheritDoc} */
99 @Override
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}));
104 }
105 else if(eventSource == selection_combinationAuthorTeam){
106 getEntity().setCombinationAuthorTeam((INomenclaturalAuthor) selection_combinationAuthorTeam.getSelection());
107 }
108 else if(eventSource == selection_exCombinationAuthorTeam){
109 getEntity().setExCombinationAuthorTeam((INomenclaturalAuthor) selection_exCombinationAuthorTeam.getSelection());
110 }
111 else if(eventSource == selection_basionymAuthorTeam){
112 getEntity().setBasionymAuthorTeam((INomenclaturalAuthor) selection_basionymAuthorTeam.getSelection());
113 }
114 else if(eventSource == selection_exBasionymAuthorTeam){
115 getEntity().setExBasionymAuthorTeam((INomenclaturalAuthor) selection_exBasionymAuthorTeam.getSelection());
116 }
117
118 if(eventSource != toggleable_cache){
119 toggleable_cache.setText(getEntity().getAuthorshipCache());
120 }
121
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));
126 }
127 }