jeudi 27 mai 2021

What are the best practices for handling menu clicks in a complex java fx application?

I am trying to create a javafx desktop application which has the following layout:


    +------------+-----------------------------+
    |            |                             |
    |            |                             |
    |            |                             |
    |            |                             |
    |            |                             |
    | MENU VIEW  |          DETAIL VIEW        |
    |            |                             |
    |            |                             |
    |            |                             |
    |            |                             |
    |            |                             |
    |            |                             |
    |            |                             |
    +------------+-----------------------------+

The menu will contain several menu options which, when clicked, change the detail pane view. The detail pane will contain complex information.

At the moment my code design looks like this:


    +----------------------------------------------------------------------+                
    |                     +---------------------------+                    |                
    |                     |         MAIN CLASS        |                    |                
    |                     |                           |                    |                
    |                     --------------|--------------                    |               -
    |                   -/              |              \-                  |                
    |      +-----------/--+      +-------\------+    +---\----------+      |                
    |      |        -/    |      |       |      |    |     \        |      |                
    |      |  MENU        |      | DETAIL PANE 1|    |DETAIL PANE 2 |      |                
    |      |  CONTROLLER  |      |  CONTROLLER  |    |  CONTROLLER  |      |                
    |      |              |      |              |    |              |      |                
    |      |              |      |              |    |              |      |                
    |      +--------------+      +--------------+    +--------------+      |                
    |                                                                      |                
    +----------------------------------------------------------------------+  

A main class which is called when the application is ran creates the menu controller which belongs to the menu view. The same controller also contains the detailview anchorpane.

The main class now adds listeners to the buttons by using a getter from the menu controller. When the listener is fired it will create the detail pane view and put on the anchorpane which it also got from the menu controller.

The reason I don't load the FXML for the detail view in the menu controller is because I want to use the data from the detail controllers in the main class for other operations.

QUESTION

Is this the way to do it? Are there any resources where I can read more about patterns/strategies to do this the "correct" way?

All the resources I can find online are more basic hello world like scenarios where everything is handled in the menu controller.

Aucun commentaire:

Enregistrer un commentaire