-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
178 changed files
with
19,349 additions
and
904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
70 changes: 70 additions & 0 deletions
70
examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/config/ResourceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
Oops, something went wrong.