commit 32bf574c75f7cb4ab0e56b84e7578d0ab8971085
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Mon Oct 17 13:31:52 2016 +0200

    ref #5458 Add support for setting distribution status filter in settings

diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java b/src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java
index 7a947363..7554f205 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java
@@ -1,37 +1,33 @@
 package eu.etaxonomy.cdm.vaadin.container;
 
-import java.util.List;
+import java.util.Collection;
+import java.util.Set;
 
 import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinSession;
 
 import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
+import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
 import eu.etaxonomy.cdm.vaadin.util.TermCacher;
 
 public class PresenceAbsenceTermContainer extends BeanItemContainer<PresenceAbsenceTerm> {
 
 	private static final long serialVersionUID = -7891310979870159325L;
 
-	private static PresenceAbsenceTermContainer instance;
-
-	private PresenceAbsenceTermContainer()
+	public PresenceAbsenceTermContainer()
 			throws IllegalArgumentException {
 		super(PresenceAbsenceTerm.class);
-		List<PresenceAbsenceTerm> terms = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
+		Collection<PresenceAbsenceTerm> distributionStatus = (Set<PresenceAbsenceTerm>) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
+        if(distributionStatus==null || distributionStatus.isEmpty()){
+            distributionStatus = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
+        }
 		TermCacher termCacher = TermCacher.getInstance();
-		for (PresenceAbsenceTerm presenceAbsenceTerm : terms) {
+		for (PresenceAbsenceTerm presenceAbsenceTerm : distributionStatus) {
 			termCacher.addPresenceAbsenceTerm(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/util/DistributionEditorUtil.java b/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
index f5e3c3ee..3f45d27c 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
@@ -21,6 +21,8 @@ public class DistributionEditorUtil {
 
     public static final String SATTR_ABBREVIATED_LABELS = "abbreviatedLabels";
 
+    public static final String SATTR_DISTRIBUTION_STATUS = "distributionStatus";
+
     public static final String SEPARATOR = ";;";
 
     public static void openDistributionView(TaxonNode taxonNode, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas) {
@@ -31,7 +33,7 @@ public class DistributionEditorUtil {
 	    //navigate to table view
 	    UI.getCurrent().getNavigator().navigateTo(VIEW_TABLE);
 	}
-    
+
     public static boolean isAbbreviatedLabels(){
     	Object isAbbreviated = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS);
 		return (isAbbreviated==null || (boolean) isAbbreviated);
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 a0d3ec55..aa3140b5 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
@@ -51,6 +51,7 @@ public class DistributionTableView extends CustomComponent implements View{
 
 	private List<String> columnList;
 	private ArrayList<String> headerList;
+    private CdmSQLContainer container;
 
 	/**
 	 * The constructor should first build the main layout, set the
@@ -84,6 +85,53 @@ public class DistributionTableView extends CustomComponent implements View{
 		table.setImmediate(false);
 		table.setWidth("100.0%");
 		table.setHeight("100.0%");
+
+        table.setColumnReorderingAllowed(true);
+        table.setSortEnabled(true);
+
+        table.setColumnCollapsingAllowed(true);
+        table.setSelectable(true);
+        table.setPageLength(20);
+        table.setFooterVisible(true);
+        table.setCacheRate(20);
+
+		table.addItemClickListener(new ItemClickListener() {
+            private static final long serialVersionUID = 2743935539139014771L;
+            @Override
+            public void itemClick(ItemClickEvent event) {
+                if(!(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.TAXON_COLUMN)) && !(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.RANK_COLUMN))){
+                    final Item item = event.getItem();
+                    Property<?> itemProperty = item.getItemProperty("uuid");
+                    UUID uuid = UUID.fromString(itemProperty.getValue().toString());
+                    final Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class);
+                    final String areaID = (String) event.getPropertyId();
+
+                    //popup window
+                    final Window popup = new Window("Choose distribution status");
+                    final ListSelect termSelect = new ListSelect();
+                    termSelect.setSizeFull();
+                    termSelect.setContainerDataSource(new PresenceAbsenceTermContainer());
+                    Button btnOk = new Button("OK", new ClickListener() {
+                        private static final long serialVersionUID = -3732219609337335697L;
+                        @Override
+                        public void buttonClick(ClickEvent event) {
+                            Object distributionStatus = termSelect.getValue();
+                            listener.updateDistributionField(areaID, distributionStatus, taxon);
+                            container.refresh();
+                            popup.close();
+                        }
+                    });
+                    VerticalLayout layout = new VerticalLayout(termSelect, btnOk);
+                    layout.setComponentAlignment(btnOk, Alignment.BOTTOM_RIGHT);
+                    popup.setContent(layout);
+                    popup.setModal(true);
+                    popup.center();
+                    UI.getCurrent().addWindow(popup);
+                }
+            }
+        });
+
+
 		mainLayout.addComponent(table, "top:75px;right:0.0px;");
 		return mainLayout;
 	}
@@ -94,7 +142,6 @@ public class DistributionTableView extends CustomComponent implements View{
 
 	@Override
 	public void enter(ViewChangeEvent event) {
-		final CdmSQLContainer container;
 		try {
 			container = listener.getSQLContainer();
 		} catch (SQLException e) {
@@ -107,8 +154,6 @@ public class DistributionTableView extends CustomComponent implements View{
 		}
 
 		table.setContainerDataSource(container);
-		table.setColumnReorderingAllowed(true);
-		table.setSortEnabled(true);
 
 		columnList = new ArrayList<String>(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,CdmQueryFactory.RANK_COLUMN}));
 		List<String> namedAreas = listener.getNamedAreasLabels();
@@ -120,48 +165,9 @@ public class DistributionTableView extends CustomComponent implements View{
 		String[] string = new String[headerList.size()];
 		table.setColumnHeaders(headerList.toArray(string));
 
-//		table.setColumnExpandRatio(propertyId, expandRatio);
-		table.setColumnCollapsingAllowed(true);
-		table.setSelectable(true);
-		table.setPageLength(20);
-		table.setFooterVisible(true);
 		table.setColumnFooter(CdmQueryFactory.TAXON_COLUMN, "Total amount of Taxa displayed: " + container.size());
-		table.setCacheRate(20);
-		
-		table.addItemClickListener(new ItemClickListener() {
-			private static final long serialVersionUID = 2743935539139014771L;
-			@Override
-			public void itemClick(ItemClickEvent event) {
-				if(!(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.TAXON_COLUMN)) && !(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.RANK_COLUMN))){
-					final Item item = event.getItem();
-					Property<?> itemProperty = item.getItemProperty("uuid");
-					UUID uuid = UUID.fromString(itemProperty.getValue().toString());
-					final Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class);
-					final String areaID = (String) event.getPropertyId();
-
-					//popup window
-					final Window popup = new Window("Choose distribution status");
-					final ListSelect termSelect = new ListSelect();
-					termSelect.setContainerDataSource(PresenceAbsenceTermContainer.getInstance());
-					Button btnOk = new Button("OK", new ClickListener() {
-						private static final long serialVersionUID = -3732219609337335697L;
-						@Override
-						public void buttonClick(ClickEvent event) {
-							Object distributionStatus = termSelect.getValue();
-							listener.updateDistributionField(areaID, distributionStatus, taxon);
-							container.refresh();
-							popup.close();
-						}
-					});
-					VerticalLayout layout = new VerticalLayout(termSelect, btnOk);
-					layout.setComponentAlignment(btnOk, Alignment.BOTTOM_RIGHT);
-					popup.setContent(layout);
-					popup.setModal(true);
-					popup.center();
-					UI.getCurrent().addWindow(popup);
-				}
-			}
-		});
+
+
 	}
 
 	private void createEditClickListener(){
@@ -202,7 +208,7 @@ public class DistributionTableView extends CustomComponent implements View{
 
 		Button settingsButton = toolbar.getSettingsButton();
 		settingsButton.addClickListener(new ClickListener() {
-			
+
 			private static final long serialVersionUID = -147703680580181544L;
 
 			@Override
@@ -230,7 +236,7 @@ public class DistributionTableView extends CustomComponent implements View{
 		});
 
 	}
-	
+
 	public void openSettings() {
 		SettingsConfigWindow cw = new SettingsConfigWindow(this);
 		Window window  = cw.createWindow();
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
index 32bb9447..75183839 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
@@ -133,6 +133,7 @@ public class SettingsConfigWindow extends CustomComponent implements ValueChange
 	public void buttonClick(ClickEvent event) {
 		Object source = event.getSource();
 		if(source==okButton){
+			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS, distStatusSelect.getValue());
 			distributionTableView.enter(null);
 			window.close();
 		}
