Page 1 of 1

Return values from popup window

PostPosted: Tue May 21, 2019 2:22 pm
by lucdep
Hi,

When I open a popup workscreen I know I kan send parameters through a HashMap; but how can I return values from the popup to the calling workscreen, eg. on closing the popup?

Thanks

Luc

Re: Return values from popup window

PostPosted: Tue May 21, 2019 6:17 pm
by rjahn
There's no specific API for that. You have different options:

1) put/set the "start" work-screen as parameter
2) open the work-screen and call a method from the new work-screen to "add a listener"
3) iterate all open work-screens, on close, and call specific methods, e.g. implement a IParameterHandler interface in your "start" work-screen

Re: Return values from popup window

PostPosted: Tue May 21, 2019 6:41 pm
by Support@SIB
This is a simple solution:

In your opener screen, write:

Code: Select all
IWorkScreen wosc = getApplication().openWorkScreen("com.sibvisions.apps.demo.screens.SubWorkScreen", Modality.Modal);
wosc.setParameter("master", this);

eventParameterChanged("closereturn").addListener(new IParameterChangedListener()
{
   public void parameterChanged(WorkScreen pScreen, String pName, Object pOld, Object pNew) throws Throwable
        {
      setTitle("Closed: " + pNew);
   }
});

In your sub screen, write e.g.:

Code: Select all
@Override
public void onClose() throws Throwable
{
   super.onClose();
   
   ((IWorkScreen)getParameter("master")).setParameter("closereturn", "Yuhu");
}


It's also possible to detect the opener automatically:

Code: Select all
@Override
public void onShow() throws Throwable
{
   super.onShow();

   if (!Beans.isDesignTime())
   {
      IComponent[] comps = getApplication().getDesktopPane().getComponents();

      if (comps != null)
      {
         for (IComponent comp : comps)
         {
            if (comp instanceof IFrame)
            {
               if (((IFrame) comp).isActive())
               {
                  IContent cont = getApplication().getContent((IFrame) comp);
                  
                  if (cont != this && cont instanceof IWorkScreen)
                  {
                     // cache opener
                     return;
                  }
               }
            }
         }
      }
   }
}

Re: Return values from popup window

PostPosted: Mon Jun 17, 2019 8:49 am
by lucdep
Hi,

This solutions seems to work in the JavaFX environment, but in Vaadin/HTML, when the popup window is closed the opening screen seems to have lost it's DataBook context and is not showing any record anymore, all fields are gray and ID field is empty. I've tried to store selection before opening the popup and restoring on closing the popup, but this doesn't help.

What could be going wrong in VAADIN?

Luc

Re: Return values from popup window

PostPosted: Mon Jun 17, 2019 1:54 pm
by Support@SIB
The above solution works in our environment and our screens. Not sure what you code does, but to try to find the problem, we need an example.

Re: Return values from popup window

PostPosted: Tue Jun 18, 2019 9:47 am
by lucdep
Hi,

Here the code I have used:
The opener screen is the workscreen for the table Book, the edit button opens a popup Author workscreen on the table Author. When the combobox Auth_ID is null a new Author is created in the popup, after which the new Auth_ID must be returned to the master Book workscreen and inserted in the field Auth_ID. When Auth_ID is not null when clicking the edit button, the popup goes in edit mode for the selected Author.

In VAADIN the popup returns to a blank Book record, in JavaFX the original Book record remains.

This is de code for the edit button in the opener (master) Book workscreen:
Code: Select all
public void doButtoneditauthor(UIActionEvent pEvent) throws Throwable
   {
      rdbBook.saveAllRows();
      HashMap<String, Object> htParam = new HashMap<String, Object>();
      if (!Logical.equals(rdbBook.getValue("AUTH_ID"), (Object)null))
      {
         htParam.put("lookupid", rdbBook.getValue("AUTH_ID"));
      }
      else
      {
         htParam.put("lookupid", (Object)null);
      }
      IWorkScreen wosc = getApplication().openWorkScreen("be.moonfox.apps.bookshelf.screens.AuthorEditWorkScreen", htParam);
      wosc.setParameter("master", this);
      eventParameterChanged("closereturn").addListener(new IParameterChangedListener()
      {
         public void parameterChanged(WorkScreen pScreen, String pName, Object pOld, Object pNew) throws Throwable
         {
            rdbBook.setValue("AUTH_ID", pNew);
            rdbBook.saveAllRows();
         }
      });
   }


In the popup Author workscreen I have following code:

Code: Select all
public void onActivate() throws Throwable
   {
      Object pID = getParameter("lookupid");
      if (!Logical.equals(pID, (Object)null))
      {
         labelHeader.setText("Edit author");
         rdbAuthor.setFilter(new Equals("ID", pID));
      }
      else
      {
         deleteButton.setEnabled(false);
         labelHeader.setText("New author");
         rdbAuthor.insert(false);
      }
   }


        @Override
   public void onClose() throws Throwable
   {
      super.onClose();
      ((IWorkScreen)getParameter("master")).setParameter("closereturn", rdbAuthor.getValue("ID"));
   }

Re: Return values from popup window

PostPosted: Tue Jun 18, 2019 1:55 pm
by Support@SIB
We'll check this.