Skip to content

Commit

Permalink
Merge pull request #396 from sialcasa/develop
Browse files Browse the repository at this point in the history
merge develop version into stable to begin new dev cycle
  • Loading branch information
manuel-mauky committed Jun 3, 2016
2 parents f81d1c5 + 547fb17 commit 88c6ed0
Show file tree
Hide file tree
Showing 385 changed files with 15,601 additions and 9,640 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ __mvvm(fx)__ is an application framework which provides you necessary components

__MVVM__ is the enhanced version of the [Presentation Model](http://martinfowler.com/eaaDev/PresentationModel.html "Presentation Model") pattern and was created by Microsoft engineers for [WPF](http://msdn.microsoft.com/en-us/library/ms754130.aspx "WPF") . JavaFX and WPF does have similarities like Databinding and descriptive UI declaration (FXML/XAML). Because of this fact we adopt best practices of the development with the Microsoft technology.

[![Commercial Support](https://img.shields.io/badge/Commercial%20Support%20-by%20Saxonia%20Systems-brightgreen.svg)](http://goo.gl/forms/WVBG3SWHuL)
[![Build Status](https://api.travis-ci.org/sialcasa/mvvmFX.svg?branch=develop)](https://travis-ci.org/sialcasa/mvvmFX)


###[Howto](../../wiki "Howto")###

### Maven dependency###
Expand All @@ -18,7 +20,7 @@ This is the stable release that can be used in production.
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx</artifactId>
<version>1.4.1</version>
<version>1.5.0</version>
</dependency>
```

Expand All @@ -30,19 +32,19 @@ Here we make bug fixes for the current stable release.
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx</artifactId>
<version>1.4.2-SNAPSHOT</version>
<version>1.5.1-SNAPSHOT</version>
</dependency>
```

#### Development Snapshot

Here we develop new features. This release is unstable and shouldn't be used in production.

```
```xml
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx</artifactId>
<version>1.5.0-SNAPSHOT</version>
<version>1.6.0-SNAPSHOT</version>
</dependency>
```

Expand Down
14 changes: 13 additions & 1 deletion examples/books-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.saxsys.mvvmfx</groupId>
<artifactId>examples</artifactId>
<version>1.4.1</version>
<version>1.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -17,6 +17,18 @@
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<!-- use resource files (fxml, css) from the java directory -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>

<dependencies>
<dependency>
<groupId>de.saxsys</groupId>
Expand Down
69 changes: 52 additions & 17 deletions examples/contacts-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,69 @@ With a dialog you can add new contacts or edit existing ones.

### Highlights and interesting parts

#### Dialogs opened with CDI-Events
#### Usage of Scopes

- 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.
[mvvmFX Scopes](https://github.com/sialcasa/mvvmFX/wiki/Scopes) are used for two scenarios in this example:

[ToolbarViewModel.java:](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/toolbar/ToolbarViewModel.java)
* Communication between the Master and the Detail View
* Dialog to add or edit a contact

```java
@Inject
private Event<OpenAddContactDialogEvent> openPopupEvent;
##### Scope for Master Detail View

In this scenario the [MasterDetailScope](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/scopes/MasterDetailScope.java) is used to provide a property where the [MasterViewModel.java](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModel.java) signals which contact should be displayed in the [DetailViewModel.java](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/detail/DetailViewModel.java).

public void addNewContactAction(){
openPopupEvent.fire(new OpenAddContactDialogEvent());
```Java
public class MasterDetailScope implements Scope {
private final ObjectProperty<Contact> selectedContact = new SimpleObjectProperty<>(this, "selectedContact");
}
```

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

```java
public class AddContactDialog implements FxmlView<AddContactDialogViewModel> {
...
```Java
public class MasterViewModel implements ViewModel {
@InjectScope
MasterDetailScope mdScope;

public void initialize() {
mdScope.selectedContactProperty().bind(selectedContact);
}
}
```

public void open(@Observes OpenAddContactDialogEvent event) {
viewModel.openDialog();
}
```Java
public class DetailViewModel implements ViewModel {
@InjectScope
MasterDetailScope mdScope;

...//Create all bindings to the information of the mdScope.selectedContactProperty()
}

```


##### Scope for Dialog Wizard

In this case the scope is used to handle the state of a multi paged dialog.

To understand the machanism of the implemented dialogs, you should check the following classes:

* [EditContactDialogView](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/editcontact/EditContactDialog.java) and [AddContactDialog](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/addcontact/AddContactDialog.java)

* Both of them are using the [ContactDialogView](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/contactdialog/ContactDialogView.java) with different configurations.

* [AddressFormViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/addressform/AddressFormViewModel.java) and [ContactFormViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/contactform/ContactFormViewModel.java) are the dialog pages (1 and 2) that are displayed in the EditContactDialog and the AddContactDialog

* Also check the Views where the dialogs are created ([ToolbarView.java](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/toolbar/ToolbarView) and [DetailView](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/detail/DetailView.java)).

######Scope usages######
The used scope is called [ContactDialogScope](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/scopes/ContactDialogScope.java) and it has three use cases:

1. Configuration (eg. title) of the [ContactDialogViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/contactdialog/ContactDialogViewModel.java) from the [EditContactDialogViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/editcontact/EditContactDialogViewModel.java) and [AddContactDialogViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/addcontact/AddContactDialogViewModel.java).

2. [DetailViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/detail/DetailViewModel) sets the Contact object that will be edited into the scope. This information is used by the dialog pages: [AddressFormViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/addressform/AddressFormViewModel.java) and [ContactFormViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/contactform/ContactFormViewModel.java)

3. [ContactDialogViewModel](src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/contactdialog/ContactDialogViewModel.java) binds the *disableProperty()* of the navigation buttons to the validation state in the scope. This validation state is bound to the validation state of the dialog pages (AddressFormView and ContactFormView).


#### 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)
Expand Down
22 changes: 16 additions & 6 deletions examples/contacts-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>de.saxsys.mvvmfx</groupId>
<artifactId>examples</artifactId>
<version>1.4.1</version>
<version>1.5.0</version>
</parent>
<artifactId>contacts-example</artifactId>

Expand All @@ -27,8 +27,18 @@
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>


<dependencies>
<dependency>
<groupId>de.saxsys</groupId>
Expand Down Expand Up @@ -106,11 +116,11 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx-testing-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx-testing-utils</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,54 @@
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);
}



@Inject
private ResourceBundle resourceBundle;

@Inject
private Repository repository;

@Override
public void initMvvmfx() throws Exception {
int numberOfContacts = 30;
for (int i = 0; i < numberOfContacts; i++) {
repository.save(ContactFactory.createRandomContact());
}
}

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

stage.setTitle(resourceBundle.getString("window.title"));

ViewTuple<MainView, MainViewModel> main = FluentViewLoader.fxmlView(MainView.class).load();



Scene rootScene = new Scene(main.getView());

rootScene.getStylesheets().add("/contacts.css");

stage.setScene(rootScene);
stage.show();
}

/**
* The shutdown of the application can be triggered by firing the {@link TriggerShutdownEvent} CDI event.
* The shutdown of the application can be triggered by firing the
* {@link TriggerShutdownEvent} CDI event.
*/
public void triggerShutdown(@Observes TriggerShutdownEvent event) {
LOG.info("Application will now shut down");
Platform.exit();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import java.util.ResourceBundle;

/**
* A singleton CDI provider that is used to load the resource bundle and provide it for the CDI injection.
* A singleton CDI provider that is used to load the resource bundle and provide
* it for the CDI injection.
*/
@Singleton
public class ResourceProvider {

/*
* Due to the @Produces annotation this resource bundle can be injected in all views.
*/
@Produces
private ResourceBundle defaultResourceBundle = ResourceBundle.getBundle("default");

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package de.saxsys.mvvmfx.examples.contacts.events;

/**
* CDI event class that is used to indicate that a contact was updated/added/removed.
* CDI event class that is used to indicate that a contact was
* updated/added/removed.
*/
public class ContactsUpdatedEvent {

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* Event class to trigger the shutdown of the application.
*/
public class TriggerShutdownEvent {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* This package contains CDI event classes.
* This package contains CDI event classes.
*/
package de.saxsys.mvvmfx.examples.contacts.events;
package de.saxsys.mvvmfx.examples.contacts.events;
Loading

0 comments on commit 88c6ed0

Please sign in to comment.