avoiding RegistrationWorkingsetPresenters to handle events from foreign view:
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 2 Apr 2019 12:16:51 +0000 (14:16 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 2 Apr 2019 12:16:51 +0000 (14:16 +0200)
    - pushing common EditorActionContext methods up
    - checking for own view in context root

src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPresenter.java

index dad06eba5bc9813d873e014122f25e8f781b9fc0..70e4fd1356f277c10ce3523a97b81e9c24a0f453 100644 (file)
@@ -415,6 +415,11 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
      */
     @EventBusListenerMethod
     public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) {
+
+        if(!isFromOwnView(event)){
+            return;
+        }
+
         if(event.getPopup() instanceof TaxonNamePopupEditor){
             Registration registration = null;
             if(newNameForRegistrationPopupEditor != null && event.getPopup().equals(newNameForRegistrationPopupEditor)){
@@ -604,6 +609,11 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
      */
     @EventBusListenerMethod
     public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) {
+
+        if(!isFromOwnView(event)){
+            return;
+        }
+
         if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
             if(event.getReason().equals(Reason.SAVE)){
                 // NOTE: adding the SpecimenTypeDesignations to the registration is done in the
@@ -679,6 +689,10 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
     @EventBusListenerMethod
     public void onEntityChangeEvent(EntityChangeEvent event){
 
+        if(!isFromOwnView(event)){
+            return;
+        }
+
         if(workingset == null){
             return;
         }
@@ -749,26 +763,13 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
         }
     }
 
-    public boolean isAtContextRoot(PopupView popupView) {
-        AbstractPopupEditor popupEditor = ((AbstractPopupEditor)popupView);
-        if(popupEditor.getEditorActionContext().size() > 1){
-            EditorActionContext topContext = (EditorActionContext) popupEditor.getEditorActionContext().get(popupEditor.getEditorActionContext().size() - 2);
-            return getView().equals(topContext.getParentView());
-        } else {
-            logger.error("Invalid EditorActionContext size. A popupeditor should at leaset have the workingset as root");
-            return false;
-        }
-    }
 
-    public EditorActionContext editorActionContextRoot(PopupView popupView) {
-        Stack<EditorActionContext>context = ((AbstractPopupEditor)popupView).getEditorActionContext();
-        return context.get(0);
-    }
 
     public Registration findRegistrationInContext(PopupView popupView) {
         Stack<EditorActionContext>context = ((AbstractPopupEditor)popupView).getEditorActionContext();
         return findRegistrationInContext(context);
     }
+
     /**
      * Finds the Registration in the EditorContext stack
      *
index 3c8172633b8cb16073de6c85aa24d2e6e9f1b8e2..920beea401de130c075435997fa31042e1fa6ea5 100644 (file)
@@ -1,6 +1,7 @@
 package eu.etaxonomy.vaadin.mvp;
 
 import java.io.Serializable;
+import java.util.Stack;
 
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.DisposableBean;
@@ -14,8 +15,10 @@ import com.vaadin.ui.Field;
 
 import eu.etaxonomy.cdm.api.application.CdmRepository;
 import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
+import eu.etaxonomy.cdm.vaadin.event.EditorActionContext;
 import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
 import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
+import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
 import eu.etaxonomy.vaadin.ui.view.PopupView;
 
 /**
@@ -217,6 +220,31 @@ public abstract class AbstractPresenter<V extends ApplicationView> implements Se
         return event.getSourceView() != null && event.getSourceView().equals(getView());
     }
 
+    public EditorActionContext editorActionContextRoot(PopupView popupView) {
+        Stack<EditorActionContext>context = ((AbstractPopupEditor)popupView).getEditorActionContext();
+        return context.get(0);
+    }
+
+    public boolean isAtContextRoot(PopupView popupView) {
+        AbstractPopupEditor popupEditor = ((AbstractPopupEditor)popupView);
+        if(popupEditor.getEditorActionContext().size() > 1){
+            EditorActionContext topContext = (EditorActionContext) popupEditor.getEditorActionContext().get(popupEditor.getEditorActionContext().size() - 2);
+            return getView().equals(topContext.getParentView());
+        } else {
+            logger.error("Invalid EditorActionContext size. A popupeditor should at leaset have the workingset as root");
+            return false;
+        }
+    }
+
+    /**
+     * @param event
+     */
+    public boolean isFromOwnView(DoneWithPopupEvent event) {
+        EditorActionContext contextRoot = editorActionContextRoot(event.getPopup());
+        return getView().equals(contextRoot.getParentView());
+    }
+
+
     @Override
     public void destroy() throws Exception {
         unsubscribeFromEventBuses();