commit b1fe8acf4d7826a091546a1d814ae5f44ec799de
Author: Fabian Reimeier <f.reimeier@bgbm.org>
Date:   Fri Oct 20 16:52:53 2017 +0200

    ref #6903

diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/component/DistributionToolbar.java b/src/main/java/eu/etaxonomy/cdm/vaadin/component/DistributionToolbar.java
new file mode 100644
index 00000000..b0c8b570
--- /dev/null
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/component/DistributionToolbar.java
@@ -0,0 +1,174 @@
+package eu.etaxonomy.cdm.vaadin.component;
+
+import java.io.Serializable;
+
+import javax.annotation.PostConstruct;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.context.event.EventListener;
+
+import com.vaadin.server.FontAwesome;
+import com.vaadin.server.ThemeResource;
+import com.vaadin.spring.annotation.SpringComponent;
+import com.vaadin.spring.annotation.UIScope;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+
+import eu.etaxonomy.cdm.api.application.CdmRepository;
+import eu.etaxonomy.cdm.service.CdmUserHelper;
+import eu.etaxonomy.cdm.vaadin.event.AuthenticationSuccessEvent;
+import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
+import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
+
+@SpringComponent("distributionToolbar")
+@UIScope
+public class DistributionToolbar extends HorizontalLayout implements Serializable{
+
+	/**
+	 * automatically generated ID
+	 */
+	private static final long serialVersionUID = 5344340511582993289L;
+
+    @Autowired
+    protected ApplicationEventPublisher eventBus;
+
+    @Autowired
+    @Qualifier("cdmRepository")
+    private CdmRepository repo;
+
+    @Autowired
+    private NavigationManager navigationManager;
+
+    @Autowired
+    private CdmUserHelper userHelper;
+
+    private final Button loginButton = new Button("Login");
+
+    private final Button logoutButton = new Button("Logout");
+
+    private final Button userButton = new Button(FontAwesome.USER);
+
+	private final Button editButton = new Button("Edit");
+
+	private final Button saveButton = new Button("Save");
+
+	private final Button detailButton = new Button("Detail");
+
+	private final Button distributionSettingsButton =  new Button("Areas and Taxa");
+
+	private final Button settingsButton =  new Button("Status");
+
+//	private final Authentication authentication;
+//	private ExcelExporter exporter = new ExcelExporter();
+
+	@PostConstruct
+    public void init() {
+		setMargin(true);
+		setSpacing(true);
+		setStyleName("toolbar");
+		setWidth("100%");
+		setHeight("75px");
+
+//		exporter.setCaption("Export");
+//		exporter.setIcon(new ThemeResource("icons/32/document-xsl.png"));
+		loginButton.addClickListener(e -> performLogin());
+		logoutButton.addClickListener(e -> performLogout());
+		saveButton.setIcon(new ThemeResource("icons/32/document-save.png"));
+		editButton.setIcon(new ThemeResource("icons/32/document-edit.png"));
+		detailButton.setIcon(new ThemeResource("icons/32/document-txt.png"));
+		settingsButton.setIcon(new ThemeResource("icons/32/settings_1.png"));
+		distributionSettingsButton.setIcon(new ThemeResource("icons/32/settings_1.png"));
+
+        HorizontalLayout leftLayout = new HorizontalLayout();
+        leftLayout.addComponent(detailButton);
+        leftLayout.addComponent(settingsButton);
+        leftLayout.addComponent(distributionSettingsButton);
+
+		HorizontalLayout rightLayout = new HorizontalLayout();
+		rightLayout.addComponent(loginButton);
+		rightLayout.addComponent(logoutButton);
+        rightLayout.addComponent(userButton);
+
+        addComponent(leftLayout);
+        setComponentAlignment(leftLayout, Alignment.MIDDLE_LEFT);
+		addComponent(rightLayout);
+		setComponentAlignment(rightLayout, Alignment.MIDDLE_RIGHT);
+		setExpandRatio(rightLayout, 1);
+		updateAuthenticationButtons();
+    }
+
+    @EventListener
+    public void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event){
+        boolean isInitialized = userButton != null;
+        // The RegistrationToolbar is being initialize even if not needed only because it is a EventListener
+        // which causes Spring to initialize it.
+        // TODO After switching to an other event bus this check can be removed
+        if(isInitialized){
+            updateAuthenticationButtons();
+        }
+    }
+
+    /**
+     * @param event
+     */
+    protected void updateAuthenticationButtons() {
+        if(userHelper.userIsAutheticated() && !userHelper.userIsAnnonymous()){
+            userButton.setCaption(userHelper.userName());
+            userButton.setVisible(true);
+            logoutButton.setVisible(true);
+            loginButton.setVisible(false);
+            saveButton.setVisible(true);
+            editButton.setVisible(true);
+            detailButton.setVisible(true);
+            settingsButton.setVisible(true);
+            distributionSettingsButton.setVisible(true);
+        } else {
+            userButton.setCaption(null);
+            userButton.setVisible(false);
+            logoutButton.setVisible(false);
+            loginButton.setVisible(true);
+            saveButton.setVisible(false);
+            editButton.setVisible(false);
+            detailButton.setVisible(false);
+            settingsButton.setVisible(false);
+            distributionSettingsButton.setVisible(false);
+        }
+    }
+
+    /**
+     * @return
+     */
+    private void performLogin() {
+        eventBus.publishEvent(new NavigationEvent("login", navigationManager.getCurrentViewName()));
+    }
+
+
+    private void performLogout() {
+        userHelper.logout();
+        updateAuthenticationButtons();
+        navigationManager.reloadCurrentView();
+    }
+
+    public Button getSettingsButton(){
+        return settingsButton;
+    }
+
+    public Button getDistributionSettingsButton() {
+		return distributionSettingsButton;
+	}
+
+	public Button getEditButton() {
+		return editButton;
+	}
+
+	public Button getSaveButton() {
+		return saveButton;
+	}
+
+	public Button getDetailButton() {
+		return detailButton;
+	}
+}
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/component/HorizontalToolbar.java b/src/main/java/eu/etaxonomy/cdm/vaadin/component/HorizontalToolbar.java
deleted file mode 100644
index 8955ba75..00000000
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/component/HorizontalToolbar.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package eu.etaxonomy.cdm.vaadin.component;
-
-import java.io.Serializable;
-
-import com.vaadin.server.ThemeResource;
-import com.vaadin.ui.Alignment;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.HorizontalLayout;
-
-import eu.etaxonomy.cdm.vaadin.security.UserHelper;
-
-public class HorizontalToolbar extends HorizontalLayout implements Serializable{
-
-
-	/**
-	 * automatically generated ID
-	 */
-	private static final long serialVersionUID = 5344340511582993289L;
-
-
-	private final Button editButton = new Button("Edit");
-
-	private final Button saveButton = new Button("Save");
-
-	private final Button detailButton = new Button("Detail");
-
-	private final Button distributionSettingsButton =  new Button("Distribution Settings");
-
-	private final Button settingsButton =  new Button("Settings");
-
-//	private final Authentication authentication;
-//	private ExcelExporter exporter = new ExcelExporter();
-
-	public HorizontalToolbar() {
-//		authentication = (Authentication) VaadinSession.getCurrent().getAttribute("authentication");
-//		CdmVaadinAuthentication authentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY);
-//		this.authentication = authentication.getAuthentication(Page.getCurrent().getLocation(), VaadinServlet.getCurrent().getServletContext().getContextPath());
-		init();
-	}
-
-    public void init() {
-		if(UserHelper.fromSession().userIsAutheticated()){
-			setMargin(true);
-			setSpacing(true);
-			setStyleName("toolbar");
-			setWidth("100%");
-			setHeight("75px");
-
-//			addComponent(editButton);
-//			addComponent(saveButton);
-			addComponent(detailButton);
-//			addComponent(exporter);
-
-//			exporter.setCaption("Export");
-//			exporter.setIcon(new ThemeResource("icons/32/document-xsl.png"));
-
-			saveButton.setIcon(new ThemeResource("icons/32/document-save.png"));
-			editButton.setIcon(new ThemeResource("icons/32/document-edit.png"));
-			detailButton.setIcon(new ThemeResource("icons/32/document-txt.png"));
-			settingsButton.setIcon(new ThemeResource("icons/32/settings_1.png"));
-			distributionSettingsButton.setIcon(new ThemeResource("icons/32/settings_1.png"));
-
-//          SecurityContext context = (SecurityContext)VaadinService.getCurrentRequest().getWrappedSession().getAttribute("context");
-//			SecurityContext context = SecurityContextHolder.getContext();
-
-			HorizontalLayout rightLayout = new HorizontalLayout();
-			rightLayout.addComponent(settingsButton);
-			rightLayout.addComponent(distributionSettingsButton);
-
-			addComponent(rightLayout);
-			setComponentAlignment(rightLayout, Alignment.MIDDLE_RIGHT);
-			setExpandRatio(rightLayout, 1);
-		}
-    }
-
-    public Button getSettingsButton(){
-        return settingsButton;
-    }
-
-    public Button getDistributionSettingsButton() {
-		return distributionSettingsButton;
-	}
-
-	public Button getEditButton() {
-		return editButton;
-	}
-
-	public Button getSaveButton() {
-		return saveButton;
-	}
-
-	public Button getDetailButton() {
-		return detailButton;
-	}
-}
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmSpringContextHelper.java b/src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmSpringContextHelper.java
index 97dd65b1..ac25b60a 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmSpringContextHelper.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmSpringContextHelper.java
@@ -96,6 +96,7 @@ public class CdmSpringContextHelper {
         return connPool;
     }
 
