commit f8b0de79fb6a1933829014d0167547aac2357775
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Wed Oct 26 15:14:27 2016 +0200

    ref #5458 Fix item initialization problems

diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/container/TaxonNodeContainer.java b/src/main/java/eu/etaxonomy/cdm/vaadin/container/TaxonNodeContainer.java
index d78b81ac..b4cc12ea 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/container/TaxonNodeContainer.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/container/TaxonNodeContainer.java
@@ -1,18 +1,13 @@
 package eu.etaxonomy.cdm.vaadin.container;
 
-import java.util.Arrays;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 
 import com.vaadin.data.Item;
 import com.vaadin.data.util.HierarchicalContainer;
 
-import eu.etaxonomy.cdm.api.service.IClassificationService;
-import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
-import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
 
 public class TaxonNodeContainer extends HierarchicalContainer {
 
@@ -20,13 +15,6 @@ public class TaxonNodeContainer extends HierarchicalContainer {
 	public static final String LABEL = "titleCache";
 	private Set<Object> itemCache = new HashSet<Object>();
 
-
-	private final List<String> nodeInitStrategy = Arrays.asList(new String[]{
-	        "taxon.sec",
-	        "taxon.name",
-	        "classification"
-	});
-
 	/**
 	 * Creates a new taxon node container
 	 * @param parentNode the parent node which will <b>not</b> be included
@@ -34,21 +22,6 @@ public class TaxonNodeContainer extends HierarchicalContainer {
 	 */
 	public TaxonNodeContainer(UuidAndTitleCache<TaxonNode> parentNode) {
 		addContainerProperty(LABEL, String.class, "[no taxon]");
-		if(parentNode==null){
-            //just load classifications
-            IClassificationService classificationService = CdmSpringContextHelper.getClassificationService();
-            List<Classification> classificationList = classificationService.listClassifications(null, null, null, nodeInitStrategy);
-            for (Classification classification : classificationList) {
-                TaxonNode rootNode = classification.getRootNode();
-                Item item = addItem(rootNode);
-                if(rootNode.getClassification()!=null){
-                    item.getItemProperty(LABEL).setValue(rootNode.getClassification().getName().getText());
-                }
-            }
-        }
-		else{
-		    addItem(parentNode);
-		}
 	}
 
 	/**
@@ -57,11 +30,12 @@ public class TaxonNodeContainer extends HierarchicalContainer {
 	@Override
 	public Item addItem(Object itemId) {
 	    if(itemId instanceof UuidAndTitleCache){
-	        if(!itemCache.contains(((UuidAndTitleCache<TaxonNode>) itemId).getId())){
-	            return super.addItem(itemId);
+	        UuidAndTitleCache<TaxonNode> uuidAndTitleCache = (UuidAndTitleCache<TaxonNode>) itemId;
+            if(!itemCache.contains(uuidAndTitleCache.getId())){
+	            Item item = super.addItem(itemId);
+	            item.getItemProperty(TaxonNodeContainer.LABEL).setValue(uuidAndTitleCache.getTitleCache());
+                return item;
 	        }
-        } else {
-            return super.addItem(itemId);
         }
 	    return null;
 	}
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java
index 7f355e36..5f187ee1 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java
@@ -9,6 +9,7 @@
  */
 package eu.etaxonomy.cdm.vaadin.view.dbstatus;
 
+import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Set;
 import java.util.UUID;
@@ -32,13 +33,14 @@ import com.vaadin.ui.Tree.ExpandListener;
 import com.vaadin.ui.TreeTable;
 import com.vaadin.ui.VerticalLayout;
 
-import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
+import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
 import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
 import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
+import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
 import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
 import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
 
@@ -71,7 +73,11 @@ public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWind
         //init classification and taxon selection
         TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode();
 
-        classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
+        try {
+            classificationBox.setContainerDataSource(new CdmSQLContainer(CdmQueryFactory.generateTableQuery("Classification")));
+        } catch (SQLException e) {
+            DistributionEditorUtil.showSqlError(e);
+        }
         Object classificationSelection = null;
         if(classificationBox.getItemIds().size()==1){
             //only one classification exists
@@ -85,11 +91,13 @@ public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWind
             classificationBox.setValue(classificationSelection);
             taxonTree.addExpandListener(this);
 
-            UUID uuid = ((CdmBase) classificationSelection).getUuid();
-            int id = ((CdmBase) classificationSelection).getId();
-            String titleCache = ((TaxonNode) classificationSelection).getClassification().getTitleCache();
+            String uuidString = (String) classificationBox.getContainerProperty(classificationSelection, "uuid").getValue();
+            int id = (int) classificationBox.getContainerProperty(classificationSelection, "id").getValue();
+            String titleCache = (String) classificationBox.getContainerProperty(classificationSelection, "titleCache").getValue();
+            UUID uuid = UUID.fromString(uuidString);
             UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache);
             taxonTree.setContainerDataSource(new TaxonNodeContainer(parent));
+            addChildItems(parent);
             if(chosenTaxonNode!=null){
                 taxonTree.select(new RowId(chosenTaxonNode.getId()));
             }
@@ -205,12 +213,9 @@ public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWind
                 String titleCache = parentNode.getClassification().getTitleCache();
                 UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache);
                 taxonTree.setContainerDataSource(new TaxonNodeContainer(parent));
-            }
-            else{
-                taxonTree.setContainerDataSource(null);
+                addChildItems(parent);
             }
         }
-
         else if(property==distAreaBox){
             TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
             NamedAreaContainer container = new NamedAreaContainer(vocabulary);
@@ -232,7 +237,7 @@ public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWind
             TermVocabulary<NamedArea> term = null;
             //TODO use field converter
             if(taxonTree.getValue()!=null){
-                taxonNode = CdmSpringContextHelper.getTaxonNodeService().find((Integer)((RowId) taxonTree.getValue()).getId()[0]);
+                taxonNode = CdmSpringContextHelper.getTaxonNodeService().load(((UuidAndTitleCache<TaxonNode>)taxonTree.getValue()).getUuid());
             }
             if(taxonNode==null){
                 taxonNode = (TaxonNode) classificationBox.getValue();
@@ -250,13 +255,19 @@ public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWind
     @Override
     public void nodeExpand(ExpandEvent event) {
         UuidAndTitleCache<TaxonNode> parent = (UuidAndTitleCache<TaxonNode>) event.getItemId();
+        addChildItems(parent);
+    }
+
+    /**
+     * @param parent
+     */
+    private void addChildItems(UuidAndTitleCache<TaxonNode> parent) {
         Collection<UuidAndTitleCache<TaxonNode>> children = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(parent);
         taxonTree.setChildrenAllowed(parent, !children.isEmpty());
         for (UuidAndTitleCache<TaxonNode> child : children) {
             Item childItem = taxonTree.addItem(child);
             if(childItem!=null){
                 taxonTree.setParent(child, parent);
-                childItem.getItemProperty(TaxonNodeContainer.LABEL).setValue(child.getTitleCache());
             }
             Collection<UuidAndTitleCache<TaxonNode>> grandChildren = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(child);
             taxonTree.setChildrenAllowed(child, !grandChildren.isEmpty());
