0

I am using an MVC model where I initialize all the action listeners for the view in the controller. For example:

The view:

    public void addStartDateListener(ChangeListener<Boolean>e){
        startDate.focusedProperty().addListener(e);
    }
    public void addFinishDateListener(ChangeListener<Boolean>e){
            finishDate.focusedProperty().addListener(e);
    }

The controller:

this.theView.addStartDateListener(new startDateFocusListener());
    this.theView.addFinishDateListener(new finishDateFocusListener());
    class finishDateFocusListener implements  ChangeListener<Boolean> {

    @Override
    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
    {
        if (newPropertyValue)
        {
            System.out.println("Finish date");
        }
        else
        {
            System.out.println("Finish date");
        }
    }

}
//focus listener to update the date whenever the focus is lost
class startDateFocusListener implements  ChangeListener<Boolean> {

    @Override
    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
    {
        if (newPropertyValue)
        {
            System.out.println("start date");
        }
        else
        {
            System.out.println("start date");
        }
    }

As the stage(which is the view) appears I need for the application to wait till it gets closed and not allow the user to perform any other action on other stages. If however I use "showAndWait()" with "initModality(Modality.APPLICATION_MODAL);" The action listeners do not get added to the view, but if I use only "initModality(Modality.APPLICATION_MODAL);" it does not allow the user to perform any actions on other stages except the one and all the action listener are fully functional, but I still need to wait till the stage gets closed and only then continue further as the rest is depending on the output of the stage that is being created. So my question is how can I do it?

I have so far tried to use Task with "setOnSucced" and etc. However no luck. I am fairly new to the MVC concept as well.

vsarunov
  • 1,433
  • 14
  • 26
  • Do you mean, you need to be notified when the stage closes? Otherwise, I'm not sure I understand what is the problem with only setting the stage's modality to APPICATION_MODAL. – Itai Dec 13 '15 at 19:20
  • @sillyfly after the stage has been created I need to pause further actions in the process where from it had been created. – vsarunov Dec 13 '15 at 19:23
  • That's a tempting option when you start programming, but it's not the way UI is programmed. If you halt the main thread (UI thread) the program will become unresponsive. The best way is probably to use `setOnCloseRequest` on the stage, like in this example - http://www.java2s.com/Code/Java/JavaFX/Stagecloseevent.htm – Itai Dec 13 '15 at 19:31
  • @sillyfly well it did not really answer my question, however you gave me a lesson into concurrency and gave me an idea how to solve it other way. I would consider the case close, should I post my around solution? – vsarunov Dec 13 '15 at 19:43
  • Post the around solution for future references. – Steven Dec 14 '15 at 01:24

0 Answers0