+
 //    public static JDBCConnectionPool createConnectionPool() {
 //        return new J2EEConnectionPool(getCurrent().getDataSource());
 //    }
@@ -159,5 +160,4 @@ public class CdmSpringContextHelper {
     }
 
 
-
 }
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 f31ee602..541f438b 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
@@ -19,7 +19,7 @@ public class DistributionEditorUtil {
 
 	public static final String SATTR_SELECTED_AREAS = "selectedAreas";
 
-    public static final String SATTR_SELECTED_VOCABULARY_UUID = "selectedVocabularyUuid";
+    public static final String SATTR_SELECTED_AREA_VOCABULARY_UUID = "selectedVocabularyUuid";
 
 	public static final String SATTR_TAXON_NODES_UUID = "taxonNodesUUID";
 
@@ -31,9 +31,9 @@ public class DistributionEditorUtil {
 
     public static final String SEPARATOR = ";;";
 
-    public static void updateDistributionView(DistributionTableView distributionTableView, List<UUID> taxonNodes, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas, UUID classificationUuid) {
+    public static void updateDistributionView(DistributionTableView distributionTableView, List<UUID> taxonNodes, TermVocabulary<NamedArea> areaVoc, Set<NamedArea> selectedAreas, UUID classificationUuid) {
 	    VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, taxonNodes);
-	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_VOCABULARY_UUID, term.getUuid());
+	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, areaVoc.getUuid());
 	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, selectedAreas);
 	    VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, classificationUuid);
 	    distributionTableView.update();
