commit aab82329b916fa15d51ec9a255b0900389777243
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Mon Sep 5 19:32:50 2016 +0200

    ref #5458 Major performance increase
    
     - refactored term loading
     - cached loaded terms
     - removed unnecessary methods and generics
     - reduces warnings

diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java b/src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java
new file mode 100644
index 00000000..faf18dbe
--- /dev/null
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java
@@ -0,0 +1,39 @@
+package eu.etaxonomy.cdm.vaadin.container;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.vaadin.data.util.BeanItemContainer;
+
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
+import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
+
+public class PresenceAbsenceTermContainer extends BeanItemContainer<PresenceAbsenceTerm> {
+
+	private static final long serialVersionUID = -7891310979870159325L;
+	
+	private static PresenceAbsenceTermContainer instance;
+	
+	public static final Map<String, PresenceAbsenceTerm> titleToTermMap = new HashMap<>();
+
+	private PresenceAbsenceTermContainer()
+			throws IllegalArgumentException {
+		super(PresenceAbsenceTerm.class);
+		List<PresenceAbsenceTerm> terms = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
+		for (PresenceAbsenceTerm presenceAbsenceTerm : terms) {
+			titleToTermMap.put(presenceAbsenceTerm.getTitleCache(), presenceAbsenceTerm);
+			addBean(presenceAbsenceTerm);
+		}
+	}
+	
+	public static PresenceAbsenceTermContainer getInstance(){
+		if(instance==null){
+			instance = new PresenceAbsenceTermContainer();
+		}
+		return instance;
+	}
+
+
+}
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
index a48bf862..16ac92d9 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
@@ -12,8 +12,6 @@ import java.util.Set;
 import java.util.SortedSet;
 import java.util.UUID;
 
-import com.vaadin.data.Container;
-import com.vaadin.data.util.BeanItemContainer;
 import com.vaadin.server.VaadinSession;
 
 import eu.etaxonomy.cdm.api.service.IClassificationService;
@@ -26,7 +24,6 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.Representation;
-import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Distribution;
@@ -231,19 +228,6 @@ public class DistributionTablePresenter implements IDistributionTableComponent.D
 		return container;
 	}
 
-	@Override
-	public Container getPresenceAbsenceContainer(){
-		BeanItemContainer<PresenceAbsenceTerm> termContainer = new BeanItemContainer<PresenceAbsenceTerm>(PresenceAbsenceTerm.class);
-		termContainer.addAll(getPresenceAbsenceTerms());
-		return termContainer;
-	}
-
-
-	@Override
-	public List<PresenceAbsenceTerm> getPresenceAbsenceTerms() {
-		return termService.listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
-	}
-
 	protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
             "$",
             "elements.*",
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java
index 32e333aa..cff4c1c1 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSelectionView.java
@@ -158,11 +158,6 @@ public class DistributionSelectionView extends CustomComponent implements IDistr
         classificationBox.setHeight("-1px");
         verticalLayout_2.addComponent(classificationBox);
 
-        // taxon tree
-        taxonTree = new Tree("Taxonomy");
-        taxonTree.setWidth("200px");
-        verticalLayout_2.addComponent(taxonTree);
-
         // distributionAreaBox
         distributionAreaBox = new ComboBox();
         distributionAreaBox.setCaption("Distribution Area");
@@ -171,6 +166,11 @@ public class DistributionSelectionView extends CustomComponent implements IDistr
         distributionAreaBox.setHeight("-1px");
         verticalLayout_2.addComponent(distributionAreaBox);
 
+        // taxon tree
+        taxonTree = new Tree("Taxonomy");
+        taxonTree.setWidth("200px");
+        verticalLayout_2.addComponent(taxonTree);
+
         // button_proceed
         button_proceed = new Button();
         button_proceed.setCaption("Proceed");
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
index 38be0a53..a72bdb5e 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
@@ -29,33 +29,35 @@ import com.vaadin.ui.Window;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
-import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.vaadin.component.DetailWindow;
 import eu.etaxonomy.cdm.vaadin.component.HorizontalToolbar;
 import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
