fix #9013: fix NPE when creating root taxon and NPE when changing taxon in taxonnode...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / classification / TaxonNodeDetailElement.java
index 529f0f9fcac508fd5761dbe216d00780fd2541f5..245d3440dc7777bf5515f015e47a3b4d2dc0773c 100644 (file)
@@ -9,9 +9,12 @@
 
 package eu.etaxonomy.taxeditor.ui.section.classification;
 
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Text;
 
@@ -25,13 +28,16 @@ import eu.etaxonomy.cdm.model.metadata.PublishEnum;
 import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 import eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement;
 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
@@ -48,46 +54,42 @@ import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
 public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode> {
 
     private boolean createNew = false;
-
-//     private EntitySelectionElement<Classification> selection_classification;
-
        private Classification classification;
+       private TaxonNode parentNode;
+       private Taxon taxon;
 
        private TaxonNodeSelectionElement selection_parentTaxonNode;
-
-       private TaxonNode parentTreeNode;
-
        private EntitySelectionElement<Taxon> selection_reuseExistingTaxon;
-       private EntitySelectionElement<Reference> selection_SecRef;
+       private EntitySelectionElement<TaxonName> selection_reuseExistingName;
+
+    private EntitySelectionElement<Reference> selection_SecRef;
        private EntitySelectionElement<Reference> selection_Ref;
-       TextWithLabelElement textTaxonSec;
+
+
+    TextWithLabelElement textTaxonSec;
+
        private TextWithLabelElement microReference;
 
-       private Taxon taxon;
 
-       private TextWithLabelElement textNewTaxonName;
+    private TextWithLabelElement textNewTaxonName;
 
        private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
 
-//     private CheckboxElement checkbox_openInEditor;
-
        private CheckboxElement checkbox_unplaced;
-
        private CheckboxElement checkbox_excluded;
        private CheckboxElement checkbox_publish;
-
-
+       private CheckboxElement checkbox_placementDoubtful;
 
     private MultilanguageTextElement multiLanguageTextExcludedNotes;
 
-//     private boolean openInEditor;
 
        private boolean complete;
 
        private boolean excluded = false;
        private boolean unplaced = false;
+       private boolean placementDoubtful = false;
+
 
-       private EntitySelectionElement<TaxonName> selection_reuseExistingName;
 
        public TaxonNodeDetailElement(CdmFormFactory formFactory,
                        ICdmFormElement formElement, boolean isCreateNew) {
@@ -96,36 +98,73 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
        }
 
 
+       public Map<Language, LanguageString> getMultiLanguageTextExcludedNotes() {
+        return multiLanguageTextExcludedNotes.getMultilanguageText();
+    }
+
+
+
+    public boolean isExcluded() {
+        return excluded;
+    }
+
+
+
+    public boolean isUnplaced() {
+        return unplaced;
+    }
+
+
+
+    public boolean isPlacementDoubtful() {
+        return placementDoubtful;
+    }
+
+    public Reference getRef() {
+        return selection_Ref.getEntity();
+    }
+    public TaxonName getExistingName() {
+        return selection_reuseExistingName.getEntity();
+    }
+    public String getMicroReference() {
+        return microReference.getText();
+    }
 
        /** {@inheritDoc} */
        @Override
        protected void createControls(ICdmFormElement formElement,
                TaxonNode entity, int style) {
-           taxon = entity.getTaxon();
+//         taxon = entity.getTaxon();
+
            if (isCreateNew()){
-//             selection_classification = formFactory
-//                             .createSelectionElement(Classification.class,//getConversationHolder(),
-//                                     formElement, "Classification",
-//                                             null, EntitySelectionElement.DELETABLE, style);
+//             setParentTreeNode(entity);
                selection_parentTaxonNode = formFactory
-                               .createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", parentTreeNode,
-                                               EntitySelectionElement.DELETABLE, style);
+                               .createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", parentNode,
+                                               EntitySelectionElement.DELETABLE, style, 100);
+
+               selection_Ref = formFactory
+                    .createSelectionElement(Reference.class,
+                            formElement, "Parent Child Relation Source", null,
+                            EntitySelectionElement.DELETABLE, style, 100);
 
-//             selection_reuseExistingTaxon = formFactory
-//                             .createSelectionElement(Taxon.class,//getConversationHolder(),
-//                                     formElement,
-//                                             "Reuse existing taxon", null,
-//                                             EntitySelectionElement.DELETABLE, style);
+            microReference = formFactory.createTextWithLabelElement(formElement,"Detail", "", style);
+            microReference.setText(parentNode.getMicroReference());
+
+               selection_reuseExistingTaxon = formFactory
+                               .createSelectionElement(Taxon.class,//getConversationHolder(),
+                                       formElement,
+                                               "Reuse existing taxon", null,
+                                               EntitySelectionElement.DELETABLE, style);
 
                selection_reuseExistingName = formFactory
                                .createSelectionElement(TaxonName.class,//getConversationHolder(),
                                        formElement,
-                                               "Reuse existing name", taxon.getName(),
+                                               "Reuse existing name", taxon != null? taxon.getName(): null,
                                                EntitySelectionElement.DELETABLE, style);
                selection_SecRef = formFactory
                     .createSelectionElement(Reference.class,//getConversationHolder(),
-                            formElement, "Secundum Reference", taxon.getSec(),
-                            EntitySelectionElement.DELETABLE, style);
+                            formElement, "Secundum Reference", taxon != null? taxon.getSec(): null,
+                            EntitySelectionElement.DELETABLE, style, 100);
 
                if (isCreateNew()){
                    textNewTaxonName = formFactory.createTextWithLabelElement(formElement,"New Taxon", "", style);
@@ -135,16 +174,24 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
 
                }
            }else{
-               TextWithLabelElement textClassification = formFactory.createTextWithLabelElement(formElement,"Classification", entity.getClassification().getTitleCache(), style);
-               textClassification.setEnabled(false);
+               taxon = getEntity().getTaxon();
+               if (entity.getParent().getTaxon() == null){
+                   TextWithLabelElement textParent = formFactory.createTextWithLabelElement(formElement,"Classification", entity.getClassification().getTitleCache(), style);
+                textParent.setEnabled(false);
+               }else{
+                   TextWithLabelElement textParent = formFactory.createTextWithLabelElement(formElement,"Parent", entity.getParent().getTaxon().getTitleCache(), style);
+                   textParent.setEnabled(false);
+               }
 
-//             TextWithLabelElement textTaxon = formFactory.createTextWithLabelElement(formElement,"Taxon", taxon.getTitleCache(), style);
-//             textTaxon.setEnabled(false);
+               selection_Ref = formFactory
+                    .createSelectionElement(Reference.class,
+                            formElement, "Parent Child Relation Source", null,
+                            EntitySelectionElement.DELETABLE, style);
 
                selection_reuseExistingTaxon = formFactory
                   .createSelectionElement(Taxon.class,//getConversationHolder(),
                           formElement,
-                          "Reuse existing taxon", taxon,
+                          "Taxon", taxon,
                           EntitySelectionElement.DELETABLE, style);
 
                textTaxonSec = formFactory.createTextWithLabelElement(formElement,"Secundum Reference", "", style);
@@ -157,26 +204,32 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
 
            }
 
