Skip to content

Commit

Permalink
Merge branch 'develop' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-mauky committed Oct 28, 2014
2 parents 592fae9 + d45b72c commit c3e8f56
Show file tree
Hide file tree
Showing 178 changed files with 19,349 additions and 904 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ __MVVM__ is the enhanced version of the [Presentation Model](http://martinfowler
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmFX</artifactId>
<version>${mvvmfx-version}</version>
<version>0.4.0</version>
</dependency>
```

### Get Help

If you need help you can use the forums on [Google Groups](https://groups.google.com/forum/#!forum/mvvmfx-dev) for asking questions and interacting with the mvvmFX developers. Additionally you can create issues, report bugs and add feature requests on the issue tracker at [github](https://github.com/sialcasa/mvvmFX/issues).

### Links

[javadoc mvvmfx core](http://sialcasa.github.io/mvvmFX/javadoc/0.2.0/mvvmfx/)
[javadoc mvvmfx core](http://sialcasa.github.io/mvvmFX/javadoc/0.4.0/mvvmfx/)

[javadoc mvvmfx-cdi](http://sialcasa.github.io/mvvmFX/javadoc/0.2.0/mvvmfx-cdi/)
[javadoc mvvmfx-cdi](http://sialcasa.github.io/mvvmFX/javadoc/0.4.0/mvvmfx-cdi/)

[javadoc mvvmfx-guice](http://sialcasa.github.io/mvvmFX/javadoc/0.2.0/mvvmfx-guice/)
[javadoc mvvmfx-guice](http://sialcasa.github.io/mvvmFX/javadoc/0.4.0/mvvmfx-guice/)

[![Build Status](https://travis-ci.org/sialcasa/mvvmFX.svg?branch=develop)](https://travis-ci.org/sialcasa/mvvmFX)
2 changes: 1 addition & 1 deletion examples/mvvmfx-cdi-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>de.saxsys</groupId>
<artifactId>mvvmFX-examples</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void main(String... args) {
}

@Override
public void start(Stage stage) {
public void startMvvmfx(Stage stage) {
ViewTuple<MainContainerView, MainContainerViewModel> tuple =
FluentViewLoader.fxmlView(MainContainerView.class).load();

Expand Down
2 changes: 1 addition & 1 deletion examples/mvvmfx-complex-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>de.saxsys</groupId>
<artifactId>mvvmFX-examples</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package de.saxsys.jfx.exampleapplication.view.maincontainer;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import de.saxsys.jfx.exampleapplication.view.personlogin.PersonLoginView;
import de.saxsys.jfx.exampleapplication.view.personwelcome.PersonWelcomeView;
import de.saxsys.jfx.exampleapplication.viewmodel.maincontainer.MainContainerViewModel;
import de.saxsys.jfx.exampleapplication.viewmodel.personwelcome.PersonWelcomeViewModel;
import de.saxsys.mvvmfx.FluentViewLoader;
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;
import de.saxsys.mvvmfx.ViewTuple;
import de.saxsys.mvvmfx.utils.notifications.NotificationCenter;
import de.saxsys.mvvmfx.utils.notifications.NotificationObserver;
import de.saxsys.mvvmfx.utils.viewlist.ViewListCellFactory;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
Expand All @@ -14,19 +19,10 @@
import javafx.scene.layout.StackPane;

import javax.inject.Inject;

import de.saxsys.jfx.exampleapplication.view.personlogin.PersonLoginView;
import de.saxsys.jfx.exampleapplication.view.personwelcome.PersonWelcomeView;
import de.saxsys.jfx.exampleapplication.viewmodel.maincontainer.MainContainerViewModel;
import de.saxsys.jfx.exampleapplication.viewmodel.personwelcome.PersonWelcomeViewModel;
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;
import de.saxsys.mvvmfx.ViewModel;
import de.saxsys.mvvmfx.internal.viewloader.View;
import de.saxsys.mvvmfx.utils.viewlist.ViewListCellFactory;
import de.saxsys.mvvmfx.utils.notifications.NotificationCenter;
import de.saxsys.mvvmfx.utils.notifications.NotificationObserver;
import de.saxsys.mvvmfx.ViewTuple;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

/**
* Main View which creates the necessary subviews, and manages them. Does not need a concrete Viewmodel, so it is typed
Expand Down Expand Up @@ -83,26 +79,24 @@ public void changed(ObservableValue<? extends Number> arg0,
viewModel.displayedPersonsProperty().add(id);
}
});

// Configure List with views
personWelcomeListView.setCellFactory(new ViewListCellFactory<Integer>() {
@Override
public ViewTuple<? extends View, ? extends ViewModel> map(Integer element) {
if (!viewMap.containsKey(element)) {
ViewTuple<PersonWelcomeView, PersonWelcomeViewModel> loadedViewTuple
= FluentViewLoader.fxmlView(PersonWelcomeView.class).load();

PersonWelcomeView codeBehind = loadedViewTuple.getCodeBehind();

codeBehind.getViewModel()
.setPersonId(element);

viewMap.put(element, loadedViewTuple);
}

return viewMap.get(element);
}
});

// Configure List with views
final ViewListCellFactory<Integer> cellFactory = element -> {
if (!viewMap.containsKey(element)) {
ViewTuple<PersonWelcomeView, PersonWelcomeViewModel> loadedViewTuple
= FluentViewLoader.fxmlView(PersonWelcomeView.class).load();

PersonWelcomeView codeBehind = loadedViewTuple.getCodeBehind();

codeBehind.getViewModel()
.setPersonId(element);

viewMap.put(element, loadedViewTuple);
}

return viewMap.get(element);
};
personWelcomeListView.setCellFactory(cellFactory);

// Bind list
personWelcomeListView.itemsProperty().bind(
Expand Down
51 changes: 51 additions & 0 deletions examples/mvvmfx-contacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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/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/contacts/ui/addcontact/AddContactDialog.java)

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

public void open(@Observes OpenAddContactDialogEvent event) {
viewModel.openDialog();
}
}
```
Binary file added examples/mvvmfx-contacts/about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/mvvmfx-contacts/address_form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/mvvmfx-contacts/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/mvvmfx-contacts/contact_form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions examples/mvvmfx-contacts/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>mvvmFX-examples</artifactId>
<groupId>de.saxsys</groupId>
<version>0.4.0</version>
</parent>
<artifactId>mvvmfx-contacts</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.2</version>
<configuration>
<mainClass>de.saxsys.mvvmfx.contacts.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmFX</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmFX-cdi</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.0.6</version>
</dependency>

<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.0.9</version>
</dependency>

<dependency>
<groupId>org.javafxdata</groupId>
<artifactId>datafx-core</artifactId>
<version>8.0b5</version>
</dependency>

<dependency>
<groupId>org.javafxdata</groupId>
<artifactId>datafx-datareader</artifactId>
<version>8.0b5</version>
</dependency>

<dependency>
<groupId>eu.lestard</groupId>
<artifactId>advanced-bindings</artifactId>
<version>0.2.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<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>
<version>0.1.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package de.saxsys.mvvmfx.contacts;

import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.stage.Stage;

import javax.enterprise.event.Observes;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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;

public class App extends MvvmfxCdiApplication{

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

public static void main(String...args){
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");

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

ViewTuple<MainView, MainViewModel> main = FluentViewLoader.fxmlView(MainView.class).resourceBundle(resourceBundle).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.
*/
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
@@ -0,0 +1,20 @@
package de.saxsys.mvvmfx.contacts.config;

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

/**
* 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", Locale.ENGLISH);

}
Loading

0 comments on commit c3e8f56

Please sign in to comment.