Merge branch 'release/5.11.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / AuthorshipDetailElement.java
index 873ff4cc6d68a1554bcfc431f34701855265d1b5..9646fb5f11ee2a863b82e5b03cb288e84576a7d8 100644 (file)
@@ -1,9 +1,8 @@
-// $Id$
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -12,42 +11,46 @@ package eu.etaxonomy.taxeditor.ui.section.name;
 
 import java.util.Arrays;
 
-import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
-import eu.etaxonomy.cdm.model.name.NonViralName;
-import eu.etaxonomy.taxeditor.model.AuthorHelper;
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.model.name.INonViralName;
+import eu.etaxonomy.cdm.model.name.IZoologicalName;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
+import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
+import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
-import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.SelectionType;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
+import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
-import eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement;
-import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 
 /**
  * <p>
  * AuthorshipDetailElement class.
  * </p>
- * 
+ *
  * @author n.hoffmann
  * @created Mar 4, 2010
  * @version 1.0
  */
 public class AuthorshipDetailElement extends
-       AbstractIdentifiableEntityDetailElement<NonViralName> implements
-               IEnableableFormElement {
+       AbstractIdentifiableEntityDetailElement<INonViralName> {
 
-       private AbstractSelectionElement selection_exBasionymAuthorTeam;
-       private AbstractSelectionElement selection_basionymAuthorTeam;
-       private AbstractSelectionElement selection_exCombinationAuthorTeam;
-       private AbstractSelectionElement selection_combinationAuthorTeam;
+    private EntitySelectionElement<TeamOrPersonBase> selectionExBasionymAuthor;
+    private EntitySelectionElement<TeamOrPersonBase> selectionBasionymAuthor;
+    private EntitySelectionElement<TeamOrPersonBase> selectionExCombinationAuthor;
+    private EntitySelectionElement<TeamOrPersonBase> selectionCombinationAuthor;
 
+    private NumberWithLabelElement text_publicationYear;
+    private NumberWithLabelElement text_originalPublicationYear;
        /**
         * <p>
         * Constructor for AuthorshipDetailElement.
         * </p>
-        * 
+        *
         * @param cdmFormFactory
         *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
         *            object.
@@ -65,53 +68,74 @@ public class AuthorshipDetailElement extends
        /** {@inheritDoc} */
        @Override
        protected void createControls(ICdmFormElement formElement,
-                       NonViralName entity, int style) {
-               toggleable_cache = formFactory.createToggleableTextField(this,
+                       INonViralName entity, int style) {
+           NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
+           if (config == null || config.isAuthorCacheActivated()){
+               toggleable_cache = formFactory.createToggleableTextField(this,
                                "Authorship Cache", entity.getAuthorshipCache(),
                                entity.isProtectedAuthorshipCache(), style);
+               addElement(toggleable_cache);
+          }
+           NomenclaturalCode code = entity.getNameType();
+
+           if (config == null || config.isAuthorshipSectionActivated()){
+            selectionCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
+                               getConversationHolder(),
+                               formElement, "Author",
+                               entity.getCombinationAuthorship(),
+                               EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+               addElement(selectionCombinationAuthor);
+               selectionExCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
+                               getConversationHolder(),
+                               formElement, "Ex Author",
+                               entity.getExCombinationAuthorship(),
+                               EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+               addElement(selectionExCombinationAuthor);
+               if (code != null){
+                if (code.equals(NomenclaturalCode.ICZN)){
+                    text_publicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Publication Year", ((IZoologicalName)entity).getPublicationYear(), style);
+
+                }
+             }
+               selectionBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
+                    formElement, "Basionym Author", entity.getBasionymAuthorship(),
+                    EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+               addElement(selectionBasionymAuthor);
+               selectionExBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
+                       formElement, "Ex Basionym Author",entity.getExBasionymAuthorship(),
+                       EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+
+               addElement(selectionExBasionymAuthor);
+                if (code != null){
+                   if (code.equals(NomenclaturalCode.ICZN)){
+
+                       text_originalPublicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Orig. Publication Year", ((IZoologicalName)entity).getOriginalPublicationYear(), style);
+
+                   }
+                }
+
+           }
 
-               selection_combinationAuthorTeam = formFactory.createSelectionElement(
-                               SelectionType.AUTHOR_TEAM, getConversationHolder(),
-                               formElement, "Author",
-                               AuthorHelper.getAuthor(entity.getCombinationAuthorTeam()),
-                               NomenclaturalAuthorTeamSelectionElement.DEFAULT, style);
-               addElement(selection_combinationAuthorTeam);
-               selection_exCombinationAuthorTeam = formFactory.createSelectionElement(
-                               SelectionType.AUTHOR_TEAM, getConversationHolder(),
-                               formElement, "Ex Author",
-                               AuthorHelper.getAuthor(entity.getExCombinationAuthorTeam()),
-                               NomenclaturalAuthorTeamSelectionElement.DEFAULT, style);
-               addElement(selection_exCombinationAuthorTeam);
-               selection_basionymAuthorTeam = formFactory.createSelectionElement(
-                               SelectionType.AUTHOR_TEAM, getConversationHolder(),
-                               formElement, "Basionym Author",
-                               AuthorHelper.getAuthor(entity.getBasionymAuthorTeam()),
-                               NomenclaturalAuthorTeamSelectionElement.DEFAULT, style);
-               addElement(selection_basionymAuthorTeam);
-               selection_exBasionymAuthorTeam = formFactory.createSelectionElement(
-                               SelectionType.AUTHOR_TEAM, getConversationHolder(),
-                               formElement, "Ex Basionym Author",
-                               AuthorHelper.getAuthor(entity.getExBasionymAuthorTeam()),
-                               NomenclaturalAuthorTeamSelectionElement.DEFAULT, style);
-               addElement(selection_exBasionymAuthorTeam);
        }
 
        /** {@inheritDoc} */
        @Override
        public void updateContent() {
                if (getEntity() == null) {
-                       setEntity(NonViralName.NewInstance(null));
+                       setEntity(TaxonNameFactory.NewNonViralInstance(null));
                }
-               NonViralName nonViralName = getEntity();
 
                super.updateContent();
-               toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
+               if (toggleable_cache != null){
+               toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
+
 
-               if (this.isIrrelevant()) {
-                       setIrrelevant(isIrrelevant());
-               } else {
-                       setIrrelevant(toggleable_cache.getState(),
-                                       Arrays.asList(new Object[] { toggleable_cache }));
+               if (this.isIrrelevant()) {
+                       setIrrelevant(isIrrelevant());
+               } else {
+                       setIrrelevant(toggleable_cache.getState(),
+                                       Arrays.asList(new Object[] { toggleable_cache }));
+               }
                }
        }
 
@@ -121,26 +145,27 @@ public class AuthorshipDetailElement extends
                if (eventSource == toggleable_cache) {
                        getEntity().setAuthorshipCache(toggleable_cache.getText(),
                                        toggleable_cache.getState());
-                       if (!isIrrelevant())
+                       if (!isIrrelevant()){
                                setIrrelevant(toggleable_cache.getState(),
                                                Arrays.asList(new Object[] { toggleable_cache }));
-               } else if (eventSource == selection_combinationAuthorTeam) {
-                       getEntity().setCombinationAuthorTeam(
-                                       (INomenclaturalAuthor) selection_combinationAuthorTeam
-                                                       .getSelection());
-               } else if (eventSource == selection_exCombinationAuthorTeam) {
-                       getEntity().setExCombinationAuthorTeam(
-                                       (INomenclaturalAuthor) selection_exCombinationAuthorTeam
-                                                       .getSelection());
-               } else if (eventSource == selection_basionymAuthorTeam) {
-                       getEntity().setBasionymAuthorTeam(
-                                       (INomenclaturalAuthor) selection_basionymAuthorTeam
-                                                       .getSelection());
-               } else if (eventSource == selection_exBasionymAuthorTeam) {
-                       getEntity().setExBasionymAuthorTeam(
-                                       (INomenclaturalAuthor) selection_exBasionymAuthorTeam
-                                                       .getSelection());
-               }
+                       }
+               } else if (eventSource == selectionCombinationAuthor) {
+                       getEntity().setCombinationAuthorship(
+                                       selectionCombinationAuthor.getSelection());
+               } else if (eventSource == selectionExCombinationAuthor) {
+                       getEntity().setExCombinationAuthorship(
+                                       selectionExCombinationAuthor.getSelection());
+               } else if (eventSource == selectionBasionymAuthor) {
+                       getEntity().setBasionymAuthorship(
+                                       selectionBasionymAuthor.getSelection());
+               } else if (eventSource == selectionExBasionymAuthor) {
+                       getEntity().setExBasionymAuthorship(
+                                       selectionExBasionymAuthor.getSelection());
+               } else if (eventSource == text_originalPublicationYear) {
+            ((IZoologicalName)getEntity()).setOriginalPublicationYear(text_originalPublicationYear.getInteger());
+        } else if (eventSource == text_publicationYear) {
+            ((IZoologicalName)getEntity()).setPublicationYear(text_publicationYear.getInteger());
+        }
 
 //             if (eventSource != toggleable_cache) {
 //                     toggleable_cache.setText(getEntity().getAuthorshipCache());
@@ -152,12 +177,15 @@ public class AuthorshipDetailElement extends
 //             if (getParentElement() instanceof AbstractCdmDetailSection)
                        firePropertyChangeEvent(new CdmPropertyChangeEvent(
                                        getParentElement(), null));
+                       EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, this.getEntity());
        }
-       
+
        @Override
        public void updateToggleableCacheField() {
-               if(! getEntity().isProtectedAuthorshipCache()){
-                       toggleable_cache.setText(getEntity().getAuthorshipCache());
-               }
+           if (toggleable_cache != null){
+               if(! getEntity().isProtectedAuthorshipCache()){
+                       toggleable_cache.setText(getEntity().getAuthorshipCache());
+               }
+           }
        }
 }