I'm currently writing the GUI for my application. As I understand in a MVC-like application are the following components for each feature:
- Business data: a complex object hierarchy containing all the data I need
- Processing code: code that works on the business data
- Controller: Somehow handles the conversion between view data and business data as well as all interactions of the user with the view
- View data: the business data, but broken down into pieces a GUI can display -
String(from text fields),
boolean(check box, toggle button),
Number(formatted text field, spinner),
Enum(radiobutton, combobox), ... .
- View: An fxml component and a class extending one of the
Additional information: The processing code also uses the business data to load/generate other data (not specified by the User/GUI) that must be saved somewhere as well. You may assume that processing code will only be run after the user has finished set up everything through the GUI.
Now I am trying to make sense of all these to put them in a working JavaFX GUI that roughly applies to the principles of the MVC family. I face the following problems:
- There are quite a lot of variations in the MVC family. Each one has another idea of how to put these elements together and how they should interact. Some say none shall know each other, other variants couple these together, others those. I don't know which one to stick to.
- No matter how I stick to it, I'll end up with a lot of classes for each feature (one class for each of the point above for each feature in the worst case), and a lot of code just handling the conversion between them: Why should I have a separate view data class (as some suggested) if all the data is already in the view?
- I'd like to go without the view class. Since the view is passive in some way, it should be able to got with fxml only for this.
- The last time I (using Swing) ended up put business data and processing code together, put the controller into the view and replaced the view data by JSON and custom serialization logic so that the conversion between both would be fully automatic. Sadly I can't apply this principle to JavaFX due to technical reasons. I also doubt this really is a good solution, even if it worked reasonably well.
What I'm asking from you:
- Where and how do I put my/which data?
- How to handle view classes? Can I go with fxml only? If yes, how do I use these components?
- What exactly should my controllers do?
- How to get my business data from the GUI? Can I go without a separate class for the view data?
If you need an example:
- My data consists of a
Path(through a text field and a browse button with file chooser dialog), an
Enumvalue (through a combobox) and and a custom object (through a custom dialog) - let's say it is a color or a date.
- My processing logic will read the file at that path, load its content and do something with it using the other data and store the result in another file.
- My view displays that data and has two buttons that open a dialog - the one for the path will store the result in a nearby text field. The one for the custom object will show the result in a label.
- And I don't really know how to build anything in between using JavaFX and fxml. I somehow need to get the data from the GUI and to make it accessible to the business logic. There are a lot of small features like this example, sometimes nested up to three levels. There might be the same one on multiple places, but most are unique.