-           selection_Ref = formFactory
-                .createSelectionElement(Reference.class,//getConversationHolder(),
-                        formElement, "Parent Child Relation Source", null,
-                        EntitySelectionElement.DELETABLE, style);
-        microReference = formFactory.createTextWithLabelElement(formElement,"Detail", "", style);
-        microReference.setText(getEntity().getMicroReference());
+
         if (!isCreateNew()){
-            selection_Ref.setEntity(entity.getReference());
+            if (entity.getReference() != null){
+                selection_Ref.setEntity(entity.getReference());
+            }
+
         }
-        parentTreeNode = entity.getParent();
-               if (entity instanceof TaxonNode && parentTreeNode.getTaxon() != null) {
-                   checkbox_publish = formFactory.createCheckbox(formElement,
-                           "Taxon is public", parentTreeNode.getTaxon().isPublish(), style);
-               }else{
-                   checkbox_publish = formFactory.createCheckbox(formElement,
-                    "Taxon is public", true, style);
-               }
-               checkbox_publish.setEnabled(isCreateNew());
+
+
+        Taxon tax = null;
+        if (entity.getTaxon() != null){
+            tax = entity.getTaxon();
+        }
+        checkbox_publish = formFactory.createCheckbox(formElement,
+                "Taxon is published", tax != null? tax.isPublish(): true, style);
+
+
+        checkbox_publish.setEnabled(isCreateNew());
+
+        checkbox_placementDoubtful = formFactory.createCheckbox(formElement,
+                "Placement is doubtful", tax!= null? entity.isDoubtful(): false, style);
+
+
+
                if(isCreateNew()){
-                  setParentTreeNode(entity.getParent());
+
 
                   String defaultPublish = PreferencesUtil.getStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
                if (defaultPublish != null && defaultPublish.equals(PublishEnum.Publish.getKey())){
@@ -184,8 +237,8 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
                } else if (defaultPublish != null && defaultPublish.equals(PublishEnum.NotPublish.getKey())){
                    checkbox_publish.setSelection(false);
                }else{
-                   if(this.getParentTreeNode() != null &&  this.getParentTreeNode().isInstanceOf(TaxonNode.class) && ((TaxonNode)this.getParentTreeNode()).getTaxon() != null){
-                       checkbox_publish.setSelection(((TaxonNode)this.getParentTreeNode()).getTaxon().isPublish());
+                   if(this.getParentTreeNode() != null &&  this.getParentTreeNode().isInstanceOf(TaxonNode.class) && this.getParentTreeNode().getTaxon() != null){
+                       checkbox_publish.setSelection(this.getParentTreeNode().getTaxon().isPublish());
                    }else{
                        checkbox_publish.setSelection(true);
                    }
@@ -195,66 +248,54 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
             setTreeNode(entity);
             complete = true;
         }
-               if (entity instanceof TaxonNode) {
-                   checkbox_unplaced = formFactory.createCheckbox(formElement,
+
+               checkbox_unplaced = formFactory.createCheckbox(formElement,
                            "Taxon is unplaced", entity.isUnplaced(), style);
-               }else{
-                   checkbox_unplaced = formFactory.createCheckbox(formElement,
-                    "Taxon is unplaced", false, style);
-               }
+
                if (isCreateNew()){
                    preFillTaxonName();
                }
 
-               if (entity instanceof TaxonNode) {
-                   checkbox_excluded = formFactory.createCheckbox(formElement,
-                           "Taxon is excluded", entity.isExcluded(), style);
-                   multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", entity.getExcludedNote(), 50, style);
-                   multiLanguageTextExcludedNotes.setEnabled(entity.isExcluded());
-               }else{
-                   checkbox_excluded = formFactory.createCheckbox(formElement,
-                    "Taxon is excluded", false, style);
-                   multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", new HashMap<Language, LanguageString>(), 50, style);
-            multiLanguageTextExcludedNotes.setEnabled(false);
-               }
+           checkbox_excluded = formFactory.createCheckbox(formElement,
+                   "Taxon is excluded", entity.isExcluded(), style);
+           multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", entity.getExcludedNote(), 50, style);
+           multiLanguageTextExcludedNotes.setEnabled(entity.isExcluded());
+
                if (!isCreateNew()){
-                   selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), style);
+                   selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), StoreUtil.getSectionStyle(TaxonNodeAgentRelationCollectionSection.class, entity.getClass().getCanonicalName()));
                    selectionNodeAgentRelation.setEntity(entity);
                    selectionNodeAgentRelation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
                }