@@ -41,7 +41,7 @@ public class DistributionEditorUtil {
 
     public static void clearSessionAttributes(){
     	VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, null);
-    	VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_VOCABULARY_UUID, null);
+    	VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, null);
     	VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, null);
     	VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, null);
     }
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/AbstractSettingsDialogWindow.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/AbstractSettingsDialogWindow.java
index 5b3354cc..35aa0570 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/AbstractSettingsDialogWindow.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/AbstractSettingsDialogWindow.java
@@ -46,12 +46,12 @@ public abstract class AbstractSettingsDialogWindow extends CustomComponent {
 		return buttonToolBar;
 	}
 
-	public Window createWindow() {
+	public Window createWindow(String caption) {
 	    window = new Window();
 	    window.setModal(true);
 	    window.setWidth("60%");
 	    window.setHeight("80%");
-	    window.setCaption("Distribution Settings");
+	    window.setCaption(caption);
 	    window.setContent(mainLayout);
 	    return window;
 	}
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionSettingsConfigWindow.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionSettingsConfigWindow.java
index 7fe955b7..afc401f3 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionSettingsConfigWindow.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionSettingsConfigWindow.java
@@ -105,13 +105,14 @@ public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWind
         taxonFilter.addValueChangeListener(this);
         taxonTree.addExpandListener(this);
 
-        TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea();
+        //init areas
+        TermVocabulary<NamedArea> chosenAreaVoc = presenter.getChosenAreaVoc();
         distAreaBox.setContainerDataSource(presenter.getDistributionContainer());
-        distAreaBox.setValue(chosenArea);
+        distAreaBox.setValue(chosenAreaVoc);
         distAreaBox.addValueChangeListener(this);
 
-        if(chosenArea!=null){
-            NamedAreaContainer container = new NamedAreaContainer(chosenArea);
+        if(chosenAreaVoc!=null){
+            NamedAreaContainer container = new NamedAreaContainer(chosenAreaVoc);
             namedAreaList.setContainerDataSource(container);
         }
         Object selectedAreas = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS);
@@ -261,7 +262,7 @@ public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWind
         Object source = event.getSource();
         if(source==okButton){
             List<UUID> taxonNodes = new ArrayList<>();
-            TermVocabulary<NamedArea> term = null;
+            TermVocabulary<NamedArea> areaVoc = null;
             String uuidString = (String) classificationBox.getContainerProperty(classificationBox.getValue(),"uuid").getValue();
             UUID classificationUuid = UUID.fromString(uuidString);
             Set<UuidAndTitleCache<TaxonNode>> treeSelection = (Set<UuidAndTitleCache<TaxonNode>>) taxonTree.getValue();
@@ -270,9 +271,9 @@ public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWind
 					taxonNodes.add(uuidAndTitleCache.getUuid());
 				}
             }
