2018-05-07 21:23:00 +02:00
|
|
|
## UI Architecture pattern:
|
2014-08-28 19:34:47 +02:00
|
|
|
We use a variant of the **Presentation Model** pattern which has some similarities with the **Model View ViewModel**
|
|
|
|
(MVVM used in Silverlight and WPF) as we use data bindings, though there are differences in the way the view and
|
|
|
|
the "code behind" is organized (due to different framework features/support).
|
2014-09-02 16:12:49 +02:00
|
|
|
|
|
|
|
We don't use the term "controller" for the JavaFX controller it has too much association with the classical MVC
|
|
|
|
controller but instead we use the term "code behind" as it describes better that this class is just a code extension of
|
|
|
|
the declarative view format.
|
|
|
|
That interpretation is also confirmed by the Java FX reference: "A controller is a compiled class that implements the
|
|
|
|
"code behind" the object hierarchy defined by the document."
|
|
|
|
|
2014-08-28 19:34:47 +02:00
|
|
|
|
|
|
|
The described pattern is only applied yet to that package:
|
2018-03-12 09:20:30 +01:00
|
|
|
bisq.desktop.main.offer.createoffer;
|
2014-08-28 19:34:47 +02:00
|
|
|
For prototyping the UI we stick first with a more rapid development style approach.
|
|
|
|
|
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
### Elements
|
2014-08-28 19:34:47 +02:00
|
|
|
* View
|
|
|
|
* CodeBehind (CB)
|
|
|
|
* Presentation Model (PM)
|
|
|
|
* Model
|
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
##### Overview:
|
2014-08-28 19:34:47 +02:00
|
|
|
* View/CB is responsible for the visual representation. No logic. No state.
|
|
|
|
* Presentation model holds the view/CB state.
|
|
|
|
* Presentation model handles view specific logic.
|
2018-05-07 21:23:00 +02:00
|
|
|
* Presentation model does validation of user input and formatting of domain data.
|
2014-08-28 19:34:47 +02:00
|
|
|
* Model is the domain specific representation of the view. It holds domain data and handles domain logic.
|
|
|
|
|
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
### View
|
2014-08-28 19:34:47 +02:00
|
|
|
Typically FXML is used.
|
|
|
|
|
|
|
|
It knows the CodeBehind (fx:controller)
|
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
##### Responsibility:
|
2014-08-28 19:34:47 +02:00
|
|
|
* Defines visible parts of the UI
|
|
|
|
* Define UI element properties
|
|
|
|
* Layout
|
|
|
|
* Style
|
|
|
|
* Event handler definition
|
|
|
|
|
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
### CodeBehind (CB)
|
2014-08-28 19:34:47 +02:00
|
|
|
It is conceptually part of the view layer. It adds functionality which cannot be expressed in the declarative FXML
|
|
|
|
format.
|
|
|
|
It is the JavaFX controller associated with the FXML view, but we don't use the term controller as it has too much
|
|
|
|
association with the classical MVC controller. It gets created by the JavaFX framework (FXMLLoader) and also the
|
|
|
|
setup with the FXML view is done by the framework.
|
|
|
|
|
2014-08-29 22:11:59 +02:00
|
|
|
It knows the presentation model (via Guice injection) but not the model.
|
2014-08-28 19:34:47 +02:00
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
##### Responsibility:
|
2014-08-28 19:34:47 +02:00
|
|
|
* Setup binding for updates from PM to view elements (also bidirectional for used for input data).
|
|
|
|
* Those binding are only simple bindings to plain presenter properties, no logical bindings.
|
|
|
|
* Listens to UI events (Actions) from UI controls and calls method in presentation model.
|
|
|
|
* Is entry node for view graph and responsible for navigation and for creation of new views.
|
|
|
|
* Passes application method calls to PM. Calls application methods on sub views.
|
|
|
|
* Handle lifecycle and self removal from scene graph.
|
|
|
|
* Can contain non-declarative (dynamic) view definitions (if that gets larger, then use a dedicated ViewBuilder)
|
|
|
|
* Has **no logic** and **no state**!
|
|
|
|
|
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
### Presentation model (PM)
|
2014-08-28 19:34:47 +02:00
|
|
|
It is the abstraction/presentation of the view.
|
|
|
|
Can be used for unit testing.
|
|
|
|
|
2014-08-29 22:11:59 +02:00
|
|
|
It knows the model (via Guice injection) but it does not know the CodeBehind (View)
|
2014-08-28 19:34:47 +02:00
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
##### Responsibility:
|
2014-08-28 19:34:47 +02:00
|
|
|
* Holds the state of the view/CB
|
|
|
|
* Formats domain data to the needed representation for the view/CB.
|
|
|
|
* Receive user input via method calls from CodeBehind.
|
|
|
|
* Validates UI input, applies business logic and converts (parse) input to model.
|
|
|
|
* Listen to updates from model via bindings.
|
|
|
|
|
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
### Data model
|
2014-08-28 19:34:47 +02:00
|
|
|
Represents the domain scope which is handled by the view.
|
|
|
|
Is interface to application domain objects.
|
|
|
|
We use Guice for dependency injection of the application domain objects.
|
|
|
|
Can be used for unit testing.
|
|
|
|
|
|
|
|
Does not know the PM and View/CB
|
|
|
|
|
2017-12-07 11:58:41 +01:00
|
|
|
##### Responsibility:
|
2014-08-28 19:34:47 +02:00
|
|
|
* Holds domain data for that view
|
|
|
|
* Apply domain business logic
|
|
|
|
* Interacts with application domain objects
|
|
|
|
* It only covers the domain represented by that view and not a lower level domain.
|
|
|
|
|
|
|
|
|
|
|
|
## References:
|
|
|
|
[Presentation Model](http://martinfowler.com/eaaDev/PresentationModel.html)
|
2014-09-02 16:12:49 +02:00
|
|
|
[Model View ViewModel - MVVM](http://msdn.microsoft.com/en-us/magazine/dd419663.aspx)
|
|
|
|
[Java FX FXML controllers]
|
2017-12-07 11:41:45 +01:00
|
|
|
(http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html#controllers)
|