Skip to content

Commit

Permalink
Merge pull request #307 from sialcasa/develop
Browse files Browse the repository at this point in the history
merge version 1.4.0 into stable
  • Loading branch information
manuel-mauky committed Oct 1, 2015
2 parents d402af5 + 8db526d commit f843f74
Show file tree
Hide file tree
Showing 254 changed files with 1,950 additions and 1,122 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ __MVVM__ is the enhanced version of the [Presentation Model](http://martinfowler
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx</artifactId>
<version>1.3.1</version>
<version>1.4.0</version>
</dependency>
```

Expand All @@ -24,7 +24,7 @@ __MVVM__ is the enhanced version of the [Presentation Model](http://martinfowler
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx</artifactId>
<version>1.4.0-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
</dependency>
```

Expand All @@ -36,9 +36,9 @@ If you need help you can use the forums on [Google Groups](https://groups.google
### Links

- [Project Page](http://sialcasa.github.io/mvvmFX/)
- [javadoc mvvmfx core](http://sialcasa.github.io/mvvmFX/javadoc/1.3.0/mvvmfx/)
- [javadoc mvvmfx-cdi](http://sialcasa.github.io/mvvmFX/javadoc/1.3.0/mvvmfx-cdi/)
- [javadoc mvvmfx-guice](http://sialcasa.github.io/mvvmFX/javadoc/1.3.0/mvvmfx-guice/)
- [javadoc mvvmfx-utils](http://sialcasa.github.io/mvvmFX/javadoc/1.3.0/mvvmfx-utils/)
- [javadoc mvvmfx-testing-utils](http://sialcasa.github.io/mvvmFX/javadoc/1.3.0/mvvmfx-testing-utils/)
- [javadoc mvvmfx core](http://sialcasa.github.io/mvvmFX/javadoc/1.4.0/mvvmfx/)
- [javadoc mvvmfx-cdi](http://sialcasa.github.io/mvvmFX/javadoc/1.4.0/mvvmfx-cdi/)
- [javadoc mvvmfx-guice](http://sialcasa.github.io/mvvmFX/javadoc/1.4.0/mvvmfx-guice/)
- [javadoc mvvmfx-utils](http://sialcasa.github.io/mvvmFX/javadoc/1.4.0/mvvmfx-utils/)
- [javadoc mvvmfx-testing-utils](http://sialcasa.github.io/mvvmFX/javadoc/1.4.0/mvvmfx-testing-utils/)

41 changes: 26 additions & 15 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
### Contains the examples for mvvmfx

Content:
At the moment we have 3 example applications:
- **books-example**: An app to search for books in a library.
- Shows how to integrate a REST backend (Optional)
- Uses EasyDI as dependency injection library
- **contacts-example**: A contact management application
- Master-Detail
- Dialogs
- CDI as dependency injection library, including CDI-Events
- Validation
- Model-Wrapper
- I18N and ResourceBundle handling
- [DataFX](http://www.javafxdata.org/)
- **todomvc-example**: A Todo-App influenced by the popular [TodoMVC.com](http://todomvc.com/).
- NotificationCenter
- MvvmFX views as items of a ListView
- [EasyBind](https://github.com/TomasMikula/EasyBind) for filtering Lists

- **mvvmfx-books-example**: An app to search for books in a library. Connects to a REST backend.
- **mvvmfx-complex-example**: contains the user interface and logic code for an example application.
To run this example you need either mvvmfx-cdi-starter or mvvmfx-guice-starter.
- **mvvmfx-cdi-starter**: contains the startup code to run the mvvmfx-complex-example with CDI/Weld
as dependency injection framework.
- **mvvmfx-guice-starter**: contains the startup code to run the mvvmfx-complex-example with Guice
as dependency injection framework.
- **mvvmfx-fx-root-example**: contains a small custom control that uses the fx:root element together with mvvmfx.
- **mvvmfx-helloworld-example**: A simple hello world view. This example is used in the [Getting Started/Step-by-Step tutorial](/../../wiki/Getting-Started-HelloWorld-%28deutsch%29).
- **mvvmfx-helloworld-without-fxml**: A hello world example that shows hot to use MvvmFX with a view implemented in pure Java and not with FXML.
- **mvvmfx-contacts**: A contact management application. This example shows a master-detail view, dialogs and the usage of CDI including CDI-Events.
This example also integrates some other JavaFX community libraries.
- **mvvmfx-synchronizefx**: This example uses the library [SynchronizeFX](https://github.com/saxsys/SynchronizeFX) to create a distributed ViewModel.
This way the state of the UI of different instances of the App (on different JVM's, on different computers) is always synchronized between the apps.

In addition to these apps we have some smaller examples. Each examples shows a specific aspect of the framework but isn't very useful by itself.

- **fx-root-example**: Shows how to use `fx:root` with mvvmFX. This way you can create your own custom components.
- **helloworld**: A minimal mvvmFX application using *FXML*.
- **helloworld-without-fxml**: A minimal mvvmFX application using pure Java code instead of *FXML*.
- **synchronizefx-example**: Shows how to integrade the library [SynchronizeFX](https://github.com/saxsys/SynchronizeFX) to implement a distributed ViewModel. This way the state of the UI of different instances of the App (on different JVM's, on different computers) is always synchronized between the apps.
- **welcome-example**: A simple app that shows a welcome message for people.
- It demonstrates the usage of [mvvmfx-cdi](https://github.com/sialcasa/mvvmFX/tree/develop/mvvmfx-cdi) and [mvvmfx-guice](https://github.com/sialcasa/mvvmFX/tree/develop/mvvmfx-guice). The complete code base is shared, only a specific starter class for each dependency injection framework is needed.
- Shows the usage of [Commands](https://github.com/sialcasa/mvvmFX/wiki/Commands).
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>mvvmfx-examples</artifactId>
<groupId>de.saxsys</groupId>
<version>1.3.1</version>
<groupId>de.saxsys.mvvmfx</groupId>
<artifactId>examples</artifactId>
<version>1.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>mvvmfx-library-example</artifactId>
<artifactId>books-example</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package de.saxsys.mvvmfx.examples.books;

import de.saxsys.mvvmfx.utils.viewlist.CachedViewModelCellFactory;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import de.saxsys.mvvmfx.FluentViewLoader;

import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;
import de.saxsys.mvvmfx.utils.viewlist.ViewListCellFactory;
import de.saxsys.mvvmfx.utils.viewlist.CachedViewModelCellFactory;

public class MainView implements FxmlView<MainViewModel> {

Expand Down Expand Up @@ -46,18 +45,13 @@ public void initialize() {

bookList.setItems(viewModel.booksProperty());


final ViewListCellFactory<BookListItemViewModel> cellFactory =
new CachedViewModelCellFactory<>(viewModel -> FluentViewLoader.fxmlView(BookListItemView.class)
.viewModel(viewModel).load());

bookList.setCellFactory(cellFactory);
bookList.setCellFactory(CachedViewModelCellFactory.createForFxmlView(BookListItemView.class));

viewModel.selectedBookProperty().bind(bookList.getSelectionModel().selectedItemProperty());
errorLabel.textProperty().bind(viewModel.errorProperty());

searchButton.disableProperty().bind(viewModel.getSearchCommand().executableProperty().not());

}

public void searchButtonPressed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public class MainViewModel implements ViewModel {
private ObjectProperty<BookListItemViewModel> selectedBook = new SimpleObjectProperty<>();

private StringProperty error = new SimpleStringProperty();

private Command searchCommand;

public MainViewModel(LibraryService libraryService) {
this.libraryService = libraryService;

searchCommand = new DelegateCommand(() -> new Action() {
@Override
protected void action() throws Exception {
Expand All @@ -53,7 +53,7 @@ protected void action() throws Exception {
public Command getSearchCommand() {
return searchCommand;
}

void search() {
Consumer<Error> errorHandler = err -> error.set(err.getMessage());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
.container {

}

.label
{
-fx-text-fill: black;
}

.title1{
-fx-font-size:50;
}

.title2{
-fx-font-size:40;
-fx-text-fill: gray;
}

.errorLabel{
-fx-font-size:20;
-fx-text-fill: red;
}

.split-pane *.split-pane-divider {
-fx-padding: 0 1 0 1;
}
.container {

}

.label
{
-fx-text-fill: black;
}

.title1{
-fx-font-size:50;
}

.title2{
-fx-font-size:40;
-fx-text-fill: gray;
}

.errorLabel{
-fx-font-size:20;
-fx-text-fill: red;
}

.split-pane *.split-pane-divider {
-fx-padding: 0 1 0 1;
}
100 changes: 100 additions & 0 deletions examples/contacts-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# MvvmFX Contacts Example

This is a more complex example application in which you can manage contacts.

It uses **mvvmFX** and **mvvmFX-CDI**. Additionally the following third-party libraries are used:

- [FontAwesomeFX](https://bitbucket.org/Jerady/fontawesomefx) for the icons
- [ControlsFX](http://fxexperience.com/controlsfx/) for the validation decorators
- [AssertJ-JavaFX](https://github.com/lestard/assertj-javafx) for easier testing of observable values in unit tests
- [DataFX](http://www.javafxdata.org/) for loading XML files
- [Advanced-Bindings](https://github.com/lestard/advanced-bindings) to simplify some bindings
- [JFX-Testrunner](https://github.com/sialcasa/jfx-testrunner) to run Tests in the JavaFX Application thread

### The Use-Case

The application has a **master-detail** view. In the master pane there is a table of all contacts.
When one contact is selected, the detail view will show the properties of the selected contact.

With a dialog you can add new contacts or edit existing ones.



### Highlights and interesting parts

#### Dialogs opened with CDI-Events

- The application uses CDI-Events to decouple the *add*/*edit* dialogs from the places where they are opened. Instead, when a
button is clicked to open a dialog, an CDI-Event is fired. The dialog reacts to this event and will open up itself.

[ToolbarViewModel.java:](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/toolbar/ToolbarViewModel.java)

```java
@Inject
private Event<OpenAddContactDialogEvent> openPopupEvent;

public void addNewContactAction(){
openPopupEvent.fire(new OpenAddContactDialogEvent());
}
```

[AddContactDialog.java:](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/addcontact/AddContactDialog.java)

```java
public class AddContactDialog implements FxmlView<AddContactDialogViewModel> {
...

public void open(@Observes OpenAddContactDialogEvent event) {
viewModel.openDialog();
}
}
```

#### ResourceBundles and I18N

There are resourceBundles available for german and english language. In [App.java](src/main/java/de/saxsys/mvvmfx/examples/contacts/App.java)
a global resourceBundle is defined for the whole application:

```java
...

@Inject
private ResourceBundle resourceBundle;


@Override
public void startMvvmfx(Stage stage) throws Exception {
LOG.info("Starting the Application");
MvvmFX.setGlobalResourceBundle(resourceBundle);

...
}
```

In addition for the menu a specific resourceBundle is defined in the [MainView.fxml](src/main/resources/de/saxsys/mvvmfx/examples/contacts/ui/main/MainView.fxml) via `fx:include`:

```xml
...
<fx:include source="../menu/MenuView.fxml" resources="menu"/>
...
```

This resourceBundle is merged internally with the global resourceBundle so that the menu can access both resources.


#### Validation

In the dialog for adding/editing contacts the mvvmFX validation feature is used.
In [ContactFormViewModel.java](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/contactform/ContactFormViewModel.java) you can see
how to define validation logic.
In the [ContactFormView.java](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/contactform/ContactFormView.java) the connection to the UI is done.
This way the aspects of validation logic and validation visualization are separated.


#### Model-Wrapper

In the [ContactFormViewModel.java](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/contactform/ContactFormViewModel.java)
the mvvmFX ModelWrapper is used to connect the Model and the ViewModel layers with reduced code size and coupling.



File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>mvvmfx-examples</artifactId>
<groupId>de.saxsys</groupId>
<version>1.3.1</version>
<groupId>de.saxsys.mvvmfx</groupId>
<artifactId>examples</artifactId>
<version>1.4.0</version>
</parent>
<artifactId>mvvmfx-contacts</artifactId>
<artifactId>contacts-example</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -23,7 +23,7 @@
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.2</version>
<configuration>
<mainClass>de.saxsys.mvvmfx.contacts.App</mainClass>
<mainClass>de.saxsys.mvvmfx.examples.contacts.App</mainClass>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -88,12 +88,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>jfx-testrunner</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.lestard</groupId>
<artifactId>assertj-javafx</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.saxsys.mvvmfx.contacts;
package de.saxsys.mvvmfx.examples.contacts;

import java.util.Locale;
import java.util.ResourceBundle;
Expand All @@ -17,18 +17,18 @@
import de.saxsys.mvvmfx.FluentViewLoader;
import de.saxsys.mvvmfx.ViewTuple;
import de.saxsys.mvvmfx.cdi.MvvmfxCdiApplication;
import de.saxsys.mvvmfx.contacts.events.TriggerShutdownEvent;
import de.saxsys.mvvmfx.contacts.model.ContactFactory;
import de.saxsys.mvvmfx.contacts.model.Repository;
import de.saxsys.mvvmfx.contacts.ui.main.MainView;
import de.saxsys.mvvmfx.contacts.ui.main.MainViewModel;
import de.saxsys.mvvmfx.examples.contacts.events.TriggerShutdownEvent;
import de.saxsys.mvvmfx.examples.contacts.model.ContactFactory;
import de.saxsys.mvvmfx.examples.contacts.model.Repository;
import de.saxsys.mvvmfx.examples.contacts.ui.main.MainView;
import de.saxsys.mvvmfx.examples.contacts.ui.main.MainViewModel;

public class App extends MvvmfxCdiApplication {

private static final Logger LOG = LoggerFactory.getLogger(App.class);

public static void main(String... args) {

Locale.setDefault(Locale.ENGLISH);

launch(args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package de.saxsys.mvvmfx.contacts.config;
package de.saxsys.mvvmfx.examples.contacts.config;

import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import java.util.Locale;
import java.util.ResourceBundle;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.saxsys.mvvmfx.contacts.events;
package de.saxsys.mvvmfx.examples.contacts.events;

/**
* CDI event class that is used to indicate that a contact was updated/added/removed.
Expand Down
Loading

0 comments on commit f843f74

Please sign in to comment.