-            term = (TermVocabulary<NamedArea>) distAreaBox.getValue();
+            areaVoc = (TermVocabulary<NamedArea>) distAreaBox.getValue();
             Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
-            DistributionEditorUtil.updateDistributionView(distributionTableView, taxonNodes, term, selectedAreas, classificationUuid);
+            DistributionEditorUtil.updateDistributionView(distributionTableView, taxonNodes, areaVoc, selectedAreas, classificationUuid);
             window.close();
         }
         else if(source==cancelButton){
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTablePresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTablePresenter.java
index 770e555a..352e871d 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTablePresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTablePresenter.java
@@ -19,16 +19,22 @@ import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.transaction.TransactionStatus;
+
 import com.vaadin.server.VaadinSession;
 import com.vaadin.spring.annotation.SpringComponent;
 import com.vaadin.spring.annotation.ViewScope;
 import com.vaadin.ui.Notification;
 
+import eu.etaxonomy.cdm.api.application.CdmRepository;
 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.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Distribution;
 import eu.etaxonomy.cdm.model.description.Feature;
@@ -38,6 +44,7 @@ import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.service.CdmUserHelper;
 import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
 import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
 import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
@@ -55,9 +62,17 @@ public class DistributionTablePresenter extends AbstractPresenter<DistributionTa
 
 	private static final long serialVersionUID = 3313043335587777217L;
 
+    @Autowired
+    private CdmUserHelper userHelper;
+
+    @Autowired
+    @Qualifier("cdmRepository")
+    private CdmRepository repo;
+
 	public int updateDistributionField(String distributionAreaString, Object comboValue, Taxon taxon) {
+	    TransactionStatus tx = repo.startTransaction();
+	    taxon = (Taxon)getRepo().getTaxonService().find(taxon.getUuid());
 	    Set<DefinedTermBase> chosenTerms = getChosenTerms();
-	    Set<NamedArea> termSet = getTermSet();
 	    NamedArea namedArea = null;
 	    for(DefinedTermBase term:chosenTerms){
 	    	Representation representation = term.getRepresentation(Language.DEFAULT());
@@ -82,6 +97,7 @@ public class DistributionTablePresenter extends AbstractPresenter<DistributionTa
 	    }
 	    if(namedArea==null){
 	    	Notification.show("Error during update of distribution term!");
+	    	repo.commitTransaction(tx);
 	    	return -1;
 	    }
 	    List<Distribution> distributions = getDistributions(taxon);
@@ -100,43 +116,44 @@ public class DistributionTablePresenter extends AbstractPresenter<DistributionTa
 			    for (TaxonDescription desc : descriptions) {
 			        // add to first taxon description
 			        desc.addElement(distribution);
-			        CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon);
+			        repo.commitTransaction(tx);
 			        return 0;
 			    }
 			} else {// there are no TaxonDescription yet.
 			    TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon);
 			    taxonDescription.addElement(distribution);