-//             checkbox_openInEditor = formFactory.createCheckbox(formElement,
-//                     "Open in Editor", true, style);
-//             setOpenInEditor(true);
+
        }
 
        private void preFillTaxonName() {
-        if(getEntity() instanceof TaxonNode ){
-            TaxonNode node = parentTreeNode;
-            if(node.getTaxon()!=null){
-                Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
-                if(taxon.getName()!=null){
-                    TaxonName name = HibernateProxyHelper.deproxy(node.getTaxon().getName());
-                    if (!isCreateNew()){
-                        textNewTaxonName.setText(name.getNameCache());
-                    } else if( ! name.isSupraGeneric() && name.getRank() != null){
-                        String taxonName = "";
-                        if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
-                            taxonName = name.getGenusOrUninomial();
-                        }
-                        else if(name.isSpecies() || name.isInfraSpecific() ){
-                            taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
-                        }
-                        if (StringUtils.isNotBlank(taxonName)){
-                               textNewTaxonName.setText(taxonName + " ");
-                               if(textNewTaxonName.getMainControl() instanceof Text){
-                                       Text text = (Text)textNewTaxonName.getMainControl();
-                                       text.setSelection(textNewTaxonName.getText().length());
-                               }
-                        }
+        TaxonNode node = parentNode;
+        if(node.getTaxon()!=null){
+            Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
+            if(taxon.getName()!=null){
+                TaxonName name = HibernateProxyHelper.deproxy(node.getTaxon().getName());
+                if (!isCreateNew()){
+                    textNewTaxonName.setText(name.getNameCache());
+                } else if( ! name.isSupraGeneric() && name.getRank() != null){
+                    String taxonName = "";
+                    if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
+                        taxonName = name.getGenusOrUninomial();
+                    }
+                    else if(name.isSpecies() || name.isInfraSpecific() ){
+                        taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
+                    }
+                    if (StringUtils.isNotBlank(taxonName)){
+                       textNewTaxonName.setText(taxonName + " ");
+                       if(textNewTaxonName.getMainControl() instanceof Text){
+                               Text text = (Text)textNewTaxonName.getMainControl();
+                               text.setSelection(textNewTaxonName.getText().length());
+                       }
                     }
                 }
             }
         }
+
     }
 
        /** {@inheritDoc} */
@@ -266,12 +307,27 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
                    if (selection_reuseExistingTaxon.getEntity() != null){
                        setTaxon(selection_reuseExistingTaxon.getEntity());
                        if (getTaxon().getSec()!= null){
-                           textTaxonSec.setText((getTaxon().getSec().getTitleCache()));
+                           if (isCreateNew()){
+                              selection_SecRef.setEntity(getTaxon().getSec());
+                           }else{
+                              textTaxonSec.setText((getTaxon().getSec().getTitleCache()));
+                           }
                        }else{
-                           textTaxonSec.setText("");
+                           if (isCreateNew()){
+                              selection_SecRef.setEntity(null);
+                           }else{
+                              textTaxonSec.setText("");
+                           }
                        }
                        checkbox_publish.setSelected(getTaxon().isPublish());
             }
+                   boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
+                   if (selection_reuseExistingName != null){
+                       selection_reuseExistingName.setEnabled(enabled);
+            }
+                   if (textNewTaxonName != null){
+                       textNewTaxonName.setEnabled(enabled);
+                   }
                        complete = true;
                } else if (eventSource == selection_reuseExistingName) {
                    boolean enabled = selection_reuseExistingName.getEntity() == null;
@@ -284,25 +340,44 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
                }
 
         if (eventSource == selection_Ref) {
-            getEntity().setReference(selection_Ref.getEntity());
+            if(!isCreateNew()){
+                getEntity().setReference(selection_Ref.getEntity());
+            }
         }else if (eventSource == selection_SecRef) {
-            taxon.setSec(selection_SecRef.getEntity());
+            if (taxon != null){
+                taxon.setSec(selection_SecRef.getEntity());
+            }
         }else if (eventSource == microReference) {
-            getEntity().setMicroReference(microReference.getText());
+            if(!isCreateNew()){
+                getEntity().setMicroReference(microReference.getText());
+            }
         }  else if (eventSource == checkbox_publish) {
-            taxon.setPublish(checkbox_publish.getSelection());
+            if (taxon != null){
+                taxon.setPublish(checkbox_publish.getSelection());
+            }
         }
 
                if (eventSource == checkbox_excluded) {
             excluded = checkbox_excluded.getSelection();
-
-            getEntity().setExcluded(excluded);
+            if (!isCreateNew()){
+                getEntity().setExcluded(excluded);
+            }
 
             multiLanguageTextExcludedNotes.setEnabled(excluded);
         }
                if (eventSource == checkbox_unplaced) {
             unplaced = checkbox_unplaced.getSelection();
-            getEntity().setUnplaced(unplaced);
+            if (!isCreateNew()){
+                getEntity().setUnplaced(unplaced);
+            }
+
+        }
+
+               if (eventSource == checkbox_placementDoubtful) {
+                   placementDoubtful = checkbox_placementDoubtful.getSelection();
+                   if (!isCreateNew()){
+                       getEntity().setDoubtful(placementDoubtful);
+                   }
 
         }
                if (eventSource == textNewTaxonName) {
@@ -328,58 +403,66 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
                return classification;
        }
 
-//     public boolean isOpenInEditor() {
-//             return openInEditor;
-//     }
 
-       public ITaxonTreeNode getParentTreeNode() {
-               return parentTreeNode;
-       }
 
-       private void setClassification(Classification classification) {
-               this.classification = classification;
-               //setParentTreeNode(classification);
+       public TaxonNode getParentTreeNode() {
+               return parentNode;
        }
 
-       private void setParentTreeNode(TaxonNode parentTreeNode) {
-               this.parentTreeNode = parentTreeNode;
-
+       public void setParentTreeNode(TaxonNode parentTreeNode) {
+               this.parentNode = parentTreeNode;
+               updateContent();
                if (parentTreeNode.getTaxon() == null) {
                        classification = parentTreeNode.getClassification();
-//                     if (selection_classification != null){
-//                         selection_classification.setEntity(classification);
-//                     }
-                       selection_parentTaxonNode.setEntity(classification.getRootNode());
-                       selection_parentTaxonNode.setClassification(classification);
-                       selection_SecRef.setEntity(classification.getReference());
+                       if (selection_parentTaxonNode != null){
+                       selection_parentTaxonNode.setEntity(classification.getRootNode());
+                       selection_parentTaxonNode.setClassification(classification);
+                       selection_SecRef.setEntity(classification.getReference());
+                       }
                } else  {
                        classification = HibernateProxyHelper
                                        .deproxy(parentTreeNode.getClassification());
-//                     if (selection_classification != null){
-//                         selection_classification.setEntity(classification);
-//                     }
-                       selection_parentTaxonNode.setEntity(HibernateProxyHelper
-                    .deproxy(parentTreeNode));
-                       selection_parentTaxonNode.setClassification(classification);
-                       selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
+                       if (selection_parentTaxonNode != null){
+                           selection_parentTaxonNode.setEntity(HibernateProxyHelper.deproxy(parentTreeNode));
+                           selection_parentTaxonNode.setClassification(classification);
+                   selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
+                       }
+
 
                }
        }
+       @Override
+       protected void updateControlStates(){
+        Collection<Object> except = new ArrayList<Object>();
+        for(ICdmFormElement formElement:getElements()){
+            if(formElement instanceof IEnableableFormElement && !((IEnableableFormElement) formElement).isEnabled()){
+                except.add(formElement);
+            }
+        }
+        if (isCreateNew() ){
+            enabled = true;
+        }else{
+            enabled = getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud);
+        }
+        setEnabled(enabled, except);
+    }
 
        private void setTreeNode(TaxonNode treeNode) {
         classification = HibernateProxyHelper
                     .deproxy(treeNode.getClassification());
         if (isCreateNew()){
-           //selection_classification.setEntity(classification);
-            selection_parentTaxonNode.setEntity(treeNode.getParent());
-            selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
-            selection_SecRef.setEntity(treeNode.getTaxon().getSec());
+           selection_parentTaxonNode.setEntity(treeNode.getParent());
+           selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
+           selection_SecRef.setEntity(treeNode.getTaxon().getSec());
         }
        }
 
        private void setTaxon(Taxon taxon) {
                this.taxon = taxon;
-               getEntity().setTaxon(taxon);
+               if (!isCreateNew()){
+                   getEntity().setTaxon(taxon);
+               }
+               this.set_publish(taxon.isPublish());
                if (isCreateNew()){
                    textNewTaxonName.setText(taxon.getName().getTitleCache());
                    if (taxon.getSec() != null){
@@ -406,19 +489,15 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
                    if (textNewTaxonName.getText() == null || !taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
                         textNewTaxonName.setText(taxonName.getTitleCache());
                    }
-                   getEntity().setTaxon(taxon);
-//                 if (!taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
-//                     textNewTaxonName.setText(taxonName.getTitleCache());
-//                 }
+                   if (!isCreateNew()){
+                       getEntity().setTaxon(taxon);
+                   }
+
                } else {
                    textNewTaxonName.setText(null);
                }
        }
 
-//     private void setOpenInEditor(boolean openInEditor) {
-//             this.openInEditor = openInEditor;
-//     }
-
        public String getTaxonName() {
         return textNewTaxonName.getText();
     }
@@ -426,7 +505,7 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
         return taxon;
     }
 
-       public Reference getReference(){
+       public Reference getSecReference(){
            return selection_SecRef.getSelection();
        }
 
@@ -449,18 +528,10 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
         return createNew;
     }
 
-    public boolean isExcluded() {
-        return excluded;
-    }
-
-    public boolean isUnplaced() {
-        return unplaced;
-    }
-
     public boolean is_publish() {
         boolean isPublishPreference = true;
-        CdmPreference defaultPublish = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
-        if (defaultPublish != null && defaultPublish.getValue().equals(PublishEnum.NotPublish.getKey())){
+        CdmPreference defaultPublish = CdmPreferenceCache.instance().get(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
+        if (defaultPublish != null && defaultPublish.getValue()!= null && defaultPublish.getValue().equals(PublishEnum.NotPublish.getKey())){
             isPublishPreference = false;
         }
         return checkbox_publish!=null?checkbox_publish.getSelection():isPublishPreference;
@@ -470,5 +541,19 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode>
         this.checkbox_publish.setSelection(publish);
     }
 
+    /**
+     * Updates all widgets to display the latest data
+     */
+    @Override
+    protected void updateContent() {
+        removeElements();
+        if (isCreateNew()){
+            createControls(this, parentNode, SWT.NONE);
+        }else{
+            createControls(this, getEntity(), SWT.NONE);
+        }
+        updateControlStates();
+    }
+
 
 }