0

The subwindow that I create does not close. I've seen some people experienced the same issue and posted the same issue but still I cannot find a solution. I have checked this, and this ,and this,and that and could not find a solution. Here' my code below for corresponding class for the window:

public class CommunicationConfigWindow extends Window
{
   private static CommunicationConfigWindow INSTANCE;    
   private final Accordion catAccordion = new Accordion();    
   private final VerticalLayout layout = new VerticalLayout();    
   private final HorizontalLayout toolbar = new HorizontalLayout();    
   private final Button applyButton = new Button( "Save&Close" );    
   private final Button cancelButton = new Button( "Cancel" );
    
   private CommunicationConfigWindow( )
   {
      this.toolbar.setDefaultComponentAlignment( Alignment.MIDDLE_CENTER );
      this.applyButton.setSizeFull();

      this.cancelButton.addClickListener( e -> {
         UI.getCurrent().removeWindow( this );
         this.close();
      } );
      this.applyButton.addStyleName( ValoTheme.BUTTON_FRIENDLY );
      this.cancelButton.addStyleName( ValoTheme.BUTTON_DANGER );

      this.cancelButton.setSizeFull();
      this.toolbar.addComponents( this.cancelButton, this.applyButton );
      this.toolbar.setSizeFull();
      this.catAccordion.addTab( new GeneralCatLayer( CatVersionEnum.CAT21 ), "CAT 21" );
      this.catAccordion.addTab( new GeneralCatLayer( CatVersionEnum.CAT23 ), "CAT 23" );
      this.catAccordion.addTab( new GeneralCatLayer( CatVersionEnum.CAT247 ), "CAT 247" );
      this.layout.addComponents( this.catAccordion, this.toolbar );
      this.setContent( this.layout );

   }


   public static CommunicationConfigWindow getINSTANCE()
   {
      if ( CommunicationConfigWindow.INSTANCE == null )
      {
         CommunicationConfigWindow.INSTANCE = new CommunicationConfigWindow();
      }
      return CommunicationConfigWindow.INSTANCE;
   }


}

This is before I click on cancel. This is after I click on cancel.

I do pop-up this window from a Display Settings Button. What happens is that:

  1. I click on a Display Settings Button and the window pops up.
  2. BEFORE I click on cancel, I click on Display Settings Button and it does not create a new window since its singleton.
  3. I click on cancel and click on Display Settings Button again, the old messed up one stays there and also creates a new window.

I basically want the window to be gone when I click on cancel or the close button but it simply does not.Why?

Thanks in advance.

Community
  • 1
  • 1
Bleach
  • 309
  • 3
  • 18

2 Answers2

2

May be problem with your singleton. Do you really need singleton window ?

If you want to add only one window on a button click. you can try with some validation like

 Window yourWindow = new Window();
        if (UI.getCurrent().getWindows().contains(yourWindow)) {
            getUI().addWindow(yourWindow);
        }

override equals in your window class

Abishek ram R
  • 196
  • 1
  • 8
  • Not really something about singleton. I got pissed off and even made it in the main class but result was the same. And thank you for this information also, I will use that too if I can actually manage to close the window. – Bleach Apr 18 '18 at 12:54
  • Use Objects for adding window instead of static or singleton objects – Abishek ram R Apr 18 '18 at 13:34
  • The singleton is a very bad idea. Even if the application will only have a single user, they may still close the browser with the window open, then start a new session while the singleton window is still open in the previous session. – Adrian Cox Apr 18 '18 at 15:42
  • @AdrianCox That's true. Thank you for the advise. – Bleach Apr 19 '18 at 09:13
0

I have not changed anything, after 2 hours spending on this, it started working eventhough I did not change a thing and I have no idea why.

Bleach
  • 309
  • 3
  • 18