Merge branch 'release/5.28.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / reference / SecundumSourceElement.java
index dbe913db586ea615dc104ea4cda9d3ec21b02b04..5c743d5039c504c3c003de1b5929e004f9d38371 100755 (executable)
@@ -13,8 +13,11 @@ import org.eclipse.swt.widgets.Label;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
+import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.reference.NamedSourceBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.SecundumSource;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.preference.Resources;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
@@ -30,6 +33,7 @@ import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
  */
 public class SecundumSourceElement extends OriginalSourceElement<SecundumSource> {
 
+       protected EntitySelectionElement<TaxonName> select_nameUsedInSource;
     /**
      * @param formFactory
      * @param formElement
@@ -50,11 +54,8 @@ public class SecundumSourceElement extends OriginalSourceElement<SecundumSource>
 
         setEntityWithoutUpdate(HibernateProxyHelper.deproxy(entity));
 
-        this.selection_Ref = formFactory.createSelectionElement(Reference.class, formElement, "Secundum", null, EntitySelectionElement.ALL, style);
+        this.selection_Ref = formFactory.createSelectionElement(Reference.class, formElement, "Secundum", getEntity()!= null? getEntity().getCitation(): null, EntitySelectionElement.ALL, style);
 
-        if (getEntity() != null){
-            selection_Ref.setEntity(getEntity().getCitation());
-        }
         selection_Ref.setBackground(this.getPersistentBackground());
         for (ICdmFormElement element: selection_Ref.getElements()){
             element.setBackground(getPersistentBackground());
@@ -64,28 +65,29 @@ public class SecundumSourceElement extends OriginalSourceElement<SecundumSource>
 
         Label sep = formFactory.createLabel(formElement.getLayoutComposite(), "");
         sep.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-
-
+        if (this.cdmEntity instanceof Taxon){
+               select_nameUsedInSource = formFactory.createSelectionElement(TaxonName.class, formElement, "Name in Source", entity != null? ((NamedSourceBase)entity).getNameUsedInSource(): null, EntitySelectionElement.DELETABLE, style);
+        }
+        
         externalLinks = formFactory.createExternalLinksSection(getConversationHolder(), formElement, "Links", false, StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
         externalLinks.setEmptySectionString("No links yet.");
         externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 3));
         externalLinks.setEntity(getEntity());
         externalLinks.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
-
-
+        
         addControl(externalLinks);
         addElement(externalLinks);
-
-//        advancedSection = formFactory.createOriginalSourceAdvancedSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(OriginalSourceAdvancedSection.class, INomenclaturalReference.class.getCanonicalName()));
-//        TableWrapData layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
-//
-//        advancedSection.setLayoutData(layoutData);
-//        advancedSection.setBackground(this.getPersistentBackground());
-//        advancedSection.setEntity(entity);
-//        advancedSection.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
-//        addControl(advancedSection);
-//        addElement(advancedSection);
         this.getLayoutComposite().layout();
+        
     }
+    @Override
+    public void handleEvent(Object eventSource) {
+        if (eventSource.equals(select_nameUsedInSource)){
+               getEntity().setNameUsedInSource(select_nameUsedInSource.getEntity());
+        }else{
+               super.handleEvent(eventSource);
+        }
+    }
+
 
 }