+import eu.etaxonomy.cdm.vaadin.container.PresenceAbsenceTermContainer;
 import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
 
-public class DistributionTableView<E> extends CustomComponent implements IDistributionTableComponent, View{
+public class DistributionTableView extends CustomComponent implements IDistributionTableComponent, View{
 
     private final class AreaColumnGenerator implements ColumnGenerator {
 		private static final long serialVersionUID = 1L;
 
 		@Override
 		public Object generateCell(Table source, Object itemId, Object columnId) {
-		    Property containerProperty = source.getContainerProperty(itemId, columnId);
+		    Property<?> containerProperty = source.getContainerProperty(itemId, columnId);
 		    Object value = null;
 		    if(containerProperty != null){
 		        value = containerProperty.getValue();
 		    }
 		    final UUID uuid = UUID.fromString(table.getItem(itemId).getItemProperty("uuid").getValue().toString());
-		    final ComboBox box = new ComboBox("Occurrence Status: ", listener.getPresenceAbsenceContainer());
+		    final ComboBox box = new ComboBox("Occurrence Status: ", PresenceAbsenceTermContainer.getInstance());
 		    final String area = columnId.toString();
 		    box.setImmediate(true);
 		    box.setBuffered(true);
-		    box.setValue(compareObjectToPAT(value));
+		    box.setValue(PresenceAbsenceTermContainer.titleToTermMap.get(value));
 		    box.addValueChangeListener(new ValueChangeListener() {
-		        @Override
+				private static final long serialVersionUID = 6221534597911674067L;
+
+				@Override
 		        public void valueChange(ValueChangeEvent event) {
 		            Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class);
 		            listener.updateDistributionField(area, box.getValue(), taxon);
@@ -158,6 +160,8 @@ public class DistributionTableView<E> extends CustomComponent implements IDistri
 		detailButton.setCaption("Detail View");
 		detailButton.addClickListener(new ClickListener() {
 
+			private static final long serialVersionUID = 1479133195403139547L;
+
 			@Override
 			public void buttonClick(ClickEvent event) {
 				try{
@@ -177,7 +181,9 @@ public class DistributionTableView<E> extends CustomComponent implements IDistri
 		Button settingsButton = toolbar.getSettingsButton();
 		settingsButton.addClickListener(new ClickListener() {
 
-            @Override
+			private static final long serialVersionUID = 3834048719431837966L;
+
+			@Override
             public void buttonClick(ClickEvent event) {
                 SettingsConfigWindow cw = new SettingsConfigWindow();
                 Window window  = cw.createWindow();
@@ -205,14 +211,4 @@ public class DistributionTableView<E> extends CustomComponent implements IDistri
 
 	}
 
-	private PresenceAbsenceTerm compareObjectToPAT(Object object){
-	    List<PresenceAbsenceTerm> presenceAbsenceTerms = listener.getPresenceAbsenceTerms();
-	    for(PresenceAbsenceTerm term:presenceAbsenceTerms){
-	        if(term.getTitleCache().equals(object)){
-	            return term;
-	        }
-	    }
-	    return null;
-	}
-
 }
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionTableComponent.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionTableComponent.java
index 16c1ab09..7250153d 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionTableComponent.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/IDistributionTableComponent.java
@@ -5,8 +5,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
 
-import com.vaadin.data.Container;
-
 import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
@@ -17,7 +15,6 @@ import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Distribution;
 import eu.etaxonomy.cdm.model.description.Feature;
-import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
@@ -28,8 +25,6 @@ public interface IDistributionTableComponent {
 	public interface DistributionTableComponentListener{
 		Set<DefinedTermBase> getChosenTerms();
 
-		List<PresenceAbsenceTerm> getPresenceAbsenceTerms();
-
 		HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon);
 
 		LazyLoadedContainer getTableContainer();
@@ -61,8 +56,6 @@ public interface IDistributionTableComponent {
 
 		List<String> getTermList();
 
-		Container getPresenceAbsenceContainer();
-
         /**
          * @return
          */