-			    taxon.addDescription(taxonDescription);
-			    CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon);
+			    repo.commitTransaction(tx);
 			    return 0;
 			}
 	    }
 	    else if(comboValue == null){//delete descriptionElementBase
-	    	distribution.getInDescription().removeElement(distribution);
-	    	CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon);
+	        DescriptionBase<?> desc = distribution.getInDescription();
+	        desc.removeElement(distribution);
+	    	repo.commitTransaction(tx);
             return 1;
 	    }
-	    else{
+	    else{//update distribution
            distribution.setStatus((PresenceAbsenceTerm)comboValue);
-           CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon);
+           repo.commitTransaction(tx);
            return 0;
         }
+	    repo.commitTransaction(tx);
 	    return -1;
 	}
 
 	public Set<DefinedTermBase> getChosenTerms() {
 		VaadinSession session = VaadinSession.getCurrent();
-		UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
+		UUID vocUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
 		getConversationHolder().getSession();
-		TermVocabulary<DefinedTermBase> term = CdmSpringContextHelper.getVocabularyService().load(termUUID, Arrays.asList("terms.representations"));
-		term = CdmBase.deproxy(term);
-		return term.getTerms();
+		TermVocabulary<DefinedTermBase> voc = CdmSpringContextHelper.getVocabularyService().load(vocUUID, Arrays.asList("terms.representations"));
+		voc = CdmBase.deproxy(voc);
+		return voc.getTerms();
 	}
 
 	public List<String> getAbbreviatedTermList() {
 		Set<NamedArea> terms = getTermSet();
-		List<String> list = new ArrayList<String>();
-		for(DefinedTermBase dtb: terms){
+		List<String> list = new ArrayList<>();
+		for(DefinedTermBase<?> dtb: terms){
 		    for(Representation r : dtb.getRepresentations()){
 		        list.add(r.getAbbreviatedLabel());
 		    }
@@ -154,8 +171,8 @@ public class DistributionTablePresenter extends AbstractPresenter<DistributionTa
 
 	private Set<NamedArea> getTermSet(){
 	    VaadinSession session = VaadinSession.getCurrent();
-	    UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
-	    TermVocabulary<NamedArea> vocabulary = CdmSpringContextHelper.getVocabularyService().load(termUUID, Arrays.asList("terms.representations"));
+	    UUID vocUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
+	    TermVocabulary<NamedArea> vocabulary = CdmSpringContextHelper.getVocabularyService().load(vocUUID, Arrays.asList("terms.representations"));
 	    vocabulary = CdmBase.deproxy(vocabulary, TermVocabulary.class);
 	    return vocabulary.getTermsOrderedByLabels(Language.DEFAULT());
 	}
@@ -185,7 +202,8 @@ public class DistributionTablePresenter extends AbstractPresenter<DistributionTa
 
 	public List<Distribution> getDistributions(Taxon taxon) {
 		Set<Feature> setFeature = new HashSet<>(Arrays.asList(Feature.DISTRIBUTION()));
-		List<Distribution> listTaxonDescription = CdmSpringContextHelper.getDescriptionService().listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
+		List<Distribution> listTaxonDescription = CdmSpringContextHelper.getDescriptionService()
+		        .listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
 		return listTaxonDescription;
 
 	}
@@ -254,7 +272,7 @@ public class DistributionTablePresenter extends AbstractPresenter<DistributionTa
             "name.$",
             "name.rank.representations",
             "name.status.type.representations",
-            "taxon2.name"
+            "taxon2.name",
     });
 
 	/**Helper Methods*/
@@ -274,4 +292,19 @@ public class DistributionTablePresenter extends AbstractPresenter<DistributionTa
 			}
 		});
 	}
