diff --git a/Development-notes.md b/Development-notes.md deleted file mode 100644 index b4737c4954..0000000000 --- a/Development-notes.md +++ /dev/null @@ -1,23 +0,0 @@ -## UI Architecure pattern: -We use the Presentation Model pattern which has some similarities with MVVM (Silverlight, WPF) as we use data -bindings, though there are differences in the way the view and the "code behind" is organized (different framework -support). -We don't use the term controller for the JavaFX controller it has too much association with the classical MVC -controller. - -View: FXML or code based View -CodeBehind (CB): JavaFX controller associated with FXML View -Presentation Model (PM) -Model: Domain data - -* State is stored in the presenter. -* Logic is stored in presenter. -* Presenter represents a abstract view of the UI. -* Presenter is not aware of the view. -* View is aware of the presenter. -* View is completely isolated from the model. - - -## References: -[Presentation Model](http://martinfowler.com/eaaDev/PresentationModel.html) -[Model View ViewModel - MVVM](http://msdn.microsoft.com/en-us/magazine/dd419663.aspx) diff --git a/UI-development-notes.md b/UI-development-notes.md new file mode 100644 index 0000000000..b04a5c9740 --- /dev/null +++ b/UI-development-notes.md @@ -0,0 +1,92 @@ +## UI Architecure pattern: +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). +We don't use the term controller for the JavaFX controller it has too much association with the classical MVC +controller. + +The described pattern is only applied yet to that package: +io.bitsquare.gui.trade.createoffer; +For prototyping the UI we stick first with a more rapid development style approach. + + +###Elements +* View +* CodeBehind (CB) +* Presentation Model (PM) +* Model + +#####Overview: +* 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. +* Presentation model does validation of user in put and formatting of domain data. +* Model is the domain specific representation of the view. It holds domain data and handles domain logic. + + +###View +Typically FXML is used. + +It knows the CodeBehind (fx:controller) + +#####Responsibility: +* Defines visible parts of the UI +* Define UI element properties +* Layout +* Style +* Event handler definition + + +###CodeBehind (CB) +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. + +It knows the presentation model but not the model. + +#####Responsibility: +* Creates presentation model and passes model from Guice injection to the presenter (might be changed). +* 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**! + + +###Presentation model (PM) +It is the abstraction/presentation of the view. +Can be used for unit testing. + +It knows the model but it does not know the CodeBehind (View) + +#####Responsibility: +* 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. + + +###Data model +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 + +#####Responsibility: +* 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) +[Model View ViewModel - MVVM](http://msdn.microsoft.com/en-us/magazine/dd419663.aspx) diff --git a/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferCB.java b/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferCB.java index 32ea66359d..f482203b71 100644 --- a/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferCB.java +++ b/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferCB.java @@ -42,31 +42,6 @@ import javafx.scene.layout.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Code behind (We don't call it controller as controller is associated with the classical MVC controller): - *

- * - Knows the presentation model, does not know the model - * - Has no logic and no state - *

- * - Creates presentation model and passes model from Guice injection to the presenter. Does not hold any reference to the model. - * //TODO is there a better way for DI of model? - * - Setup binding from presenter to view elements (also bidirectional - used for input data). Binding are only to plain - * presenter properties. There are no logical bindings or cross-view element bindings. - * - Listens to UI events (Actions) from view and calls method in presentation model. - * - Is entry node for view graph and responsible for navigation and creation of new views. - * - Passes application API method calls to Presenter. Calls application methods on sub views. - * - Handle lifecycle and self removal from scene graph. - * - Can contain non-declarative (dynamic) view definitions (if it gets larger, then use a dedicated ViewBuilder) - *

- * View: - * - Typically declared in FXML. Dynamic parts are declared in Controller. If more view elements need to be defined in - * code then use a ViewBuilder. - *

- * ViewBuilder (optional): - * - Additionally or instead of FXML view. If no FXML then controller setup need to be handles by ViewBuilder. - *

- * Note: Don't assign the root node as it is defined in the base class! - */ public class CreateOfferCB extends CachedViewController { private static final Logger log = LoggerFactory.getLogger(CreateOfferCB.class); @@ -88,6 +63,7 @@ public class CreateOfferCB extends CachedViewController { // Constructor /////////////////////////////////////////////////////////////////////////////////////////// + //TODO find a better solution, handle at base class? @Inject public CreateOfferCB(CreateOfferModel model) { pm = new CreateOfferPM(model); diff --git a/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferModel.java b/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferModel.java index 0ecac21c74..15cd8ffb34 100644 --- a/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferModel.java +++ b/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferModel.java @@ -52,12 +52,9 @@ import org.slf4j.LoggerFactory; import static com.google.common.base.Preconditions.checkArgument; /** - * Data model: - * Does not know the Presenter and View (CodeBehind) - * Use Guice for DI to get domain objects - *

- * - Holds domain data - * - Apply business logic (no view related, that is done in presenter) + * Domain for that UI element. + * Note that the create offer domain has a deeper scope in the application domain (TradeManager). + * That model is just responsible for the domain specific parts displayed needed in that UI element. */ class CreateOfferModel { private static final Logger log = LoggerFactory.getLogger(CreateOfferModel.class); diff --git a/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferPM.java b/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferPM.java index 34fb3024b3..8e679d04db 100644 --- a/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferPM.java +++ b/src/main/java/io/bitsquare/gui/trade/createoffer/CreateOfferPM.java @@ -42,17 +42,6 @@ import org.slf4j.LoggerFactory; import static io.bitsquare.gui.util.BSFormatter.*; import static javafx.beans.binding.Bindings.createStringBinding; -/** - * Presentation model: - * Knows Model, does not know the View (CodeBehind) - *

- * - Holds data and state of the View (formatting,...) - * - Receive user input via method calls from CodeBehind. - * - Validates input, applies business logic and converts input to Model. - * - Format model data to properties used for binding from the view (The view setup the bindings). - * - Listen to updates from Model via Bindings (The PM setup the bindings to the model). - * - Can be used for unit testing - */ class CreateOfferPM { private static final Logger log = LoggerFactory.getLogger(CreateOfferPM.class);