+
+	/**
+	 *
+	 * {@inheritDoc}
+	 */
+	@Override
+	protected void onPresenterReady() {
+//        VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID, taxonNodes);
+//        VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID, voc.getUuid());
+//        VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS, selectedAreas);
+//        VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_CLASSIFICATION, classificationUuid);
+	    if(userHelper.userIsAutheticated() && !userHelper.userIsAnnonymous()) {
+            getView().openDistributionSettings();
+        }
+    }
 }
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableViewBean.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableViewBean.java
index 28d29655..e766a52c 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableViewBean.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableViewBean.java
@@ -15,6 +15,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.UUID;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.core.GrantedAuthority;
 
 import com.vaadin.data.Item;
@@ -39,7 +40,7 @@ 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.component.DistributionToolbar;
 import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
 import eu.etaxonomy.cdm.vaadin.container.PresenceAbsenceTermContainer;
 import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
@@ -60,7 +61,9 @@ public class DistributionTableViewBean extends AbstractPageView<DistributionTabl
 	private static final long serialVersionUID = 1L;
     public static final String NAME = "distTable";
 
-    private HorizontalToolbar toolbar;
+    @Autowired
+    private DistributionToolbar toolbar;
+
 	private Table table;
 	private Grid grid;
 
@@ -81,7 +84,6 @@ public class DistributionTableViewBean extends AbstractPageView<DistributionTabl
 		setHeight("100.0%");
 
 		//Horizontal Toolbar
-		toolbar = new HorizontalToolbar();
 		mainLayout.addComponent(toolbar, "top:0.0px;right:0.0px;");
 
 		// table + formatting
@@ -166,7 +168,7 @@ public class DistributionTableViewBean extends AbstractPageView<DistributionTabl
             }
         });
 
-		mainLayout.addComponent(table, "top:75px;right:0.0px;");
+		mainLayout.addComponent(table, "top:75px;right:10.0px;left:10.0px;");
 
 		return mainLayout;
 	}
@@ -215,9 +217,11 @@ public class DistributionTableViewBean extends AbstractPageView<DistributionTabl
 		Button detailButton = toolbar.getDetailButton();
 		detailButton.setCaption("Detail View");
 		detailButton.addClickListener(event -> {
-				Object selectedItemId = DistributionTableViewBean.this.grid.getSelectedRow();
+				Object selectedItemId = DistributionTableViewBean.this.table.getValue();
+//				Object selectedItemId = DistributionTableViewBean.this.grid.getSelectedRow();
 				if(selectedItemId!=null){
-					final UUID uuid = UUID.fromString(grid.getContainerDataSource().getItem(selectedItemId).getItemProperty("uuid").getValue().toString());
+				    final UUID uuid = UUID.fromString(table.getContainerDataSource().getItem(selectedItemId).getItemProperty("uuid").getValue().toString());
+//					final UUID uuid = UUID.fromString(grid.getContainerDataSource().getItem(selectedItemId).getItemProperty("uuid").getValue().toString());
 					Taxon taxon = HibernateProxyHelper.deproxy(CdmSpringContextHelper.getTaxonService().load(uuid), Taxon.class);
 					List<DescriptionElementBase> listDescriptions = getPresenter().listDescriptionElementsForTaxon(taxon, null);
 					DetailWindow detailWindow = new DetailWindow(taxon, listDescriptions);
@@ -244,7 +248,7 @@ public class DistributionTableViewBean extends AbstractPageView<DistributionTabl
 	@Override
 	public void openSettings() {
 		SettingsConfigWindow cw = new SettingsConfigWindow(this);
-		Window window  = cw.createWindow();
+		Window window  = cw.createWindow("Status");
 		UI.getCurrent().addWindow(window);
 	}
 
@@ -256,7 +260,7 @@ public class DistributionTableViewBean extends AbstractPageView<DistributionTabl
 		if(distributionSettingConfigWindow==null){
 			distributionSettingConfigWindow = new DistributionSettingsConfigWindow(this);
 		}
-        Window window  = distributionSettingConfigWindow.createWindow();
+        Window window  = distributionSettingConfigWindow.createWindow("Areas and Taxa");
         UI.getCurrent().addWindow(window);
 	}
 
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/NoCommitFieldGroup.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/NoCommitFieldGroup.java
new file mode 100644
index 00000000..a6fd14da
--- /dev/null
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/NoCommitFieldGroup.java
@@ -0,0 +1,26 @@
+/**
+* Copyright (C) 2017 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
+
+import com.vaadin.data.fieldgroup.FieldGroup;
+
+/**
+ * @author freimeier
+ * @since 18.10.2017
+ *
+ */
+public class NoCommitFieldGroup extends FieldGroup{
+	@Override
+	public boolean isReadOnly() {
+		return false;
+	}
+
+	@Override
+	public void commit() {}
+}
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/SettingsPresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/SettingsPresenter.java
index 91508846..cfddefea 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/SettingsPresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/SettingsPresenter.java
@@ -24,24 +24,29 @@ import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
 import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
+import eu.etaxonomy.cdm.vaadin.view.distributionStatus.DistributionSettingsConfigWindow;
+import eu.etaxonomy.cdm.vaadin.view.distributionStatus.SettingsConfigWindow;
 
 /**
+ * Note: This presenter is used for {@link SettingsConfigWindow} AND {@link DistributionSettingsConfigWindow}
+ *
  * @author alex
  * @date 22.04.2015
  *
+ *
  */
 public class SettingsPresenter {
 
     private Container distributionContainer;
     private Container distributionStatusContainer;
-    private UUID termUUID;
+    private UUID vocUUID;
 
 
 
     public SettingsPresenter(){
-		Object selectedVocabularyUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
+		Object selectedVocabularyUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
 		if(selectedVocabularyUuidString!=null){
-			termUUID = UUID.fromString(selectedVocabularyUuidString.toString());
+			vocUUID = UUID.fromString(selectedVocabularyUuidString.toString());
 		}
 		distributionContainer = new IndexedContainer(getNamedAreaList());
 		distributionStatusContainer = new IndexedContainer(getPresenceAbsenceVocabulary());
@@ -63,8 +68,8 @@ public class SettingsPresenter {
     	return null;
     }
 
-    public TermVocabulary getChosenArea(){
-        return CdmSpringContextHelper.getVocabularyService().load(termUUID);
+    public TermVocabulary getChosenAreaVoc(){
+        return CdmSpringContextHelper.getVocabularyService().load(vocUUID);
     }
 
     public Container getDistributionContainer() {
